Update from https://crrev.com/320343
This required some manual patching to ui/event and ui/gfx.
Sky tests were suppressed.
https://github.com/domokit/mojo/issues/64
BUG=401761
R=jamesr@chromium.org
Review URL: https://codereview.chromium.org/1001833005
diff --git a/base/BUILD.gn b/base/BUILD.gn
index 402b19a..69f366e 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -9,6 +9,41 @@
import("//build/config/android/rules.gni")
}
+source_set("base_paths") {
+ sources = [
+ "base_paths.cc",
+ "base_paths.h",
+ "base_paths_android.cc",
+ "base_paths_android.h",
+ "base_paths_mac.h",
+ "base_paths_mac.mm",
+ "base_paths_posix.cc",
+ "base_paths_posix.h",
+ "base_paths_win.cc",
+ "base_paths_win.h",
+ ]
+
+ if (is_android || is_mac) {
+ sources -= [ "base_paths_posix.cc" ]
+ }
+
+ if (is_nacl) {
+ sources -= [
+ "base_paths.cc",
+ "base_paths_posix.cc",
+ ]
+ }
+
+ defines = [ "BASE_IMPLEMENTATION" ]
+
+ deps = [
+ "//base/memory",
+ "//base/process",
+ ]
+
+ visibility = [ ":base" ]
+}
+
component("base") {
sources = [
"allocator/allocator_extension.cc",
@@ -92,16 +127,6 @@
"base64.cc",
"base64.h",
"base_export.h",
- "base_paths.cc",
- "base_paths.h",
- "base_paths_android.cc",
- "base_paths_android.h",
- "base_paths_mac.h",
- "base_paths_mac.mm",
- "base_paths_posix.cc",
- "base_paths_posix.h",
- "base_paths_win.cc",
- "base_paths_win.h",
"base_switches.h",
"basictypes.h",
"big_endian.cc",
@@ -135,43 +160,6 @@
"cpu.h",
"critical_closure.h",
"critical_closure_internal_ios.mm",
- "debug/alias.cc",
- "debug/alias.h",
- "debug/asan_invalid_access.cc",
- "debug/asan_invalid_access.h",
- "debug/crash_logging.cc",
- "debug/crash_logging.h",
- "debug/debugger.cc",
- "debug/debugger.h",
- "debug/debugger_posix.cc",
- "debug/debugger_win.cc",
- "debug/dump_without_crashing.cc",
- "debug/dump_without_crashing.h",
- "debug/gdi_debug_util_win.cc",
- "debug/gdi_debug_util_win.h",
- "third_party/dmg_fp/dmg_fp.h",
- "third_party/dmg_fp/dtoa_wrapper.cc",
- "third_party/dmg_fp/g_fmt.cc",
- "third_party/icu/icu_utf.cc",
- "third_party/icu/icu_utf.h",
- "third_party/superfasthash/superfasthash.c",
-
- # This file depends on files from the "allocator" target,
- # but this target does not depend on "allocator" (see
- # allocator.gyp for details).
- "debug/leak_annotations.h",
- "debug/leak_tracker.h",
- "debug/proc_maps_linux.cc",
- "debug/proc_maps_linux.h",
- "debug/profiler.cc",
- "debug/profiler.h",
- "debug/stack_trace.cc",
- "debug/stack_trace.h",
- "debug/stack_trace_android.cc",
- "debug/stack_trace_posix.cc",
- "debug/stack_trace_win.cc",
- "debug/task_annotator.cc",
- "debug/task_annotator.h",
"deferred_sequenced_task_runner.cc",
"deferred_sequenced_task_runner.h",
"environment.cc",
@@ -243,20 +231,6 @@
"ios/scoped_critical_action.mm",
"ios/weak_nsobject.h",
"ios/weak_nsobject.mm",
- "json/json_file_value_serializer.cc",
- "json/json_file_value_serializer.h",
- "json/json_parser.cc",
- "json/json_parser.h",
- "json/json_reader.cc",
- "json/json_reader.h",
- "json/json_string_value_serializer.cc",
- "json/json_string_value_serializer.h",
- "json/json_value_converter.cc",
- "json/json_value_converter.h",
- "json/json_writer.cc",
- "json/json_writer.h",
- "json/string_escape.cc",
- "json/string_escape.h",
"lazy_instance.cc",
"lazy_instance.h",
"linux_util.cc",
@@ -316,46 +290,6 @@
"macros.h",
"md5.cc",
"md5.h",
- "memory/aligned_memory.cc",
- "memory/aligned_memory.h",
- "memory/discardable_memory.cc",
- "memory/discardable_memory.h",
- "memory/discardable_memory_android.cc",
- "memory/discardable_memory_emulated.cc",
- "memory/discardable_memory_emulated.h",
- "memory/discardable_memory_linux.cc",
- "memory/discardable_memory_mac.cc",
- "memory/discardable_memory_manager.cc",
- "memory/discardable_memory_manager.h",
- "memory/discardable_memory_shmem.cc",
- "memory/discardable_memory_shmem.h",
- "memory/discardable_memory_shmem_allocator.cc",
- "memory/discardable_memory_shmem_allocator.h",
- "memory/discardable_memory_win.cc",
- "memory/discardable_shared_memory.cc",
- "memory/discardable_shared_memory.h",
- "memory/linked_ptr.h",
- "memory/manual_constructor.h",
- "memory/memory_pressure_listener.cc",
- "memory/memory_pressure_listener.h",
- "memory/raw_scoped_refptr_mismatch_checker.h",
- "memory/ref_counted.cc",
- "memory/ref_counted.h",
- "memory/ref_counted_delete_on_message_loop.h",
- "memory/ref_counted_memory.cc",
- "memory/ref_counted_memory.h",
- "memory/scoped_policy.h",
- "memory/scoped_ptr.h",
- "memory/scoped_vector.h",
- "memory/shared_memory.h",
- "memory/shared_memory_android.cc",
- "memory/shared_memory_nacl.cc",
- "memory/shared_memory_posix.cc",
- "memory/shared_memory_win.cc",
- "memory/singleton.cc",
- "memory/singleton.h",
- "memory/weak_ptr.cc",
- "memory/weak_ptr.h",
"message_loop/incoming_task_queue.cc",
"message_loop/incoming_task_queue.h",
"message_loop/message_loop.cc",
@@ -380,33 +314,6 @@
"message_loop/message_pump_mac.mm",
"message_loop/message_pump_win.cc",
"message_loop/message_pump_win.h",
- "metrics/bucket_ranges.cc",
- "metrics/bucket_ranges.h",
- "metrics/field_trial.cc",
- "metrics/field_trial.h",
- "metrics/histogram.cc",
- "metrics/histogram.h",
- "metrics/histogram_base.cc",
- "metrics/histogram_base.h",
- "metrics/histogram_delta_serialization.",
- "metrics/histogram_delta_serialization.cc",
- "metrics/histogram_flattener.h",
- "metrics/histogram_macros.h",
- "metrics/histogram_samples.cc",
- "metrics/histogram_samples.h",
- "metrics/histogram_snapshot_manager.cc",
- "metrics/histogram_snapshot_manager.h",
- "metrics/sample_map.cc",
- "metrics/sample_map.h",
- "metrics/sample_vector.cc",
- "metrics/sample_vector.h",
- "metrics/sparse_histogram.cc",
- "metrics/sparse_histogram.h",
- "metrics/statistics_recorder.cc",
- "metrics/statistics_recorder.h",
- "metrics/user_metrics.cc",
- "metrics/user_metrics.h",
- "metrics/user_metrics_action.h",
"move.h",
"native_library.h",
"native_library_mac.mm",
@@ -453,54 +360,6 @@
"power_monitor/power_monitor_source.cc",
"power_monitor/power_monitor_source.h",
"power_monitor/power_observer.h",
- "process/internal_linux.cc",
- "process/internal_linux.h",
- "process/kill.cc",
- "process/kill.h",
- "process/kill_mac.cc",
- "process/kill_posix.cc",
- "process/kill_win.cc",
- "process/launch.cc",
- "process/launch.h",
- "process/launch_ios.cc",
- "process/launch_mac.cc",
- "process/launch_posix.cc",
- "process/launch_win.cc",
- "process/memory.cc",
- "process/memory.h",
- "process/memory_linux.cc",
- "process/memory_mac.mm",
- "process/memory_win.cc",
- "process/process.h",
- "process/process_handle_freebsd.cc",
- "process/process_handle_linux.cc",
- "process/process_handle_mac.cc",
- "process/process_handle_openbsd.cc",
- "process/process_handle_posix.cc",
- "process/process_handle_win.cc",
- "process/process_info.h",
- "process/process_info_linux.cc",
- "process/process_info_mac.cc",
- "process/process_info_win.cc",
- "process/process_iterator.cc",
- "process/process_iterator.h",
- "process/process_iterator_freebsd.cc",
- "process/process_iterator_linux.cc",
- "process/process_iterator_mac.cc",
- "process/process_iterator_openbsd.cc",
- "process/process_iterator_win.cc",
- "process/process_linux.cc",
- "process/process_metrics.cc",
- "process/process_metrics.h",
- "process/process_metrics_freebsd.cc",
- "process/process_metrics_ios.cc",
- "process/process_metrics_linux.cc",
- "process/process_metrics_mac.cc",
- "process/process_metrics_openbsd.cc",
- "process/process_metrics_posix.cc",
- "process/process_metrics_win.cc",
- "process/process_posix.cc",
- "process/process_win.cc",
"profiler/alternate_timer.cc",
"profiler/alternate_timer.h",
"profiler/scoped_profile.cc",
@@ -608,6 +467,12 @@
"task_runner.h",
"task_runner_util.h",
"template_util.h",
+ "third_party/dmg_fp/dmg_fp.h",
+ "third_party/dmg_fp/dtoa_wrapper.cc",
+ "third_party/dmg_fp/g_fmt.cc",
+ "third_party/icu/icu_utf.cc",
+ "third_party/icu/icu_utf.h",
+ "third_party/superfasthash/superfasthash.c",
"thread_task_runner_handle.cc",
"thread_task_runner_handle.h",
"threading/non_thread_safe.h",
@@ -673,34 +538,6 @@
"timer/mock_timer.h",
"timer/timer.cc",
"timer/timer.h",
- "trace_event/memory_dump_manager.cc",
- "trace_event/memory_dump_manager.h",
- "trace_event/memory_dump_provider.h",
- "trace_event/process_memory_dump.cc",
- "trace_event/process_memory_dump.h",
- "trace_event/process_memory_maps.cc",
- "trace_event/process_memory_maps.h",
- "trace_event/process_memory_maps_dump_provider.cc",
- "trace_event/process_memory_maps_dump_provider.h",
- "trace_event/process_memory_totals.cc",
- "trace_event/process_memory_totals.h",
- "trace_event/process_memory_totals_dump_provider.cc",
- "trace_event/process_memory_totals_dump_provider.h",
- "trace_event/trace_event.h",
- "trace_event/trace_event_android.cc",
- "trace_event/trace_event_argument.cc",
- "trace_event/trace_event_argument.h",
- "trace_event/trace_event_impl.cc",
- "trace_event/trace_event_impl.h",
- "trace_event/trace_event_impl_constants.cc",
- "trace_event/trace_event_memory.cc",
- "trace_event/trace_event_memory.h",
- "trace_event/trace_event_synthetic_delay.cc",
- "trace_event/trace_event_synthetic_delay.h",
- "trace_event/trace_event_system_stats_monitor.cc",
- "trace_event/trace_event_system_stats_monitor.h",
- "trace_event/trace_event_win.cc",
- "trace_event/trace_event_win.h",
"tracked_objects.cc",
"tracked_objects.h",
"tracking_info.cc",
@@ -765,6 +602,63 @@
"win/wrapped_window_proc.h",
]
+ sources -= [
+ "sys_info_freebsd.cc",
+ "sys_info_openbsd.cc",
+ ]
+
+ defines = [ "BASE_IMPLEMENTATION" ]
+
+ deps = [
+ ":base_static",
+ "//base/allocator:allocator_extension_thunks",
+ "//base/third_party/dynamic_annotations",
+ "//base/third_party/nspr",
+ "//third_party/modp_b64",
+ ]
+
+ public_deps = [
+ ":base_paths",
+ "//base/debug",
+ "//base/json",
+ "//base/memory",
+ "//base/metrics",
+ "//base/process",
+ "//base/trace_event",
+ ]
+
+ # Allow more direct string conversions on platforms with native utf8
+ # strings
+ if (is_mac || is_ios || is_chromeos) {
+ defines += [ "SYSTEM_NATIVE_UTF8" ]
+ }
+
+ if (is_android) {
+ sources -= [ "power_monitor/power_monitor_device_source_posix.cc" ]
+
+ # Android uses some Linux sources, put those back.
+ set_sources_assignment_filter([])
+ sources += [
+ "files/file_path_watcher_linux.cc",
+ "posix/unix_domain_socket_linux.cc",
+ "sys_info_linux.cc",
+ ]
+ set_sources_assignment_filter(sources_assignment_filter)
+
+ deps += [
+ ":base_jni_headers",
+ "//third_party/ashmem",
+ "//third_party/android_tools:cpu_features",
+ ]
+
+ # logging.cc uses the Android logging library.
+ libs = [ "log" ]
+ }
+
+ if (is_chromeos) {
+ sources -= [ "power_monitor/power_monitor_device_source_posix.cc" ]
+ }
+
if (is_nacl) {
# We reset sources_assignment_filter in order to explicitly include
# the linux file (which would otherwise be filtered out).
@@ -780,110 +674,27 @@
"allocator/type_profiler_control.cc",
"allocator/type_profiler_control.h",
"async_socket_io_handler_posix.cc",
- "base_paths.cc",
"cpu.cc",
+ "files/file_enumerator_posix.cc",
"files/file_proxy.cc",
"files/file_util.cc",
- "files/file_util_proxy.cc",
- "files/scoped_temp_dir.cc",
- "path_service.cc",
- "scoped_native_library.cc",
- ]
- }
-
- sources -= [
- "process/process_handle_freebsd.cc",
- "process/process_handle_openbsd.cc",
- "process/process_iterator_freebsd.cc",
- "process/process_iterator_openbsd.cc",
- "process/process_metrics_freebsd.cc",
- "process/process_metrics_openbsd.cc",
- "sys_info_freebsd.cc",
- "sys_info_openbsd.cc",
- ]
-
- defines = [ "BASE_IMPLEMENTATION" ]
-
- deps = [
- ":base_static",
- "//base/allocator:allocator_extension_thunks",
- "//base/third_party/dynamic_annotations",
- "//base/third_party/nspr",
- "//third_party/modp_b64",
- ]
-
- # Allow more direct string conversions on platforms with native utf8
- # strings
- if (is_mac || is_ios || is_chromeos) {
- defines += [ "SYSTEM_NATIVE_UTF8" ]
- }
-
- if (is_android) {
- sources += [
- "memory/discardable_memory_ashmem.cc",
- "memory/discardable_memory_ashmem.h",
- "memory/discardable_memory_ashmem_allocator.cc",
- "memory/discardable_memory_ashmem_allocator.h",
- ]
- sources -= [
- "base_paths_posix.cc",
- "power_monitor/power_monitor_device_source_posix.cc",
- ]
-
- # Android uses some Linux sources, put those back.
- set_sources_assignment_filter([])
- sources += [
- "debug/proc_maps_linux.cc",
- "files/file_path_watcher_linux.cc",
- "posix/unix_domain_socket_linux.cc",
- "process/internal_linux.cc",
- "process/memory_linux.cc",
- "process/process_handle_linux.cc",
- "process/process_iterator_linux.cc",
- "process/process_metrics_linux.cc",
- "sys_info_linux.cc",
- ]
- set_sources_assignment_filter(sources_assignment_filter)
-
- deps += [
- ":base_jni_headers",
- "//third_party/ashmem",
- "//third_party/android_tools:cpu_features",
- ]
-
- # logging.cc uses the Android logging library.
- libs = [ "log" ]
-
- sources -= [ "debug/stack_trace_posix.cc" ]
- }
-
- if (is_chromeos) {
- sources -= [ "power_monitor/power_monitor_device_source_posix.cc" ]
- }
-
- if (is_nacl) {
- # These things would otherwise be built on a Posix build but aren't
- # supported on NaCl.
- sources -= [
- "debug/stack_trace_posix.cc",
- "files/file_enumerator_posix.cc",
"files/file_util_posix.cc",
- "memory/shared_memory_posix.cc",
+ "files/file_util_proxy.cc",
+ "files/important_file_writer.cc",
+ "files/important_file_writer.h",
+ "files/scoped_temp_dir.cc",
"message_loop/message_pump_libevent.cc",
- "metrics/field_trial.cc",
"native_library_posix.cc",
- "process/kill_posix.cc",
- "process/launch_posix.cc",
- "process/process_metrics_posix.cc",
- "process/process_posix.cc",
+ "path_service.cc",
"rand_util_posix.cc",
+ "scoped_native_library.cc",
"sync_socket_posix.cc",
+ "sys_info.cc",
"sys_info_posix.cc",
]
} else {
# Remove NaCl stuff.
sources -= [
- "memory/shared_memory_nacl.cc",
"os_compat_nacl.cc",
"os_compat_nacl.h",
"rand_util_nacl.cc",
@@ -922,12 +733,7 @@
# Mac.
if (is_mac) {
- sources += [
- "memory/discardable_memory_mach.cc",
- "memory/discardable_memory_mach.h",
- ]
sources -= [
- "base_paths_posix.cc",
"native_library_posix.cc",
"strings/sys_string_conversions_posix.cc",
]
@@ -990,6 +796,8 @@
configs -= [ "//build/config/compiler:optimize" ]
configs += [ "//build/config/compiler:optimize_max" ]
}
+
+ allow_circular_includes_from = public_deps
}
# This is the subset of files from base that should not be used with a dynamic
@@ -1065,11 +873,66 @@
configs += [ "//build/config/compiler:no_size_t_to_int_warning" ]
}
+if (is_linux && !is_chromeos) {
+ # TODO(GYP): Figure out which of these work and are needed on other platforms.
+ test("base_perftests") {
+ sources = [
+ "message_loop/message_pump_perftest.cc",
+
+ # "test/run_all_unittests.cc",
+ "threading/thread_perftest.cc",
+ ]
+ deps = [
+ ":base",
+ "//base/test:test_support",
+ "//base/test:test_support_perf",
+ "//testing/perf",
+ "//testing/gtest",
+ ]
+
+ if (is_android) {
+ deps += [ "//testing/android:native_test_native_code" ]
+ }
+ }
+
+ test("base_i18n_perftests") {
+ sources = [
+ "i18n/streaming_utf8_validator_perftest.cc",
+ ]
+ deps = [
+ ":base",
+ ":i18n",
+ "//base/test:test_support",
+ "//base/test:test_support_perf",
+ "//testing/gtest",
+ ]
+ }
+
+ if (!is_ios) {
+ executable("build_utf8_validator_tables") {
+ sources = [
+ "i18n/build_utf8_validator_tables.cc",
+ ]
+ deps = [
+ ":base",
+ "//third_party/icu:icuuc",
+ ]
+ }
+
+ executable("check_example") {
+ sources = [
+ "check_example.cc",
+ ]
+ deps = [
+ ":base",
+ ]
+ }
+ }
+}
+
source_set("prefs") {
sources = [
"prefs/base_prefs_export.h",
- "prefs/base_prefs_switches.cc",
- "prefs/base_prefs_switches.h",
"prefs/default_pref_store.cc",
"prefs/default_pref_store.h",
"prefs/json_pref_store.cc",
@@ -1272,7 +1135,6 @@
"mac/scoped_sending_event_unittest.mm",
"md5_unittest.cc",
"memory/aligned_memory_unittest.cc",
- "memory/discardable_memory_manager_unittest.cc",
"memory/discardable_memory_unittest.cc",
"memory/discardable_shared_memory_unittest.cc",
"memory/linked_ptr_unittest.cc",
@@ -1421,6 +1283,8 @@
"win/wrapped_window_proc_unittest.cc",
]
+ defines = []
+
deps = [
":base",
":i18n",
@@ -1437,6 +1301,12 @@
"//third_party/icu",
]
+ # Allow more direct string conversions on platforms with native utf8
+ # strings
+ if (is_mac || is_ios || is_chromeos) {
+ defines += [ "SYSTEM_NATIVE_UTF8" ]
+ }
+
if (is_android) {
apk_deps = [
":base_java",
@@ -1471,7 +1341,7 @@
if (is_linux) {
sources -= [ "file_version_info_unittest.cc" ]
sources += [ "nix/xdg_util_unittest.cc" ]
- defines = [ "USE_SYMBOLIZE" ]
+ defines += [ "USE_SYMBOLIZE" ]
if (use_glib) {
configs += [ "//build/config/linux:glib" ]
}
@@ -1501,8 +1371,8 @@
# GYP: //base.gyp:base_jni_headers
generate_jni("base_jni_headers") {
sources = [
- "android/java/src/org/chromium/base/ApplicationStatus.java",
"android/java/src/org/chromium/base/AnimationFrameTimeHistogram.java",
+ "android/java/src/org/chromium/base/ApplicationStatus.java",
"android/java/src/org/chromium/base/BuildInfo.java",
"android/java/src/org/chromium/base/CommandLine.java",
"android/java/src/org/chromium/base/ContentUriUtils.java",
diff --git a/base/OWNERS b/base/OWNERS
index 03c20e7..5d3e38b 100644
--- a/base/OWNERS
+++ b/base/OWNERS
@@ -24,26 +24,6 @@
per-file *.isolate=csharp@chromium.org
per-file *.isolate=maruel@chromium.org
-per-file bind.h=ajwong@chromium.org
-per-file bind_helpers.cc=ajwong@chromium.org
-per-file bind_helpers.h=ajwong@chromium.org
-per-file bind_helpers_unittest.cc=ajwong@chromium.org
-per-file bind.h.pump=ajwong@chromium.org
-per-file bind_internal.h=ajwong@chromium.org
-per-file bind_internal.h.pump=ajwong@chromium.org
-per-file bind_internal_win.h=ajwong@chromium.org
-per-file bind_internal_win.h.pump=ajwong@chromium.org
-per-file bind_unittest.cc=ajwong@chromium.org
-per-file bind_unittest.nc=ajwong@chromium.org
-per-file callback_forward.h=ajwong@chromium.org
-per-file callback.h=ajwong@chromium.org
-per-file callback_helpers.h=ajwong@chromium.org
-per-file callback.h.pump=ajwong@chromium.org
-per-file callback_internal.cc=ajwong@chromium.org
-per-file callback_internal.h=ajwong@chromium.org
-per-file callback_unittest.cc=ajwong@chromium.org
-per-file callback_unittest.h=ajwong@chromium.org
-per-file callback_unittest.nc=ajwong@chromium.org
per-file security_unittest.cc=jln@chromium.org
# For Android-specific changes:
diff --git a/base/allocator/allocator_extension.h b/base/allocator/allocator_extension.h
index de3119f..e65822b 100644
--- a/base/allocator/allocator_extension.h
+++ b/base/allocator/allocator_extension.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H
-#define BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H
+#ifndef BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_
+#define BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_
#include <stddef.h> // for size_t
@@ -56,4 +56,4 @@
} // namespace allocator
} // namespace base
-#endif
+#endif // BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_
diff --git a/base/allocator/allocator_extension_thunks.h b/base/allocator/allocator_extension_thunks.h
index 1e97a84..4e5027b 100644
--- a/base/allocator/allocator_extension_thunks.h
+++ b/base/allocator/allocator_extension_thunks.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_ALLOCATOR_ALLOCATOR_THUNKS_EXTENSION_H
-#define BASE_ALLOCATOR_ALLOCATOR_THUNKS_EXTENSION_H
+#ifndef BASE_ALLOCATOR_ALLOCATOR_EXTENSION_THUNKS_H_
+#define BASE_ALLOCATOR_ALLOCATOR_EXTENSION_THUNKS_H_
#include <stddef.h> // for size_t
@@ -33,4 +33,4 @@
} // namespace allocator
} // namespace base
-#endif
+#endif // BASE_ALLOCATOR_ALLOCATOR_EXTENSION_THUNKS_H_
diff --git a/base/android/base_jni_onload.cc b/base/android/base_jni_onload.cc
index c3a65d4..7ab4982 100644
--- a/base/android/base_jni_onload.cc
+++ b/base/android/base_jni_onload.cc
@@ -19,6 +19,7 @@
}
bool Init() {
+ InitAtExitManager();
JNIEnv* env = base::android::AttachCurrentThread();
base::android::InitReplacementClassLoader(env,
base::android::GetClassLoader(env));
diff --git a/base/android/important_file_writer_android.h b/base/android/important_file_writer_android.h
index 20956ba..88e4441 100644
--- a/base/android/important_file_writer_android.h
+++ b/base/android/important_file_writer_android.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef NATIVE_FRAMEWORK_CHROME_IMPORTANT_FILE_WRITE_ANDROID_H_
-#define NATIVE_FRAMEWORK_CHROME_IMPORTANT_FILE_WRITE_ANDROID_H_
+#ifndef BASE_ANDROID_IMPORTANT_FILE_WRITER_ANDROID_H_
+#define BASE_ANDROID_IMPORTANT_FILE_WRITER_ANDROID_H_
#include <jni.h>
@@ -15,4 +15,4 @@
} // namespace android
} // namespace base
-#endif // NATIVE_FRAMEWORK_CHROME_IMPORTANT_FILE_WRITE_ANDROID_H_
+#endif // BASE_ANDROID_IMPORTANT_FILE_WRITER_ANDROID_H_
diff --git a/base/android/java/src/org/chromium/base/AnimationFrameTimeHistogram.java b/base/android/java/src/org/chromium/base/AnimationFrameTimeHistogram.java
index ad5cdd8..d4b0d98 100644
--- a/base/android/java/src/org/chromium/base/AnimationFrameTimeHistogram.java
+++ b/base/android/java/src/org/chromium/base/AnimationFrameTimeHistogram.java
@@ -9,6 +9,8 @@
import android.animation.AnimatorListenerAdapter;
import android.animation.TimeAnimator;
import android.animation.TimeAnimator.TimeListener;
+import android.annotation.TargetApi;
+import android.os.Build;
import android.util.Log;
/**
@@ -80,6 +82,9 @@
/**
* Record Android animation frame rate and return the result.
*/
+ // Note: TimeAnimator was added to the Android public API in level 16, but has actually been
+ // available since level 14. So, it's safe to use TimeAnimator here, even on ICS.
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private static class Recorder implements TimeListener {
// TODO(kkimlabs): If we can use in the future, migrate to Choreographer for minimal
// workload.
diff --git a/base/android/java/src/org/chromium/base/JavaHandlerThread.java b/base/android/java/src/org/chromium/base/JavaHandlerThread.java
index 9643a63..3153a9b 100644
--- a/base/android/java/src/org/chromium/base/JavaHandlerThread.java
+++ b/base/android/java/src/org/chromium/base/JavaHandlerThread.java
@@ -4,6 +4,8 @@
package org.chromium.base;
+import android.annotation.TargetApi;
+import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
@@ -35,15 +37,18 @@
});
}
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2)
@CalledByNative
private void stop(final long nativeThread, final long nativeEvent) {
+ final boolean quitSafely = Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2;
new Handler(mThread.getLooper()).post(new Runnable() {
@Override
public void run() {
nativeStopThread(nativeThread, nativeEvent);
+ if (!quitSafely) mThread.quit();
}
});
- mThread.quitSafely();
+ if (quitSafely) mThread.quitSafely();
}
private native void nativeInitializeThread(long nativeJavaHandlerThread, long nativeEvent);
diff --git a/base/android/java/src/org/chromium/base/SysUtils.java b/base/android/java/src/org/chromium/base/SysUtils.java
index 1455a61..9dad516 100644
--- a/base/android/java/src/org/chromium/base/SysUtils.java
+++ b/base/android/java/src/org/chromium/base/SysUtils.java
@@ -4,6 +4,7 @@
package org.chromium.base;
+import android.annotation.TargetApi;
import android.app.ActivityManager;
import android.content.Context;
import android.os.Build;
@@ -19,10 +20,6 @@
* Exposes system related information about the current device.
*/
public class SysUtils {
- // Any device that runs this or an older version of the system cannot be considered 'low-end'
- private static final int ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD =
- Build.VERSION_CODES.JELLY_BEAN_MR2;
-
// A device reporting strictly more total memory in megabytes cannot be considered 'low-end'.
private static final int ANDROID_LOW_MEMORY_DEVICE_THRESHOLD_MB = 512;
@@ -107,6 +104,7 @@
return sLowEndDevice.booleanValue();
}
+ @TargetApi(Build.VERSION_CODES.KITKAT)
private static boolean detectLowEndDevice() {
assert CommandLine.isInitialized();
if (CommandLine.getInstance().hasSwitch(BaseSwitches.ENABLE_LOW_END_DEVICE_MODE)) {
@@ -115,7 +113,8 @@
if (CommandLine.getInstance().hasSwitch(BaseSwitches.DISABLE_LOW_END_DEVICE_MODE)) {
return false;
}
- if (Build.VERSION.SDK_INT <= ANDROID_LOW_MEMORY_ANDROID_SDK_THRESHOLD) {
+ // Any pre-KitKat device cannot be considered 'low-end'.
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
return false;
}
diff --git a/base/android/java_handler_thread.h b/base/android/java_handler_thread.h
index 7cd274d..c9a2c02 100644
--- a/base/android/java_handler_thread.h
+++ b/base/android/java_handler_thread.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_THREADING_JAVA_THREAD_H_
-#define BASE_THREADING_JAVA_THREAD_H_
+#ifndef BASE_ANDROID_JAVA_HANDLER_THREAD_H_
+#define BASE_ANDROID_JAVA_HANDLER_THREAD_H_
#include <jni.h>
@@ -46,4 +46,4 @@
} // namespace android
} // namespace base
-#endif // BASE_THREADING_JAVA_THREAD_H_
+#endif // BASE_ANDROID_JAVA_HANDLER_THREAD_H_
diff --git a/base/android/jni_generator/jni_generator.gyp b/base/android/jni_generator/jni_generator.gyp
index 2ea36b0..4a17f3e 100644
--- a/base/android/jni_generator/jni_generator.gyp
+++ b/base/android/jni_generator/jni_generator.gyp
@@ -7,6 +7,9 @@
{
'target_name': 'jni_generator_py_tests',
'type': 'none',
+ 'variables': {
+ 'stamp': '<(INTERMEDIATE_DIR)/jni_generator_py_tests.stamp',
+ },
'actions': [
{
'action_name': 'run_jni_generator_py_tests',
@@ -17,10 +20,11 @@
'golden_sample_for_tests_jni.h',
],
'outputs': [
- '',
+ '<(stamp)',
],
'action': [
'python', 'jni_generator_tests.py',
+ '--stamp=<(stamp)',
],
},
],
diff --git a/base/android/jni_generator/jni_generator_tests.py b/base/android/jni_generator/jni_generator_tests.py
index e29bc0c..6014847 100755
--- a/base/android/jni_generator/jni_generator_tests.py
+++ b/base/android/jni_generator/jni_generator_tests.py
@@ -13,6 +13,7 @@
import difflib
import inspect
+import optparse
import os
import sys
import unittest
@@ -1148,5 +1149,27 @@
self.assertGoldenTextEquals(jni_from_java.GetContent())
+def TouchStamp(stamp_path):
+ dir_name = os.path.dirname(stamp_path)
+ if not os.path.isdir(dir_name):
+ os.makedirs()
+
+ with open(stamp_path, 'a'):
+ os.utime(stamp_path, None)
+
+
+def main(argv):
+ parser = optparse.OptionParser()
+ parser.add_option('--stamp', help='Path to touch on success.')
+ options, _ = parser.parse_args(argv[1:])
+
+ test_result = unittest.main(argv=argv[0:1], exit=False)
+
+ if test_result.result.wasSuccessful() and options.stamp:
+ TouchStamp(options.stamp)
+
+ return not test_result.result.wasSuccessful()
+
+
if __name__ == '__main__':
- unittest.main()
+ sys.exit(main(sys.argv))
diff --git a/base/android/jni_generator/sample_for_tests.h b/base/android/jni_generator/sample_for_tests.h
index 4d76408..c98cf97 100644
--- a/base/android/jni_generator/sample_for_tests.h
+++ b/base/android/jni_generator/sample_for_tests.h
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#ifndef BASE_ANDROID_JNI_GENERATOR_SAMPLE_FOR_TESTS_H_
+#define BASE_ANDROID_JNI_GENERATOR_SAMPLE_FOR_TESTS_H_
+
#include <jni.h>
#include <map>
#include <string>
@@ -48,3 +51,5 @@
} // namespace android
} // namespace base
+
+#endif // BASE_ANDROID_JNI_GENERATOR_SAMPLE_FOR_TESTS_H_
diff --git a/base/android/jni_string.cc b/base/android/jni_string.cc
index d25fed8..57c2805 100644
--- a/base/android/jni_string.cc
+++ b/base/android/jni_string.cc
@@ -18,7 +18,7 @@
return result;
}
-}
+} // namespace
namespace base {
namespace android {
diff --git a/base/android/library_loader/library_load_from_apk_status_codes.h b/base/android/library_loader/library_load_from_apk_status_codes.h
index f99eebc..9591d3f 100644
--- a/base/android/library_loader/library_load_from_apk_status_codes.h
+++ b/base/android/library_loader/library_load_from_apk_status_codes.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_ANDROID_LIBRARY_LOAD_FROM_APK_STATUS_CODES_H_
-#define BASE_ANDROID_LIBRARY_LOAD_FROM_APK_STATUS_CODES_H_
+#ifndef BASE_ANDROID_LIBRARY_LOADER_LIBRARY_LOAD_FROM_APK_STATUS_CODES_H_
+#define BASE_ANDROID_LIBRARY_LOADER_LIBRARY_LOAD_FROM_APK_STATUS_CODES_H_
namespace base {
namespace android {
@@ -43,4 +43,4 @@
} // namespace android
} // namespace base
-#endif // BASE_ANDROID_LIBRARY_LOAD_FROM_APK_STATUS_CODES_H_
+#endif // BASE_ANDROID_LIBRARY_LOADER_LIBRARY_LOAD_FROM_APK_STATUS_CODES_H_
diff --git a/base/android/library_loader/library_loader_hooks.cc b/base/android/library_loader/library_loader_hooks.cc
index 97aec8c..555420a 100644
--- a/base/android/library_loader/library_loader_hooks.cc
+++ b/base/android/library_loader/library_loader_hooks.cc
@@ -123,9 +123,6 @@
}
bool RegisterLibraryLoaderEntryHook(JNIEnv* env) {
- // We need the AtExitManager to be created at the very beginning.
- g_at_exit_manager = new base::AtExitManager();
-
return RegisterNativesImpl(env);
}
@@ -142,5 +139,9 @@
Java_LibraryLoader_getLibraryProcessType(env));
}
+void InitAtExitManager() {
+ g_at_exit_manager = new base::AtExitManager();
+}
+
} // namespace android
} // namespace base
diff --git a/base/android/library_loader/library_loader_hooks.h b/base/android/library_loader/library_loader_hooks.h
index 7e8d527..ca3c5a2 100644
--- a/base/android/library_loader/library_loader_hooks.h
+++ b/base/android/library_loader/library_loader_hooks.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_ANDROID_LIBRARY_LOADER_HOOKS_H_
-#define BASE_ANDROID_LIBRARY_LOADER_HOOKS_H_
+#ifndef BASE_ANDROID_LIBRARY_LOADER_LIBRARY_LOADER_HOOKS_H_
+#define BASE_ANDROID_LIBRARY_LOADER_LIBRARY_LOADER_HOOKS_H_
#include <jni.h>
@@ -64,7 +64,11 @@
// Return the process type the shared library is loaded in.
BASE_EXPORT LibraryProcessType GetLibraryProcessType(JNIEnv* env);
+// Initialize AtExitManager, this must be done at the begining of loading
+// shared library.
+void InitAtExitManager();
+
} // namespace android
} // namespace base
-#endif // BASE_ANDROID_LIBRARY_LOADER_HOOKS_H_
+#endif // BASE_ANDROID_LIBRARY_LOADER_LIBRARY_LOADER_HOOKS_H_
diff --git a/base/android/trace_event_binding.h b/base/android/trace_event_binding.h
index ed06266..1c1a60b 100644
--- a/base/android/trace_event_binding.h
+++ b/base/android/trace_event_binding.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_ANDROID_TRACE_EVENT_H_
-#define BASE_ANDROID_TRACE_EVENT_H_
+#ifndef BASE_ANDROID_TRACE_EVENT_BINDING_H_
+#define BASE_ANDROID_TRACE_EVENT_BINDING_H_
#include <jni.h>
@@ -15,4 +15,4 @@
} // namespace android
} // namespace base
-#endif // CONTENT_COMMON_ANDROID_TRACE_EVENT_H_
+#endif // BASE_ANDROID_TRACE_EVENT_BINDING_H_
diff --git a/base/atomicops_internals_arm64_gcc.h b/base/atomicops_internals_arm64_gcc.h
index bb6a346..ddcfec9 100644
--- a/base/atomicops_internals_arm64_gcc.h
+++ b/base/atomicops_internals_arm64_gcc.h
@@ -301,7 +301,7 @@
return *ptr;
}
-} // namespace base::subtle
+} // namespace subtle
} // namespace base
#endif // BASE_ATOMICOPS_INTERNALS_ARM64_GCC_H_
diff --git a/base/atomicops_internals_arm_gcc.h b/base/atomicops_internals_arm_gcc.h
index e654afa..44c91c8 100644
--- a/base/atomicops_internals_arm_gcc.h
+++ b/base/atomicops_internals_arm_gcc.h
@@ -288,7 +288,7 @@
return *ptr;
}
-} // namespace base::subtle
+} // namespace subtle
} // namespace base
#endif // BASE_ATOMICOPS_INTERNALS_ARM_GCC_H_
diff --git a/base/atomicops_internals_atomicword_compat.h b/base/atomicops_internals_atomicword_compat.h
index e02d11d..342a6e4 100644
--- a/base/atomicops_internals_atomicword_compat.h
+++ b/base/atomicops_internals_atomicword_compat.h
@@ -92,8 +92,8 @@
reinterpret_cast<volatile const Atomic32*>(ptr));
}
-} // namespace base::subtle
-} // namespace base
+} // namespace subtle
+} // namespace base
#endif // !defined(ARCH_CPU_64_BITS)
diff --git a/base/atomicops_internals_gcc.h b/base/atomicops_internals_gcc.h
index ed1b2d7..35c95fe 100644
--- a/base/atomicops_internals_gcc.h
+++ b/base/atomicops_internals_gcc.h
@@ -99,7 +99,7 @@
return *ptr;
}
-} // namespace base::subtle
+} // namespace subtle
} // namespace base
#endif // BASE_ATOMICOPS_INTERNALS_GCC_H_
diff --git a/base/atomicops_internals_mac.h b/base/atomicops_internals_mac.h
index ccbb896..98864a7 100644
--- a/base/atomicops_internals_mac.h
+++ b/base/atomicops_internals_mac.h
@@ -191,7 +191,7 @@
#endif // defined(__LP64__)
-} // namespace base::subtle
-} // namespace base
+} // namespace subtle
+} // namespace base
#endif // BASE_ATOMICOPS_INTERNALS_MAC_H_
diff --git a/base/atomicops_internals_mips_gcc.h b/base/atomicops_internals_mips_gcc.h
index e206e03..b4551b8 100644
--- a/base/atomicops_internals_mips_gcc.h
+++ b/base/atomicops_internals_mips_gcc.h
@@ -274,7 +274,7 @@
}
#endif
-} // namespace base::subtle
-} // namespace base
+} // namespace subtle
+} // namespace base
#endif // BASE_ATOMICOPS_INTERNALS_MIPS_GCC_H_
diff --git a/base/atomicops_internals_portable.h b/base/atomicops_internals_portable.h
index b25099f..d285610 100644
--- a/base/atomicops_internals_portable.h
+++ b/base/atomicops_internals_portable.h
@@ -221,7 +221,7 @@
}
#endif // defined(ARCH_CPU_64_BITS)
-}
-} // namespace base::subtle
+} // namespace subtle
+} // namespace base
#endif // BASE_ATOMICOPS_INTERNALS_PORTABLE_H_
diff --git a/base/atomicops_internals_x86_gcc.h b/base/atomicops_internals_x86_gcc.h
index 69eacdb..f0d2242 100644
--- a/base/atomicops_internals_x86_gcc.h
+++ b/base/atomicops_internals_x86_gcc.h
@@ -220,8 +220,8 @@
#endif // defined(__x86_64__)
-} // namespace base::subtle
-} // namespace base
+} // namespace subtle
+} // namespace base
#undef ATOMICOPS_COMPILER_BARRIER
diff --git a/base/atomicops_internals_x86_msvc.h b/base/atomicops_internals_x86_msvc.h
index 26f1813..71ddca2 100644
--- a/base/atomicops_internals_x86_msvc.h
+++ b/base/atomicops_internals_x86_msvc.h
@@ -189,7 +189,7 @@
#endif // defined(_WIN64)
-} // namespace base::subtle
+} // namespace subtle
} // namespace base
#endif // BASE_ATOMICOPS_INTERNALS_X86_MSVC_H_
diff --git a/base/auto_reset.h b/base/auto_reset.h
index 32f138e..a5bcfaa 100644
--- a/base/auto_reset.h
+++ b/base/auto_reset.h
@@ -36,6 +36,6 @@
DISALLOW_COPY_AND_ASSIGN(AutoReset);
};
-}
+} // namespace base
#endif // BASE_AUTO_RESET_H_
diff --git a/base/barrier_closure.cc b/base/barrier_closure.cc
index 5abe2bf..1b77429 100644
--- a/base/barrier_closure.cc
+++ b/base/barrier_closure.cc
@@ -39,7 +39,7 @@
base::Closure BarrierClosure(int num_callbacks_left,
const base::Closure& done_closure) {
- DCHECK(num_callbacks_left >= 0);
+ DCHECK_GE(num_callbacks_left, 0);
if (num_callbacks_left == 0)
done_closure.Run();
diff --git a/base/base.gyp b/base/base.gyp
index 3888ad9..5f640d8 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -338,8 +338,6 @@
],
'sources': [
'prefs/base_prefs_export.h',
- 'prefs/base_prefs_switches.cc',
- 'prefs/base_prefs_switches.h',
'prefs/default_pref_store.cc',
'prefs/default_pref_store.h',
'prefs/json_pref_store.cc',
@@ -543,7 +541,6 @@
'mac/scoped_sending_event_unittest.mm',
'md5_unittest.cc',
'memory/aligned_memory_unittest.cc',
- 'memory/discardable_memory_manager_unittest.cc',
'memory/discardable_memory_unittest.cc',
'memory/discardable_shared_memory_unittest.cc',
'memory/linked_ptr_unittest.cc',
@@ -835,19 +832,20 @@
['include', '^sys_string_conversions_mac_unittest\\.mm$'],
],
}],
- ['OS == "android" and _toolset == "target"', {
- 'sources': [
- 'memory/discardable_memory_ashmem_allocator_unittest.cc',
- ],
- }],
['OS == "android"', {
'sources/': [
['include', '^debug/proc_maps_linux_unittest\\.cc$'],
],
}],
+ # Enable more direct string conversions on platforms with native utf8
+ # strings
+ ['OS=="mac" or OS=="ios" or <(chromeos)==1 or <(chromecast)==1', {
+ 'defines': ['SYSTEM_NATIVE_UTF8'],
+ }],
], # target_conditions
},
{
+ # GN: //base:base_perftests
'target_name': 'base_perftests',
'type': '<(gtest_target_type)',
'dependencies': [
@@ -870,6 +868,7 @@
],
},
{
+ # GN: //base:base_i18n_perftests
'target_name': 'base_i18n_perftests',
'type': '<(gtest_target_type)',
'dependencies': [
@@ -1077,6 +1076,7 @@
['OS!="ios"', {
'targets': [
{
+ # GN: //base:check_example
'target_name': 'check_example',
'type': 'executable',
'sources': [
diff --git a/base/base.gypi b/base/base.gypi
index 0f8fff2..ebc7e3e 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -319,12 +319,8 @@
'memory/discardable_memory.cc',
'memory/discardable_memory.h',
'memory/discardable_memory_android.cc',
- 'memory/discardable_memory_emulated.cc',
- 'memory/discardable_memory_emulated.h',
'memory/discardable_memory_linux.cc',
'memory/discardable_memory_mac.cc',
- 'memory/discardable_memory_manager.cc',
- 'memory/discardable_memory_manager.h',
'memory/discardable_memory_shmem.cc',
'memory/discardable_memory_shmem.h',
'memory/discardable_memory_shmem_allocator.cc',
@@ -829,14 +825,6 @@
['include', '^threading/platform_thread_linux\\.cc$'],
],
}],
- ['OS == "android" and _toolset == "target" and >(nacl_untrusted_build)==0', {
- 'sources': [
- 'memory/discardable_memory_ashmem.cc',
- 'memory/discardable_memory_ashmem.h',
- 'memory/discardable_memory_ashmem_allocator.cc',
- 'memory/discardable_memory_ashmem_allocator.h',
- ],
- }],
['OS == "android" and >(nacl_untrusted_build)==0', {
'sources!': [
'base_paths_posix.cc',
@@ -979,10 +967,6 @@
],
}],
['(OS == "mac" or OS == "ios") and >(nacl_untrusted_build)==0', {
- 'sources': [
- 'memory/discardable_memory_mach.cc',
- 'memory/discardable_memory_mach.h',
- ],
'sources/': [
['exclude', '^files/file_path_watcher_stub\\.cc$'],
['exclude', '^base_paths_posix\\.cc$'],
diff --git a/base/base_unittests.isolate b/base/base_unittests.isolate
index 5126fb3..e329152 100644
--- a/base/base_unittests.isolate
+++ b/base/base_unittests.isolate
@@ -3,14 +3,20 @@
# found in the LICENSE file.
{
'conditions': [
- ['OS=="android" or OS=="linux" or OS=="mac" or OS=="win"', {
+ ['use_x11==0', {
'variables': {
- 'files': [
- 'test/data/',
+ 'command': [
+ '../testing/test_env.py',
+ '<(PRODUCT_DIR)/base_unittests<(EXECUTABLE_SUFFIX)',
+ '--brave-new-test-launcher',
+ '--test-launcher-bot-mode',
+ '--asan=<(asan)',
+ '--msan=<(msan)',
+ '--tsan=<(tsan)',
],
},
}],
- ['OS=="linux"', {
+ ['use_x11==1', {
'variables': {
'command': [
'../testing/xvfb.py',
@@ -24,13 +30,14 @@
],
'files': [
'../testing/xvfb.py',
+ '<(PRODUCT_DIR)/xdisplaycheck<(EXECUTABLE_SUFFIX)',
],
},
}],
- ['OS=="linux" and use_ozone==0', {
+ ['OS=="android" or OS=="linux" or OS=="mac" or OS=="win"', {
'variables': {
'files': [
- '<(PRODUCT_DIR)/xdisplaycheck<(EXECUTABLE_SUFFIX)',
+ 'test/data/',
],
},
}],
@@ -43,19 +50,6 @@
'read_only': 1,
},
}],
- ['OS=="mac" or OS=="win"', {
- 'variables': {
- 'command': [
- '../testing/test_env.py',
- '<(PRODUCT_DIR)/base_unittests<(EXECUTABLE_SUFFIX)',
- '--brave-new-test-launcher',
- '--test-launcher-bot-mode',
- '--asan=<(asan)',
- '--msan=<(msan)',
- '--tsan=<(tsan)',
- ],
- },
- }],
['OS=="mac" and asan==1 and fastbuild==0', {
'variables': {
'files': [
diff --git a/base/build_time.h b/base/build_time.h
index c7df479..4f0abc3 100644
--- a/base/build_time.h
+++ b/base/build_time.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_BUILD_TIME_
-#define BASE_BUILD_TIME_
+#ifndef BASE_BUILD_TIME_H_
+#define BASE_BUILD_TIME_H_
#include "base/base_export.h"
#include "base/time/time.h"
@@ -25,4 +25,4 @@
} // namespace base
-#endif // BASE_BUILD_TIME_
+#endif // BASE_BUILD_TIME_H_
diff --git a/base/callback_forward.h b/base/callback_forward.h
index 7983248..262c306 100644
--- a/base/callback_forward.h
+++ b/base/callback_forward.h
@@ -14,4 +14,4 @@
} // namespace base
-#endif // BASE_CALLBACK_FORWARD_H
+#endif // BASE_CALLBACK_FORWARD_H_
diff --git a/base/command_line.cc b/base/command_line.cc
index 6125667..d28a4b4 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -187,7 +187,7 @@
// static
void CommandLine::set_slash_is_not_a_switch() {
// The last switch prefix should be slash, so adjust the size to skip it.
- DCHECK(wcscmp(kSwitchPrefixes[arraysize(kSwitchPrefixes) - 1], L"/") == 0);
+ DCHECK_EQ(wcscmp(kSwitchPrefixes[arraysize(kSwitchPrefixes) - 1], L"/"), 0);
switch_prefix_count = arraysize(kSwitchPrefixes) - 1;
}
#endif
diff --git a/base/containers/hash_tables.h b/base/containers/hash_tables.h
index 6bf029e..d13c469 100644
--- a/base/containers/hash_tables.h
+++ b/base/containers/hash_tables.h
@@ -320,7 +320,7 @@
}
};
-}
+} // namespace BASE_HASH_NAMESPACE
#undef DEFINE_PAIR_HASH_FUNCTION_START
#undef DEFINE_PAIR_HASH_FUNCTION_END
diff --git a/base/containers/mru_cache.h b/base/containers/mru_cache.h
index 15ea2fc..ed1ad25 100644
--- a/base/containers/mru_cache.h
+++ b/base/containers/mru_cache.h
@@ -213,8 +213,7 @@
template<class PayloadType>
class MRUCacheNullDeletor {
public:
- void operator()(PayloadType& payload) {
- }
+ void operator()(const PayloadType& payload) {}
};
// A container that does not do anything to free its data. Use this when storing
@@ -244,9 +243,7 @@
template<class PayloadType>
class MRUCachePointerDeletor {
public:
- void operator()(PayloadType& payload) {
- delete payload;
- }
+ void operator()(const PayloadType& payload) { delete payload; }
};
// A cache that owns the payload type, which must be a non-const pointer type.
diff --git a/base/containers/stack_container.h b/base/containers/stack_container.h
index 87fa036..54090d3 100644
--- a/base/containers/stack_container.h
+++ b/base/containers/stack_container.h
@@ -176,6 +176,7 @@
Allocator allocator_;
ContainerType container_;
+ private:
DISALLOW_COPY_AND_ASSIGN(StackContainer);
};
diff --git a/base/debug/BUILD.gn b/base/debug/BUILD.gn
new file mode 100644
index 0000000..37a0ab2
--- /dev/null
+++ b/base/debug/BUILD.gn
@@ -0,0 +1,75 @@
+# Copyright (c) 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+source_set("debug") {
+ sources = [
+ "alias.cc",
+ "alias.h",
+ "asan_invalid_access.cc",
+ "asan_invalid_access.h",
+ "crash_logging.cc",
+ "crash_logging.h",
+ "debugger.cc",
+ "debugger.h",
+ "debugger_posix.cc",
+ "debugger_win.cc",
+ "dump_without_crashing.cc",
+ "dump_without_crashing.h",
+ "gdi_debug_util_win.cc",
+ "gdi_debug_util_win.h",
+
+ # This file depends on files from the "allocator" target,
+ # but this target does not depend on "allocator" (see
+ # allocator.gyp for details).
+ "leak_annotations.h",
+ "leak_tracker.h",
+ "proc_maps_linux.cc",
+ "proc_maps_linux.h",
+ "profiler.cc",
+ "profiler.h",
+ "stack_trace.cc",
+ "stack_trace.h",
+ "stack_trace_android.cc",
+ "stack_trace_posix.cc",
+ "stack_trace_win.cc",
+ "task_annotator.cc",
+ "task_annotator.h",
+ ]
+
+ if (is_android) {
+ # Android uses some Linux sources, put those back.
+ set_sources_assignment_filter([])
+ sources += [ "proc_maps_linux.cc" ]
+ set_sources_assignment_filter(sources_assignment_filter)
+
+ sources -= [ "stack_trace_posix.cc" ]
+ }
+
+ if (is_nacl) {
+ sources -= [
+ "crash_logging.cc",
+ "crash_logging.h",
+ "stack_trace.cc",
+ "stack_trace_posix.cc",
+ ]
+ }
+
+ defines = [ "BASE_IMPLEMENTATION" ]
+
+ deps = [
+ "//base/memory",
+ "//base/process",
+ ]
+
+ if (is_linux) {
+ deps += [ "//base/third_party/symbolize" ]
+ }
+
+ allow_circular_includes_from = [
+ "//base/memory",
+ "//base/process",
+ ]
+
+ visibility = [ "//base/*" ]
+}
diff --git a/base/debug/debugger.h b/base/debug/debugger.h
index d62ea3f..8680e28 100644
--- a/base/debug/debugger.h
+++ b/base/debug/debugger.h
@@ -6,8 +6,8 @@
// debuggers. You should use this to test if you're running under a debugger,
// and if you would like to yield (breakpoint) into the debugger.
-#ifndef BASE_DEBUG_DEBUGGER_H
-#define BASE_DEBUG_DEBUGGER_H
+#ifndef BASE_DEBUG_DEBUGGER_H_
+#define BASE_DEBUG_DEBUGGER_H_
#include "base/base_export.h"
@@ -41,4 +41,4 @@
} // namespace debug
} // namespace base
-#endif // BASE_DEBUG_DEBUGGER_H
+#endif // BASE_DEBUG_DEBUGGER_H_
diff --git a/base/debug/leak_annotations.h b/base/debug/leak_annotations.h
index 27fe663..ef37959 100644
--- a/base/debug/leak_annotations.h
+++ b/base/debug/leak_annotations.h
@@ -21,15 +21,7 @@
#if defined(LEAK_SANITIZER) && !defined(OS_NACL)
-// Public LSan API from <sanitizer/lsan_interface.h>.
-extern "C" {
-void __lsan_disable();
-void __lsan_enable();
-void __lsan_ignore_object(const void *p);
-
-// Invoke leak detection immediately. If leaks are found, the process will exit.
-void __lsan_do_leak_check();
-} // extern "C"
+#include <sanitizer/lsan_interface.h>
class ScopedLeakSanitizerDisabler {
public:
@@ -46,7 +38,6 @@
#else
-// If neither HeapChecker nor LSan are used, the annotations should be no-ops.
#define ANNOTATE_SCOPED_MEMORY_LEAK ((void)0)
#define ANNOTATE_LEAKING_OBJECT_PTR(X) ((void)0)
diff --git a/base/debug/profiler.h b/base/debug/profiler.h
index e1dda89..c50555e 100644
--- a/base/debug/profiler.h
+++ b/base/debug/profiler.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_DEBUG_PROFILER_H
-#define BASE_DEBUG_PROFILER_H
+#ifndef BASE_DEBUG_PROFILER_H_
+#define BASE_DEBUG_PROFILER_H_
#include <string>
@@ -87,4 +87,4 @@
} // namespace debug
} // namespace base
-#endif // BASE_DEBUG_DEBUGGER_H
+#endif // BASE_DEBUG_PROFILER_H__
diff --git a/base/deferred_sequenced_task_runner.h b/base/deferred_sequenced_task_runner.h
index bc8db7a..110d988 100644
--- a/base/deferred_sequenced_task_runner.h
+++ b/base/deferred_sequenced_task_runner.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_DEFERRED_SEQUENCED_TASKRUNNER_H_
-#define BASE_DEFERRED_SEQUENCED_TASKRUNNER_H_
+#ifndef BASE_DEFERRED_SEQUENCED_TASK_RUNNER_H_
+#define BASE_DEFERRED_SEQUENCED_TASK_RUNNER_H_
#include <vector>
@@ -75,4 +75,4 @@
} // namespace base
-#endif // BASE_DEFERRED_SEQUENCED_TASKRUNNER_H_
+#endif // BASE_DEFERRED_SEQUENCED_TASK_RUNNER_H_
diff --git a/base/event_types.h b/base/event_types.h
index af586e4..9905800 100644
--- a/base/event_types.h
+++ b/base/event_types.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_EVENT_TYPES_H
-#define BASE_EVENT_TYPES_H
+#ifndef BASE_EVENT_TYPES_H_
+#define BASE_EVENT_TYPES_H_
#include "build/build_config.h"
@@ -34,4 +34,4 @@
} // namespace base
-#endif // BASE_EVENT_TYPES_H
+#endif // BASE_EVENT_TYPES_H_
diff --git a/base/files/file_path_watcher_browsertest.cc b/base/files/file_path_watcher_browsertest.cc
index 9081626..bc7e630 100644
--- a/base/files/file_path_watcher_browsertest.cc
+++ b/base/files/file_path_watcher_browsertest.cc
@@ -192,6 +192,7 @@
ScopedTempDir temp_dir_;
scoped_refptr<NotificationCollector> collector_;
+ private:
DISALLOW_COPY_AND_ASSIGN(FilePathWatcherTest);
};
diff --git a/base/files/file_util_unittest.cc b/base/files/file_util_unittest.cc
index af932ce..b107b0f 100644
--- a/base/files/file_util_unittest.cc
+++ b/base/files/file_util_unittest.cc
@@ -197,9 +197,9 @@
// interface to query whether a given file is present.
class FindResultCollector {
public:
- explicit FindResultCollector(FileEnumerator& enumerator) {
+ explicit FindResultCollector(FileEnumerator* enumerator) {
FilePath cur_file;
- while (!(cur_file = enumerator.Next()).value().empty()) {
+ while (!(cur_file = enumerator->Next()).value().empty()) {
FilePath::StringType path = cur_file.value();
// The file should not be returned twice.
EXPECT_TRUE(files_.end() == files_.find(path))
@@ -824,7 +824,7 @@
// Make sure the file in the directory can't be enumerated.
FileEnumerator f1(subdir_path, true, FileEnumerator::FILES);
EXPECT_TRUE(PathExists(subdir_path));
- FindResultCollector c1(f1);
+ FindResultCollector c1(&f1);
EXPECT_EQ(0, c1.size());
EXPECT_FALSE(GetPosixFilePermissions(file_name, &mode));
@@ -835,7 +835,7 @@
// Make sure the file in the directory can be enumerated.
FileEnumerator f2(subdir_path, true, FileEnumerator::FILES);
- FindResultCollector c2(f2);
+ FindResultCollector c2(&f2);
EXPECT_TRUE(c2.HasFile(file_name));
EXPECT_EQ(1, c2.size());
@@ -1871,7 +1871,7 @@
// Only enumerate files.
FileEnumerator f1(temp_dir_.path(), true, FileEnumerator::FILES);
- FindResultCollector c1(f1);
+ FindResultCollector c1(&f1);
EXPECT_TRUE(c1.HasFile(file1));
EXPECT_TRUE(c1.HasFile(file2_abs));
EXPECT_TRUE(c1.HasFile(dir2file));
@@ -1880,7 +1880,7 @@
// Only enumerate directories.
FileEnumerator f2(temp_dir_.path(), true, FileEnumerator::DIRECTORIES);
- FindResultCollector c2(f2);
+ FindResultCollector c2(&f2);
EXPECT_TRUE(c2.HasFile(dir1));
EXPECT_TRUE(c2.HasFile(dir2));
EXPECT_TRUE(c2.HasFile(dir2inner));
@@ -1889,7 +1889,7 @@
// Only enumerate directories non-recursively.
FileEnumerator f2_non_recursive(
temp_dir_.path(), false, FileEnumerator::DIRECTORIES);
- FindResultCollector c2_non_recursive(f2_non_recursive);
+ FindResultCollector c2_non_recursive(&f2_non_recursive);
EXPECT_TRUE(c2_non_recursive.HasFile(dir1));
EXPECT_TRUE(c2_non_recursive.HasFile(dir2));
EXPECT_EQ(2, c2_non_recursive.size());
@@ -1898,7 +1898,7 @@
FileEnumerator f2_dotdot(temp_dir_.path(), false,
FileEnumerator::DIRECTORIES |
FileEnumerator::INCLUDE_DOT_DOT);
- FindResultCollector c2_dotdot(f2_dotdot);
+ FindResultCollector c2_dotdot(&f2_dotdot);
EXPECT_TRUE(c2_dotdot.HasFile(dir1));
EXPECT_TRUE(c2_dotdot.HasFile(dir2));
EXPECT_TRUE(c2_dotdot.HasFile(temp_dir_.path().Append(FPL(".."))));
@@ -1906,7 +1906,7 @@
// Enumerate files and directories.
FileEnumerator f3(temp_dir_.path(), true, FILES_AND_DIRECTORIES);
- FindResultCollector c3(f3);
+ FindResultCollector c3(&f3);
EXPECT_TRUE(c3.HasFile(dir1));
EXPECT_TRUE(c3.HasFile(dir2));
EXPECT_TRUE(c3.HasFile(file1));
@@ -1918,7 +1918,7 @@
// Non-recursive operation.
FileEnumerator f4(temp_dir_.path(), false, FILES_AND_DIRECTORIES);
- FindResultCollector c4(f4);
+ FindResultCollector c4(&f4);
EXPECT_TRUE(c4.HasFile(dir2));
EXPECT_TRUE(c4.HasFile(dir2));
EXPECT_TRUE(c4.HasFile(file1));
@@ -1927,7 +1927,7 @@
// Enumerate with a pattern.
FileEnumerator f5(temp_dir_.path(), true, FILES_AND_DIRECTORIES, FPL("dir*"));
- FindResultCollector c5(f5);
+ FindResultCollector c5(&f5);
EXPECT_TRUE(c5.HasFile(dir1));
EXPECT_TRUE(c5.HasFile(dir2));
EXPECT_TRUE(c5.HasFile(dir2file));
@@ -1946,7 +1946,7 @@
// the file system so skip this test for XP.
// Enumerate the reparse point.
FileEnumerator f6(dir1, true, FILES_AND_DIRECTORIES);
- FindResultCollector c6(f6);
+ FindResultCollector c6(&f6);
FilePath inner2 = dir1.Append(FPL("inner"));
EXPECT_TRUE(c6.HasFile(inner2));
EXPECT_TRUE(c6.HasFile(inner2.Append(FPL("innerfile.txt"))));
@@ -1956,7 +1956,7 @@
// No changes for non recursive operation.
FileEnumerator f7(temp_dir_.path(), false, FILES_AND_DIRECTORIES);
- FindResultCollector c7(f7);
+ FindResultCollector c7(&f7);
EXPECT_TRUE(c7.HasFile(dir2));
EXPECT_TRUE(c7.HasFile(dir2));
EXPECT_TRUE(c7.HasFile(file1));
@@ -1965,7 +1965,7 @@
// Should not enumerate inside dir1 when using recursion.
FileEnumerator f8(temp_dir_.path(), true, FILES_AND_DIRECTORIES);
- FindResultCollector c8(f8);
+ FindResultCollector c8(&f8);
EXPECT_TRUE(c8.HasFile(dir1));
EXPECT_TRUE(c8.HasFile(dir2));
EXPECT_TRUE(c8.HasFile(file1));
diff --git a/base/guid_posix.cc b/base/guid_posix.cc
index 9681b08..f0fedc2 100644
--- a/base/guid_posix.cc
+++ b/base/guid_posix.cc
@@ -39,4 +39,4 @@
bytes[1] & 0x0000ffffffffffffULL);
}
-} // namespace guid
+} // namespace base
diff --git a/base/guid_win.cc b/base/guid_win.cc
index cdb860a..da3453d 100644
--- a/base/guid_win.cc
+++ b/base/guid_win.cc
@@ -35,4 +35,4 @@
return WideToUTF8(guid_string.substr(1, guid_string.length() - 2));
}
-} // namespace guid
+} // namespace base
diff --git a/base/i18n/string_compare.h b/base/i18n/string_compare.h
index f0f3e29..158c93b 100644
--- a/base/i18n/string_compare.h
+++ b/base/i18n/string_compare.h
@@ -25,4 +25,4 @@
} // namespace i18n
} // namespace base
-#endif // BASE_I18N_STRING_COMPARATOR_H_
+#endif // BASE_I18N_STRING_COMPARE_H_
diff --git a/base/i18n/timezone.h b/base/i18n/timezone.h
index b7275f7..f7fda94 100644
--- a/base/i18n/timezone.h
+++ b/base/i18n/timezone.h
@@ -18,4 +18,4 @@
} // namespace base
-#endif // BASE_TIME_TIMEZONE_H_
+#endif // BASE_I18N_TIMEZONE_H_
diff --git a/base/json/BUILD.gn b/base/json/BUILD.gn
new file mode 100644
index 0000000..0310ea9
--- /dev/null
+++ b/base/json/BUILD.gn
@@ -0,0 +1,37 @@
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+source_set("json") {
+ sources = [
+ "json_file_value_serializer.cc",
+ "json_file_value_serializer.h",
+ "json_parser.cc",
+ "json_parser.h",
+ "json_reader.cc",
+ "json_reader.h",
+ "json_string_value_serializer.cc",
+ "json_string_value_serializer.h",
+ "json_value_converter.cc",
+ "json_value_converter.h",
+ "json_writer.cc",
+ "json_writer.h",
+ "string_escape.cc",
+ "string_escape.h",
+ ]
+
+ if (is_nacl) {
+ sources -= [
+ "json_file_value_serializer.cc",
+ "json_file_value_serializer.h",
+ ]
+ }
+
+ defines = [ "BASE_IMPLEMENTATION" ]
+
+ deps = [
+ "//base/memory",
+ ]
+
+ visibility = [ "//base/*" ]
+}
diff --git a/base/json/json_value_serializer_unittest.cc b/base/json/json_value_serializer_unittest.cc
index 225ee67..b8aebe0 100644
--- a/base/json/json_value_serializer_unittest.cc
+++ b/base/json/json_value_serializer_unittest.cc
@@ -61,7 +61,7 @@
const char kLinuxLineEnds[] = "\n";
// Verifies the generated JSON against the expected output.
-void CheckJSONIsStillTheSame(Value& value) {
+void CheckJSONIsStillTheSame(const Value& value) {
// Serialize back the output.
std::string serialized_json;
JSONStringValueSerializer str_serializer(&serialized_json);
diff --git a/base/mac/authorization_util.mm b/base/mac/authorization_util.mm
index 003c26d..1dfd5a0 100644
--- a/base/mac/authorization_util.mm
+++ b/base/mac/authorization_util.mm
@@ -28,10 +28,9 @@
AuthorizationFlags extraFlags) {
// Create an empty AuthorizationRef.
ScopedAuthorizationRef authorization;
- OSStatus status = AuthorizationCreate(NULL,
- kAuthorizationEmptyEnvironment,
+ OSStatus status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment,
kAuthorizationFlagDefaults,
- &authorization);
+ authorization.get_pointer());
if (status != errAuthorizationSuccess) {
OSSTATUS_LOG(ERROR, status) << "AuthorizationCreate";
return NULL;
diff --git a/base/mac/cocoa_protocols.h b/base/mac/cocoa_protocols.h
index ab34a19..a28795c 100644
--- a/base/mac/cocoa_protocols.h
+++ b/base/mac/cocoa_protocols.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_COCOA_PROTOCOLS_MAC_H_
-#define BASE_COCOA_PROTOCOLS_MAC_H_
+#ifndef BASE_MAC_COCOA_PROTOCOLS_H_
+#define BASE_MAC_COCOA_PROTOCOLS_H_
#import <Cocoa/Cocoa.h>
@@ -28,4 +28,4 @@
#undef DEFINE_EMPTY_PROTOCOL
-#endif // BASE_COCOA_PROTOCOLS_MAC_H_
+#endif // BASE_MAC_COCOA_PROTOCOLS_H_
diff --git a/base/mac/libdispatch_task_runner.h b/base/mac/libdispatch_task_runner.h
index f5fd866..b479bc7 100644
--- a/base/mac/libdispatch_task_runner.h
+++ b/base/mac/libdispatch_task_runner.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_MAC_LIBDISPATCH_SEQUENCED_TASK_RUNNER_H_
-#define BASE_MAC_LIBDISPATCH_SEQUENCED_TASK_RUNNER_H_
+#ifndef BASE_MAC_LIBDISPATCH_TASK_RUNNER_H_
+#define BASE_MAC_LIBDISPATCH_TASK_RUNNER_H_
#include <dispatch/dispatch.h>
@@ -77,4 +77,4 @@
} // namespace mac
} // namespace base
-#endif // BASE_MAC_LIBDISPATCH_SEQUENCED_TASK_RUNNER_H_
+#endif // BASE_MAC_LIBDISPATCH_TASK_RUNNER_H_
diff --git a/base/mac/scoped_authorizationref.h b/base/mac/scoped_authorizationref.h
index 6413f2e..1811488 100644
--- a/base/mac/scoped_authorizationref.h
+++ b/base/mac/scoped_authorizationref.h
@@ -49,9 +49,7 @@
return authorization_;
}
- AuthorizationRef* operator&() {
- return &authorization_;
- }
+ AuthorizationRef* get_pointer() { return &authorization_; }
AuthorizationRef get() const {
return authorization_;
diff --git a/base/mac/scoped_mach_vm.cc b/base/mac/scoped_mach_vm.cc
index 1c28d9c..d52c77f 100644
--- a/base/mac/scoped_mach_vm.cc
+++ b/base/mac/scoped_mach_vm.cc
@@ -8,8 +8,8 @@
namespace mac {
void ScopedMachVM::reset(vm_address_t address, vm_size_t size) {
- DCHECK(address % PAGE_SIZE == 0);
- DCHECK(size % PAGE_SIZE == 0);
+ DCHECK_EQ(address % PAGE_SIZE, 0u);
+ DCHECK_EQ(size % PAGE_SIZE, 0u);
if (size_) {
if (address_ < address) {
diff --git a/base/mac/scoped_mach_vm.h b/base/mac/scoped_mach_vm.h
index b130a79..ffc00d5 100644
--- a/base/mac/scoped_mach_vm.h
+++ b/base/mac/scoped_mach_vm.h
@@ -48,10 +48,9 @@
class BASE_EXPORT ScopedMachVM {
public:
explicit ScopedMachVM(vm_address_t address = 0, vm_size_t size = 0)
- : address_(address),
- size_(size) {
- DCHECK(address % PAGE_SIZE == 0);
- DCHECK(size % PAGE_SIZE == 0);
+ : address_(address), size_(size) {
+ DCHECK_EQ(address % PAGE_SIZE, 0u);
+ DCHECK_EQ(size % PAGE_SIZE, 0u);
}
~ScopedMachVM() {
diff --git a/base/memory/BUILD.gn b/base/memory/BUILD.gn
new file mode 100644
index 0000000..5d016ff
--- /dev/null
+++ b/base/memory/BUILD.gn
@@ -0,0 +1,64 @@
+# Copyright (c) 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+source_set("memory") {
+ sources = [
+ "aligned_memory.cc",
+ "aligned_memory.h",
+ "discardable_memory.cc",
+ "discardable_memory.h",
+ "discardable_memory_android.cc",
+ "discardable_memory_linux.cc",
+ "discardable_memory_mac.cc",
+ "discardable_memory_shmem.cc",
+ "discardable_memory_shmem.h",
+ "discardable_memory_shmem_allocator.cc",
+ "discardable_memory_shmem_allocator.h",
+ "discardable_memory_win.cc",
+ "discardable_shared_memory.cc",
+ "discardable_shared_memory.h",
+ "linked_ptr.h",
+ "manual_constructor.h",
+ "memory_pressure_listener.cc",
+ "memory_pressure_listener.h",
+ "raw_scoped_refptr_mismatch_checker.h",
+ "ref_counted.cc",
+ "ref_counted.h",
+ "ref_counted_delete_on_message_loop.h",
+ "ref_counted_memory.cc",
+ "ref_counted_memory.h",
+ "scoped_policy.h",
+ "scoped_ptr.h",
+ "scoped_vector.h",
+ "shared_memory.h",
+ "shared_memory_android.cc",
+ "shared_memory_nacl.cc",
+ "shared_memory_posix.cc",
+ "shared_memory_win.cc",
+ "singleton.cc",
+ "singleton.h",
+ "weak_ptr.cc",
+ "weak_ptr.h",
+ ]
+
+ if (is_nacl) {
+ sources -= [
+ "discardable_memory.cc",
+ "discardable_memory.h",
+ "discardable_memory_shmem.cc",
+ "discardable_memory_shmem.h",
+ "discardable_memory_shmem_allocator.cc",
+ "discardable_memory_shmem_allocator.h",
+ "discardable_shared_memory.cc",
+ "discardable_shared_memory.h",
+ "shared_memory_posix.cc",
+ ]
+ } else {
+ sources -= [ "shared_memory_nacl.cc" ]
+ }
+
+ defines = [ "BASE_IMPLEMENTATION" ]
+
+ visibility = [ "//base/*" ]
+}
diff --git a/base/memory/discardable_memory.cc b/base/memory/discardable_memory.cc
index 3d82f91..7d19f9a 100644
--- a/base/memory/discardable_memory.cc
+++ b/base/memory/discardable_memory.cc
@@ -14,9 +14,6 @@
DiscardableMemoryType type;
const char* name;
} kTypeNamePairs[] = {
- { DISCARDABLE_MEMORY_TYPE_ASHMEM, "ashmem" },
- { DISCARDABLE_MEMORY_TYPE_MACH, "mach" },
- { DISCARDABLE_MEMORY_TYPE_EMULATED, "emulated" },
{ DISCARDABLE_MEMORY_TYPE_SHMEM, "shmem" }
};
diff --git a/base/memory/discardable_memory.h b/base/memory/discardable_memory.h
index c49a99f..4e5a9af 100644
--- a/base/memory/discardable_memory.h
+++ b/base/memory/discardable_memory.h
@@ -17,18 +17,9 @@
enum DiscardableMemoryType {
DISCARDABLE_MEMORY_TYPE_NONE,
- DISCARDABLE_MEMORY_TYPE_ASHMEM,
- DISCARDABLE_MEMORY_TYPE_MACH,
- DISCARDABLE_MEMORY_TYPE_EMULATED,
DISCARDABLE_MEMORY_TYPE_SHMEM
};
-enum DiscardableMemoryLockStatus {
- DISCARDABLE_MEMORY_LOCK_STATUS_FAILED,
- DISCARDABLE_MEMORY_LOCK_STATUS_PURGED,
- DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS
-};
-
// Platform abstraction for discardable memory. DiscardableMemory is used to
// cache large objects without worrying about blowing out memory, both on mobile
// devices where there is no swap, and desktop devices where unused free memory
@@ -89,23 +80,10 @@
// Create a DiscardableMemory instance with preferred type and |size|.
static scoped_ptr<DiscardableMemory> CreateLockedMemory(size_t size);
- // Discardable memory implementations might allow an elevated usage level
- // while in frequent use. Call this to have the usage reduced to the base
- // level. Returns true if there's no need to call this again until
- // memory instances have been used. This indicates that all discardable
- // memory implementations have reduced usage to the base level or below.
- // Note: calling this too often or while discardable memory is in frequent
- // use can hurt performance, whereas calling it too infrequently can result
- // in memory bloat.
- static bool ReduceMemoryUsage();
-
// Locks the memory so that it will not be purged by the system. Returns
- // DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS on success. If the return value is
- // DISCARDABLE_MEMORY_LOCK_STATUS_FAILED then this object should be
- // discarded and a new one should be created. If the return value is
- // DISCARDABLE_MEMORY_LOCK_STATUS_PURGED then the memory is present but any
- // data that was in it is gone.
- virtual DiscardableMemoryLockStatus Lock() WARN_UNUSED_RESULT = 0;
+ // true on success. If the return value is false then this object should be
+ // discarded and a new one should be created.
+ virtual bool Lock() WARN_UNUSED_RESULT = 0;
// Unlocks the memory so that it can be purged by the system. Must be called
// after every successful lock call.
diff --git a/base/memory/discardable_memory_android.cc b/base/memory/discardable_memory_android.cc
index 2b35587..a36f54e 100644
--- a/base/memory/discardable_memory_android.cc
+++ b/base/memory/discardable_memory_android.cc
@@ -4,57 +4,16 @@
#include "base/memory/discardable_memory.h"
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/lazy_instance.h"
#include "base/logging.h"
-#include "base/memory/discardable_memory_ashmem.h"
-#include "base/memory/discardable_memory_ashmem_allocator.h"
-#include "base/memory/discardable_memory_emulated.h"
#include "base/memory/discardable_memory_shmem.h"
-#include "base/sys_info.h"
namespace base {
-namespace {
-
-const char kAshmemAllocatorName[] = "DiscardableMemoryAshmemAllocator";
-
-// For Ashmem, have the DiscardableMemoryManager trigger userspace eviction
-// when address space usage gets too high (e.g. 512 MBytes).
-const size_t kAshmemMemoryLimit = 512 * 1024 * 1024;
-
-size_t GetOptimalAshmemRegionSizeForAllocator() {
- // Note that this may do some I/O (without hitting the disk though) so it
- // should not be called on the critical path.
- return base::SysInfo::AmountOfPhysicalMemory() / 8;
-}
-
-// Holds the shared state used for allocations.
-struct SharedState {
- SharedState()
- : manager(kAshmemMemoryLimit, kAshmemMemoryLimit, TimeDelta::Max()),
- allocator(kAshmemAllocatorName,
- GetOptimalAshmemRegionSizeForAllocator()) {}
-
- internal::DiscardableMemoryManager manager;
- internal::DiscardableMemoryAshmemAllocator allocator;
-};
-LazyInstance<SharedState>::Leaky g_shared_state = LAZY_INSTANCE_INITIALIZER;
-
-} // namespace
-
-// static
-bool DiscardableMemory::ReduceMemoryUsage() {
- return internal::DiscardableMemoryEmulated::ReduceMemoryUsage();
-}
// static
void DiscardableMemory::GetSupportedTypes(
std::vector<DiscardableMemoryType>* types) {
const DiscardableMemoryType supported_types[] = {
- DISCARDABLE_MEMORY_TYPE_SHMEM,
- DISCARDABLE_MEMORY_TYPE_ASHMEM,
- DISCARDABLE_MEMORY_TYPE_EMULATED
+ DISCARDABLE_MEMORY_TYPE_SHMEM
};
types->assign(supported_types, supported_types + arraysize(supported_types));
}
@@ -63,34 +22,9 @@
scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
DiscardableMemoryType type, size_t size) {
switch (type) {
- case DISCARDABLE_MEMORY_TYPE_ASHMEM: {
- SharedState* const shared_state = g_shared_state.Pointer();
- scoped_ptr<internal::DiscardableMemoryAshmem> memory(
- new internal::DiscardableMemoryAshmem(
- size, &shared_state->allocator, &shared_state->manager));
- if (!memory->Initialize())
- return nullptr;
-
- return memory.Pass();
- }
- case DISCARDABLE_MEMORY_TYPE_EMULATED: {
- scoped_ptr<internal::DiscardableMemoryEmulated> memory(
- new internal::DiscardableMemoryEmulated(size));
- if (!memory->Initialize())
- return nullptr;
-
- return memory.Pass();
- }
- case DISCARDABLE_MEMORY_TYPE_SHMEM: {
- scoped_ptr<internal::DiscardableMemoryShmem> memory(
- new internal::DiscardableMemoryShmem(size));
- if (!memory->Initialize())
- return nullptr;
-
- return memory.Pass();
- }
+ case DISCARDABLE_MEMORY_TYPE_SHMEM:
+ return make_scoped_ptr(new internal::DiscardableMemoryShmem(size));
case DISCARDABLE_MEMORY_TYPE_NONE:
- case DISCARDABLE_MEMORY_TYPE_MACH:
NOTREACHED();
return nullptr;
}
diff --git a/base/memory/discardable_memory_ashmem.cc b/base/memory/discardable_memory_ashmem.cc
deleted file mode 100644
index a590e53..0000000
--- a/base/memory/discardable_memory_ashmem.cc
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/memory/discardable_memory_ashmem.h"
-
-#include "base/memory/discardable_memory_ashmem_allocator.h"
-
-namespace base {
-namespace internal {
-
-DiscardableMemoryAshmem::DiscardableMemoryAshmem(
- size_t bytes,
- DiscardableMemoryAshmemAllocator* allocator,
- DiscardableMemoryManager* manager)
- : bytes_(bytes),
- allocator_(allocator),
- manager_(manager),
- is_locked_(false) {
- manager_->Register(this, bytes_);
-}
-
-DiscardableMemoryAshmem::~DiscardableMemoryAshmem() {
- if (is_locked_)
- Unlock();
-
- manager_->Unregister(this);
-}
-
-bool DiscardableMemoryAshmem::Initialize() {
- return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
-}
-
-DiscardableMemoryLockStatus DiscardableMemoryAshmem::Lock() {
- DCHECK(!is_locked_);
-
- bool purged = false;
- if (!manager_->AcquireLock(this, &purged))
- return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
-
- is_locked_ = true;
- return purged ? DISCARDABLE_MEMORY_LOCK_STATUS_PURGED
- : DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS;
-}
-
-void DiscardableMemoryAshmem::Unlock() {
- DCHECK(is_locked_);
- manager_->ReleaseLock(this);
- is_locked_ = false;
-}
-
-void* DiscardableMemoryAshmem::Memory() const {
- DCHECK(is_locked_);
- DCHECK(ashmem_chunk_);
- return ashmem_chunk_->Memory();
-}
-
-bool DiscardableMemoryAshmem::AllocateAndAcquireLock() {
- if (ashmem_chunk_)
- return ashmem_chunk_->Lock();
-
- ashmem_chunk_ = allocator_->Allocate(bytes_);
- return false;
-}
-
-void DiscardableMemoryAshmem::ReleaseLock() {
- ashmem_chunk_->Unlock();
-}
-
-void DiscardableMemoryAshmem::Purge() {
- ashmem_chunk_.reset();
-}
-
-} // namespace internal
-} // namespace base
diff --git a/base/memory/discardable_memory_ashmem.h b/base/memory/discardable_memory_ashmem.h
deleted file mode 100644
index 1269cc2..0000000
--- a/base/memory/discardable_memory_ashmem.h
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_MEMORY_DISCARDABLE_MEMORY_ASHMEM_H_
-#define BASE_MEMORY_DISCARDABLE_MEMORY_ASHMEM_H_
-
-#include "base/memory/discardable_memory.h"
-
-#include "base/macros.h"
-#include "base/memory/discardable_memory_manager.h"
-
-namespace base {
-namespace internal {
-
-class DiscardableAshmemChunk;
-class DiscardableMemoryAshmemAllocator;
-class DiscardableMemoryManager;
-
-class DiscardableMemoryAshmem
- : public DiscardableMemory,
- public internal::DiscardableMemoryManagerAllocation {
- public:
- explicit DiscardableMemoryAshmem(size_t bytes,
- DiscardableMemoryAshmemAllocator* allocator,
- DiscardableMemoryManager* manager);
-
- ~DiscardableMemoryAshmem() override;
-
- bool Initialize();
-
- // Overridden from DiscardableMemory:
- DiscardableMemoryLockStatus Lock() override;
- void Unlock() override;
- void* Memory() const override;
-
- // Overridden from internal::DiscardableMemoryManagerAllocation:
- bool AllocateAndAcquireLock() override;
- void ReleaseLock() override;
- void Purge() override;
-
- private:
- const size_t bytes_;
- DiscardableMemoryAshmemAllocator* const allocator_;
- DiscardableMemoryManager* const manager_;
- bool is_locked_;
- scoped_ptr<DiscardableAshmemChunk> ashmem_chunk_;
-
- DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryAshmem);
-};
-
-} // namespace internal
-} // namespace base
-
-#endif // BASE_MEMORY_DISCARDABLE_MEMORY_ASHMEM_H_
diff --git a/base/memory/discardable_memory_ashmem_allocator.cc b/base/memory/discardable_memory_ashmem_allocator.cc
deleted file mode 100644
index 3d4af92..0000000
--- a/base/memory/discardable_memory_ashmem_allocator.cc
+++ /dev/null
@@ -1,528 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/memory/discardable_memory_ashmem_allocator.h"
-
-#include <sys/mman.h>
-#include <unistd.h>
-
-#include <algorithm>
-#include <cmath>
-#include <limits>
-#include <set>
-#include <utility>
-
-#include "base/basictypes.h"
-#include "base/containers/hash_tables.h"
-#include "base/files/file_util.h"
-#include "base/files/scoped_file.h"
-#include "base/logging.h"
-#include "base/memory/scoped_vector.h"
-#include "third_party/ashmem/ashmem.h"
-
-// The allocator consists of three parts (classes):
-// - DiscardableMemoryAshmemAllocator: entry point of all allocations (through
-// its Allocate() method) that are dispatched to the AshmemRegion instances
-// (which it owns).
-// - AshmemRegion: manages allocations and destructions inside a single large
-// (e.g. 32 MBytes) ashmem region.
-// - DiscardableAshmemChunk: class mimicking the DiscardableMemory interface
-// whose instances are returned to the client.
-
-namespace base {
-namespace {
-
-// Only tolerate fragmentation in used chunks *caused by the client* (as opposed
-// to the allocator when a free chunk is reused). The client can cause such
-// fragmentation by e.g. requesting 4097 bytes. This size would be rounded up to
-// 8192 by the allocator which would cause 4095 bytes of fragmentation (which is
-// currently the maximum allowed). If the client requests 4096 bytes and a free
-// chunk of 8192 bytes is available then the free chunk gets splitted into two
-// pieces to minimize fragmentation (since 8192 - 4096 = 4096 which is greater
-// than 4095).
-// TODO(pliard): tune this if splitting chunks too often leads to performance
-// issues.
-const size_t kMaxChunkFragmentationBytes = 4096 - 1;
-
-const size_t kMinAshmemRegionSize = 32 * 1024 * 1024;
-
-// Returns 0 if the provided size is too high to be aligned.
-size_t AlignToNextPage(size_t size) {
- const size_t kPageSize = 4096;
- DCHECK_EQ(static_cast<int>(kPageSize), getpagesize());
- if (size > std::numeric_limits<size_t>::max() - kPageSize + 1)
- return 0;
- const size_t mask = ~(kPageSize - 1);
- return (size + kPageSize - 1) & mask;
-}
-
-bool CreateAshmemRegion(const char* name,
- size_t size,
- int* out_fd,
- uintptr_t* out_address) {
- base::ScopedFD fd(ashmem_create_region(name, size));
- if (!fd.is_valid()) {
- DLOG(ERROR) << "ashmem_create_region() failed";
- return false;
- }
-
- const int err = ashmem_set_prot_region(fd.get(), PROT_READ | PROT_WRITE);
- if (err < 0) {
- DLOG(ERROR) << "Error " << err << " when setting protection of ashmem";
- return false;
- }
-
- // There is a problem using MAP_PRIVATE here. As we are constantly calling
- // Lock() and Unlock(), data could get lost if they are not written to the
- // underlying file when Unlock() gets called.
- void* const address = mmap(
- NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd.get(), 0);
- if (address == MAP_FAILED) {
- DPLOG(ERROR) << "Failed to map memory.";
- return false;
- }
-
- *out_fd = fd.release();
- *out_address = reinterpret_cast<uintptr_t>(address);
- return true;
-}
-
-bool CloseAshmemRegion(int fd, size_t size, void* address) {
- if (munmap(address, size) == -1) {
- DPLOG(ERROR) << "Failed to unmap memory.";
- close(fd);
- return false;
- }
- return close(fd) == 0;
-}
-
-bool LockAshmemRegion(int fd, size_t off, size_t size) {
- return ashmem_pin_region(fd, off, size) != ASHMEM_WAS_PURGED;
-}
-
-bool UnlockAshmemRegion(int fd, size_t off, size_t size) {
- const int failed = ashmem_unpin_region(fd, off, size);
- if (failed)
- DLOG(ERROR) << "Failed to unpin memory.";
- return !failed;
-}
-
-} // namespace
-
-namespace internal {
-
-class AshmemRegion {
- public:
- // Note that |allocator| must outlive |this|.
- static scoped_ptr<AshmemRegion> Create(
- size_t size,
- const std::string& name,
- DiscardableMemoryAshmemAllocator* allocator) {
- DCHECK_EQ(size, AlignToNextPage(size));
- int fd;
- uintptr_t base;
- if (!CreateAshmemRegion(name.c_str(), size, &fd, &base))
- return scoped_ptr<AshmemRegion>();
- return make_scoped_ptr(new AshmemRegion(fd, size, base, allocator));
- }
-
- ~AshmemRegion() {
- const bool result = CloseAshmemRegion(
- fd_, size_, reinterpret_cast<void*>(base_));
- DCHECK(result);
- DCHECK(!highest_allocated_chunk_);
- }
-
- // Returns a new instance of DiscardableAshmemChunk whose size is greater or
- // equal than |actual_size| (which is expected to be greater or equal than
- // |client_requested_size|).
- // Allocation works as follows:
- // 1) Reuse a previously freed chunk and return it if it succeeded. See
- // ReuseFreeChunk_Locked() below for more information.
- // 2) If no free chunk could be reused and the region is not big enough for
- // the requested size then NULL is returned.
- // 3) If there is enough room in the ashmem region then a new chunk is
- // returned. This new chunk starts at |offset_| which is the end of the
- // previously highest chunk in the region.
- scoped_ptr<DiscardableAshmemChunk> Allocate_Locked(
- size_t client_requested_size,
- size_t actual_size) {
- DCHECK_LE(client_requested_size, actual_size);
- allocator_->lock_.AssertAcquired();
-
- // Check that the |highest_allocated_chunk_| field doesn't contain a stale
- // pointer. It should point to either a free chunk or a used chunk.
- DCHECK(!highest_allocated_chunk_ ||
- address_to_free_chunk_map_.find(highest_allocated_chunk_) !=
- address_to_free_chunk_map_.end() ||
- used_to_previous_chunk_map_.find(highest_allocated_chunk_) !=
- used_to_previous_chunk_map_.end());
-
- scoped_ptr<DiscardableAshmemChunk> memory = ReuseFreeChunk_Locked(
- client_requested_size, actual_size);
- if (memory)
- return memory.Pass();
-
- if (size_ - offset_ < actual_size) {
- // This region does not have enough space left to hold the requested size.
- return scoped_ptr<DiscardableAshmemChunk>();
- }
-
- uintptr_t const address = base_ + offset_;
- memory.reset(
- new DiscardableAshmemChunk(this, fd_, reinterpret_cast<void*>(address),
- offset_, actual_size));
-
- used_to_previous_chunk_map_.insert(
- std::make_pair(address, highest_allocated_chunk_));
- highest_allocated_chunk_ = reinterpret_cast<uintptr_t>(address);
- offset_ += actual_size;
- DCHECK_LE(offset_, size_);
- return memory.Pass();
- }
-
- void OnChunkDeletion(uintptr_t chunk, size_t size) {
- AutoLock auto_lock(allocator_->lock_);
- MergeAndAddFreeChunk_Locked(chunk, size);
- // Note that |this| might be deleted beyond this point.
- }
-
- private:
- struct FreeChunk {
- FreeChunk() : previous_chunk(0), start(0), size(0) {}
-
- explicit FreeChunk(size_t size)
- : previous_chunk(0),
- start(0),
- size(size) {
- }
-
- FreeChunk(uintptr_t previous_chunk, uintptr_t start, size_t size)
- : previous_chunk(previous_chunk),
- start(start),
- size(size) {
- DCHECK_LT(previous_chunk, start);
- }
-
- uintptr_t const previous_chunk;
- uintptr_t const start;
- const size_t size;
-
- bool is_null() const { return !start; }
-
- bool operator<(const FreeChunk& other) const {
- return size < other.size;
- }
- };
-
- // Note that |allocator| must outlive |this|.
- AshmemRegion(int fd,
- size_t size,
- uintptr_t base,
- DiscardableMemoryAshmemAllocator* allocator)
- : fd_(fd),
- size_(size),
- base_(base),
- allocator_(allocator),
- highest_allocated_chunk_(0),
- offset_(0) {
- DCHECK_GE(fd_, 0);
- DCHECK_GE(size, kMinAshmemRegionSize);
- DCHECK(base);
- DCHECK(allocator);
- }
-
- // Tries to reuse a previously freed chunk by doing a closest size match.
- scoped_ptr<DiscardableAshmemChunk> ReuseFreeChunk_Locked(
- size_t client_requested_size,
- size_t actual_size) {
- allocator_->lock_.AssertAcquired();
- const FreeChunk reused_chunk = RemoveFreeChunkFromIterator_Locked(
- free_chunks_.lower_bound(FreeChunk(actual_size)));
- if (reused_chunk.is_null())
- return scoped_ptr<DiscardableAshmemChunk>();
-
- used_to_previous_chunk_map_.insert(
- std::make_pair(reused_chunk.start, reused_chunk.previous_chunk));
- size_t reused_chunk_size = reused_chunk.size;
- // |client_requested_size| is used below rather than |actual_size| to
- // reflect the amount of bytes that would not be usable by the client (i.e.
- // wasted). Using |actual_size| instead would not allow us to detect
- // fragmentation caused by the client if he did misaligned allocations.
- DCHECK_GE(reused_chunk.size, client_requested_size);
- const size_t fragmentation_bytes =
- reused_chunk.size - client_requested_size;
-
- if (fragmentation_bytes > kMaxChunkFragmentationBytes) {
- // Split the free chunk being recycled so that its unused tail doesn't get
- // reused (i.e. locked) which would prevent it from being evicted under
- // memory pressure.
- reused_chunk_size = actual_size;
- uintptr_t const new_chunk_start = reused_chunk.start + actual_size;
- if (reused_chunk.start == highest_allocated_chunk_) {
- // We also need to update the pointer to the highest allocated chunk in
- // case we are splitting the highest chunk.
- highest_allocated_chunk_ = new_chunk_start;
- }
- DCHECK_GT(reused_chunk.size, actual_size);
- const size_t new_chunk_size = reused_chunk.size - actual_size;
- // Note that merging is not needed here since there can't be contiguous
- // free chunks at this point.
- AddFreeChunk_Locked(
- FreeChunk(reused_chunk.start, new_chunk_start, new_chunk_size));
- }
-
- const size_t offset = reused_chunk.start - base_;
- LockAshmemRegion(fd_, offset, reused_chunk_size);
- scoped_ptr<DiscardableAshmemChunk> memory(
- new DiscardableAshmemChunk(this, fd_,
- reinterpret_cast<void*>(reused_chunk.start),
- offset, reused_chunk_size));
- return memory.Pass();
- }
-
- // Makes the chunk identified with the provided arguments free and possibly
- // merges this chunk with the previous and next contiguous ones.
- // If the provided chunk is the only one used (and going to be freed) in the
- // region then the internal ashmem region is closed so that the underlying
- // physical pages are immediately released.
- // Note that free chunks are unlocked therefore they can be reclaimed by the
- // kernel if needed (under memory pressure) but they are not immediately
- // released unfortunately since madvise(MADV_REMOVE) and
- // fallocate(FALLOC_FL_PUNCH_HOLE) don't seem to work on ashmem. This might
- // change in versions of kernel >=3.5 though. The fact that free chunks are
- // not immediately released is the reason why we are trying to minimize
- // fragmentation in order not to cause "artificial" memory pressure.
- void MergeAndAddFreeChunk_Locked(uintptr_t chunk, size_t size) {
- allocator_->lock_.AssertAcquired();
- size_t new_free_chunk_size = size;
- // Merge with the previous chunk.
- uintptr_t first_free_chunk = chunk;
- DCHECK(!used_to_previous_chunk_map_.empty());
- const hash_map<uintptr_t, uintptr_t>::iterator previous_chunk_it =
- used_to_previous_chunk_map_.find(chunk);
- DCHECK(previous_chunk_it != used_to_previous_chunk_map_.end());
- uintptr_t previous_chunk = previous_chunk_it->second;
- used_to_previous_chunk_map_.erase(previous_chunk_it);
-
- if (previous_chunk) {
- const FreeChunk free_chunk = RemoveFreeChunk_Locked(previous_chunk);
- if (!free_chunk.is_null()) {
- new_free_chunk_size += free_chunk.size;
- first_free_chunk = previous_chunk;
- if (chunk == highest_allocated_chunk_)
- highest_allocated_chunk_ = previous_chunk;
-
- // There should not be more contiguous previous free chunks.
- previous_chunk = free_chunk.previous_chunk;
- DCHECK(!address_to_free_chunk_map_.count(previous_chunk));
- }
- }
-
- // Merge with the next chunk if free and present.
- uintptr_t next_chunk = chunk + size;
- const FreeChunk next_free_chunk = RemoveFreeChunk_Locked(next_chunk);
- if (!next_free_chunk.is_null()) {
- new_free_chunk_size += next_free_chunk.size;
- if (next_free_chunk.start == highest_allocated_chunk_)
- highest_allocated_chunk_ = first_free_chunk;
-
- // Same as above.
- DCHECK(
- !address_to_free_chunk_map_.count(next_chunk + next_free_chunk.size));
- }
-
- const bool whole_ashmem_region_is_free =
- used_to_previous_chunk_map_.empty();
- if (!whole_ashmem_region_is_free) {
- AddFreeChunk_Locked(
- FreeChunk(previous_chunk, first_free_chunk, new_free_chunk_size));
- return;
- }
-
- // The whole ashmem region is free thus it can be deleted.
- DCHECK_EQ(base_, first_free_chunk);
- DCHECK_EQ(base_, highest_allocated_chunk_);
- DCHECK(free_chunks_.empty());
- DCHECK(address_to_free_chunk_map_.empty());
- DCHECK(used_to_previous_chunk_map_.empty());
- highest_allocated_chunk_ = 0;
- allocator_->DeleteAshmemRegion_Locked(this); // Deletes |this|.
- }
-
- void AddFreeChunk_Locked(const FreeChunk& free_chunk) {
- allocator_->lock_.AssertAcquired();
- const std::multiset<FreeChunk>::iterator it = free_chunks_.insert(
- free_chunk);
- address_to_free_chunk_map_.insert(std::make_pair(free_chunk.start, it));
- // Update the next used contiguous chunk, if any, since its previous chunk
- // may have changed due to free chunks merging/splitting.
- uintptr_t const next_used_contiguous_chunk =
- free_chunk.start + free_chunk.size;
- hash_map<uintptr_t, uintptr_t>::iterator previous_it =
- used_to_previous_chunk_map_.find(next_used_contiguous_chunk);
- if (previous_it != used_to_previous_chunk_map_.end())
- previous_it->second = free_chunk.start;
- }
-
- // Finds and removes the free chunk, if any, whose start address is
- // |chunk_start|. Returns a copy of the unlinked free chunk or a free chunk
- // whose content is null if it was not found.
- FreeChunk RemoveFreeChunk_Locked(uintptr_t chunk_start) {
- allocator_->lock_.AssertAcquired();
- const hash_map<
- uintptr_t, std::multiset<FreeChunk>::iterator>::iterator it =
- address_to_free_chunk_map_.find(chunk_start);
- if (it == address_to_free_chunk_map_.end())
- return FreeChunk();
- return RemoveFreeChunkFromIterator_Locked(it->second);
- }
-
- // Same as above but takes an iterator in.
- FreeChunk RemoveFreeChunkFromIterator_Locked(
- std::multiset<FreeChunk>::iterator free_chunk_it) {
- allocator_->lock_.AssertAcquired();
- if (free_chunk_it == free_chunks_.end())
- return FreeChunk();
- DCHECK(free_chunk_it != free_chunks_.end());
- const FreeChunk free_chunk(*free_chunk_it);
- address_to_free_chunk_map_.erase(free_chunk_it->start);
- free_chunks_.erase(free_chunk_it);
- return free_chunk;
- }
-
- const int fd_;
- const size_t size_;
- uintptr_t const base_;
- DiscardableMemoryAshmemAllocator* const allocator_;
- // Points to the chunk with the highest address in the region. This pointer
- // needs to be carefully updated when chunks are merged/split.
- uintptr_t highest_allocated_chunk_;
- // Points to the end of |highest_allocated_chunk_|.
- size_t offset_;
- // Allows free chunks recycling (lookup, insertion and removal) in O(log N).
- // Note that FreeChunk values are indexed by their size and also note that
- // multiple free chunks can have the same size (which is why multiset<> is
- // used instead of e.g. set<>).
- std::multiset<FreeChunk> free_chunks_;
- // Used while merging free contiguous chunks to erase free chunks (from their
- // start address) in constant time. Note that multiset<>::{insert,erase}()
- // don't invalidate iterators (except the one for the element being removed
- // obviously).
- hash_map<
- uintptr_t, std::multiset<FreeChunk>::iterator> address_to_free_chunk_map_;
- // Maps the address of *used* chunks to the address of their previous
- // contiguous chunk.
- hash_map<uintptr_t, uintptr_t> used_to_previous_chunk_map_;
-
- DISALLOW_COPY_AND_ASSIGN(AshmemRegion);
-};
-
-DiscardableAshmemChunk::~DiscardableAshmemChunk() {
- if (locked_)
- UnlockAshmemRegion(fd_, offset_, size_);
- ashmem_region_->OnChunkDeletion(reinterpret_cast<uintptr_t>(address_), size_);
-}
-
-bool DiscardableAshmemChunk::Lock() {
- DCHECK(!locked_);
- locked_ = true;
- return LockAshmemRegion(fd_, offset_, size_);
-}
-
-void DiscardableAshmemChunk::Unlock() {
- DCHECK(locked_);
- locked_ = false;
- UnlockAshmemRegion(fd_, offset_, size_);
-}
-
-void* DiscardableAshmemChunk::Memory() const {
- return address_;
-}
-
-// Note that |ashmem_region| must outlive |this|.
-DiscardableAshmemChunk::DiscardableAshmemChunk(AshmemRegion* ashmem_region,
- int fd,
- void* address,
- size_t offset,
- size_t size)
- : ashmem_region_(ashmem_region),
- fd_(fd),
- address_(address),
- offset_(offset),
- size_(size),
- locked_(true) {
-}
-
-DiscardableMemoryAshmemAllocator::DiscardableMemoryAshmemAllocator(
- const std::string& name,
- size_t ashmem_region_size)
- : name_(name),
- ashmem_region_size_(
- std::max(kMinAshmemRegionSize, AlignToNextPage(ashmem_region_size))),
- last_ashmem_region_size_(0) {
- DCHECK_GE(ashmem_region_size_, kMinAshmemRegionSize);
-}
-
-DiscardableMemoryAshmemAllocator::~DiscardableMemoryAshmemAllocator() {
- DCHECK(ashmem_regions_.empty());
-}
-
-scoped_ptr<DiscardableAshmemChunk> DiscardableMemoryAshmemAllocator::Allocate(
- size_t size) {
- const size_t aligned_size = AlignToNextPage(size);
- if (!aligned_size)
- return scoped_ptr<DiscardableAshmemChunk>();
- // TODO(pliard): make this function less naive by e.g. moving the free chunks
- // multiset to the allocator itself in order to decrease even more
- // fragmentation/speedup allocation. Note that there should not be more than a
- // couple (=5) of AshmemRegion instances in practice though.
- AutoLock auto_lock(lock_);
- DCHECK_LE(ashmem_regions_.size(), 5U);
- for (ScopedVector<AshmemRegion>::iterator it = ashmem_regions_.begin();
- it != ashmem_regions_.end(); ++it) {
- scoped_ptr<DiscardableAshmemChunk> memory(
- (*it)->Allocate_Locked(size, aligned_size));
- if (memory)
- return memory.Pass();
- }
- // The creation of the (large) ashmem region might fail if the address space
- // is too fragmented. In case creation fails the allocator retries by
- // repetitively dividing the size by 2.
- const size_t min_region_size = std::max(kMinAshmemRegionSize, aligned_size);
- for (size_t region_size = std::max(ashmem_region_size_, aligned_size);
- region_size >= min_region_size;
- region_size = AlignToNextPage(region_size / 2)) {
- scoped_ptr<AshmemRegion> new_region(
- AshmemRegion::Create(region_size, name_.c_str(), this));
- if (!new_region)
- continue;
- last_ashmem_region_size_ = region_size;
- ashmem_regions_.push_back(new_region.release());
- return ashmem_regions_.back()->Allocate_Locked(size, aligned_size);
- }
- // TODO(pliard): consider adding an histogram to see how often this happens.
- return scoped_ptr<DiscardableAshmemChunk>();
-}
-
-size_t DiscardableMemoryAshmemAllocator::last_ashmem_region_size() const {
- AutoLock auto_lock(lock_);
- return last_ashmem_region_size_;
-}
-
-void DiscardableMemoryAshmemAllocator::DeleteAshmemRegion_Locked(
- AshmemRegion* region) {
- lock_.AssertAcquired();
- // Note that there should not be more than a couple of ashmem region instances
- // in |ashmem_regions_|.
- DCHECK_LE(ashmem_regions_.size(), 5U);
- const ScopedVector<AshmemRegion>::iterator it = std::find(
- ashmem_regions_.begin(), ashmem_regions_.end(), region);
- DCHECK(ashmem_regions_.end() != it);
- std::swap(*it, ashmem_regions_.back());
- ashmem_regions_.pop_back();
-}
-
-} // namespace internal
-} // namespace base
diff --git a/base/memory/discardable_memory_ashmem_allocator.h b/base/memory/discardable_memory_ashmem_allocator.h
deleted file mode 100644
index 996dde9..0000000
--- a/base/memory/discardable_memory_ashmem_allocator.h
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_MEMORY_DISCARDABLE_MEMORY_ASHMEM_ALLOCATOR_H_
-#define BASE_MEMORY_DISCARDABLE_MEMORY_ASHMEM_ALLOCATOR_H_
-
-#include <string>
-
-#include "base/base_export.h"
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_vector.h"
-#include "base/synchronization/lock.h"
-
-namespace base {
-namespace internal {
-
-class AshmemRegion;
-
-// Internal class, whose instances are returned to the client of the allocator
-// (e.g. DiscardableMemoryAshmem), that mimicks the DiscardableMemory interface.
-class BASE_EXPORT_PRIVATE DiscardableAshmemChunk {
- public:
- ~DiscardableAshmemChunk();
-
- // Returns whether the memory is still resident.
- bool Lock();
-
- void Unlock();
-
- void* Memory() const;
-
- private:
- friend class AshmemRegion;
-
- DiscardableAshmemChunk(AshmemRegion* ashmem_region,
- int fd,
- void* address,
- size_t offset,
- size_t size);
-
- AshmemRegion* const ashmem_region_;
- const int fd_;
- void* const address_;
- const size_t offset_;
- const size_t size_;
- bool locked_;
-
- DISALLOW_COPY_AND_ASSIGN(DiscardableAshmemChunk);
-};
-
-// Ashmem regions are backed by a file (descriptor) therefore they are a limited
-// resource. This allocator minimizes the problem by allocating large ashmem
-// regions internally and returning smaller chunks to the client.
-// Allocated chunks are systematically aligned on a page boundary therefore this
-// allocator should not be used for small allocations.
-class BASE_EXPORT_PRIVATE DiscardableMemoryAshmemAllocator {
- public:
- // Note that |name| is only used for debugging/measurement purposes.
- // |ashmem_region_size| is the size that will be used to create the underlying
- // ashmem regions and is expected to be greater or equal than 32 MBytes.
- DiscardableMemoryAshmemAllocator(const std::string& name,
- size_t ashmem_region_size);
-
- ~DiscardableMemoryAshmemAllocator();
-
- // Note that the allocator must outlive the returned DiscardableAshmemChunk
- // instance.
- scoped_ptr<DiscardableAshmemChunk> Allocate(size_t size);
-
- // Returns the size of the last ashmem region which was created. This is used
- // for testing only.
- size_t last_ashmem_region_size() const;
-
- private:
- friend class AshmemRegion;
-
- void DeleteAshmemRegion_Locked(AshmemRegion* region);
-
- const std::string name_;
- const size_t ashmem_region_size_;
- mutable Lock lock_;
- size_t last_ashmem_region_size_;
- ScopedVector<AshmemRegion> ashmem_regions_;
-
- DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryAshmemAllocator);
-};
-
-} // namespace internal
-} // namespace base
-
-#endif // BASE_MEMORY_DISCARDABLE_MEMORY_ASHMEM_ALLOCATOR_H_
diff --git a/base/memory/discardable_memory_ashmem_allocator_unittest.cc b/base/memory/discardable_memory_ashmem_allocator_unittest.cc
deleted file mode 100644
index e9f63ba..0000000
--- a/base/memory/discardable_memory_ashmem_allocator_unittest.cc
+++ /dev/null
@@ -1,319 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/memory/discardable_memory_ashmem_allocator.h"
-
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "base/memory/discardable_memory.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/strings/string_split.h"
-#include "base/strings/stringprintf.h"
-#include "build/build_config.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-namespace internal {
-
-const char kAllocatorName[] = "allocator-for-testing";
-
-const size_t kAshmemRegionSizeForTesting = 32 * 1024 * 1024;
-const size_t kPageSize = 4096;
-
-const size_t kMaxAllowedAllocationSize =
- std::numeric_limits<size_t>::max() - kPageSize + 1;
-
-class DiscardableMemoryAshmemAllocatorTest : public testing::Test {
- protected:
- DiscardableMemoryAshmemAllocatorTest()
- : allocator_(kAllocatorName, kAshmemRegionSizeForTesting) {
- }
-
- DiscardableMemoryAshmemAllocator allocator_;
-};
-
-void WriteToDiscardableAshmemChunk(DiscardableAshmemChunk* memory,
- size_t size) {
- // Write to the first and the last pages only to avoid paging in up to 64
- // MBytes.
- static_cast<char*>(memory->Memory())[0] = 'a';
- static_cast<char*>(memory->Memory())[size - 1] = 'a';
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest, Basic) {
- const size_t size = 128;
- scoped_ptr<DiscardableAshmemChunk> memory(allocator_.Allocate(size));
- ASSERT_TRUE(memory);
- WriteToDiscardableAshmemChunk(memory.get(), size);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest, ZeroAllocationIsNotSupported) {
- scoped_ptr<DiscardableAshmemChunk> memory(allocator_.Allocate(0));
- ASSERT_FALSE(memory);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest, TooLargeAllocationFails) {
- scoped_ptr<DiscardableAshmemChunk> memory(
- allocator_.Allocate(kMaxAllowedAllocationSize + 1));
- // Page-alignment would have caused an overflow resulting in a small
- // allocation if the input size wasn't checked correctly.
- ASSERT_FALSE(memory);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest,
- AshmemRegionsAreNotSmallerThanRequestedSize) {
- // The creation of the underlying ashmem region is expected to fail since
- // there should not be enough room in the address space. When ashmem creation
- // fails, the allocator repetitively retries by dividing the size by 2. This
- // size should not be smaller than the size the user requested so the
- // allocation here should just fail (and not succeed with the minimum ashmem
- // region size).
- scoped_ptr<DiscardableAshmemChunk> memory(
- allocator_.Allocate(kMaxAllowedAllocationSize));
- ASSERT_FALSE(memory);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest,
- AshmemRegionsAreAlwaysPageAligned) {
- // Use a separate allocator here so that we can override the ashmem region
- // size.
- DiscardableMemoryAshmemAllocator allocator(
- kAllocatorName, kMaxAllowedAllocationSize);
- scoped_ptr<DiscardableAshmemChunk> memory(allocator.Allocate(kPageSize));
- ASSERT_TRUE(memory);
- EXPECT_GT(kMaxAllowedAllocationSize, allocator.last_ashmem_region_size());
- ASSERT_TRUE(allocator.last_ashmem_region_size() % kPageSize == 0);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest, LargeAllocation) {
- const size_t size = 64 * 1024 * 1024;
- scoped_ptr<DiscardableAshmemChunk> memory(allocator_.Allocate(size));
- ASSERT_TRUE(memory);
- WriteToDiscardableAshmemChunk(memory.get(), size);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest, ChunksArePageAligned) {
- scoped_ptr<DiscardableAshmemChunk> memory(allocator_.Allocate(kPageSize));
- ASSERT_TRUE(memory);
- EXPECT_EQ(0U, reinterpret_cast<uint64_t>(memory->Memory()) % kPageSize);
- WriteToDiscardableAshmemChunk(memory.get(), kPageSize);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest, AllocateFreeAllocate) {
- scoped_ptr<DiscardableAshmemChunk> memory(allocator_.Allocate(kPageSize));
- // Extra allocation that prevents the region from being deleted when |memory|
- // gets deleted.
- scoped_ptr<DiscardableAshmemChunk> memory_lock(
- allocator_.Allocate(kPageSize));
- ASSERT_TRUE(memory);
- void* const address = memory->Memory();
- memory->Unlock(); // Tests that the reused chunk is being locked correctly.
- memory.reset();
- memory = allocator_.Allocate(kPageSize);
- ASSERT_TRUE(memory);
- // The previously freed chunk should be reused.
- EXPECT_EQ(address, memory->Memory());
- WriteToDiscardableAshmemChunk(memory.get(), kPageSize);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest,
- FreeingWholeAshmemRegionClosesAshmem) {
- scoped_ptr<DiscardableAshmemChunk> memory(allocator_.Allocate(kPageSize));
- ASSERT_TRUE(memory);
- const int kMagic = 0xdeadbeef;
- *static_cast<int*>(memory->Memory()) = kMagic;
- memory.reset();
- // The previous ashmem region should have been closed thus it should not be
- // reused.
- memory = allocator_.Allocate(kPageSize);
- ASSERT_TRUE(memory);
- EXPECT_NE(kMagic, *static_cast<const int*>(memory->Memory()));
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest, AllocateUsesBestFitAlgorithm) {
- scoped_ptr<DiscardableAshmemChunk> memory1(
- allocator_.Allocate(3 * kPageSize));
- ASSERT_TRUE(memory1);
- scoped_ptr<DiscardableAshmemChunk> memory2(
- allocator_.Allocate(2 * kPageSize));
- ASSERT_TRUE(memory2);
- scoped_ptr<DiscardableAshmemChunk> memory3(
- allocator_.Allocate(1 * kPageSize));
- ASSERT_TRUE(memory3);
- void* const address_3 = memory3->Memory();
- memory1.reset();
- // Don't free |memory2| to avoid merging the 3 blocks together.
- memory3.reset();
- memory1 = allocator_.Allocate(1 * kPageSize);
- ASSERT_TRUE(memory1);
- // The chunk whose size is closest to the requested size should be reused.
- EXPECT_EQ(address_3, memory1->Memory());
- WriteToDiscardableAshmemChunk(memory1.get(), kPageSize);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest, MergeFreeChunks) {
- scoped_ptr<DiscardableAshmemChunk> memory1(allocator_.Allocate(kPageSize));
- ASSERT_TRUE(memory1);
- scoped_ptr<DiscardableAshmemChunk> memory2(allocator_.Allocate(kPageSize));
- ASSERT_TRUE(memory2);
- scoped_ptr<DiscardableAshmemChunk> memory3(allocator_.Allocate(kPageSize));
- ASSERT_TRUE(memory3);
- scoped_ptr<DiscardableAshmemChunk> memory4(allocator_.Allocate(kPageSize));
- ASSERT_TRUE(memory4);
- void* const memory1_address = memory1->Memory();
- memory1.reset();
- memory3.reset();
- // Freeing |memory2| (located between memory1 and memory3) should merge the
- // three free blocks together.
- memory2.reset();
- memory1 = allocator_.Allocate(3 * kPageSize);
- EXPECT_EQ(memory1_address, memory1->Memory());
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest, MergeFreeChunksAdvanced) {
- scoped_ptr<DiscardableAshmemChunk> memory1(
- allocator_.Allocate(4 * kPageSize));
- ASSERT_TRUE(memory1);
- scoped_ptr<DiscardableAshmemChunk> memory2(
- allocator_.Allocate(4 * kPageSize));
- ASSERT_TRUE(memory2);
- void* const memory1_address = memory1->Memory();
- memory1.reset();
- memory1 = allocator_.Allocate(2 * kPageSize);
- memory2.reset();
- // At this point, the region should be in this state:
- // 8 KBytes (used), 24 KBytes (free).
- memory2 = allocator_.Allocate(6 * kPageSize);
- EXPECT_EQ(
- static_cast<const char*>(memory2->Memory()),
- static_cast<const char*>(memory1_address) + 2 * kPageSize);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest, MergeFreeChunksAdvanced2) {
- scoped_ptr<DiscardableAshmemChunk> memory1(
- allocator_.Allocate(4 * kPageSize));
- ASSERT_TRUE(memory1);
- scoped_ptr<DiscardableAshmemChunk> memory2(
- allocator_.Allocate(4 * kPageSize));
- ASSERT_TRUE(memory2);
- void* const memory1_address = memory1->Memory();
- memory1.reset();
- memory1 = allocator_.Allocate(2 * kPageSize);
- scoped_ptr<DiscardableAshmemChunk> memory3(
- allocator_.Allocate(2 * kPageSize));
- // At this point, the region should be in this state:
- // 8 KBytes (used), 8 KBytes (used), 16 KBytes (used).
- memory3.reset();
- memory2.reset();
- // At this point, the region should be in this state:
- // 8 KBytes (used), 24 KBytes (free).
- memory2 = allocator_.Allocate(6 * kPageSize);
- EXPECT_EQ(
- static_cast<const char*>(memory2->Memory()),
- static_cast<const char*>(memory1_address) + 2 * kPageSize);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest,
- MergeFreeChunksAndDeleteAshmemRegion) {
- scoped_ptr<DiscardableAshmemChunk> memory1(
- allocator_.Allocate(4 * kPageSize));
- ASSERT_TRUE(memory1);
- scoped_ptr<DiscardableAshmemChunk> memory2(
- allocator_.Allocate(4 * kPageSize));
- ASSERT_TRUE(memory2);
- memory1.reset();
- memory1 = allocator_.Allocate(2 * kPageSize);
- scoped_ptr<DiscardableAshmemChunk> memory3(
- allocator_.Allocate(2 * kPageSize));
- // At this point, the region should be in this state:
- // 8 KBytes (used), 8 KBytes (used), 16 KBytes (used).
- memory1.reset();
- memory3.reset();
- // At this point, the region should be in this state:
- // 8 KBytes (free), 8 KBytes (used), 8 KBytes (free).
- const int kMagic = 0xdeadbeef;
- *static_cast<int*>(memory2->Memory()) = kMagic;
- memory2.reset();
- // The whole region should have been deleted.
- memory2 = allocator_.Allocate(2 * kPageSize);
- EXPECT_NE(kMagic, *static_cast<int*>(memory2->Memory()));
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest,
- TooLargeFreeChunksDontCauseTooMuchFragmentationWhenRecycled) {
- // Keep |memory_1| below allocated so that the ashmem region doesn't get
- // closed when |memory_2| is deleted.
- scoped_ptr<DiscardableAshmemChunk> memory_1(allocator_.Allocate(64 * 1024));
- ASSERT_TRUE(memory_1);
- scoped_ptr<DiscardableAshmemChunk> memory_2(allocator_.Allocate(32 * 1024));
- ASSERT_TRUE(memory_2);
- void* const address = memory_2->Memory();
- memory_2.reset();
- const size_t size = 16 * 1024;
- memory_2 = allocator_.Allocate(size);
- ASSERT_TRUE(memory_2);
- EXPECT_EQ(address, memory_2->Memory());
- WriteToDiscardableAshmemChunk(memory_2.get(), size);
- scoped_ptr<DiscardableAshmemChunk> memory_3(allocator_.Allocate(size));
- // The unused tail (16 KBytes large) of the previously freed chunk should be
- // reused.
- EXPECT_EQ(static_cast<char*>(address) + size, memory_3->Memory());
- WriteToDiscardableAshmemChunk(memory_3.get(), size);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest, UseMultipleAshmemRegions) {
- // Leave one page untouched at the end of the ashmem region.
- const size_t size = kAshmemRegionSizeForTesting - kPageSize;
- scoped_ptr<DiscardableAshmemChunk> memory1(allocator_.Allocate(size));
- ASSERT_TRUE(memory1);
- WriteToDiscardableAshmemChunk(memory1.get(), size);
-
- scoped_ptr<DiscardableAshmemChunk> memory2(
- allocator_.Allocate(kAshmemRegionSizeForTesting));
- ASSERT_TRUE(memory2);
- WriteToDiscardableAshmemChunk(memory2.get(), kAshmemRegionSizeForTesting);
- // The last page of the first ashmem region should be used for this
- // allocation.
- scoped_ptr<DiscardableAshmemChunk> memory3(allocator_.Allocate(kPageSize));
- ASSERT_TRUE(memory3);
- WriteToDiscardableAshmemChunk(memory3.get(), kPageSize);
- EXPECT_EQ(memory3->Memory(), static_cast<char*>(memory1->Memory()) + size);
-}
-
-TEST_F(DiscardableMemoryAshmemAllocatorTest,
- HighestAllocatedChunkPointerIsUpdatedWhenHighestChunkGetsSplit) {
- // Prevents the ashmem region from getting closed when |memory2| gets freed.
- scoped_ptr<DiscardableAshmemChunk> memory1(allocator_.Allocate(kPageSize));
- ASSERT_TRUE(memory1);
-
- scoped_ptr<DiscardableAshmemChunk> memory2(
- allocator_.Allocate(4 * kPageSize));
- ASSERT_TRUE(memory2);
-
- memory2.reset();
- memory2 = allocator_.Allocate(kPageSize);
- // There should now be a free chunk of size 3 * |kPageSize| starting at offset
- // 2 * |kPageSize| and the pointer to the highest allocated chunk should have
- // also been updated to |base_| + 2 * |kPageSize|. This pointer is used to
- // maintain the container mapping a chunk address to its previous chunk and
- // this map is in turn used while merging previous contiguous chunks.
-
- // Allocate more than 3 * |kPageSize| so that the free chunk of size 3 *
- // |kPageSize| is not reused and |highest_allocated_chunk_| gets used instead.
- scoped_ptr<DiscardableAshmemChunk> memory3(
- allocator_.Allocate(4 * kPageSize));
- ASSERT_TRUE(memory3);
-
- // Deleting |memory3| (whose size is 4 * |kPageSize|) should result in a merge
- // with its previous chunk which is the free chunk of size |3 * kPageSize|.
- memory3.reset();
- memory3 = allocator_.Allocate((3 + 4) * kPageSize);
- EXPECT_EQ(memory3->Memory(),
- static_cast<const char*>(memory2->Memory()) + kPageSize);
-}
-
-} // namespace internal
-} // namespace base
diff --git a/base/memory/discardable_memory_emulated.cc b/base/memory/discardable_memory_emulated.cc
deleted file mode 100644
index b12d7ce..0000000
--- a/base/memory/discardable_memory_emulated.cc
+++ /dev/null
@@ -1,112 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/memory/discardable_memory_emulated.h"
-
-#include "base/lazy_instance.h"
-#include "base/memory/discardable_memory_manager.h"
-
-namespace base {
-namespace {
-
-// This is admittedly pretty magical.
-const size_t kEmulatedMemoryLimit = 512 * 1024 * 1024;
-const size_t kEmulatedSoftMemoryLimit = 32 * 1024 * 1024;
-const size_t kEmulatedHardMemoryLimitExpirationTimeMs = 1000;
-
-// internal::DiscardableMemoryManager has an explicit constructor that takes
-// a number of memory limit parameters. The LeakyLazyInstanceTraits doesn't
-// handle the case. Thus, we need our own class here.
-struct DiscardableMemoryManagerLazyInstanceTraits {
- // Leaky as discardable memory clients can use this after the exit handler
- // has been called.
- static const bool kRegisterOnExit = false;
-#ifndef NDEBUG
- static const bool kAllowedToAccessOnNonjoinableThread = true;
-#endif
-
- static internal::DiscardableMemoryManager* New(void* instance) {
- return new (instance) internal::DiscardableMemoryManager(
- kEmulatedMemoryLimit,
- kEmulatedSoftMemoryLimit,
- TimeDelta::FromMilliseconds(kEmulatedHardMemoryLimitExpirationTimeMs));
- }
- static void Delete(internal::DiscardableMemoryManager* instance) {
- instance->~DiscardableMemoryManager();
- }
-};
-
-LazyInstance<internal::DiscardableMemoryManager,
- DiscardableMemoryManagerLazyInstanceTraits>
- g_manager = LAZY_INSTANCE_INITIALIZER;
-
-} // namespace
-
-namespace internal {
-
-DiscardableMemoryEmulated::DiscardableMemoryEmulated(size_t bytes)
- : bytes_(bytes),
- is_locked_(false) {
- g_manager.Pointer()->Register(this, bytes);
-}
-
-DiscardableMemoryEmulated::~DiscardableMemoryEmulated() {
- if (is_locked_)
- Unlock();
- g_manager.Pointer()->Unregister(this);
-}
-
-// static
-bool DiscardableMemoryEmulated::ReduceMemoryUsage() {
- return g_manager.Pointer()->ReduceMemoryUsage();
-}
-
-// static
-void DiscardableMemoryEmulated::ReduceMemoryUsageUntilWithinLimit(
- size_t bytes) {
- g_manager.Pointer()->ReduceMemoryUsageUntilWithinLimit(bytes);
-}
-
-bool DiscardableMemoryEmulated::Initialize() {
- return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
-}
-
-DiscardableMemoryLockStatus DiscardableMemoryEmulated::Lock() {
- DCHECK(!is_locked_);
-
- bool purged = false;
- if (!g_manager.Pointer()->AcquireLock(this, &purged))
- return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
-
- is_locked_ = true;
- return purged ? DISCARDABLE_MEMORY_LOCK_STATUS_PURGED
- : DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS;
-}
-
-void DiscardableMemoryEmulated::Unlock() {
- DCHECK(is_locked_);
- g_manager.Pointer()->ReleaseLock(this);
- is_locked_ = false;
-}
-
-void* DiscardableMemoryEmulated::Memory() const {
- DCHECK(is_locked_);
- DCHECK(memory_);
- return memory_.get();
-}
-
-bool DiscardableMemoryEmulated::AllocateAndAcquireLock() {
- if (memory_)
- return true;
-
- memory_.reset(new uint8[bytes_]);
- return false;
-}
-
-void DiscardableMemoryEmulated::Purge() {
- memory_.reset();
-}
-
-} // namespace internal
-} // namespace base
diff --git a/base/memory/discardable_memory_emulated.h b/base/memory/discardable_memory_emulated.h
deleted file mode 100644
index aa01a9d..0000000
--- a/base/memory/discardable_memory_emulated.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_MEMORY_DISCARDABLE_MEMORY_EMULATED_H_
-#define BASE_MEMORY_DISCARDABLE_MEMORY_EMULATED_H_
-
-#include "base/memory/discardable_memory.h"
-
-#include "base/memory/discardable_memory_manager.h"
-
-namespace base {
-namespace internal {
-
-class DiscardableMemoryEmulated
- : public DiscardableMemory,
- public internal::DiscardableMemoryManagerAllocation {
- public:
- explicit DiscardableMemoryEmulated(size_t bytes);
- ~DiscardableMemoryEmulated() override;
-
- static bool ReduceMemoryUsage();
-
- // TODO(reveman): Remove this as it is breaking the discardable memory design
- // principle that implementations should not rely on information this is
- // unavailable in kernel space. crbug.com/400423
- BASE_EXPORT static void ReduceMemoryUsageUntilWithinLimit(size_t bytes);
-
- bool Initialize();
-
- // Overridden from DiscardableMemory:
- DiscardableMemoryLockStatus Lock() override;
- void Unlock() override;
- void* Memory() const override;
-
- // Overridden from internal::DiscardableMemoryManagerAllocation:
- bool AllocateAndAcquireLock() override;
- void ReleaseLock() override {}
- void Purge() override;
-
- private:
- const size_t bytes_;
- scoped_ptr<uint8[]> memory_;
- bool is_locked_;
-
- DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryEmulated);
-};
-
-} // namespace internal
-} // namespace base
-
-#endif // BASE_MEMORY_DISCARDABLE_MEMORY_EMULATED_H_
diff --git a/base/memory/discardable_memory_linux.cc b/base/memory/discardable_memory_linux.cc
index 670ad7e..b394e07 100644
--- a/base/memory/discardable_memory_linux.cc
+++ b/base/memory/discardable_memory_linux.cc
@@ -5,22 +5,15 @@
#include "base/memory/discardable_memory.h"
#include "base/logging.h"
-#include "base/memory/discardable_memory_emulated.h"
#include "base/memory/discardable_memory_shmem.h"
namespace base {
// static
-bool DiscardableMemory::ReduceMemoryUsage() {
- return internal::DiscardableMemoryEmulated::ReduceMemoryUsage();
-}
-
-// static
void DiscardableMemory::GetSupportedTypes(
std::vector<DiscardableMemoryType>* types) {
const DiscardableMemoryType supported_types[] = {
- DISCARDABLE_MEMORY_TYPE_SHMEM,
- DISCARDABLE_MEMORY_TYPE_EMULATED
+ DISCARDABLE_MEMORY_TYPE_SHMEM
};
types->assign(supported_types, supported_types + arraysize(supported_types));
}
@@ -29,25 +22,9 @@
scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
DiscardableMemoryType type, size_t size) {
switch (type) {
- case DISCARDABLE_MEMORY_TYPE_EMULATED: {
- scoped_ptr<internal::DiscardableMemoryEmulated> memory(
- new internal::DiscardableMemoryEmulated(size));
- if (!memory->Initialize())
- return nullptr;
-
- return memory.Pass();
- }
- case DISCARDABLE_MEMORY_TYPE_SHMEM: {
- scoped_ptr<internal::DiscardableMemoryShmem> memory(
- new internal::DiscardableMemoryShmem(size));
- if (!memory->Initialize())
- return nullptr;
-
- return memory.Pass();
- }
+ case DISCARDABLE_MEMORY_TYPE_SHMEM:
+ return make_scoped_ptr(new internal::DiscardableMemoryShmem(size));
case DISCARDABLE_MEMORY_TYPE_NONE:
- case DISCARDABLE_MEMORY_TYPE_ASHMEM:
- case DISCARDABLE_MEMORY_TYPE_MACH:
NOTREACHED();
return nullptr;
}
diff --git a/base/memory/discardable_memory_mac.cc b/base/memory/discardable_memory_mac.cc
index 2881f5e..d7e6345 100644
--- a/base/memory/discardable_memory_mac.cc
+++ b/base/memory/discardable_memory_mac.cc
@@ -5,26 +5,16 @@
#include "base/memory/discardable_memory.h"
#include "base/logging.h"
-#include "base/memory/discardable_memory_emulated.h"
-#include "base/memory/discardable_memory_mach.h"
-#include "base/memory/discardable_memory_manager.h"
#include "base/memory/discardable_memory_shmem.h"
#include "base/memory/scoped_ptr.h"
namespace base {
// static
-bool DiscardableMemory::ReduceMemoryUsage() {
- return internal::DiscardableMemoryEmulated::ReduceMemoryUsage();
-}
-
-// static
void DiscardableMemory::GetSupportedTypes(
std::vector<DiscardableMemoryType>* types) {
const DiscardableMemoryType supported_types[] = {
- DISCARDABLE_MEMORY_TYPE_SHMEM,
- DISCARDABLE_MEMORY_TYPE_MACH,
- DISCARDABLE_MEMORY_TYPE_EMULATED
+ DISCARDABLE_MEMORY_TYPE_SHMEM
};
types->assign(supported_types, supported_types + arraysize(supported_types));
}
@@ -33,32 +23,9 @@
scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
DiscardableMemoryType type, size_t size) {
switch (type) {
- case DISCARDABLE_MEMORY_TYPE_MACH: {
- scoped_ptr<internal::DiscardableMemoryMach> memory(
- new internal::DiscardableMemoryMach(size));
- if (!memory->Initialize())
- return nullptr;
-
- return memory.Pass();
- }
- case DISCARDABLE_MEMORY_TYPE_EMULATED: {
- scoped_ptr<internal::DiscardableMemoryEmulated> memory(
- new internal::DiscardableMemoryEmulated(size));
- if (!memory->Initialize())
- return nullptr;
-
- return memory.Pass();
- }
- case DISCARDABLE_MEMORY_TYPE_SHMEM: {
- scoped_ptr<internal::DiscardableMemoryShmem> memory(
- new internal::DiscardableMemoryShmem(size));
- if (!memory->Initialize())
- return nullptr;
-
- return memory.Pass();
- }
+ case DISCARDABLE_MEMORY_TYPE_SHMEM:
+ return make_scoped_ptr(new internal::DiscardableMemoryShmem(size));
case DISCARDABLE_MEMORY_TYPE_NONE:
- case DISCARDABLE_MEMORY_TYPE_ASHMEM:
NOTREACHED();
return nullptr;
}
diff --git a/base/memory/discardable_memory_mach.cc b/base/memory/discardable_memory_mach.cc
deleted file mode 100644
index d96de79..0000000
--- a/base/memory/discardable_memory_mach.cc
+++ /dev/null
@@ -1,152 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/memory/discardable_memory_mach.h"
-
-#include <mach/mach.h>
-
-#include "base/basictypes.h"
-#include "base/compiler_specific.h"
-#include "base/lazy_instance.h"
-#include "base/logging.h"
-#include "base/mac/mach_logging.h"
-
-namespace base {
-namespace {
-
-// For Mach, have the DiscardableMemoryManager trigger userspace eviction when
-// address space usage gets too high (e.g. 512 MBytes).
-const size_t kMachMemoryLimit = 512 * 1024 * 1024;
-
-// internal::DiscardableMemoryManager has an explicit constructor that takes
-// a number of memory limit parameters. The LeakyLazyInstanceTraits doesn't
-// handle the case. Thus, we need our own class here.
-struct DiscardableMemoryManagerLazyInstanceTraits {
- // Leaky as discardable memory clients can use this after the exit handler
- // has been called.
- static const bool kRegisterOnExit = false;
-#ifndef NDEBUG
- static const bool kAllowedToAccessOnNonjoinableThread = true;
-#endif
-
- static internal::DiscardableMemoryManager* New(void* instance) {
- return new (instance) internal::DiscardableMemoryManager(
- kMachMemoryLimit, kMachMemoryLimit, TimeDelta::Max());
- }
- static void Delete(internal::DiscardableMemoryManager* instance) {
- instance->~DiscardableMemoryManager();
- }
-};
-
-LazyInstance<internal::DiscardableMemoryManager,
- DiscardableMemoryManagerLazyInstanceTraits>
- g_manager = LAZY_INSTANCE_INITIALIZER;
-
-// The VM subsystem allows tagging of memory and 240-255 is reserved for
-// application use (see mach/vm_statistics.h). Pick 252 (after chromium's atomic
-// weight of ~52).
-const int kDiscardableMemoryTag = VM_MAKE_TAG(252);
-
-} // namespace
-
-namespace internal {
-
-DiscardableMemoryMach::DiscardableMemoryMach(size_t bytes)
- : memory_(0, 0), bytes_(mach_vm_round_page(bytes)), is_locked_(false) {
- g_manager.Pointer()->Register(this, bytes);
-}
-
-DiscardableMemoryMach::~DiscardableMemoryMach() {
- if (is_locked_)
- Unlock();
- g_manager.Pointer()->Unregister(this);
-}
-
-bool DiscardableMemoryMach::Initialize() {
- return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
-}
-
-DiscardableMemoryLockStatus DiscardableMemoryMach::Lock() {
- DCHECK(!is_locked_);
-
- bool purged = false;
- if (!g_manager.Pointer()->AcquireLock(this, &purged))
- return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
-
- is_locked_ = true;
- return purged ? DISCARDABLE_MEMORY_LOCK_STATUS_PURGED
- : DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS;
-}
-
-void DiscardableMemoryMach::Unlock() {
- DCHECK(is_locked_);
- g_manager.Pointer()->ReleaseLock(this);
- is_locked_ = false;
-}
-
-void* DiscardableMemoryMach::Memory() const {
- DCHECK(is_locked_);
- return reinterpret_cast<void*>(memory_.address());
-}
-
-bool DiscardableMemoryMach::AllocateAndAcquireLock() {
- kern_return_t ret;
- bool persistent;
- if (!memory_.size()) {
- vm_address_t address = 0;
- ret = vm_allocate(
- mach_task_self(),
- &address,
- bytes_,
- VM_FLAGS_ANYWHERE | VM_FLAGS_PURGABLE | kDiscardableMemoryTag);
- MACH_CHECK(ret == KERN_SUCCESS, ret) << "vm_allocate";
- memory_.reset(address, bytes_);
-
- // When making a fresh allocation, it's impossible for |persistent| to
- // be true.
- persistent = false;
- } else {
- // |persistent| will be reset to false below if appropriate, but when
- // reusing an existing allocation, it's possible for it to be true.
- persistent = true;
-
-#if !defined(NDEBUG)
- ret = vm_protect(mach_task_self(),
- memory_.address(),
- memory_.size(),
- FALSE,
- VM_PROT_DEFAULT);
- MACH_DCHECK(ret == KERN_SUCCESS, ret) << "vm_protect";
-#endif
- }
-
- int state = VM_PURGABLE_NONVOLATILE;
- ret = vm_purgable_control(
- mach_task_self(), memory_.address(), VM_PURGABLE_SET_STATE, &state);
- MACH_CHECK(ret == KERN_SUCCESS, ret) << "vm_purgable_control";
- if (state & VM_PURGABLE_EMPTY)
- persistent = false;
-
- return persistent;
-}
-
-void DiscardableMemoryMach::ReleaseLock() {
- int state = VM_PURGABLE_VOLATILE | VM_VOLATILE_GROUP_DEFAULT;
- kern_return_t ret = vm_purgable_control(
- mach_task_self(), memory_.address(), VM_PURGABLE_SET_STATE, &state);
- MACH_CHECK(ret == KERN_SUCCESS, ret) << "vm_purgable_control";
-
-#if !defined(NDEBUG)
- ret = vm_protect(
- mach_task_self(), memory_.address(), memory_.size(), FALSE, VM_PROT_NONE);
- MACH_DCHECK(ret == KERN_SUCCESS, ret) << "vm_protect";
-#endif
-}
-
-void DiscardableMemoryMach::Purge() {
- memory_.reset();
-}
-
-} // namespace internal
-} // namespace base
diff --git a/base/memory/discardable_memory_mach.h b/base/memory/discardable_memory_mach.h
deleted file mode 100644
index b3b4b48..0000000
--- a/base/memory/discardable_memory_mach.h
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_MEMORY_DISCARDABLE_MEMORY_MACH_H_
-#define BASE_MEMORY_DISCARDABLE_MEMORY_MACH_H_
-
-#include "base/memory/discardable_memory.h"
-
-#include "base/mac/scoped_mach_vm.h"
-#include "base/memory/discardable_memory_manager.h"
-
-namespace base {
-namespace internal {
-
-class DiscardableMemoryMach
- : public DiscardableMemory,
- public internal::DiscardableMemoryManagerAllocation {
- public:
- explicit DiscardableMemoryMach(size_t bytes);
- ~DiscardableMemoryMach() override;
-
- bool Initialize();
-
- // Overridden from DiscardableMemory:
- DiscardableMemoryLockStatus Lock() override;
- void Unlock() override;
- void* Memory() const override;
-
- // Overridden from internal::DiscardableMemoryManagerAllocation:
- bool AllocateAndAcquireLock() override;
- void ReleaseLock() override;
- void Purge() override;
-
- private:
- mac::ScopedMachVM memory_;
- const size_t bytes_;
- bool is_locked_;
-
- DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryMach);
-};
-
-} // namespace internal
-} // namespace base
-
-#endif // BASE_MEMORY_DISCARDABLE_MEMORY_MACH_H_
diff --git a/base/memory/discardable_memory_manager.cc b/base/memory/discardable_memory_manager.cc
deleted file mode 100644
index cbbdb47..0000000
--- a/base/memory/discardable_memory_manager.cc
+++ /dev/null
@@ -1,218 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/memory/discardable_memory_manager.h"
-
-#include "base/bind.h"
-#include "base/containers/adapters.h"
-#include "base/containers/hash_tables.h"
-#include "base/containers/mru_cache.h"
-#include "base/debug/crash_logging.h"
-#include "base/strings/string_number_conversions.h"
-#include "base/synchronization/lock.h"
-#include "base/trace_event/trace_event.h"
-
-namespace base {
-namespace internal {
-
-DiscardableMemoryManager::DiscardableMemoryManager(
- size_t memory_limit,
- size_t soft_memory_limit,
- TimeDelta hard_memory_limit_expiration_time)
- : allocations_(AllocationMap::NO_AUTO_EVICT),
- bytes_allocated_(0u),
- memory_limit_(memory_limit),
- soft_memory_limit_(soft_memory_limit),
- hard_memory_limit_expiration_time_(hard_memory_limit_expiration_time) {
- BytesAllocatedChanged(bytes_allocated_);
-}
-
-DiscardableMemoryManager::~DiscardableMemoryManager() {
- DCHECK(allocations_.empty());
- DCHECK_EQ(0u, bytes_allocated_);
-}
-
-void DiscardableMemoryManager::SetMemoryLimit(size_t bytes) {
- AutoLock lock(lock_);
- memory_limit_ = bytes;
- PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired(
- Now(), memory_limit_);
-}
-
-void DiscardableMemoryManager::SetSoftMemoryLimit(size_t bytes) {
- AutoLock lock(lock_);
- soft_memory_limit_ = bytes;
-}
-
-void DiscardableMemoryManager::SetHardMemoryLimitExpirationTime(
- TimeDelta hard_memory_limit_expiration_time) {
- AutoLock lock(lock_);
- hard_memory_limit_expiration_time_ = hard_memory_limit_expiration_time;
-}
-
-bool DiscardableMemoryManager::ReduceMemoryUsage() {
- return PurgeIfNotUsedSinceHardLimitCutoffUntilWithinSoftMemoryLimit();
-}
-
-void DiscardableMemoryManager::ReduceMemoryUsageUntilWithinLimit(size_t bytes) {
- AutoLock lock(lock_);
- PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired(Now(),
- bytes);
-}
-
-void DiscardableMemoryManager::Register(Allocation* allocation, size_t bytes) {
- AutoLock lock(lock_);
- DCHECK(allocations_.Peek(allocation) == allocations_.end());
- allocations_.Put(allocation, AllocationInfo(bytes));
-}
-
-void DiscardableMemoryManager::Unregister(Allocation* allocation) {
- AutoLock lock(lock_);
- AllocationMap::iterator it = allocations_.Peek(allocation);
- DCHECK(it != allocations_.end());
- const AllocationInfo& info = it->second;
-
- if (info.purgable) {
- size_t bytes_purgable = info.bytes;
- DCHECK_LE(bytes_purgable, bytes_allocated_);
- bytes_allocated_ -= bytes_purgable;
- BytesAllocatedChanged(bytes_allocated_);
- }
- allocations_.Erase(it);
-}
-
-bool DiscardableMemoryManager::AcquireLock(Allocation* allocation,
- bool* purged) {
- AutoLock lock(lock_);
- // Note: |allocations_| is an MRU cache, and use of |Get| here updates that
- // cache.
- AllocationMap::iterator it = allocations_.Get(allocation);
- DCHECK(it != allocations_.end());
- AllocationInfo* info = &it->second;
-
- if (!info->bytes)
- return false;
-
- TimeTicks now = Now();
- size_t bytes_required = info->purgable ? 0u : info->bytes;
-
- if (memory_limit_) {
- size_t limit = 0;
- if (bytes_required < memory_limit_)
- limit = memory_limit_ - bytes_required;
-
- PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired(now,
- limit);
- }
-
- // Check for overflow.
- if (std::numeric_limits<size_t>::max() - bytes_required < bytes_allocated_)
- return false;
-
- *purged = !allocation->AllocateAndAcquireLock();
- info->purgable = false;
- info->last_usage = now;
- if (bytes_required) {
- bytes_allocated_ += bytes_required;
- BytesAllocatedChanged(bytes_allocated_);
- }
- return true;
-}
-
-void DiscardableMemoryManager::ReleaseLock(Allocation* allocation) {
- AutoLock lock(lock_);
- // Note: |allocations_| is an MRU cache, and use of |Get| here updates that
- // cache.
- AllocationMap::iterator it = allocations_.Get(allocation);
- DCHECK(it != allocations_.end());
- AllocationInfo* info = &it->second;
-
- TimeTicks now = Now();
- allocation->ReleaseLock();
- info->purgable = true;
- info->last_usage = now;
-
- PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired(
- now, memory_limit_);
-}
-
-void DiscardableMemoryManager::PurgeAll() {
- AutoLock lock(lock_);
- PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired(Now(), 0);
-}
-
-bool DiscardableMemoryManager::IsRegisteredForTest(
- Allocation* allocation) const {
- AutoLock lock(lock_);
- AllocationMap::const_iterator it = allocations_.Peek(allocation);
- return it != allocations_.end();
-}
-
-bool DiscardableMemoryManager::CanBePurgedForTest(
- Allocation* allocation) const {
- AutoLock lock(lock_);
- AllocationMap::const_iterator it = allocations_.Peek(allocation);
- return it != allocations_.end() && it->second.purgable;
-}
-
-size_t DiscardableMemoryManager::GetBytesAllocatedForTest() const {
- AutoLock lock(lock_);
- return bytes_allocated_;
-}
-
-bool DiscardableMemoryManager::
- PurgeIfNotUsedSinceHardLimitCutoffUntilWithinSoftMemoryLimit() {
- AutoLock lock(lock_);
-
- PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired(
- Now() - hard_memory_limit_expiration_time_, soft_memory_limit_);
-
- return bytes_allocated_ <= soft_memory_limit_;
-}
-
-void DiscardableMemoryManager::
- PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired(
- TimeTicks timestamp,
- size_t limit) {
- lock_.AssertAcquired();
-
- size_t bytes_allocated_before_purging = bytes_allocated_;
- for (auto& entry : base::Reversed(allocations_)) {
- Allocation* allocation = entry.first;
- AllocationInfo* info = &entry.second;
-
- if (bytes_allocated_ <= limit)
- break;
-
- bool purgable = info->purgable && info->last_usage <= timestamp;
- if (!purgable)
- continue;
-
- size_t bytes_purgable = info->bytes;
- DCHECK_LE(bytes_purgable, bytes_allocated_);
- bytes_allocated_ -= bytes_purgable;
- info->purgable = false;
- allocation->Purge();
- }
-
- if (bytes_allocated_ != bytes_allocated_before_purging)
- BytesAllocatedChanged(bytes_allocated_);
-}
-
-void DiscardableMemoryManager::BytesAllocatedChanged(
- size_t new_bytes_allocated) const {
- TRACE_COUNTER_ID1(
- "base", "DiscardableMemoryUsage", this, new_bytes_allocated);
-
- static const char kDiscardableMemoryUsageKey[] = "dm-usage";
- base::debug::SetCrashKeyValue(kDiscardableMemoryUsageKey,
- Uint64ToString(new_bytes_allocated));
-}
-
-TimeTicks DiscardableMemoryManager::Now() const {
- return TimeTicks::Now();
-}
-
-} // namespace internal
-} // namespace base
diff --git a/base/memory/discardable_memory_manager.h b/base/memory/discardable_memory_manager.h
deleted file mode 100644
index 43737f8..0000000
--- a/base/memory/discardable_memory_manager.h
+++ /dev/null
@@ -1,166 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_MEMORY_DISCARDABLE_MEMORY_MANAGER_H_
-#define BASE_MEMORY_DISCARDABLE_MEMORY_MANAGER_H_
-
-#include "base/base_export.h"
-#include "base/containers/hash_tables.h"
-#include "base/containers/mru_cache.h"
-#include "base/synchronization/lock.h"
-#include "base/time/time.h"
-
-namespace base {
-namespace internal {
-
-// This interface is used by the DiscardableMemoryManager class to provide some
-// level of userspace control over discardable memory allocations.
-class DiscardableMemoryManagerAllocation {
- public:
- // Allocate and acquire a lock that prevents the allocation from being purged
- // by the system. Returns true if memory was previously allocated and is still
- // resident.
- virtual bool AllocateAndAcquireLock() = 0;
-
- // Release a previously acquired lock on the allocation so that it can be
- // purged by the system.
- virtual void ReleaseLock() = 0;
-
- // Explicitly purge this allocation. It is illegal to call this while a lock
- // is acquired on the allocation.
- virtual void Purge() = 0;
-
- protected:
- virtual ~DiscardableMemoryManagerAllocation() {}
-};
-
-} // namespace internal
-} // namespace base
-
-namespace base {
-namespace internal {
-
-// The DiscardableMemoryManager manages a collection of
-// DiscardableMemoryManagerAllocation instances. It is used on platforms that
-// need some level of userspace control over discardable memory. It keeps track
-// of all allocation instances (in case they need to be purged), and the total
-// amount of allocated memory (in case this forces a purge). When memory usage
-// reaches the limit, the manager purges the LRU memory.
-class BASE_EXPORT_PRIVATE DiscardableMemoryManager {
- public:
- typedef DiscardableMemoryManagerAllocation Allocation;
-
- DiscardableMemoryManager(size_t memory_limit,
- size_t soft_memory_limit,
- TimeDelta hard_memory_limit_expiration_time);
- virtual ~DiscardableMemoryManager();
-
- // The maximum number of bytes of memory that may be allocated before we force
- // a purge.
- void SetMemoryLimit(size_t bytes);
-
- // The number of bytes of memory that may be allocated but unused for the hard
- // limit expiration time without getting purged.
- void SetSoftMemoryLimit(size_t bytes);
-
- // Sets the memory usage cutoff time for hard memory limit.
- void SetHardMemoryLimitExpirationTime(
- TimeDelta hard_memory_limit_expiration_time);
-
- // This will attempt to reduce memory footprint until within soft memory
- // limit. Returns true if there's no need to call this again until allocations
- // have been used.
- bool ReduceMemoryUsage();
-
- // This can be called to attempt to reduce memory footprint until within
- // limit for bytes to keep under moderate pressure.
- void ReduceMemoryUsageUntilWithinLimit(size_t bytes);
-
- // Adds the given allocation to the manager's collection.
- void Register(Allocation* allocation, size_t bytes);
-
- // Removes the given allocation from the manager's collection.
- void Unregister(Allocation* allocation);
-
- // Returns false if an error occurred. Otherwise, returns true and sets
- // |purged| to indicate whether or not allocation has been purged since last
- // use.
- bool AcquireLock(Allocation* allocation, bool* purged);
-
- // Release a previously acquired lock on allocation. This allows the manager
- // to purge it if necessary.
- void ReleaseLock(Allocation* allocation);
-
- // Purges all discardable memory.
- void PurgeAll();
-
- // Returns true if allocation has been added to the manager's collection. This
- // should only be used by tests.
- bool IsRegisteredForTest(Allocation* allocation) const;
-
- // Returns true if allocation can be purged. This should only be used by
- // tests.
- bool CanBePurgedForTest(Allocation* allocation) const;
-
- // Returns total amount of allocated discardable memory. This should only be
- // used by tests.
- size_t GetBytesAllocatedForTest() const;
-
- private:
- struct AllocationInfo {
- explicit AllocationInfo(size_t bytes) : bytes(bytes), purgable(false) {}
-
- const size_t bytes;
- bool purgable;
- TimeTicks last_usage;
- };
- typedef HashingMRUCache<Allocation*, AllocationInfo> AllocationMap;
-
- // Purges memory not used since |hard_memory_limit_expiration_time_| before
- // "right now" until usage is less or equal to |soft_memory_limit_|.
- // Returns true if total amount of memory is less or equal to soft memory
- // limit.
- bool PurgeIfNotUsedSinceHardLimitCutoffUntilWithinSoftMemoryLimit();
-
- // Purges memory that has not been used since |timestamp| until usage is less
- // or equal to |limit|.
- // Caller must acquire |lock_| prior to calling this function.
- void PurgeIfNotUsedSinceTimestampUntilUsageIsWithinLimitWithLockAcquired(
- TimeTicks timestamp,
- size_t limit);
-
- // Called when a change to |bytes_allocated_| has been made.
- void BytesAllocatedChanged(size_t new_bytes_allocated) const;
-
- // Virtual for tests.
- virtual TimeTicks Now() const;
-
- // Needs to be held when accessing members.
- mutable Lock lock_;
-
- // A MRU cache of all allocated bits of memory. Used for purging.
- AllocationMap allocations_;
-
- // The total amount of allocated memory.
- size_t bytes_allocated_;
-
- // The maximum number of bytes of memory that may be allocated.
- size_t memory_limit_;
-
- // The number of bytes of memory that may be allocated but not used for
- // |hard_memory_limit_expiration_time_| amount of time when receiving an idle
- // notification.
- size_t soft_memory_limit_;
-
- // Amount of time it takes for an allocation to become affected by
- // |soft_memory_limit_|.
- TimeDelta hard_memory_limit_expiration_time_;
-
- DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryManager);
-};
-
-} // namespace internal
-} // namespace base
-
-#endif // BASE_MEMORY_DISCARDABLE_MEMORY_MANAGER_H_
diff --git a/base/memory/discardable_memory_manager_unittest.cc b/base/memory/discardable_memory_manager_unittest.cc
deleted file mode 100644
index 6717f09..0000000
--- a/base/memory/discardable_memory_manager_unittest.cc
+++ /dev/null
@@ -1,490 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/memory/discardable_memory_manager.h"
-
-#include "base/bind.h"
-#include "base/synchronization/waitable_event.h"
-#include "base/threading/thread.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-namespace {
-
-class TestAllocationImpl : public internal::DiscardableMemoryManagerAllocation {
- public:
- TestAllocationImpl() : is_allocated_(false), is_locked_(false) {}
- ~TestAllocationImpl() override { DCHECK(!is_locked_); }
-
- // Overridden from internal::DiscardableMemoryManagerAllocation:
- bool AllocateAndAcquireLock() override {
- bool was_allocated = is_allocated_;
- is_allocated_ = true;
- DCHECK(!is_locked_);
- is_locked_ = true;
- return was_allocated;
- }
- void ReleaseLock() override {
- DCHECK(is_locked_);
- is_locked_ = false;
- }
- void Purge() override {
- DCHECK(is_allocated_);
- is_allocated_ = false;
- }
-
- bool is_locked() const { return is_locked_; }
-
- private:
- bool is_allocated_;
- bool is_locked_;
-};
-
-// Tests can assume that the default limit is at least 1024. Tests that rely on
-// something else needs to explicit set the limit.
-const size_t kDefaultMemoryLimit = 1024;
-const size_t kDefaultSoftMemoryLimit = kDefaultMemoryLimit;
-
-class TestDiscardableMemoryManagerImpl
- : public internal::DiscardableMemoryManager {
- public:
- TestDiscardableMemoryManagerImpl()
- : DiscardableMemoryManager(kDefaultMemoryLimit,
- kDefaultSoftMemoryLimit,
- TimeDelta::Max()) {}
-
- void SetNow(TimeTicks now) { now_ = now; }
-
- private:
- // Overriden from internal::DiscardableMemoryManager:
- TimeTicks Now() const override { return now_; }
-
- TimeTicks now_;
-};
-
-class DiscardableMemoryManagerTestBase {
- public:
- DiscardableMemoryManagerTestBase() {}
-
- protected:
- enum LockStatus {
- LOCK_STATUS_FAILED,
- LOCK_STATUS_PURGED,
- LOCK_STATUS_SUCCESS
- };
-
- size_t BytesAllocated() const { return manager_.GetBytesAllocatedForTest(); }
-
- void SetMemoryLimit(size_t bytes) { manager_.SetMemoryLimit(bytes); }
-
- void SetSoftMemoryLimit(size_t bytes) { manager_.SetSoftMemoryLimit(bytes); }
-
- void SetHardMemoryLimitExpirationTime(TimeDelta time) {
- manager_.SetHardMemoryLimitExpirationTime(time);
- }
-
- void Register(TestAllocationImpl* allocation, size_t bytes) {
- manager_.Register(allocation, bytes);
- }
-
- void Unregister(TestAllocationImpl* allocation) {
- manager_.Unregister(allocation);
- }
-
- bool IsRegistered(TestAllocationImpl* allocation) const {
- return manager_.IsRegisteredForTest(allocation);
- }
-
- LockStatus Lock(TestAllocationImpl* allocation) {
- bool purged;
- if (!manager_.AcquireLock(allocation, &purged))
- return LOCK_STATUS_FAILED;
- return purged ? LOCK_STATUS_PURGED : LOCK_STATUS_SUCCESS;
- }
-
- void Unlock(TestAllocationImpl* allocation) {
- manager_.ReleaseLock(allocation);
- }
-
- LockStatus RegisterAndLock(TestAllocationImpl* allocation, size_t bytes) {
- manager_.Register(allocation, bytes);
- return Lock(allocation);
- }
-
- bool CanBePurged(TestAllocationImpl* allocation) const {
- return manager_.CanBePurgedForTest(allocation);
- }
-
- void SetNow(TimeTicks now) { manager_.SetNow(now); }
-
- void PurgeAll() { return manager_.PurgeAll(); }
-
- bool ReduceMemoryUsage() { return manager_.ReduceMemoryUsage(); }
-
- void ReduceMemoryUsageUntilWithinLimit(size_t bytes) {
- manager_.ReduceMemoryUsageUntilWithinLimit(bytes);
- }
-
- private:
- TestDiscardableMemoryManagerImpl manager_;
-};
-
-class DiscardableMemoryManagerTest : public DiscardableMemoryManagerTestBase,
- public testing::Test {
- public:
- DiscardableMemoryManagerTest() {}
-};
-
-TEST_F(DiscardableMemoryManagerTest, CreateAndLock) {
- size_t size = 1024;
- TestAllocationImpl allocation;
- Register(&allocation, size);
- EXPECT_TRUE(IsRegistered(&allocation));
- EXPECT_EQ(LOCK_STATUS_PURGED, Lock(&allocation));
- EXPECT_TRUE(allocation.is_locked());
- EXPECT_EQ(1024u, BytesAllocated());
- EXPECT_FALSE(CanBePurged(&allocation));
- Unlock(&allocation);
- Unregister(&allocation);
-}
-
-TEST_F(DiscardableMemoryManagerTest, CreateZeroSize) {
- size_t size = 0;
- TestAllocationImpl allocation;
- Register(&allocation, size);
- EXPECT_TRUE(IsRegistered(&allocation));
- EXPECT_EQ(LOCK_STATUS_FAILED, Lock(&allocation));
- EXPECT_EQ(0u, BytesAllocated());
- Unregister(&allocation);
-}
-
-TEST_F(DiscardableMemoryManagerTest, LockAfterUnlock) {
- size_t size = 1024;
- TestAllocationImpl allocation;
- RegisterAndLock(&allocation, size);
- EXPECT_EQ(1024u, BytesAllocated());
- EXPECT_FALSE(CanBePurged(&allocation));
-
- // Now unlock so we can lock later.
- Unlock(&allocation);
- EXPECT_TRUE(CanBePurged(&allocation));
-
- EXPECT_EQ(LOCK_STATUS_SUCCESS, Lock(&allocation));
- EXPECT_FALSE(CanBePurged(&allocation));
- Unlock(&allocation);
- Unregister(&allocation);
-}
-
-TEST_F(DiscardableMemoryManagerTest, LockAfterPurge) {
- size_t size = 1024;
- TestAllocationImpl allocation;
- RegisterAndLock(&allocation, size);
- EXPECT_EQ(1024u, BytesAllocated());
- EXPECT_FALSE(CanBePurged(&allocation));
-
- // Now unlock so we can lock later.
- Unlock(&allocation);
- EXPECT_TRUE(CanBePurged(&allocation));
-
- // Force the system to purge.
- PurgeAll();
-
- EXPECT_EQ(LOCK_STATUS_PURGED, Lock(&allocation));
- EXPECT_FALSE(CanBePurged(&allocation));
-
- Unlock(&allocation);
- Unregister(&allocation);
-}
-
-TEST_F(DiscardableMemoryManagerTest, LockAfterPurgeAndCannotReallocate) {
- size_t size = 1024;
- TestAllocationImpl allocation;
- RegisterAndLock(&allocation, size);
- EXPECT_EQ(1024u, BytesAllocated());
- EXPECT_FALSE(CanBePurged(&allocation));
-
- // Now unlock so we can lock later.
- Unlock(&allocation);
- EXPECT_TRUE(CanBePurged(&allocation));
-
- // Set max allowed allocation to 1 byte. This will cause the memory to be
- // purged.
- SetMemoryLimit(1);
-
- EXPECT_EQ(LOCK_STATUS_PURGED, Lock(&allocation));
- EXPECT_FALSE(CanBePurged(&allocation));
-
- Unlock(&allocation);
- Unregister(&allocation);
-}
-
-TEST_F(DiscardableMemoryManagerTest, Overflow) {
- size_t size = 1024;
- {
- TestAllocationImpl allocation;
- RegisterAndLock(&allocation, size);
- EXPECT_EQ(1024u, BytesAllocated());
-
- size_t massive_size = std::numeric_limits<size_t>::max();
- TestAllocationImpl massive_allocation;
- Register(&massive_allocation, massive_size);
- EXPECT_EQ(LOCK_STATUS_FAILED, Lock(&massive_allocation));
- EXPECT_EQ(1024u, BytesAllocated());
-
- Unlock(&allocation);
- EXPECT_EQ(LOCK_STATUS_PURGED, Lock(&massive_allocation));
- Unlock(&massive_allocation);
- Unregister(&massive_allocation);
- Unregister(&allocation);
- }
- EXPECT_EQ(0u, BytesAllocated());
-}
-
-class PermutationTestData {
- public:
- PermutationTestData(unsigned d0, unsigned d1, unsigned d2) {
- ordering_[0] = d0;
- ordering_[1] = d1;
- ordering_[2] = d2;
- }
-
- const unsigned* ordering() const { return ordering_; }
-
- private:
- unsigned ordering_[3];
-};
-
-class DiscardableMemoryManagerPermutationTest
- : public DiscardableMemoryManagerTestBase,
- public testing::TestWithParam<PermutationTestData> {
- public:
- DiscardableMemoryManagerPermutationTest() {}
-
- protected:
- // Use memory in order specified by ordering parameter.
- void RegisterAndUseAllocations() {
- for (int i = 0; i < 3; ++i) {
- RegisterAndLock(&allocation_[i], 1024);
- Unlock(&allocation_[i]);
- }
- for (int i = 0; i < 3; ++i) {
- int index = GetParam().ordering()[i];
- EXPECT_NE(LOCK_STATUS_FAILED, Lock(&allocation_[index]));
- // Leave i == 0 locked.
- if (i > 0)
- Unlock(&allocation_[index]);
- }
- }
-
- TestAllocationImpl* allocation(unsigned position) {
- return &allocation_[GetParam().ordering()[position]];
- }
-
- void UnlockAndUnregisterAllocations() {
- for (int i = 0; i < 3; ++i) {
- if (allocation_[i].is_locked())
- Unlock(&allocation_[i]);
- Unregister(&allocation_[i]);
- }
- }
-
- private:
- TestAllocationImpl allocation_[3];
-};
-
-// Verify that memory was discarded in the correct order after reducing usage to
-// limit.
-TEST_P(DiscardableMemoryManagerPermutationTest, LRUDiscarded) {
- RegisterAndUseAllocations();
-
- SetMemoryLimit(2048);
-
- ReduceMemoryUsageUntilWithinLimit(1024);
-
- EXPECT_NE(LOCK_STATUS_FAILED, Lock(allocation(2)));
- EXPECT_EQ(LOCK_STATUS_PURGED, Lock(allocation(1)));
- // 0 should still be locked.
- EXPECT_TRUE(allocation(0)->is_locked());
-
- UnlockAndUnregisterAllocations();
-}
-
-// Verify that memory was discarded in the correct order after changing
-// memory limit.
-TEST_P(DiscardableMemoryManagerPermutationTest, LRUDiscardedExceedLimit) {
- RegisterAndUseAllocations();
-
- SetMemoryLimit(2048);
-
- EXPECT_NE(LOCK_STATUS_FAILED, Lock(allocation(2)));
- EXPECT_EQ(LOCK_STATUS_PURGED, Lock(allocation(1)));
- // 0 should still be locked.
- EXPECT_TRUE(allocation(0)->is_locked());
-
- UnlockAndUnregisterAllocations();
-}
-
-// Verify that no more memory than necessary was discarded after changing
-// memory limit.
-TEST_P(DiscardableMemoryManagerPermutationTest, LRUDiscardedAmount) {
- SetMemoryLimit(4096);
-
- RegisterAndUseAllocations();
-
- SetMemoryLimit(2048);
-
- EXPECT_EQ(LOCK_STATUS_SUCCESS, Lock(allocation(2)));
- EXPECT_EQ(LOCK_STATUS_PURGED, Lock(allocation(1)));
- // 0 should still be locked.
- EXPECT_TRUE(allocation(0)->is_locked());
-
- UnlockAndUnregisterAllocations();
-}
-
-TEST_P(DiscardableMemoryManagerPermutationTest, PurgeFreesAllUnlocked) {
- RegisterAndUseAllocations();
-
- PurgeAll();
-
- for (int i = 0; i < 3; ++i) {
- if (i == 0)
- EXPECT_TRUE(allocation(i)->is_locked());
- else
- EXPECT_EQ(LOCK_STATUS_PURGED, Lock(allocation(i)));
- }
-
- UnlockAndUnregisterAllocations();
-}
-
-INSTANTIATE_TEST_CASE_P(DiscardableMemoryManagerPermutationTests,
- DiscardableMemoryManagerPermutationTest,
- ::testing::Values(PermutationTestData(0, 1, 2),
- PermutationTestData(0, 2, 1),
- PermutationTestData(1, 0, 2),
- PermutationTestData(1, 2, 0),
- PermutationTestData(2, 0, 1),
- PermutationTestData(2, 1, 0)));
-
-TEST_F(DiscardableMemoryManagerTest, NormalDestruction) {
- {
- size_t size = 1024;
- TestAllocationImpl allocation;
- Register(&allocation, size);
- Unregister(&allocation);
- }
- EXPECT_EQ(0u, BytesAllocated());
-}
-
-TEST_F(DiscardableMemoryManagerTest, DestructionAfterLocked) {
- {
- size_t size = 1024;
- TestAllocationImpl allocation;
- RegisterAndLock(&allocation, size);
- EXPECT_EQ(1024u, BytesAllocated());
- EXPECT_FALSE(CanBePurged(&allocation));
- Unlock(&allocation);
- Unregister(&allocation);
- }
- EXPECT_EQ(0u, BytesAllocated());
-}
-
-TEST_F(DiscardableMemoryManagerTest, DestructionAfterPurged) {
- {
- size_t size = 1024;
- TestAllocationImpl allocation;
- RegisterAndLock(&allocation, size);
- EXPECT_EQ(1024u, BytesAllocated());
- Unlock(&allocation);
- EXPECT_TRUE(CanBePurged(&allocation));
- SetMemoryLimit(0);
- EXPECT_EQ(0u, BytesAllocated());
- Unregister(&allocation);
- }
- EXPECT_EQ(0u, BytesAllocated());
-}
-
-TEST_F(DiscardableMemoryManagerTest, ReduceMemoryUsage) {
- SetMemoryLimit(3072);
- SetSoftMemoryLimit(1024);
- SetHardMemoryLimitExpirationTime(TimeDelta::FromInternalValue(1));
-
- size_t size = 1024;
- TestAllocationImpl allocation[3];
- RegisterAndLock(&allocation[0], size);
- RegisterAndLock(&allocation[1], size);
- RegisterAndLock(&allocation[2], size);
- EXPECT_EQ(3072u, BytesAllocated());
-
- // Above soft limit but nothing that can be purged.
- EXPECT_FALSE(ReduceMemoryUsage());
-
- SetNow(TimeTicks::FromInternalValue(0));
- Unlock(&allocation[0]);
-
- // Above soft limit but still nothing that can be purged as all unlocked
- // allocations are within the hard limit cutoff time.
- EXPECT_FALSE(ReduceMemoryUsage());
-
- SetNow(TimeTicks::FromInternalValue(1));
- Unlock(&allocation[1]);
-
- // One unlocked allocation is no longer within the hard limit cutoff time. It
- // should be purged and ReduceMemoryUsage() should return false as we're not
- // yet within the soft memory limit.
- EXPECT_FALSE(ReduceMemoryUsage());
- EXPECT_EQ(2048u, BytesAllocated());
-
- // One more unlocked allocation is no longer within the hard limit cutoff
- // time. It should be purged and ReduceMemoryUsage() should return true as
- // we're now within the soft memory limit.
- SetNow(TimeTicks::FromInternalValue(2));
- EXPECT_TRUE(ReduceMemoryUsage());
- EXPECT_EQ(1024u, BytesAllocated());
-
- Unlock(&allocation[2]);
-
- Unregister(&allocation[0]);
- Unregister(&allocation[1]);
- Unregister(&allocation[2]);
-}
-
-class ThreadedDiscardableMemoryManagerTest
- : public DiscardableMemoryManagerTest {
- public:
- ThreadedDiscardableMemoryManagerTest()
- : memory_usage_thread_("memory_usage_thread"),
- thread_sync_(true, false) {}
-
- void SetUp() override { memory_usage_thread_.Start(); }
-
- void TearDown() override { memory_usage_thread_.Stop(); }
-
- void UseMemoryHelper() {
- size_t size = 1024;
- TestAllocationImpl allocation;
- RegisterAndLock(&allocation, size);
- Unlock(&allocation);
- Unregister(&allocation);
- }
-
- void SignalHelper() { thread_sync_.Signal(); }
-
- Thread memory_usage_thread_;
- WaitableEvent thread_sync_;
-};
-
-TEST_F(ThreadedDiscardableMemoryManagerTest, UseMemoryOnThread) {
- memory_usage_thread_.message_loop()->PostTask(
- FROM_HERE,
- Bind(&ThreadedDiscardableMemoryManagerTest::UseMemoryHelper,
- Unretained(this)));
- memory_usage_thread_.message_loop()->PostTask(
- FROM_HERE,
- Bind(&ThreadedDiscardableMemoryManagerTest::SignalHelper,
- Unretained(this)));
- thread_sync_.Wait();
-}
-
-} // namespace
-} // namespace base
diff --git a/base/memory/discardable_memory_shmem.cc b/base/memory/discardable_memory_shmem.cc
index 9056279..059d84c 100644
--- a/base/memory/discardable_memory_shmem.cc
+++ b/base/memory/discardable_memory_shmem.cc
@@ -11,7 +11,10 @@
namespace internal {
DiscardableMemoryShmem::DiscardableMemoryShmem(size_t bytes)
- : bytes_(bytes), is_locked_(false) {
+ : chunk_(DiscardableMemoryShmemAllocator::GetInstance()
+ ->AllocateLockedDiscardableMemory(bytes)),
+ is_locked_(true) {
+ DCHECK(chunk_);
}
DiscardableMemoryShmem::~DiscardableMemoryShmem() {
@@ -19,37 +22,27 @@
Unlock();
}
-bool DiscardableMemoryShmem::Initialize() {
- return Lock() != DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
-}
-
-DiscardableMemoryLockStatus DiscardableMemoryShmem::Lock() {
+bool DiscardableMemoryShmem::Lock() {
DCHECK(!is_locked_);
+ DCHECK(chunk_);
- if (chunk_ && chunk_->Lock()) {
- is_locked_ = true;
- return DISCARDABLE_MEMORY_LOCK_STATUS_SUCCESS;
+ if (!chunk_->Lock()) {
+ chunk_.reset();
+ return false;
}
- chunk_ = DiscardableMemoryShmemAllocator::GetInstance()
- ->AllocateLockedDiscardableMemory(bytes_);
- if (!chunk_)
- return DISCARDABLE_MEMORY_LOCK_STATUS_FAILED;
-
is_locked_ = true;
- return DISCARDABLE_MEMORY_LOCK_STATUS_PURGED;
+ return true;
}
void DiscardableMemoryShmem::Unlock() {
DCHECK(is_locked_);
- DCHECK(chunk_);
chunk_->Unlock();
is_locked_ = false;
}
void* DiscardableMemoryShmem::Memory() const {
DCHECK(is_locked_);
- DCHECK(chunk_);
return chunk_->Memory();
}
diff --git a/base/memory/discardable_memory_shmem.h b/base/memory/discardable_memory_shmem.h
index 98d3b97..f394562 100644
--- a/base/memory/discardable_memory_shmem.h
+++ b/base/memory/discardable_memory_shmem.h
@@ -20,12 +20,11 @@
bool Initialize();
// Overridden from DiscardableMemory:
- DiscardableMemoryLockStatus Lock() override;
+ bool Lock() override;
void Unlock() override;
void* Memory() const override;
private:
- const size_t bytes_;
scoped_ptr<DiscardableMemoryShmemChunk> chunk_;
bool is_locked_;
diff --git a/base/memory/discardable_memory_unittest.cc b/base/memory/discardable_memory_unittest.cc
index fb1eba6..a769e17 100644
--- a/base/memory/discardable_memory_unittest.cc
+++ b/base/memory/discardable_memory_unittest.cc
@@ -38,8 +38,12 @@
}
bool IsNativeType(DiscardableMemoryType type) {
- return type == DISCARDABLE_MEMORY_TYPE_ASHMEM ||
- type == DISCARDABLE_MEMORY_TYPE_MACH;
+#if defined(OS_ANDROID)
+ // SHMEM is backed by native discardable memory on Android.
+ return type == DISCARDABLE_MEMORY_TYPE_SHMEM;
+#else
+ return false;
+#endif
}
TEST_P(DiscardableMemoryTest, SupportedNatively) {
@@ -65,14 +69,7 @@
const scoped_ptr<DiscardableMemory> memory(CreateLockedMemory(kSize));
ASSERT_TRUE(memory);
void* addr = memory->Memory();
- ASSERT_NE(nullptr, addr);
-
- memory->Unlock();
-
- EXPECT_NE(DISCARDABLE_MEMORY_LOCK_STATUS_FAILED, memory->Lock());
- addr = memory->Memory();
- ASSERT_NE(nullptr, addr);
-
+ EXPECT_NE(nullptr, addr);
memory->Unlock();
}
@@ -107,7 +104,7 @@
memory = CreateLockedMemory(kLargeSize);
ASSERT_TRUE(memory);
void* addr = memory->Memory();
- ASSERT_NE(nullptr, addr);
+ EXPECT_NE(nullptr, addr);
memory->Unlock();
}
}
diff --git a/base/memory/discardable_memory_win.cc b/base/memory/discardable_memory_win.cc
index 670ad7e..b394e07 100644
--- a/base/memory/discardable_memory_win.cc
+++ b/base/memory/discardable_memory_win.cc
@@ -5,22 +5,15 @@
#include "base/memory/discardable_memory.h"
#include "base/logging.h"
-#include "base/memory/discardable_memory_emulated.h"
#include "base/memory/discardable_memory_shmem.h"
namespace base {
// static
-bool DiscardableMemory::ReduceMemoryUsage() {
- return internal::DiscardableMemoryEmulated::ReduceMemoryUsage();
-}
-
-// static
void DiscardableMemory::GetSupportedTypes(
std::vector<DiscardableMemoryType>* types) {
const DiscardableMemoryType supported_types[] = {
- DISCARDABLE_MEMORY_TYPE_SHMEM,
- DISCARDABLE_MEMORY_TYPE_EMULATED
+ DISCARDABLE_MEMORY_TYPE_SHMEM
};
types->assign(supported_types, supported_types + arraysize(supported_types));
}
@@ -29,25 +22,9 @@
scoped_ptr<DiscardableMemory> DiscardableMemory::CreateLockedMemoryWithType(
DiscardableMemoryType type, size_t size) {
switch (type) {
- case DISCARDABLE_MEMORY_TYPE_EMULATED: {
- scoped_ptr<internal::DiscardableMemoryEmulated> memory(
- new internal::DiscardableMemoryEmulated(size));
- if (!memory->Initialize())
- return nullptr;
-
- return memory.Pass();
- }
- case DISCARDABLE_MEMORY_TYPE_SHMEM: {
- scoped_ptr<internal::DiscardableMemoryShmem> memory(
- new internal::DiscardableMemoryShmem(size));
- if (!memory->Initialize())
- return nullptr;
-
- return memory.Pass();
- }
+ case DISCARDABLE_MEMORY_TYPE_SHMEM:
+ return make_scoped_ptr(new internal::DiscardableMemoryShmem(size));
case DISCARDABLE_MEMORY_TYPE_NONE:
- case DISCARDABLE_MEMORY_TYPE_ASHMEM:
- case DISCARDABLE_MEMORY_TYPE_MACH:
NOTREACHED();
return nullptr;
}
diff --git a/base/memory/memory_pressure_listener.h b/base/memory/memory_pressure_listener.h
index f159fb0..6adaeee 100644
--- a/base/memory/memory_pressure_listener.h
+++ b/base/memory/memory_pressure_listener.h
@@ -7,8 +7,8 @@
// The app will try to discard buffers that aren't deemed essential (individual
// modules will implement their own policy).
-#ifndef BASE_MEMORY_PRESSURE_LISTENER_H_
-#define BASE_MEMORY_PRESSURE_LISTENER_H_
+#ifndef BASE_MEMORY_MEMORY_PRESSURE_LISTENER_H_
+#define BASE_MEMORY_MEMORY_PRESSURE_LISTENER_H_
#include "base/base_export.h"
#include "base/basictypes.h"
@@ -82,4 +82,4 @@
} // namespace base
-#endif // BASE_MEMORY_PRESSURE_LISTENER_H_
+#endif // BASE_MEMORY_MEMORY_PRESSURE_LISTENER_H_
diff --git a/base/memory/shared_memory_posix.cc b/base/memory/shared_memory_posix.cc
index fd26ad1..d6c290f 100644
--- a/base/memory/shared_memory_posix.cc
+++ b/base/memory/shared_memory_posix.cc
@@ -16,6 +16,7 @@
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/process/process_metrics.h"
+#include "base/profiler/scoped_tracker.h"
#include "base/safe_strerror_posix.h"
#include "base/strings/utf_string_conversions.h"
#include "base/synchronization/lock.h"
@@ -118,6 +119,11 @@
// In case we want to delete it later, it may be useful to save the value
// of mem_filename after FilePathForMemoryName().
bool SharedMemory::Create(const SharedMemoryCreateOptions& options) {
+ // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466437
+ // is fixed.
+ tracked_objects::ScopedTracker tracking_profile1(
+ FROM_HERE_WITH_EXPLICIT_FUNCTION(
+ "466437 SharedMemory::Create::Start"));
DCHECK_EQ(-1, mapped_file_);
if (options.size == 0) return false;
@@ -140,11 +146,22 @@
// Q: Why not use the shm_open() etc. APIs?
// A: Because they're limited to 4mb on OS X. FFFFFFFUUUUUUUUUUU
FilePath directory;
- if (GetShmemTempDir(options.executable, &directory))
+ if (GetShmemTempDir(options.executable, &directory)) {
+ // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466437
+ // is fixed.
+ tracked_objects::ScopedTracker tracking_profile2(
+ FROM_HERE_WITH_EXPLICIT_FUNCTION(
+ "466437 SharedMemory::Create::OpenTemporaryFile"));
fp.reset(CreateAndOpenTemporaryFileInDir(directory, &path));
+ }
if (fp) {
if (options.share_read_only) {
+ // TODO(erikchen): Remove ScopedTracker below once
+ // http://crbug.com/466437 is fixed.
+ tracked_objects::ScopedTracker tracking_profile3(
+ FROM_HERE_WITH_EXPLICIT_FUNCTION(
+ "466437 SharedMemory::Create::OpenReadonly"));
// Also open as readonly so that we can ShareReadOnlyToProcess.
readonly_fd.reset(HANDLE_EINTR(open(path.value().c_str(), O_RDONLY)));
if (!readonly_fd.is_valid()) {
@@ -153,6 +170,12 @@
return false;
}
}
+
+ // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466437
+ // is fixed.
+ tracked_objects::ScopedTracker tracking_profile4(
+ FROM_HERE_WITH_EXPLICIT_FUNCTION(
+ "466437 SharedMemory::Create::Unlink"));
// Deleting the file prevents anyone else from mapping it in (making it
// private), and prevents the need for cleanup (once the last fd is
// closed, it is truly freed).
@@ -453,7 +476,7 @@
case SHARE_READONLY:
// We could imagine re-opening the file from /dev/fd, but that can't make
// it readonly on Mac: https://codereview.chromium.org/27265002/#msg10
- CHECK(readonly_mapped_file_ >= 0);
+ CHECK_GE(readonly_mapped_file_, 0);
handle_to_dup = readonly_mapped_file_;
break;
}
diff --git a/base/message_loop/message_pump_default.h b/base/message_loop/message_pump_default.h
index d63e810..8aeaa62 100644
--- a/base/message_loop/message_pump_default.h
+++ b/base/message_loop/message_pump_default.h
@@ -38,4 +38,4 @@
} // namespace base
-#endif // BASE__MESSAGE_LOOPMESSAGE_PUMP_DEFAULT_H_
+#endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_DEFAULT_H_
diff --git a/base/message_loop/message_pump_dispatcher.h b/base/message_loop/message_pump_dispatcher.h
index 0dea226..5b1bd55 100644
--- a/base/message_loop/message_pump_dispatcher.h
+++ b/base/message_loop/message_pump_dispatcher.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_DISPATCHER_H
-#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_DISPATCHER_H
+#ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_DISPATCHER_H_
+#define BASE_MESSAGE_LOOP_MESSAGE_PUMP_DISPATCHER_H_
#include <stdint.h>
@@ -40,4 +40,4 @@
} // namespace base
-#endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_DISPATCHER_H
+#endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_DISPATCHER_H_
diff --git a/base/message_loop/message_pump_win.cc b/base/message_loop/message_pump_win.cc
index 5ef3a50..8226495 100644
--- a/base/message_loop/message_pump_win.cc
+++ b/base/message_loop/message_pump_win.cc
@@ -673,7 +673,7 @@
// |IOHandler| is at least pointer-size aligned, so the lowest two bits are
// always cleared. We use the lowest bit to distinguish completion keys with
// and without the associated |IOContext|.
- DCHECK((key & 1) == 0);
+ DCHECK_EQ(key & 1, 0u);
// Mark the completion key as context-less.
if (!has_valid_io_context)
diff --git a/base/metrics/BUILD.gn b/base/metrics/BUILD.gn
new file mode 100644
index 0000000..804e59b
--- /dev/null
+++ b/base/metrics/BUILD.gn
@@ -0,0 +1,49 @@
+# Copyright (c) 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+source_set("metrics") {
+ sources = [
+ "bucket_ranges.cc",
+ "bucket_ranges.h",
+ "field_trial.cc",
+ "field_trial.h",
+ "histogram.cc",
+ "histogram.h",
+ "histogram_base.cc",
+ "histogram_base.h",
+ "histogram_delta_serialization.",
+ "histogram_delta_serialization.cc",
+ "histogram_flattener.h",
+ "histogram_macros.h",
+ "histogram_samples.cc",
+ "histogram_samples.h",
+ "histogram_snapshot_manager.cc",
+ "histogram_snapshot_manager.h",
+ "sample_map.cc",
+ "sample_map.h",
+ "sample_vector.cc",
+ "sample_vector.h",
+ "sparse_histogram.cc",
+ "sparse_histogram.h",
+ "statistics_recorder.cc",
+ "statistics_recorder.h",
+ "user_metrics.cc",
+ "user_metrics.h",
+ "user_metrics_action.h",
+ ]
+
+ if (is_nacl) {
+ sources -= [ "field_trial.cc" ]
+ }
+
+ defines = [ "BASE_IMPLEMENTATION" ]
+
+ deps = [
+ "//base/debug",
+ "//base/json",
+ "//base/memory",
+ ]
+
+ visibility = [ "//base/*" ]
+}
diff --git a/base/numerics/safe_conversions.h b/base/numerics/safe_conversions.h
index fe85fc6..d9b77f7 100644
--- a/base/numerics/safe_conversions.h
+++ b/base/numerics/safe_conversions.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_SAFE_CONVERSIONS_H_
-#define BASE_SAFE_CONVERSIONS_H_
+#ifndef BASE_NUMERICS_SAFE_CONVERSIONS_H_
+#define BASE_NUMERICS_SAFE_CONVERSIONS_H_
#include <limits>
@@ -60,5 +60,4 @@
} // namespace base
-#endif // BASE_SAFE_CONVERSIONS_H_
-
+#endif // BASE_NUMERICS_SAFE_CONVERSIONS_H_
diff --git a/base/numerics/safe_conversions_impl.h b/base/numerics/safe_conversions_impl.h
index c26757a..504ce7e 100644
--- a/base/numerics/safe_conversions_impl.h
+++ b/base/numerics/safe_conversions_impl.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_SAFE_CONVERSIONS_IMPL_H_
-#define BASE_SAFE_CONVERSIONS_IMPL_H_
+#ifndef BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_
+#define BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_
#include <limits>
@@ -212,5 +212,4 @@
} // namespace internal
} // namespace base
-#endif // BASE_SAFE_CONVERSIONS_IMPL_H_
-
+#endif // BASE_NUMERICS_SAFE_CONVERSIONS_IMPL_H_
diff --git a/base/numerics/safe_math.h b/base/numerics/safe_math.h
index ccda1c8..1309446 100644
--- a/base/numerics/safe_math.h
+++ b/base/numerics/safe_math.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_SAFE_MATH_H_
-#define BASE_SAFE_MATH_H_
+#ifndef BASE_NUMERICS_SAFE_MATH_H_
+#define BASE_NUMERICS_SAFE_MATH_H_
#include "base/numerics/safe_math_impl.h"
@@ -269,4 +269,4 @@
} // namespace base
-#endif // BASE_SAFE_MATH_H_
+#endif // BASE_NUMERICS_SAFE_MATH_H_
diff --git a/base/numerics/safe_math_impl.h b/base/numerics/safe_math_impl.h
index 663f393..c845189 100644
--- a/base/numerics/safe_math_impl.h
+++ b/base/numerics/safe_math_impl.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SAFE_MATH_IMPL_H_
-#define SAFE_MATH_IMPL_H_
+#ifndef BASE_NUMERICS_SAFE_MATH_IMPL_H_
+#define BASE_NUMERICS_SAFE_MATH_IMPL_H_
#include <stdint.h>
@@ -498,4 +498,4 @@
} // namespace internal
} // namespace base
-#endif // SAFE_MATH_IMPL_H_
+#endif // BASE_NUMERICS_SAFE_MATH_IMPL_H_
diff --git a/base/observer_list.h b/base/observer_list.h
index ef45269..f7b9267 100644
--- a/base/observer_list.h
+++ b/base/observer_list.h
@@ -79,7 +79,7 @@
// also the FOR_EACH_OBSERVER macro defined below.
class Iterator {
public:
- Iterator(ObserverListBase<ObserverType>& list);
+ explicit Iterator(ObserverListBase<ObserverType>* list);
~Iterator();
ObserverType* GetNext();
@@ -126,12 +126,11 @@
template <class ObserverType>
ObserverListBase<ObserverType>::Iterator::Iterator(
- ObserverListBase<ObserverType>& list)
- : list_(list.AsWeakPtr()),
+ ObserverListBase<ObserverType>* list)
+ : list_(list->AsWeakPtr()),
index_(0),
- max_index_(list.type_ == NOTIFY_ALL ?
- std::numeric_limits<size_t>::max() :
- list.observers_.size()) {
+ max_index_(list->type_ == NOTIFY_ALL ? std::numeric_limits<size_t>::max()
+ : list->observers_.size()) {
++list_->notify_depth_;
}
@@ -228,15 +227,15 @@
}
};
-#define FOR_EACH_OBSERVER(ObserverType, observer_list, func) \
- do { \
- if ((observer_list).might_have_observers()) { \
- ObserverListBase<ObserverType>::Iterator \
- it_inside_observer_macro(observer_list); \
- ObserverType* obs; \
- while ((obs = it_inside_observer_macro.GetNext()) != NULL) \
- obs->func; \
- } \
+#define FOR_EACH_OBSERVER(ObserverType, observer_list, func) \
+ do { \
+ if ((observer_list).might_have_observers()) { \
+ ObserverListBase<ObserverType>::Iterator it_inside_observer_macro( \
+ &observer_list); \
+ ObserverType* obs; \
+ while ((obs = it_inside_observer_macro.GetNext()) != NULL) \
+ obs->func; \
+ } \
} while (0)
#endif // BASE_OBSERVER_LIST_H__
diff --git a/base/observer_list_threadsafe.h b/base/observer_list_threadsafe.h
index 1a663337..46ce880 100644
--- a/base/observer_list_threadsafe.h
+++ b/base/observer_list_threadsafe.h
@@ -199,6 +199,7 @@
scoped_refptr<base::MessageLoopProxy> loop;
ObserverList<ObserverType> list;
+ private:
DISALLOW_COPY_AND_ASSIGN(ObserverListContext);
};
@@ -212,7 +213,6 @@
template <class Method, class Params>
void NotifyWrapper(ObserverListContext* context,
const UnboundMethod<ObserverType, Method, Params>& method) {
-
// Check that this list still needs notifications.
{
base::AutoLock lock(list_lock_);
@@ -228,7 +228,7 @@
}
{
- typename ObserverList<ObserverType>::Iterator it(context->list);
+ typename ObserverList<ObserverType>::Iterator it(&context->list);
ObserverType* obs;
while ((obs = it.GetNext()) != NULL)
method.Run(obs);
diff --git a/base/path_service.cc b/base/path_service.cc
index ce4966e..3c437ee 100644
--- a/base/path_service.cc
+++ b/base/path_service.cc
@@ -33,7 +33,7 @@
// Mac and Android.
bool PathProviderPosix(int key, FilePath* result);
#endif
-}
+} // namespace base
namespace {
diff --git a/base/path_service.h b/base/path_service.h
index 554eb9e..025550f 100644
--- a/base/path_service.h
+++ b/base/path_service.h
@@ -15,7 +15,7 @@
namespace base {
class FilePath;
class ScopedPathOverride;
-} // namespace
+} // namespace base
// The path service is a global table mapping keys to file system paths. It is
// OK to use this service from multiple threads.
diff --git a/base/pending_task.h b/base/pending_task.h
index a2edc69..fddfc86 100644
--- a/base/pending_task.h
+++ b/base/pending_task.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef PENDING_TASK_H_
-#define PENDING_TASK_H_
+#ifndef BASE_PENDING_TASK_H_
+#define BASE_PENDING_TASK_H_
#include <queue>
@@ -57,4 +57,4 @@
} // namespace base
-#endif // PENDING_TASK_H_
+#endif // BASE_PENDING_TASK_H_
diff --git a/base/pickle.cc b/base/pickle.cc
index d461f41..6eb207f 100644
--- a/base/pickle.cc
+++ b/base/pickle.cc
@@ -152,15 +152,15 @@
return true;
}
-bool PickleIterator::ReadWString(std::wstring* result) {
+bool PickleIterator::ReadStringPiece(base::StringPiece* result) {
int len;
if (!ReadInt(&len))
return false;
- const char* read_from = GetReadPointerAndAdvance(len, sizeof(wchar_t));
+ const char* read_from = GetReadPointerAndAdvance(len);
if (!read_from)
return false;
- result->assign(reinterpret_cast<const wchar_t*>(read_from), len);
+ *result = base::StringPiece(read_from, len);
return true;
}
@@ -176,6 +176,19 @@
return true;
}
+bool PickleIterator::ReadStringPiece16(base::StringPiece16* result) {
+ int len;
+ if (!ReadInt(&len))
+ return false;
+ const char* read_from = GetReadPointerAndAdvance(len, sizeof(char16));
+ if (!read_from)
+ return false;
+
+ *result = base::StringPiece16(reinterpret_cast<const char16*>(read_from),
+ len);
+ return true;
+}
+
bool PickleIterator::ReadData(const char** data, int* length) {
*length = 0;
*data = 0;
@@ -271,22 +284,14 @@
return *this;
}
-bool Pickle::WriteString(const std::string& value) {
+bool Pickle::WriteString(const base::StringPiece& value) {
if (!WriteInt(static_cast<int>(value.size())))
return false;
return WriteBytes(value.data(), static_cast<int>(value.size()));
}
-bool Pickle::WriteWString(const std::wstring& value) {
- if (!WriteInt(static_cast<int>(value.size())))
- return false;
-
- return WriteBytes(value.data(),
- static_cast<int>(value.size() * sizeof(wchar_t)));
-}
-
-bool Pickle::WriteString16(const string16& value) {
+bool Pickle::WriteString16(const base::StringPiece16& value) {
if (!WriteInt(static_cast<int>(value.size())))
return false;
diff --git a/base/pickle.h b/base/pickle.h
index f2a198e..e6b9d81 100644
--- a/base/pickle.h
+++ b/base/pickle.h
@@ -13,6 +13,7 @@
#include "base/gtest_prod_util.h"
#include "base/logging.h"
#include "base/strings/string16.h"
+#include "base/strings/string_piece.h"
class Pickle;
@@ -39,8 +40,11 @@
bool ReadFloat(float* result) WARN_UNUSED_RESULT;
bool ReadDouble(double* result) WARN_UNUSED_RESULT;
bool ReadString(std::string* result) WARN_UNUSED_RESULT;
- bool ReadWString(std::wstring* result) WARN_UNUSED_RESULT;
+ // The StringPiece data will only be valid for the lifetime of the message.
+ bool ReadStringPiece(base::StringPiece* result) WARN_UNUSED_RESULT;
bool ReadString16(base::string16* result) WARN_UNUSED_RESULT;
+ // The StringPiece16 data will only be valid for the lifetime of the message.
+ bool ReadStringPiece16(base::StringPiece16* result) WARN_UNUSED_RESULT;
// A pointer to the data will be placed in |*data|, and the length will be
// placed in |*length|. The pointer placed into |*data| points into the
@@ -195,9 +199,8 @@
bool WriteDouble(double value) {
return WritePOD(value);
}
- bool WriteString(const std::string& value);
- bool WriteWString(const std::wstring& value);
- bool WriteString16(const base::string16& value);
+ bool WriteString(const base::StringPiece& value);
+ bool WriteString16(const base::StringPiece16& value);
// "Data" is a blob with a length. When you read it out you will be given the
// length. See also WriteBytes.
bool WriteData(const char* data, int length);
diff --git a/base/pickle_unittest.cc b/base/pickle_unittest.cc
index 1fa1f32..a2c405c 100644
--- a/base/pickle_unittest.cc
+++ b/base/pickle_unittest.cc
@@ -30,10 +30,13 @@
const std::string teststring("Hello world"); // note non-aligned string length
const std::wstring testwstring(L"Hello, world");
const base::string16 teststring16(base::ASCIIToUTF16("Hello, world"));
+const char testrawstring[] = "Hello new world"; // Test raw string writing
+// Test raw char16 writing, assumes UTF16 encoding is ANSI for alpha chars.
+const base::char16 testrawstring16[] = {'A', 'l', 'o', 'h', 'a', 0};
const char testdata[] = "AAA\0BBB\0";
const int testdatalen = arraysize(testdata) - 1;
-// checks that the result
+// checks that the results can be read correctly from the Pickle
void VerifyResult(const Pickle& pickle) {
PickleIterator iter(pickle);
@@ -83,14 +86,18 @@
EXPECT_TRUE(iter.ReadString(&outstring));
EXPECT_EQ(teststring, outstring);
- std::wstring outwstring;
- EXPECT_TRUE(iter.ReadWString(&outwstring));
- EXPECT_EQ(testwstring, outwstring);
-
base::string16 outstring16;
EXPECT_TRUE(iter.ReadString16(&outstring16));
EXPECT_EQ(teststring16, outstring16);
+ base::StringPiece outstringpiece;
+ EXPECT_TRUE(iter.ReadStringPiece(&outstringpiece));
+ EXPECT_EQ(testrawstring, outstringpiece);
+
+ base::StringPiece16 outstringpiece16;
+ EXPECT_TRUE(iter.ReadStringPiece16(&outstringpiece16));
+ EXPECT_EQ(testrawstring16, outstringpiece16);
+
const char* outdata;
int outdatalen;
EXPECT_TRUE(iter.ReadData(&outdata, &outdatalen));
@@ -119,8 +126,9 @@
EXPECT_TRUE(pickle.WriteFloat(testfloat));
EXPECT_TRUE(pickle.WriteDouble(testdouble));
EXPECT_TRUE(pickle.WriteString(teststring));
- EXPECT_TRUE(pickle.WriteWString(testwstring));
EXPECT_TRUE(pickle.WriteString16(teststring16));
+ EXPECT_TRUE(pickle.WriteString(testrawstring));
+ EXPECT_TRUE(pickle.WriteString16(testrawstring16));
EXPECT_TRUE(pickle.WriteData(testdata, testdatalen));
VerifyResult(pickle);
@@ -198,9 +206,9 @@
EXPECT_EQ("", outstr);
}
-TEST(PickleTest, ZeroLenWStr) {
+TEST(PickleTest, ZeroLenStr16) {
Pickle pickle;
- EXPECT_TRUE(pickle.WriteWString(std::wstring()));
+ EXPECT_TRUE(pickle.WriteString16(base::string16()));
PickleIterator iter(pickle);
std::string outstr;
@@ -217,13 +225,13 @@
EXPECT_FALSE(iter.ReadString(&outstr));
}
-TEST(PickleTest, BadLenWStr) {
+TEST(PickleTest, BadLenStr16) {
Pickle pickle;
EXPECT_TRUE(pickle.WriteInt(-1));
PickleIterator iter(pickle);
- std::wstring woutstr;
- EXPECT_FALSE(iter.ReadWString(&woutstr));
+ base::string16 outstr;
+ EXPECT_FALSE(iter.ReadString16(&outstr));
}
TEST(PickleTest, FindNext) {
@@ -391,13 +399,6 @@
EXPECT_TRUE(bad_len.WriteInt(1 << 31));
iter = PickleIterator(bad_len);
EXPECT_FALSE(iter.ReadString16(&str16));
-
- // Check we don't fail in a length check with large WStrings.
- Pickle big_len;
- EXPECT_TRUE(big_len.WriteInt(1 << 30));
- iter = PickleIterator(big_len);
- std::wstring wstr;
- EXPECT_FALSE(iter.ReadWString(&wstr));
}
// Check we can write zero bytes of data and 'data' can be NULL.
diff --git a/base/posix/unix_domain_socket_linux.cc b/base/posix/unix_domain_socket_linux.cc
index 203285b..16d8eaa 100644
--- a/base/posix/unix_domain_socket_linux.cc
+++ b/base/posix/unix_domain_socket_linux.cc
@@ -136,8 +136,8 @@
const unsigned payload_len = cmsg->cmsg_len - CMSG_LEN(0);
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_RIGHTS) {
- DCHECK(payload_len % sizeof(int) == 0);
- DCHECK(wire_fds == NULL);
+ DCHECK_EQ(payload_len % sizeof(int), 0u);
+ DCHECK_EQ(wire_fds, static_cast<void*>(nullptr));
wire_fds = reinterpret_cast<int*>(CMSG_DATA(cmsg));
wire_fds_len = payload_len / sizeof(int);
}
@@ -146,8 +146,8 @@
// SCM_CREDENTIALS.
if (cmsg->cmsg_level == SOL_SOCKET &&
cmsg->cmsg_type == SCM_CREDENTIALS) {
- DCHECK(payload_len == sizeof(struct ucred));
- DCHECK(pid == -1);
+ DCHECK_EQ(payload_len, sizeof(struct ucred));
+ DCHECK_EQ(pid, -1);
pid = reinterpret_cast<struct ucred*>(CMSG_DATA(cmsg))->pid;
}
#endif
diff --git a/base/prefs/base_prefs_switches.cc b/base/prefs/base_prefs_switches.cc
deleted file mode 100644
index 304248b..0000000
--- a/base/prefs/base_prefs_switches.cc
+++ /dev/null
@@ -1,12 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/prefs/base_prefs_switches.h"
-
-namespace switches {
-
-// Pretty-prints pref JSON files.
-const char kPrettyPrintPrefs[] = "pretty-print-prefs";
-
-} // namespace switches
diff --git a/base/prefs/base_prefs_switches.h b/base/prefs/base_prefs_switches.h
deleted file mode 100644
index 7a6b665..0000000
--- a/base/prefs/base_prefs_switches.h
+++ /dev/null
@@ -1,14 +0,0 @@
-// Copyright 2015 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_PREFS_BASE_PREFS_SWITCHES_H_
-#define BASE_PREFS_BASE_PREFS_SWITCHES_H_
-
-namespace switches {
-
-extern const char kPrettyPrintPrefs[];
-
-} // namespace switches
-
-#endif // BASE_PREFS_BASE_PREFS_SWITCHES_H_
diff --git a/base/prefs/json_pref_store.cc b/base/prefs/json_pref_store.cc
index 2e34b50..47cd424 100644
--- a/base/prefs/json_pref_store.cc
+++ b/base/prefs/json_pref_store.cc
@@ -8,14 +8,12 @@
#include "base/bind.h"
#include "base/callback.h"
-#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/json/json_file_value_serializer.h"
#include "base/json/json_string_value_serializer.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram.h"
-#include "base/prefs/base_prefs_switches.h"
#include "base/prefs/pref_filter.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string_util.h"
@@ -400,10 +398,10 @@
pref_filter_->FilterSerializeData(prefs_.get());
JSONStringValueSerializer serializer(output);
- if (base::CommandLine::ForCurrentProcess()->HasSwitch(
- switches::kPrettyPrintPrefs)) {
- serializer.set_pretty_print(true);
- }
+ // Not pretty-printing prefs shrinks pref file size by ~30%. To obtain
+ // readable prefs for debugging purposes, you can dump your prefs into any
+ // command-line or online JSON pretty printing tool.
+ serializer.set_pretty_print(false);
return serializer.Serialize(*prefs_);
}
diff --git a/base/prefs/pref_member.h b/base/prefs/pref_member.h
index b47cae2..078be95 100644
--- a/base/prefs/pref_member.h
+++ b/base/prefs/pref_member.h
@@ -273,6 +273,7 @@
// tree.
mutable ValueType value_;
+ private:
DISALLOW_COPY_AND_ASSIGN(Internal);
};
diff --git a/base/prefs/pref_notifier_impl.cc b/base/prefs/pref_notifier_impl.cc
index 6bf9603..7ae5fe6 100644
--- a/base/prefs/pref_notifier_impl.cc
+++ b/base/prefs/pref_notifier_impl.cc
@@ -22,7 +22,7 @@
// Verify that there are no pref observers when we shut down.
for (PrefObserverMap::iterator it = pref_observers_.begin();
it != pref_observers_.end(); ++it) {
- PrefObserverList::Iterator obs_iterator(*(it->second));
+ PrefObserverList::Iterator obs_iterator(it->second);
if (obs_iterator.GetNext()) {
LOG(WARNING) << "pref observer found at shutdown " << it->first;
}
diff --git a/base/prefs/pref_notifier_impl_unittest.cc b/base/prefs/pref_notifier_impl_unittest.cc
index 0ecf138..c3cbf4f 100644
--- a/base/prefs/pref_notifier_impl_unittest.cc
+++ b/base/prefs/pref_notifier_impl_unittest.cc
@@ -58,7 +58,7 @@
return false;
PrefObserverList* observer_list = observer_iterator->second;
- PrefObserverList::Iterator it(*observer_list);
+ PrefObserverList::Iterator it(observer_list);
PrefObserver* existing_obs;
size_t count = 0;
while ((existing_obs = it.GetNext()) != NULL) {
diff --git a/base/process/BUILD.gn b/base/process/BUILD.gn
new file mode 100644
index 0000000..125b451
--- /dev/null
+++ b/base/process/BUILD.gn
@@ -0,0 +1,107 @@
+# Copyright (c) 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+source_set("process") {
+ sources = [
+ "internal_linux.cc",
+ "internal_linux.h",
+ "kill.cc",
+ "kill.h",
+ "kill_mac.cc",
+ "kill_posix.cc",
+ "kill_win.cc",
+ "launch.cc",
+ "launch.h",
+ "launch_ios.cc",
+ "launch_mac.cc",
+ "launch_posix.cc",
+ "launch_win.cc",
+ "memory.cc",
+ "memory.h",
+ "memory_linux.cc",
+ "memory_mac.mm",
+ "memory_win.cc",
+ "process.h",
+ "process_handle_freebsd.cc",
+ "process_handle_linux.cc",
+ "process_handle_mac.cc",
+ "process_handle_openbsd.cc",
+ "process_handle_posix.cc",
+ "process_handle_win.cc",
+ "process_info.h",
+ "process_info_linux.cc",
+ "process_info_mac.cc",
+ "process_info_win.cc",
+ "process_iterator.cc",
+ "process_iterator.h",
+ "process_iterator_freebsd.cc",
+ "process_iterator_linux.cc",
+ "process_iterator_mac.cc",
+ "process_iterator_openbsd.cc",
+ "process_iterator_win.cc",
+ "process_linux.cc",
+ "process_metrics.cc",
+ "process_metrics.h",
+ "process_metrics_freebsd.cc",
+ "process_metrics_ios.cc",
+ "process_metrics_linux.cc",
+ "process_metrics_mac.cc",
+ "process_metrics_openbsd.cc",
+ "process_metrics_posix.cc",
+ "process_metrics_win.cc",
+ "process_posix.cc",
+ "process_win.cc",
+ ]
+
+ sources -= [
+ "process_handle_freebsd.cc",
+ "process_handle_openbsd.cc",
+ "process_iterator_freebsd.cc",
+ "process_iterator_openbsd.cc",
+ "process_metrics_freebsd.cc",
+ "process_metrics_openbsd.cc",
+ ]
+
+ if (is_android) {
+ # Android uses some Linux sources, put those back.
+ set_sources_assignment_filter([])
+ sources += [
+ "internal_linux.cc",
+ "memory_linux.cc",
+ "process_handle_linux.cc",
+ "process_iterator_linux.cc",
+ "process_metrics_linux.cc",
+ ]
+ set_sources_assignment_filter(sources_assignment_filter)
+ }
+
+ if (is_nacl) {
+ sources -= [
+ "kill.cc",
+ "kill.h",
+ "kill_posix.cc",
+ "launch.cc",
+ "launch.h",
+ "launch_posix.cc",
+ "memory.cc",
+ "memory.h",
+ "process_iterator.cc",
+ "process_iterator.h",
+ "process_metrics.cc",
+ "process_metrics_posix.cc",
+ "process_posix.cc",
+ ]
+ }
+
+ defines = [ "BASE_IMPLEMENTATION" ]
+
+ deps = [
+ "//base/memory",
+ "//base/third_party/dynamic_annotations",
+ ]
+
+ allow_circular_includes_from = [ "//base/memory" ]
+
+ visibility = [ "//base/*" ]
+}
diff --git a/base/process/internal_linux.h b/base/process/internal_linux.h
index 5fc3356..1837f94 100644
--- a/base/process/internal_linux.h
+++ b/base/process/internal_linux.h
@@ -5,8 +5,8 @@
// This file contains internal routines that are called by other files in
// base/process/.
-#ifndef BASE_PROCESS_LINUX_INTERNAL_H_
-#define BASE_PROCESS_LINUX_INTERNAL_H_
+#ifndef BASE_PROCESS_INTERNAL_LINUX_H_
+#define BASE_PROCESS_INTERNAL_LINUX_H_
#include <unistd.h>
@@ -87,4 +87,4 @@
} // namespace internal
} // namespace base
-#endif // BASE_PROCESS_LINUX_INTERNAL_H_
+#endif // BASE_PROCESS_INTERNAL_LINUX_H_
diff --git a/base/process/kill_mac.cc b/base/process/kill_mac.cc
index 8c42400..a4e0a14 100644
--- a/base/process/kill_mac.cc
+++ b/base/process/kill_mac.cc
@@ -66,8 +66,8 @@
// work in that case, but waitpid won't, and killing a non-child might not be
// the best approach.
void WaitForChildToDie(pid_t child, int timeout) {
- DCHECK(child > 0);
- DCHECK(timeout > 0);
+ DCHECK_GT(child, 0);
+ DCHECK_GT(timeout, 0);
// DON'T ADD ANY EARLY RETURNS TO THIS FUNCTION without ensuring that
// |child| has been reaped. Specifically, even if a kqueue, kevent, or other
diff --git a/base/process/memory.cc b/base/process/memory.cc
index 1dbc363..8542dc5 100644
--- a/base/process/memory.cc
+++ b/base/process/memory.cc
@@ -27,4 +27,4 @@
#endif
-}
+} // namespace base
diff --git a/base/process/process.h b/base/process/process.h
index a834a29..41eef10 100644
--- a/base/process/process.h
+++ b/base/process/process.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_PROCESS_PROCESS_PROCESS_H_
-#define BASE_PROCESS_PROCESS_PROCESS_H_
+#ifndef BASE_PROCESS_PROCESS_H_
+#define BASE_PROCESS_PROCESS_H_
#include "base/base_export.h"
#include "base/basictypes.h"
@@ -92,9 +92,11 @@
void Close();
// Terminates the process with extreme prejudice. The given |result_code| will
- // be the exit code of the process.
+ // be the exit code of the process. If |wait| is true, this method will wait
+ // for up to one minute for the process to actually terminate.
+ // Returns true if the process terminates within the allowed time.
// NOTE: On POSIX |result_code| is ignored.
- void Terminate(int result_code);
+ bool Terminate(int result_code, bool wait) const;
// Waits for the process to exit. Returns true on success.
// On POSIX, if the process has been signaled then |exit_code| is set to -1.
@@ -130,4 +132,4 @@
} // namespace base
-#endif // BASE_PROCESS_PROCESS_PROCESS_H_
+#endif // BASE_PROCESS_PROCESS_H_
diff --git a/base/process/process_linux.cc b/base/process/process_linux.cc
index 59ee288..88a310e 100644
--- a/base/process/process_linux.cc
+++ b/base/process/process_linux.cc
@@ -103,7 +103,7 @@
&proc)) {
std::vector<std::string> proc_parts;
base::SplitString(proc, ':', &proc_parts);
- DCHECK(proc_parts.size() == 3);
+ DCHECK_EQ(proc_parts.size(), 3u);
bool ret = proc_parts[2] == std::string(kBackground);
return ret;
} else {
diff --git a/base/process/process_metrics_unittest.cc b/base/process/process_metrics_unittest.cc
index dbfaa1a..76767b0 100644
--- a/base/process/process_metrics_unittest.cc
+++ b/base/process/process_metrics_unittest.cc
@@ -143,29 +143,29 @@
"Hugepagesize: 4096 kB\n";
EXPECT_TRUE(ParseProcMeminfo(valid_input1, &meminfo));
- EXPECT_TRUE(meminfo.total == 3981504);
- EXPECT_TRUE(meminfo.free == 140764);
- EXPECT_TRUE(meminfo.buffers == 116480);
- EXPECT_TRUE(meminfo.cached == 406160);
- EXPECT_TRUE(meminfo.active_anon == 2972352);
- EXPECT_TRUE(meminfo.active_file == 179688);
- EXPECT_TRUE(meminfo.inactive_anon == 270108);
- EXPECT_TRUE(meminfo.inactive_file == 202748);
- EXPECT_TRUE(meminfo.swap_total == 5832280);
- EXPECT_TRUE(meminfo.swap_free == 3672368);
- EXPECT_TRUE(meminfo.dirty == 184);
+ EXPECT_EQ(meminfo.total, 3981504);
+ EXPECT_EQ(meminfo.free, 140764);
+ EXPECT_EQ(meminfo.buffers, 116480);
+ EXPECT_EQ(meminfo.cached, 406160);
+ EXPECT_EQ(meminfo.active_anon, 2972352);
+ EXPECT_EQ(meminfo.active_file, 179688);
+ EXPECT_EQ(meminfo.inactive_anon, 270108);
+ EXPECT_EQ(meminfo.inactive_file, 202748);
+ EXPECT_EQ(meminfo.swap_total, 5832280);
+ EXPECT_EQ(meminfo.swap_free, 3672368);
+ EXPECT_EQ(meminfo.dirty, 184);
#if defined(OS_CHROMEOS)
- EXPECT_TRUE(meminfo.shmem == 140204);
- EXPECT_TRUE(meminfo.slab == 54212);
+ EXPECT_EQ(meminfo.shmem, 140204);
+ EXPECT_EQ(meminfo.slab, 54212);
#endif
EXPECT_TRUE(ParseProcMeminfo(valid_input2, &meminfo));
- EXPECT_TRUE(meminfo.total == 255908);
- EXPECT_TRUE(meminfo.free == 69936);
- EXPECT_TRUE(meminfo.buffers == 15812);
- EXPECT_TRUE(meminfo.cached == 115124);
- EXPECT_TRUE(meminfo.swap_total == 524280);
- EXPECT_TRUE(meminfo.swap_free == 524200);
- EXPECT_TRUE(meminfo.dirty == 4);
+ EXPECT_EQ(meminfo.total, 255908);
+ EXPECT_EQ(meminfo.free, 69936);
+ EXPECT_EQ(meminfo.buffers, 15812);
+ EXPECT_EQ(meminfo.cached, 115124);
+ EXPECT_EQ(meminfo.swap_total, 524280);
+ EXPECT_EQ(meminfo.swap_free, 524200);
+ EXPECT_EQ(meminfo.dirty, 4);
}
TEST_F(SystemMetricsTest, ParseVmstat) {
@@ -260,13 +260,13 @@
"pgrefill_high 0\n"
"pgrefill_movable 0\n";
EXPECT_TRUE(ParseProcVmstat(valid_input1, &meminfo));
- EXPECT_TRUE(meminfo.pswpin == 179);
- EXPECT_TRUE(meminfo.pswpout == 406);
- EXPECT_TRUE(meminfo.pgmajfault == 487192);
+ EXPECT_EQ(meminfo.pswpin, 179);
+ EXPECT_EQ(meminfo.pswpout, 406);
+ EXPECT_EQ(meminfo.pgmajfault, 487192);
EXPECT_TRUE(ParseProcVmstat(valid_input2, &meminfo));
- EXPECT_TRUE(meminfo.pswpin == 12);
- EXPECT_TRUE(meminfo.pswpout == 901);
- EXPECT_TRUE(meminfo.pgmajfault == 2023);
+ EXPECT_EQ(meminfo.pswpin, 12);
+ EXPECT_EQ(meminfo.pswpout, 901);
+ EXPECT_EQ(meminfo.pgmajfault, 2023);
}
#endif // defined(OS_LINUX) || defined(OS_ANDROID)
diff --git a/base/process/process_posix.cc b/base/process/process_posix.cc
index a36bf77..1c4210b 100644
--- a/base/process/process_posix.cc
+++ b/base/process/process_posix.cc
@@ -287,12 +287,13 @@
// end up w/ a zombie when it does finally exit.
}
-void Process::Terminate(int result_code) {
+bool Process::Terminate(int result_code, bool wait) const {
// result_code isn't supportable.
DCHECK(IsValid());
// We don't wait here. It's the responsibility of other code to reap the
// child.
- KillProcess(process_, result_code, false);
+ // TODO(rvargas) crbug/417532: Move the implementation here.
+ return KillProcess(process_, result_code, wait);
}
bool Process::WaitForExit(int* exit_code) {
@@ -324,4 +325,4 @@
return getpriority(PRIO_PROCESS, process_);
}
-} // namspace base
+} // namespace base
diff --git a/base/process/process_unittest.cc b/base/process/process_unittest.cc
index 535a36f..ba8e4e6 100644
--- a/base/process/process_unittest.cc
+++ b/base/process/process_unittest.cc
@@ -123,7 +123,7 @@
exit_code = kDummyExitCode;
int kExpectedExitCode = 250;
- process.Terminate(kExpectedExitCode);
+ process.Terminate(kExpectedExitCode, false);
process.WaitForExitWithTimeout(TestTimeouts::action_max_timeout(),
&exit_code);
@@ -160,7 +160,7 @@
EXPECT_FALSE(process.WaitForExitWithTimeout(timeout, &exit_code));
EXPECT_EQ(kDummyExitCode, exit_code);
- process.Terminate(kDummyExitCode);
+ process.Terminate(kDummyExitCode, false);
}
// Ensure that the priority of a process is restored correctly after
diff --git a/base/process/process_win.cc b/base/process/process_win.cc
index b62fdb4..32da8ab 100644
--- a/base/process/process_win.cc
+++ b/base/process/process_win.cc
@@ -123,17 +123,10 @@
process_.Close();
}
-void Process::Terminate(int result_code) {
+bool Process::Terminate(int result_code, bool wait) const {
DCHECK(IsValid());
-
- // Call NtTerminateProcess directly, without going through the import table,
- // which might have been hooked with a buggy replacement by third party
- // software. http://crbug.com/81449.
- HMODULE module = GetModuleHandle(L"ntdll.dll");
- typedef UINT (WINAPI *TerminateProcessPtr)(HANDLE handle, UINT code);
- TerminateProcessPtr terminate_process = reinterpret_cast<TerminateProcessPtr>(
- GetProcAddress(module, "NtTerminateProcess"));
- terminate_process(Handle(), result_code);
+ // TODO(rvargas) crbug/417532: Move the implementation here.
+ return KillProcess(Handle(), result_code, wait);
}
bool Process::WaitForExit(int* exit_code) {
diff --git a/base/scoped_generic.h b/base/scoped_generic.h
index da42609..f6807e2 100644
--- a/base/scoped_generic.h
+++ b/base/scoped_generic.h
@@ -53,7 +53,7 @@
// typedef ScopedGeneric<int, FooScopedTraits> ScopedFoo;
template<typename T, typename Traits>
class ScopedGeneric {
- MOVE_ONLY_TYPE_FOR_CPP_03(ScopedGeneric, RValue)
+ MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedGeneric)
private:
// This must be first since it's used inline below.
@@ -83,15 +83,21 @@
: data_(value, traits) {
}
- // Move constructor for C++03 move emulation.
- ScopedGeneric(RValue rvalue)
- : data_(rvalue.object->release(), rvalue.object->get_traits()) {
+ // Move constructor. Allows initialization from a ScopedGeneric rvalue.
+ ScopedGeneric(ScopedGeneric<T, Traits>&& rvalue)
+ : data_(rvalue.release(), rvalue.get_traits()) {
}
~ScopedGeneric() {
FreeIfNecessary();
}
+ // operator=. Allows assignment from a ScopedGeneric rvalue.
+ ScopedGeneric& operator=(ScopedGeneric<T, Traits>&& rvalue) {
+ reset(rvalue.release());
+ return *this;
+ }
+
// Frees the currently owned object, if any. Then takes ownership of a new
// object, if given. Self-resets are not allowd as on scoped_ptr. See
// http://crbug.com/162971
diff --git a/base/scoped_generic_unittest.cc b/base/scoped_generic_unittest.cc
index f0dca22..b28e154 100644
--- a/base/scoped_generic_unittest.cc
+++ b/base/scoped_generic_unittest.cc
@@ -85,7 +85,7 @@
EXPECT_EQ(kSecond, values_freed[1]);
values_freed.clear();
- // Pass.
+ // Pass constructor.
{
ScopedInt a(kFirst, traits);
ScopedInt b(a.Pass());
@@ -93,8 +93,25 @@
ASSERT_EQ(IntTraits::InvalidValue(), a.get());
ASSERT_EQ(kFirst, b.get());
}
+
ASSERT_EQ(1u, values_freed.size());
ASSERT_EQ(kFirst, values_freed[0]);
+ values_freed.clear();
+
+ // Pass assign.
+ {
+ ScopedInt a(kFirst, traits);
+ ScopedInt b(kSecond, traits);
+ b = a.Pass();
+ ASSERT_EQ(1u, values_freed.size());
+ EXPECT_EQ(kSecond, values_freed[0]);
+ ASSERT_EQ(IntTraits::InvalidValue(), a.get());
+ ASSERT_EQ(kFirst, b.get());
+ }
+
+ ASSERT_EQ(2u, values_freed.size());
+ EXPECT_EQ(kFirst, values_freed[1]);
+ values_freed.clear();
}
TEST(ScopedGenericTest, Operators) {
diff --git a/base/scoped_native_library.h b/base/scoped_native_library.h
index e9923f4..c0e93f3 100644
--- a/base/scoped_native_library.h
+++ b/base/scoped_native_library.h
@@ -49,4 +49,4 @@
} // namespace base
-#endif // BASE_MEMORY_NATIVE_LIBRARY_H_
+#endif // BASE_SCOPED_NATIVE_LIBRARY_H_
diff --git a/base/sequenced_task_runner.h b/base/sequenced_task_runner.h
index 71dcf05..6bb3f2b 100644
--- a/base/sequenced_task_runner.h
+++ b/base/sequenced_task_runner.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_SEQUENCED_TASKRUNNER_H_
-#define BASE_SEQUENCED_TASKRUNNER_H_
+#ifndef BASE_SEQUENCED_TASK_RUNNER_H_
+#define BASE_SEQUENCED_TASK_RUNNER_H_
#include "base/base_export.h"
#include "base/sequenced_task_runner_helpers.h"
@@ -156,4 +156,4 @@
} // namespace base
-#endif // BASE_SEQUENCED_TASKRUNNER_H_
+#endif // BASE_SEQUENCED_TASK_RUNNER_H_
diff --git a/base/stl_util_unittest.cc b/base/stl_util_unittest.cc
index 06ea7cd..42004eb 100644
--- a/base/stl_util_unittest.cc
+++ b/base/stl_util_unittest.cc
@@ -28,7 +28,7 @@
int value_;
};
-}
+} // namespace
namespace base {
namespace {
diff --git a/base/strings/nullable_string16.h b/base/strings/nullable_string16.h
index 5997d17..016c25c 100644
--- a/base/strings/nullable_string16.h
+++ b/base/strings/nullable_string16.h
@@ -41,6 +41,6 @@
BASE_EXPORT std::ostream& operator<<(std::ostream& out,
const NullableString16& value);
-} // namespace
+} // namespace base
#endif // BASE_STRINGS_NULLABLE_STRING16_H_
diff --git a/base/strings/string_piece_unittest.cc b/base/strings/string_piece_unittest.cc
index 7f50cfb..5336603 100644
--- a/base/strings/string_piece_unittest.cc
+++ b/base/strings/string_piece_unittest.cc
@@ -602,13 +602,13 @@
// check comparison operations on strings longer than 4 bytes.
ASSERT_TRUE(abc == BasicStringPiece<TypeParam>(alphabet));
- ASSERT_TRUE(abc.compare(BasicStringPiece<TypeParam>(alphabet)) == 0);
+ ASSERT_EQ(abc.compare(BasicStringPiece<TypeParam>(alphabet)), 0);
ASSERT_TRUE(abc < BasicStringPiece<TypeParam>(alphabet_z));
- ASSERT_TRUE(abc.compare(BasicStringPiece<TypeParam>(alphabet_z)) < 0);
+ ASSERT_LT(abc.compare(BasicStringPiece<TypeParam>(alphabet_z)), 0);
ASSERT_TRUE(abc > BasicStringPiece<TypeParam>(alphabet_y));
- ASSERT_TRUE(abc.compare(BasicStringPiece<TypeParam>(alphabet_y)) > 0);
+ ASSERT_GT(abc.compare(BasicStringPiece<TypeParam>(alphabet_y)), 0);
}
// Test operations only supported by std::string version.
diff --git a/base/strings/string_split.cc b/base/strings/string_split.cc
index 7ef4760..692f300 100644
--- a/base/strings/string_split.cc
+++ b/base/strings/string_split.cc
@@ -138,9 +138,9 @@
char c,
std::vector<std::string>* r) {
#if CHAR_MIN < 0
- DCHECK(c >= 0);
+ DCHECK_GE(c, 0);
#endif
- DCHECK(c < 0x7F);
+ DCHECK_LT(c, 0x7F);
SplitStringT(str, c, true, r);
}
@@ -195,9 +195,9 @@
std::vector<std::string>* r) {
DCHECK(IsStringUTF8(str));
#if CHAR_MIN < 0
- DCHECK(c >= 0);
+ DCHECK_GE(c, 0);
#endif
- DCHECK(c < 0x7F);
+ DCHECK_LT(c, 0x7F);
SplitStringT(str, c, false, r);
}
diff --git a/base/strings/sys_string_conversions_unittest.cc b/base/strings/sys_string_conversions_unittest.cc
index d2d38e4..0cdd428 100644
--- a/base/strings/sys_string_conversions_unittest.cc
+++ b/base/strings/sys_string_conversions_unittest.cc
@@ -75,7 +75,9 @@
#if defined(OS_LINUX) // Tests depend on setting a specific Linux locale.
TEST(SysStrings, SysWideToNativeMB) {
+#if !defined(SYSTEM_NATIVE_UTF8)
ScopedLocale locale("en_US.utf-8");
+#endif
EXPECT_EQ("Hello, world", SysWideToNativeMB(L"Hello, world"));
EXPECT_EQ("\xe4\xbd\xa0\xe5\xa5\xbd", SysWideToNativeMB(L"\x4f60\x597d"));
@@ -105,7 +107,9 @@
// We assume the test is running in a UTF8 locale.
TEST(SysStrings, SysNativeMBToWide) {
+#if !defined(SYSTEM_NATIVE_UTF8)
ScopedLocale locale("en_US.utf-8");
+#endif
EXPECT_EQ(L"Hello, world", SysNativeMBToWide("Hello, world"));
EXPECT_EQ(L"\x4f60\x597d", SysNativeMBToWide("\xe4\xbd\xa0\xe5\xa5\xbd"));
// >16 bits
@@ -159,7 +163,9 @@
TEST(SysStrings, SysNativeMBAndWide) {
+#if !defined(SYSTEM_NATIVE_UTF8)
ScopedLocale locale("en_US.utf-8");
+#endif
for (size_t i = 0; i < arraysize(kConvertRoundtripCases); ++i) {
std::wstring wide = kConvertRoundtripCases[i];
std::wstring trip = SysNativeMBToWide(SysWideToNativeMB(wide));
diff --git a/base/strings/utf_offset_string_conversions_unittest.cc b/base/strings/utf_offset_string_conversions_unittest.cc
index 529939f..9398a56 100644
--- a/base/strings/utf_offset_string_conversions_unittest.cc
+++ b/base/strings/utf_offset_string_conversions_unittest.cc
@@ -293,4 +293,4 @@
EXPECT_EQ(2u, adjustments_on_adjusted_string[5].output_length);
}
-} // namaspace base
+} // namespace base
diff --git a/base/strings/utf_string_conversions_unittest.cc b/base/strings/utf_string_conversions_unittest.cc
index 009af7c..a7b12ff 100644
--- a/base/strings/utf_string_conversions_unittest.cc
+++ b/base/strings/utf_string_conversions_unittest.cc
@@ -208,4 +208,4 @@
EXPECT_EQ(expected, converted);
}
-} // base
+} // namespace base
diff --git a/base/sys_info_android.cc b/base/sys_info_android.cc
index b62aed9..245097f 100644
--- a/base/sys_info_android.cc
+++ b/base/sys_info_android.cc
@@ -60,7 +60,7 @@
// version to avoid unnecessarily comparison errors with the latest release.
// This should be manually kept up-to-date on each Android release.
const int kDefaultAndroidMajorVersion = 5;
-const int kDefaultAndroidMinorVersion = 0;
+const int kDefaultAndroidMinorVersion = 1;
const int kDefaultAndroidBugfixVersion = 99;
// Parse out the OS version numbers from the system properties.
diff --git a/base/sys_info_linux.cc b/base/sys_info_linux.cc
index 2e679ed..c698f91 100644
--- a/base/sys_info_linux.cc
+++ b/base/sys_info_linux.cc
@@ -43,7 +43,7 @@
if (limit > std::numeric_limits<size_t>::max()) {
limit = 0;
}
- DCHECK(limit > 0);
+ DCHECK_GT(limit, 0u);
return static_cast<size_t>(limit);
}
diff --git a/base/system_monitor/system_monitor_unittest.cc b/base/system_monitor/system_monitor_unittest.cc
index d63bc3d..f3db4c7 100644
--- a/base/system_monitor/system_monitor_unittest.cc
+++ b/base/system_monitor/system_monitor_unittest.cc
@@ -23,6 +23,7 @@
MessageLoop message_loop_;
scoped_ptr<SystemMonitor> system_monitor_;
+ private:
DISALLOW_COPY_AND_ASSIGN(SystemMonitorTest);
};
diff --git a/base/test/BUILD.gn b/base/test/BUILD.gn
index 120159e..55e710d 100644
--- a/base/test/BUILD.gn
+++ b/base/test/BUILD.gn
@@ -8,6 +8,20 @@
import("//build/config/android/rules.gni")
}
+source_set("test_config") {
+ # TODO http://crbug.com/412064 enable this flag all the time.
+ testonly = !is_component_build
+ sources = [
+ "test_switches.cc",
+ "test_switches.h",
+ "test_timeouts.cc",
+ "test_timeouts.h",
+ ]
+ deps = [
+ "//base",
+ ]
+}
+
# GYP: //base/base.gyp:test_support_base
source_set("test_support") {
# TODO http://crbug.com/412064 enable this flag all the time.
@@ -94,10 +108,6 @@
"test_support_android.h",
"test_support_ios.h",
"test_support_ios.mm",
- "test_switches.cc",
- "test_switches.h",
- "test_timeouts.cc",
- "test_timeouts.h",
"thread_test_helper.cc",
"thread_test_helper.h",
"trace_event_analyzer.cc",
@@ -109,6 +119,7 @@
]
public_deps = [
+ ":test_config",
"//base",
"//base:i18n",
"//base:base_static",
diff --git a/base/test/histogram_tester.cc b/base/test/histogram_tester.cc
index 412059a..ea738b0 100644
--- a/base/test/histogram_tester.cc
+++ b/base/test/histogram_tester.cc
@@ -90,7 +90,7 @@
const std::string& name,
base::HistogramBase::Sample sample,
base::HistogramBase::Count expected_count,
- base::HistogramSamples& samples) const {
+ const base::HistogramSamples& samples) const {
int actual_count = samples.GetCount(sample);
std::map<std::string, HistogramSamples*>::const_iterator histogram_data;
histogram_data = histograms_snapshot_.find(name);
@@ -104,9 +104,10 @@
<< ").";
}
-void HistogramTester::CheckTotalCount(const std::string& name,
- base::HistogramBase::Count expected_count,
- base::HistogramSamples& samples) const {
+void HistogramTester::CheckTotalCount(
+ const std::string& name,
+ base::HistogramBase::Count expected_count,
+ const base::HistogramSamples& samples) const {
int actual_count = samples.TotalCount();
std::map<std::string, HistogramSamples*>::const_iterator histogram_data;
histogram_data = histograms_snapshot_.find(name);
diff --git a/base/test/histogram_tester.h b/base/test/histogram_tester.h
index b672308..96317f9 100644
--- a/base/test/histogram_tester.h
+++ b/base/test/histogram_tester.h
@@ -59,14 +59,14 @@
void CheckBucketCount(const std::string& name,
base::HistogramBase::Sample sample,
base::Histogram::Count expected_count,
- base::HistogramSamples& samples) const;
+ const base::HistogramSamples& samples) const;
// Verifies that the total number of values recorded for the histogram |name|
// is |expected_count|. This is checked against |samples| minus the snapshot
// that was taken for |name|.
void CheckTotalCount(const std::string& name,
base::Histogram::Count expected_count,
- base::HistogramSamples& samples) const;
+ const base::HistogramSamples& samples) const;
// Used to determine the histogram changes made during this instance's
// lifecycle. This instance takes ownership of the samples, which are deleted
diff --git a/base/test/mock_devices_changed_observer.h b/base/test/mock_devices_changed_observer.h
index 3ada16b..3255002 100644
--- a/base/test/mock_devices_changed_observer.h
+++ b/base/test/mock_devices_changed_observer.h
@@ -21,6 +21,7 @@
MOCK_METHOD1(OnDevicesChanged,
void(base::SystemMonitor::DeviceType device_type));
+ private:
DISALLOW_COPY_AND_ASSIGN(MockDevicesChangedObserver);
};
diff --git a/base/test/null_task_runner.cc b/base/test/null_task_runner.cc
index bf43e6d..ffa6bdf 100644
--- a/base/test/null_task_runner.cc
+++ b/base/test/null_task_runner.cc
@@ -28,4 +28,4 @@
return true;
}
-} // namespace
+} // namespace base
diff --git a/base/test/null_task_runner.h b/base/test/null_task_runner.h
index 2cde880..0f44751 100644
--- a/base/test/null_task_runner.h
+++ b/base/test/null_task_runner.h
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#ifndef BASE_TEST_NULL_TASK_RUNNER_H_
+#define BASE_TEST_NULL_TASK_RUNNER_H_
+
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/single_thread_task_runner.h"
@@ -30,4 +33,6 @@
DISALLOW_COPY_AND_ASSIGN(NullTaskRunner);
};
-} // namespace
+} // namespace base
+
+#endif // BASE_TEST_NULL_TASK_RUNNER_H_
diff --git a/base/test/sequenced_task_runner_test_template.h b/base/test/sequenced_task_runner_test_template.h
index 48f5354..c208d3c 100644
--- a/base/test/sequenced_task_runner_test_template.h
+++ b/base/test/sequenced_task_runner_test_template.h
@@ -6,8 +6,8 @@
// pass in order to be conformant. See task_runner_test_template.h for a
// description of how to use the constructs in this file; these work the same.
-#ifndef BASE_SEQUENCED_TASK_RUNNER_TEST_TEMPLATE_H_
-#define BASE_SEQUENCED_TASK_RUNNER_TEST_TEMPLATE_H_
+#ifndef BASE_TEST_SEQUENCED_TASK_RUNNER_TEST_TEMPLATE_H_
+#define BASE_TEST_SEQUENCED_TASK_RUNNER_TEST_TEMPLATE_H_
#include <cstddef>
#include <iosfwd>
@@ -338,4 +338,4 @@
} // namespace base
-#endif // BASE_TASK_RUNNER_TEST_TEMPLATE_H_
+#endif // BASE_TEST_SEQUENCED_TASK_RUNNER_TEST_TEMPLATE_H_
diff --git a/base/test/sequenced_worker_pool_owner.h b/base/test/sequenced_worker_pool_owner.h
index b52dd67..bf5f2f7 100644
--- a/base/test/sequenced_worker_pool_owner.h
+++ b/base/test/sequenced_worker_pool_owner.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_THREADING_SEQUENCED_WORKER_POOL_UNITTEST_H_
-#define BASE_THREADING_SEQUENCED_WORKER_POOL_UNITTEST_H_
+#ifndef BASE_TEST_SEQUENCED_WORKER_POOL_OWNER_H_
+#define BASE_TEST_SEQUENCED_WORKER_POOL_OWNER_H_
#include <cstddef>
#include <string>
@@ -58,4 +58,4 @@
} // namespace base
-#endif // BASE_THREADING_SEQUENCED_WORKER_POOL_UNITTEST_H_
+#endif // BASE_TEST_SEQUENCED_WORKER_POOL_OWNER_H_
diff --git a/base/test/simple_test_clock.h b/base/test/simple_test_clock.h
index e8a79c5..a70f99c 100644
--- a/base/test/simple_test_clock.h
+++ b/base/test/simple_test_clock.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_SIMPLE_TEST_CLOCK_H_
-#define BASE_SIMPLE_TEST_CLOCK_H_
+#ifndef BASE_TEST_SIMPLE_TEST_CLOCK_H_
+#define BASE_TEST_SIMPLE_TEST_CLOCK_H_
#include "base/compiler_specific.h"
#include "base/synchronization/lock.h"
@@ -38,4 +38,4 @@
} // namespace base
-#endif // BASE_SIMPLE_TEST_CLOCK_H_
+#endif // BASE_TEST_SIMPLE_TEST_CLOCK_H_
diff --git a/base/test/simple_test_tick_clock.h b/base/test/simple_test_tick_clock.h
index a637543..aebdebc 100644
--- a/base/test/simple_test_tick_clock.h
+++ b/base/test/simple_test_tick_clock.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_SIMPLE_TEST_TICK_CLOCK_H_
-#define BASE_SIMPLE_TEST_TICK_CLOCK_H_
+#ifndef BASE_TEST_SIMPLE_TEST_TICK_CLOCK_H_
+#define BASE_TEST_SIMPLE_TEST_TICK_CLOCK_H_
#include "base/compiler_specific.h"
#include "base/synchronization/lock.h"
@@ -35,4 +35,4 @@
} // namespace base
-#endif // BASE_SIMPLE_TEST_TICK_CLOCK_H_
+#endif // BASE_TEST_SIMPLE_TEST_TICK_CLOCK_H_
diff --git a/base/test/task_runner_test_template.h b/base/test/task_runner_test_template.h
index 73aa1f4..9bcf70b 100644
--- a/base/test/task_runner_test_template.h
+++ b/base/test/task_runner_test_template.h
@@ -212,4 +212,4 @@
} // namespace base
-#endif //#define BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_
+#endif // BASE_TEST_TASK_RUNNER_TEST_TEMPLATE_H_
diff --git a/base/test/test_file_util_win.cc b/base/test/test_file_util_win.cc
index af8bd76..5496a55 100644
--- a/base/test/test_file_util_win.cc
+++ b/base/test/test_file_util_win.cc
@@ -175,7 +175,7 @@
// Move back to the position we just read from.
// Note that SetFilePointer will also fail if total_bytes isn't sector
// aligned, but that shouldn't happen here.
- DCHECK((total_bytes % kOneMB) == 0);
+ DCHECK_EQ(total_bytes % kOneMB, 0);
SetFilePointer(file_handle.Get(), total_bytes, NULL, FILE_BEGIN);
if (!::WriteFile(file_handle.Get(), buffer, kOneMB, &bytes_written, NULL) ||
bytes_written != kOneMB) {
diff --git a/base/test/test_mock_time_task_runner.cc b/base/test/test_mock_time_task_runner.cc
index 8e65ccf..6bcab8b 100644
--- a/base/test/test_mock_time_task_runner.cc
+++ b/base/test/test_mock_time_task_runner.cc
@@ -100,6 +100,13 @@
ProcessAllTasksNoLaterThan(TimeDelta::Max());
}
+void TestMockTimeTaskRunner::ClearPendingTasks() {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ AutoLock scoped_lock(tasks_lock_);
+ while (!tasks_.empty())
+ tasks_.pop();
+}
+
Time TestMockTimeTaskRunner::Now() const {
DCHECK(thread_checker_.CalledOnValidThread());
return now_;
diff --git a/base/test/test_mock_time_task_runner.h b/base/test/test_mock_time_task_runner.h
index 5f06013..c38fd6d 100644
--- a/base/test/test_mock_time_task_runner.h
+++ b/base/test/test_mock_time_task_runner.h
@@ -61,6 +61,9 @@
// elapse.
void RunUntilIdle();
+ // Clears the queue of pending tasks without running them.
+ void ClearPendingTasks();
+
// Returns the current virtual time (initially starting at the Unix epoch).
Time Now() const;
diff --git a/base/test/test_reg_util_win.h b/base/test/test_reg_util_win.h
index db71838..5f23b7f 100644
--- a/base/test/test_reg_util_win.h
+++ b/base/test/test_reg_util_win.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_TEST_TEST_REG_UTIL_H_
-#define BASE_TEST_TEST_REG_UTIL_H_
+#ifndef BASE_TEST_TEST_REG_UTIL_WIN_H_
+#define BASE_TEST_TEST_REG_UTIL_WIN_H_
// Registry utility functions used only by tests.
@@ -74,4 +74,4 @@
} // namespace registry_util
-#endif // BASE_TEST_TEST_REG_UTIL_H_
+#endif // BASE_TEST_TEST_REG_UTIL_WIN_H_
diff --git a/base/third_party/dynamic_annotations/BUILD.gn b/base/third_party/dynamic_annotations/BUILD.gn
index d6a5123..bc324ae 100644
--- a/base/third_party/dynamic_annotations/BUILD.gn
+++ b/base/third_party/dynamic_annotations/BUILD.gn
@@ -6,7 +6,10 @@
# Native client doesn't need dynamic annotations, so we provide a
# dummy target in order for clients to not have to special-case the
# dependency.
- group("dynamic_annotations") {
+ source_set("dynamic_annotations") {
+ sources = [
+ "dynamic_annotations.h",
+ ]
}
} else {
source_set("dynamic_annotations") {
diff --git a/base/threading/sequenced_worker_pool.cc b/base/threading/sequenced_worker_pool.cc
index 19b81b7..f20d997 100644
--- a/base/threading/sequenced_worker_pool.cc
+++ b/base/threading/sequenced_worker_pool.cc
@@ -1091,7 +1091,7 @@
void SequencedWorkerPool::Inner::FinishStartingAdditionalThread(
int thread_number) {
// Called outside of the lock.
- DCHECK(thread_number > 0);
+ DCHECK_GT(thread_number, 0);
// The worker is assigned to the list when the thread actually starts, which
// will manage the memory of the pointer.
diff --git a/base/threading/sequenced_worker_pool_unittest.cc b/base/threading/sequenced_worker_pool_unittest.cc
index 9d0f607..c132731 100644
--- a/base/threading/sequenced_worker_pool_unittest.cc
+++ b/base/threading/sequenced_worker_pool_unittest.cc
@@ -54,7 +54,7 @@
void Unblock(size_t count) {
{
base::AutoLock lock(lock_);
- DCHECK(unblock_counter_ == 0);
+ DCHECK_EQ(unblock_counter_, 0u);
unblock_counter_ = count;
}
cond_var_.Signal();
diff --git a/base/threading/thread.cc b/base/threading/thread.cc
index ad1360b..ea5b174 100644
--- a/base/threading/thread.cc
+++ b/base/threading/thread.cc
@@ -6,11 +6,12 @@
#include "base/bind.h"
#include "base/lazy_instance.h"
+#include "base/profiler/scoped_tracker.h"
+#include "base/synchronization/waitable_event.h"
#include "base/third_party/dynamic_annotations/dynamic_annotations.h"
#include "base/threading/thread_id_name_manager.h"
#include "base/threading/thread_local.h"
#include "base/threading/thread_restrictions.h"
-#include "base/synchronization/waitable_event.h"
#if defined(OS_WIN)
#include "base/win/scoped_com_initializer.h"
@@ -94,6 +95,11 @@
}
bool Thread::StartWithOptions(const Options& options) {
+ // TODO(eroman): Remove once crbug.com/465458 is solved.
+ tracked_objects::ScopedTracker tracking_profile(
+ FROM_HERE_WITH_EXPLICIT_FUNCTION(
+ "465458 base::Thread::StartWithOptions"));
+
DCHECK(!message_loop_);
#if defined(OS_WIN)
DCHECK((com_status_ != STA) ||
@@ -111,6 +117,11 @@
return false;
}
+ // TODO(eroman): Remove once crbug.com/465458 is solved.
+ tracked_objects::ScopedTracker tracking_profile_wait(
+ FROM_HERE_WITH_EXPLICIT_FUNCTION(
+ "465458 base::Thread::StartWithOptions (Wait)"));
+
// Wait for the thread to start and initialize message_loop_
base::ThreadRestrictions::ScopedAllowWait allow_wait;
startup_data.event.Wait();
diff --git a/base/threading/thread_collision_warner_unittest.cc b/base/threading/thread_collision_warner_unittest.cc
index 26faff4..d7ce79e 100644
--- a/base/threading/thread_collision_warner_unittest.cc
+++ b/base/threading/thread_collision_warner_unittest.cc
@@ -146,24 +146,23 @@
class QueueUser : public base::DelegateSimpleThread::Delegate {
public:
- explicit QueueUser(NonThreadSafeQueue& queue)
- : queue_(queue) {}
+ explicit QueueUser(NonThreadSafeQueue* queue) : queue_(queue) {}
void Run() override {
- queue_.push(0);
- queue_.pop();
+ queue_->push(0);
+ queue_->pop();
}
private:
- NonThreadSafeQueue& queue_;
+ NonThreadSafeQueue* queue_;
};
AssertReporter* local_reporter = new AssertReporter();
NonThreadSafeQueue queue(local_reporter);
- QueueUser queue_user_a(queue);
- QueueUser queue_user_b(queue);
+ QueueUser queue_user_a(&queue);
+ QueueUser queue_user_b(&queue);
base::DelegateSimpleThread thread_a(&queue_user_a, "queue_user_thread_a");
base::DelegateSimpleThread thread_b(&queue_user_b, "queue_user_thread_b");
@@ -204,24 +203,23 @@
class QueueUser : public base::DelegateSimpleThread::Delegate {
public:
- explicit QueueUser(NonThreadSafeQueue& queue)
- : queue_(queue) {}
+ explicit QueueUser(NonThreadSafeQueue* queue) : queue_(queue) {}
void Run() override {
- queue_.push(0);
- queue_.pop();
+ queue_->push(0);
+ queue_->pop();
}
private:
- NonThreadSafeQueue& queue_;
+ NonThreadSafeQueue* queue_;
};
AssertReporter* local_reporter = new AssertReporter();
NonThreadSafeQueue queue(local_reporter);
- QueueUser queue_user_a(queue);
- QueueUser queue_user_b(queue);
+ QueueUser queue_user_a(&queue);
+ QueueUser queue_user_b(&queue);
base::DelegateSimpleThread thread_a(&queue_user_a, "queue_user_thread_a");
base::DelegateSimpleThread thread_b(&queue_user_b, "queue_user_thread_b");
@@ -264,23 +262,22 @@
// a lock.
class QueueUser : public base::DelegateSimpleThread::Delegate {
public:
- QueueUser(NonThreadSafeQueue& queue, base::Lock& lock)
- : queue_(queue),
- lock_(lock) {}
+ QueueUser(NonThreadSafeQueue* queue, base::Lock* lock)
+ : queue_(queue), lock_(lock) {}
void Run() override {
{
- base::AutoLock auto_lock(lock_);
- queue_.push(0);
+ base::AutoLock auto_lock(*lock_);
+ queue_->push(0);
}
{
- base::AutoLock auto_lock(lock_);
- queue_.pop();
+ base::AutoLock auto_lock(*lock_);
+ queue_->pop();
}
}
private:
- NonThreadSafeQueue& queue_;
- base::Lock& lock_;
+ NonThreadSafeQueue* queue_;
+ base::Lock* lock_;
};
AssertReporter* local_reporter = new AssertReporter();
@@ -289,8 +286,8 @@
base::Lock lock;
- QueueUser queue_user_a(queue, lock);
- QueueUser queue_user_b(queue, lock);
+ QueueUser queue_user_a(&queue, &lock);
+ QueueUser queue_user_b(&queue, &lock);
base::DelegateSimpleThread thread_a(&queue_user_a, "queue_user_thread_a");
base::DelegateSimpleThread thread_b(&queue_user_b, "queue_user_thread_b");
@@ -338,27 +335,26 @@
// a lock.
class QueueUser : public base::DelegateSimpleThread::Delegate {
public:
- QueueUser(NonThreadSafeQueue& queue, base::Lock& lock)
- : queue_(queue),
- lock_(lock) {}
+ QueueUser(NonThreadSafeQueue* queue, base::Lock* lock)
+ : queue_(queue), lock_(lock) {}
void Run() override {
{
- base::AutoLock auto_lock(lock_);
- queue_.push(0);
+ base::AutoLock auto_lock(*lock_);
+ queue_->push(0);
}
{
- base::AutoLock auto_lock(lock_);
- queue_.bar();
+ base::AutoLock auto_lock(*lock_);
+ queue_->bar();
}
{
- base::AutoLock auto_lock(lock_);
- queue_.pop();
+ base::AutoLock auto_lock(*lock_);
+ queue_->pop();
}
}
private:
- NonThreadSafeQueue& queue_;
- base::Lock& lock_;
+ NonThreadSafeQueue* queue_;
+ base::Lock* lock_;
};
AssertReporter* local_reporter = new AssertReporter();
@@ -367,8 +363,8 @@
base::Lock lock;
- QueueUser queue_user_a(queue, lock);
- QueueUser queue_user_b(queue, lock);
+ QueueUser queue_user_a(&queue, &lock);
+ QueueUser queue_user_b(&queue, &lock);
base::DelegateSimpleThread thread_a(&queue_user_a, "queue_user_thread_a");
base::DelegateSimpleThread thread_b(&queue_user_b, "queue_user_thread_b");
diff --git a/base/threading/thread_local_storage.h b/base/threading/thread_local_storage.h
index 53ebe55..ea41b34 100644
--- a/base/threading/thread_local_storage.h
+++ b/base/threading/thread_local_storage.h
@@ -136,6 +136,7 @@
DISALLOW_COPY_AND_ASSIGN(Slot);
};
+ private:
DISALLOW_COPY_AND_ASSIGN(ThreadLocalStorage);
};
diff --git a/base/threading/thread_restrictions.h b/base/threading/thread_restrictions.h
index 1e5f510..75d8925 100644
--- a/base/threading/thread_restrictions.h
+++ b/base/threading/thread_restrictions.h
@@ -43,7 +43,7 @@
class RenderWidgetResizeHelper;
class ScopedAllowWaitForAndroidLayoutTests;
class TextInputClientMac;
-}
+} // namespace content
namespace dbus {
class Bus;
}
diff --git a/base/threading/worker_pool_posix.cc b/base/threading/worker_pool_posix.cc
index 5aa50ba..32a5e92 100644
--- a/base/threading/worker_pool_posix.cc
+++ b/base/threading/worker_pool_posix.cc
@@ -27,14 +27,6 @@
const int kIdleSecondsBeforeExit = 10 * 60;
-#ifdef ADDRESS_SANITIZER
-const int kWorkerThreadStackSize = 256 * 1024;
-#else
-// A stack size of 64 KB is too small for the CERT_PKIXVerifyCert
-// function of NSS because of NSS bug 439169.
-const int kWorkerThreadStackSize = 128 * 1024;
-#endif
-
class WorkerPoolImpl {
public:
WorkerPoolImpl();
@@ -168,7 +160,7 @@
// which will delete itself on exit.
WorkerThread* worker =
new WorkerThread(name_prefix_, this);
- PlatformThread::CreateNonJoinable(kWorkerThreadStackSize, worker);
+ PlatformThread::CreateNonJoinable(0, worker);
}
}
diff --git a/base/time/clock.h b/base/time/clock.h
index be389be..507a850 100644
--- a/base/time/clock.h
+++ b/base/time/clock.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_CLOCK_H_
-#define BASE_CLOCK_H_
+#ifndef BASE_TIME_CLOCK_H_
+#define BASE_TIME_CLOCK_H_
#include "base/base_export.h"
#include "base/time/time.h"
@@ -37,4 +37,4 @@
} // namespace base
-#endif // BASE_CLOCK_H_
+#endif // BASE_TIME_CLOCK_H_
diff --git a/base/time/default_clock.h b/base/time/default_clock.h
index 3d2e947..0b8250e 100644
--- a/base/time/default_clock.h
+++ b/base/time/default_clock.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_DEFAULT_CLOCK_H_
-#define BASE_DEFAULT_CLOCK_H_
+#ifndef BASE_TIME_DEFAULT_CLOCK_H_
+#define BASE_TIME_DEFAULT_CLOCK_H_
#include "base/base_export.h"
#include "base/compiler_specific.h"
@@ -22,4 +22,4 @@
} // namespace base
-#endif // BASE_DEFAULT_CLOCK_H_
+#endif // BASE_TIME_DEFAULT_CLOCK_H_
diff --git a/base/time/default_tick_clock.h b/base/time/default_tick_clock.h
index a6d6b15..cb041e6 100644
--- a/base/time/default_tick_clock.h
+++ b/base/time/default_tick_clock.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_DEFAULT_TICK_CLOCK_H_
-#define BASE_DEFAULT_TICK_CLOCK_H_
+#ifndef BASE_TIME_DEFAULT_TICK_CLOCK_H_
+#define BASE_TIME_DEFAULT_TICK_CLOCK_H_
#include "base/base_export.h"
#include "base/compiler_specific.h"
@@ -22,4 +22,4 @@
} // namespace base
-#endif // BASE_DEFAULT_CLOCK_H_
+#endif // BASE_TIME_DEFAULT_TICK_CLOCK_H_
diff --git a/base/time/tick_clock.h b/base/time/tick_clock.h
index 2b8691f..f7aba53 100644
--- a/base/time/tick_clock.h
+++ b/base/time/tick_clock.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef BASE_TICK_CLOCK_H_
-#define BASE_TICK_CLOCK_H_
+#ifndef BASE_TIME_TICK_CLOCK_H_
+#define BASE_TIME_TICK_CLOCK_H_
#include "base/base_export.h"
#include "base/time/time.h"
@@ -37,4 +37,4 @@
} // namespace base
-#endif // BASE_TICK_CLOCK_H_
+#endif // BASE_TIME_TICK_CLOCK_H_
diff --git a/base/time/time_win.cc b/base/time/time_win.cc
index 8ae7640..d2403f2 100644
--- a/base/time/time_win.cc
+++ b/base/time/time_win.cc
@@ -203,12 +203,12 @@
UINT period = g_high_res_timer_enabled ? kMinTimerIntervalHighResMs
: kMinTimerIntervalLowResMs;
if (activating) {
- DCHECK(g_high_res_timer_count != max);
+ DCHECK_NE(g_high_res_timer_count, max);
++g_high_res_timer_count;
if (g_high_res_timer_count == 1)
timeBeginPeriod(period);
} else {
- DCHECK(g_high_res_timer_count != 0);
+ DCHECK_NE(g_high_res_timer_count, 0u);
--g_high_res_timer_count;
if (g_high_res_timer_count == 0)
timeEndPeriod(period);
diff --git a/base/timer/mock_timer.h b/base/timer/mock_timer.h
index b07c9c0..e18a5c0 100644
--- a/base/timer/mock_timer.h
+++ b/base/timer/mock_timer.h
@@ -38,4 +38,4 @@
} // namespace base
-#endif // !BASE_TIMER_MOCK_TIMER_H_
+#endif // BASE_TIMER_MOCK_TIMER_H_
diff --git a/base/trace_event/BUILD.gn b/base/trace_event/BUILD.gn
new file mode 100644
index 0000000..eec607b
--- /dev/null
+++ b/base/trace_event/BUILD.gn
@@ -0,0 +1,61 @@
+# Copyright (c) 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+source_set("trace_event") {
+ sources = [
+ "memory_dump_manager.cc",
+ "memory_dump_manager.h",
+ "memory_dump_provider.h",
+ "process_memory_dump.cc",
+ "process_memory_dump.h",
+ "process_memory_maps.cc",
+ "process_memory_maps.h",
+ "process_memory_maps_dump_provider.cc",
+ "process_memory_maps_dump_provider.h",
+ "process_memory_totals.cc",
+ "process_memory_totals.h",
+ "process_memory_totals_dump_provider.cc",
+ "process_memory_totals_dump_provider.h",
+ "trace_event.h",
+ "trace_event_android.cc",
+ "trace_event_argument.cc",
+ "trace_event_argument.h",
+ "trace_event_impl.cc",
+ "trace_event_impl.h",
+ "trace_event_impl_constants.cc",
+ "trace_event_memory.cc",
+ "trace_event_memory.h",
+ "trace_event_synthetic_delay.cc",
+ "trace_event_synthetic_delay.h",
+ "trace_event_system_stats_monitor.cc",
+ "trace_event_system_stats_monitor.h",
+ "trace_event_win.cc",
+ "trace_event_win.h",
+ ]
+
+ if (is_nacl) {
+ sources -= [
+ "process_memory_totals_dump_provider.cc",
+ "trace_event_system_stats_monitor.cc",
+ ]
+ }
+
+ defines = [ "BASE_IMPLEMENTATION" ]
+
+ deps = [
+ "//base/debug",
+ "//base/json",
+ "//base/memory",
+ "//base/process",
+ "//base/third_party/dynamic_annotations",
+ ]
+
+ allow_circular_includes_from = [
+ "//base/debug",
+ "//base/memory",
+ "//base/process",
+ ]
+
+ visibility = [ "//base/*" ]
+}
diff --git a/base/trace_event/memory_dump_manager.cc b/base/trace_event/memory_dump_manager.cc
index cbed238..8b2d930 100644
--- a/base/trace_event/memory_dump_manager.cc
+++ b/base/trace_event/memory_dump_manager.cc
@@ -37,7 +37,8 @@
NOTREACHED();
return "UNKNOWN";
}
-}
+
+} // namespace
// TODO(primiano): this should be smarter and should do something similar to
// trace event synthetic delays.
diff --git a/base/trace_event/memory_dump_manager_unittest.cc b/base/trace_event/memory_dump_manager_unittest.cc
index 78be377..251a92a 100644
--- a/base/trace_event/memory_dump_manager_unittest.cc
+++ b/base/trace_event/memory_dump_manager_unittest.cc
@@ -148,5 +148,5 @@
DisableTracing();
}
-} // namespace trace_Event
+} // namespace trace_event
} // namespace base
diff --git a/base/trace_event/process_memory_maps_dump_provider.cc b/base/trace_event/process_memory_maps_dump_provider.cc
index 93feded..fbe0eb1 100644
--- a/base/trace_event/process_memory_maps_dump_provider.cc
+++ b/base/trace_event/process_memory_maps_dump_provider.cc
@@ -47,7 +47,7 @@
region->protection_flags = 0;
*smaps >> protection_flags;
- CHECK(4UL == protection_flags.size());
+ CHECK_EQ(4UL, protection_flags.size());
if (protection_flags[0] == 'r') {
region->protection_flags |=
ProcessMemoryMaps::VMRegion::kProtectionFlagsRead;
diff --git a/base/trace_event/process_memory_totals_dump_provider_unittest.cc b/base/trace_event/process_memory_totals_dump_provider_unittest.cc
index 4a60036..c37e612 100644
--- a/base/trace_event/process_memory_totals_dump_provider_unittest.cc
+++ b/base/trace_event/process_memory_totals_dump_provider_unittest.cc
@@ -39,5 +39,5 @@
EXPECT_EQ(rss_after - rss_before, kAllocSize);
}
-} // namespace trace_Event
+} // namespace trace_event
} // namespace base
diff --git a/base/trace_event/trace_event.h b/base/trace_event/trace_event.h
index c30a84a..b90a3ea 100644
--- a/base/trace_event/trace_event.h
+++ b/base/trace_event/trace_event.h
@@ -1607,4 +1607,4 @@
} // namespace trace_event
} // namespace base
-#endif /* BASE_TRACE_EVENT_TRACE_EVENT_H_ */
+#endif // BASE_TRACE_EVENT_TRACE_EVENT_H_
diff --git a/base/trace_event/trace_event_impl.cc b/base/trace_event/trace_event_impl.cc
index 445cb6d..72b46f9 100644
--- a/base/trace_event/trace_event_impl.cc
+++ b/base/trace_event/trace_event_impl.cc
@@ -430,25 +430,22 @@
// and unlocks at the end of scope if locked.
class TraceLog::OptionalAutoLock {
public:
- explicit OptionalAutoLock(Lock& lock)
- : lock_(lock),
- locked_(false) {
- }
+ explicit OptionalAutoLock(Lock* lock) : lock_(lock), locked_(false) {}
~OptionalAutoLock() {
if (locked_)
- lock_.Release();
+ lock_->Release();
}
void EnsureAcquired() {
if (!locked_) {
- lock_.Acquire();
+ lock_->Acquire();
locked_ = true;
}
}
private:
- Lock& lock_;
+ Lock* lock_;
bool locked_;
DISALLOW_COPY_AND_ASSIGN(OptionalAutoLock);
};
@@ -624,7 +621,7 @@
void TraceEvent::UpdateDuration(const TimeTicks& now,
const TimeTicks& thread_now) {
- DCHECK(duration_.ToInternalValue() == -1);
+ DCHECK_EQ(duration_.ToInternalValue(), -1);
duration_ = now - timestamp_;
thread_duration_ = thread_now - thread_timestamp_;
}
@@ -1977,7 +1974,7 @@
std::string console_message;
if (*category_group_enabled &
(ENABLED_FOR_RECORDING | ENABLED_FOR_MONITORING)) {
- OptionalAutoLock lock(lock_);
+ OptionalAutoLock lock(&lock_);
TraceEvent* trace_event = NULL;
if (thread_local_event_buffer) {
@@ -2130,7 +2127,7 @@
std::string console_message;
if (*category_group_enabled & ENABLED_FOR_RECORDING) {
- OptionalAutoLock lock(lock_);
+ OptionalAutoLock lock(&lock_);
TraceEvent* trace_event = GetEventByHandleInternal(handle, &lock);
if (trace_event) {
@@ -2490,18 +2487,35 @@
// Do a second pass to check for explicitly disabled categories
// (those explicitly enabled have priority due to first pass).
category_group_tokens.Reset();
+ bool category_group_disabled = false;
while (category_group_tokens.GetNext()) {
std::string category_group_token = category_group_tokens.token();
for (StringList::const_iterator ci = excluded_.begin();
ci != excluded_.end(); ++ci) {
- if (MatchPattern(category_group_token.c_str(), ci->c_str()))
- return false;
+ if (MatchPattern(category_group_token.c_str(), ci->c_str())) {
+ // Current token of category_group_name is present in excluded_list.
+ // Flag the exclusion and proceed further to check if any of the
+ // remaining categories of category_group_name is not present in the
+ // excluded_ list.
+ category_group_disabled = true;
+ break;
+ }
+ // One of the category of category_group_name is not present in
+ // excluded_ list. So, it has to be included_ list. Enable the
+ // category_group_name for recording.
+ category_group_disabled = false;
}
+ // One of the categories present in category_group_name is not present in
+ // excluded_ list. Implies this category_group_name group can be enabled
+ // for recording, since one of its groups is enabled for recording.
+ if (!category_group_disabled)
+ break;
}
// If the category group is not excluded, and there are no included patterns
// we consider this category group enabled, as long as it had categories
// other than disabled-by-default.
- return included_.empty() && had_enabled_by_default;
+ return !category_group_disabled &&
+ included_.empty() && had_enabled_by_default;
}
bool CategoryFilter::IsCategoryEnabled(const char* category_name) const {
@@ -2571,7 +2585,7 @@
ScopedTraceBinaryEfficient::ScopedTraceBinaryEfficient(
const char* category_group, const char* name) {
// The single atom works because for now the category_group can only be "gpu".
- DCHECK(strcmp(category_group, "gpu") == 0);
+ DCHECK_EQ(strcmp(category_group, "gpu"), 0);
static TRACE_EVENT_API_ATOMIC_WORD atomic = 0;
INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO_CUSTOM_VARIABLES(
category_group, atomic, category_group_enabled_);
diff --git a/base/trace_event/trace_event_synthetic_delay.h b/base/trace_event/trace_event_synthetic_delay.h
index 14801be..0df794b 100644
--- a/base/trace_event/trace_event_synthetic_delay.h
+++ b/base/trace_event/trace_event_synthetic_delay.h
@@ -163,4 +163,4 @@
} // namespace trace_event_internal
-#endif /* BASE_TRACE_EVENT_TRACE_EVENT_SYNTHETIC_DELAY_H_ */
+#endif // BASE_TRACE_EVENT_TRACE_EVENT_SYNTHETIC_DELAY_H_
diff --git a/base/trace_event/trace_event_unittest.cc b/base/trace_event/trace_event_unittest.cc
index a6bc0d4..0d3b091 100644
--- a/base/trace_event/trace_event_unittest.cc
+++ b/base/trace_event/trace_event_unittest.cc
@@ -1205,8 +1205,8 @@
EndTraceAndFlush();
EXPECT_TRUE(FindMatchingValue("cat", "inc2"));
EXPECT_FALSE(FindMatchingValue("cat", "inc"));
- EXPECT_FALSE(FindMatchingValue("cat", "inc2,inc"));
- EXPECT_FALSE(FindMatchingValue("cat", "inc,inc2"));
+ EXPECT_TRUE(FindMatchingValue("cat", "inc2,inc"));
+ EXPECT_TRUE(FindMatchingValue("cat", "inc,inc2"));
// Exclude existent wildcard -> all categories not matching wildcard
Clear();
@@ -2624,18 +2624,18 @@
EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("not-excluded-category"));
EXPECT_FALSE(
default_cf.IsCategoryGroupEnabled("disabled-by-default-category"));
- EXPECT_FALSE(default_cf.IsCategoryGroupEnabled("Category1,CategoryDebug"));
- EXPECT_FALSE(default_cf.IsCategoryGroupEnabled("CategoryDebug,Category1"));
- EXPECT_FALSE(default_cf.IsCategoryGroupEnabled("CategoryTest,Category2"));
+ EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("Category1,CategoryDebug"));
+ EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("CategoryDebug,Category1"));
+ EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("CategoryTest,Category2"));
// Make sure that upon an empty string, we fall back to the default filter.
default_cf = CategoryFilter();
category_filter_str = default_cf.ToString();
EXPECT_STREQ("-*Debug,-*Test", category_filter_str.c_str());
EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("not-excluded-category"));
- EXPECT_FALSE(default_cf.IsCategoryGroupEnabled("Category1,CategoryDebug"));
- EXPECT_FALSE(default_cf.IsCategoryGroupEnabled("CategoryDebug,Category1"));
- EXPECT_FALSE(default_cf.IsCategoryGroupEnabled("CategoryTest,Category2"));
+ EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("Category1,CategoryDebug"));
+ EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("CategoryDebug,Category1"));
+ EXPECT_TRUE(default_cf.IsCategoryGroupEnabled("CategoryTest,Category2"));
// Using an arbitrary non-empty filter.
CategoryFilter cf("included,-excluded,inc_pattern*,-exc_pattern*");
diff --git a/base/tracked_objects.cc b/base/tracked_objects.cc
index fc29e2e..5359d89 100644
--- a/base/tracked_objects.cc
+++ b/base/tracked_objects.cc
@@ -163,11 +163,6 @@
return queue_duration_sample_;
}
-void DeathData::ResetMax() {
- run_duration_max_ = 0;
- queue_duration_max_ = 0;
-}
-
void DeathData::Clear() {
count_ = 0;
run_duration_sum_ = 0;
@@ -232,10 +227,6 @@
void Births::RecordBirth() { ++birth_count_; }
-void Births::ForgetBirth() { --birth_count_; }
-
-void Births::Clear() { birth_count_ = 0; }
-
//------------------------------------------------------------------------------
// ThreadData maintains the central data for all births and deaths on a single
// thread.
@@ -399,12 +390,12 @@
}
// static
-void ThreadData::Snapshot(bool reset_max, ProcessDataSnapshot* process_data) {
+void ThreadData::Snapshot(ProcessDataSnapshot* process_data) {
// Add births that have run to completion to |collected_data|.
// |birth_counts| tracks the total number of births recorded at each location
// for which we have not seen a death count.
BirthCountMap birth_counts;
- ThreadData::SnapshotAllExecutedTasks(reset_max, process_data, &birth_counts);
+ ThreadData::SnapshotAllExecutedTasks(process_data, &birth_counts);
// Add births that are still active -- i.e. objects that have tallied a birth,
// but have not yet tallied a matching death, and hence must be either
@@ -587,8 +578,7 @@
}
// static
-void ThreadData::SnapshotAllExecutedTasks(bool reset_max,
- ProcessDataSnapshot* process_data,
+void ThreadData::SnapshotAllExecutedTasks(ProcessDataSnapshot* process_data,
BirthCountMap* birth_counts) {
if (!kTrackAllTaskObjects)
return; // Not compiled in.
@@ -605,19 +595,18 @@
for (ThreadData* thread_data = my_list;
thread_data;
thread_data = thread_data->next()) {
- thread_data->SnapshotExecutedTasks(reset_max, process_data, birth_counts);
+ thread_data->SnapshotExecutedTasks(process_data, birth_counts);
}
}
-void ThreadData::SnapshotExecutedTasks(bool reset_max,
- ProcessDataSnapshot* process_data,
+void ThreadData::SnapshotExecutedTasks(ProcessDataSnapshot* process_data,
BirthCountMap* birth_counts) {
// Get copy of data, so that the data will not change during the iterations
// and processing.
ThreadData::BirthMap birth_map;
ThreadData::DeathMap death_map;
ThreadData::ParentChildSet parent_child_set;
- SnapshotMaps(reset_max, &birth_map, &death_map, &parent_child_set);
+ SnapshotMaps(&birth_map, &death_map, &parent_child_set);
for (ThreadData::DeathMap::const_iterator it = death_map.begin();
it != death_map.end(); ++it) {
@@ -641,8 +630,7 @@
}
// This may be called from another thread.
-void ThreadData::SnapshotMaps(bool reset_max,
- BirthMap* birth_map,
+void ThreadData::SnapshotMaps(BirthMap* birth_map,
DeathMap* death_map,
ParentChildSet* parent_child_set) {
base::AutoLock lock(map_lock_);
@@ -652,8 +640,6 @@
for (DeathMap::iterator it = death_map_.begin();
it != death_map_.end(); ++it) {
(*death_map)[it->first] = it->second;
- if (reset_max)
- it->second.ResetMax();
}
if (!kTrackParentChildLinks)
@@ -664,26 +650,6 @@
parent_child_set->insert(*it);
}
-// static
-void ThreadData::ResetAllThreadData() {
- ThreadData* my_list = first();
-
- for (ThreadData* thread_data = my_list;
- thread_data;
- thread_data = thread_data->next())
- thread_data->Reset();
-}
-
-void ThreadData::Reset() {
- base::AutoLock lock(map_lock_);
- for (DeathMap::iterator it = death_map_.begin();
- it != death_map_.end(); ++it)
- it->second.Clear();
- for (BirthMap::iterator it = birth_map_.begin();
- it != birth_map_.end(); ++it)
- it->second->Clear();
-}
-
static void OptionallyInitializeAlternateTimer() {
NowFunction* alternate_time_source = GetAlternateTimeSource();
if (alternate_time_source)
diff --git a/base/tracked_objects.h b/base/tracked_objects.h
index 5196f19..7840fec 100644
--- a/base/tracked_objects.h
+++ b/base/tracked_objects.h
@@ -240,13 +240,6 @@
// When we have a birth we update the count for this birthplace.
void RecordBirth();
- // When a birthplace is changed (updated), we need to decrement the counter
- // for the old instance.
- void ForgetBirth();
-
- // Hack to quickly reset all counts to zero.
- void Clear();
-
private:
// The number of births on this thread for our location_.
int birth_count_;
@@ -284,9 +277,6 @@
int32 queue_duration_max() const;
int32 queue_duration_sample() const;
- // Reset the max values to zero.
- void ResetMax();
-
// Reset all tallies to zero. This is used as a hack on realtime data.
void Clear();
@@ -386,9 +376,7 @@
static ThreadData* Get();
// Fills |process_data| with all the recursive results in our process.
- // During the scavenging, if |reset_max| is true, then the DeathData instances
- // max-values are reset to zero during this scan.
- static void Snapshot(bool reset_max, ProcessDataSnapshot* process_data);
+ static void Snapshot(ProcessDataSnapshot* process_data);
// Finds (or creates) a place to count births from the given location in this
// thread, and increment that tally.
@@ -427,12 +415,6 @@
const std::string& thread_name() const { return thread_name_; }
- // Hack: asynchronously clear all birth counts and death tallies data values
- // in all ThreadData instances. The numerical (zeroing) part is done without
- // use of a locks or atomics exchanges, and may (for int64 values) produce
- // bogus counts VERY rarely.
- static void ResetAllThreadData();
-
// Initializes all statics if needed (this initialization call should be made
// while we are single threaded). Returns false if unable to initialize.
static bool Initialize();
@@ -530,11 +512,8 @@
// Snapshot (under a lock) the profiled data for the tasks in each ThreadData
// instance. Also updates the |birth_counts| tally for each task to keep
- // track of the number of living instances of the task. If |reset_max| is
- // true, then the max values in each DeathData instance are reset during the
- // scan.
- static void SnapshotAllExecutedTasks(bool reset_max,
- ProcessDataSnapshot* process_data,
+ // track of the number of living instances of the task.
+ static void SnapshotAllExecutedTasks(ProcessDataSnapshot* process_data,
BirthCountMap* birth_counts);
// Snapshots (under a lock) the profiled data for the tasks for this thread
@@ -542,26 +521,17 @@
// with with entries in the death_map_ -- into |process_data|. Also updates
// the |birth_counts| tally for each task to keep track of the number of
// living instances of the task -- that is, each task maps to the number of
- // births for the task that have not yet been balanced by a death. If
- // |reset_max| is true, then the max values in each DeathData instance are
- // reset during the scan.
- void SnapshotExecutedTasks(bool reset_max,
- ProcessDataSnapshot* process_data,
+ // births for the task that have not yet been balanced by a death.
+ void SnapshotExecutedTasks(ProcessDataSnapshot* process_data,
BirthCountMap* birth_counts);
// Using our lock, make a copy of the specified maps. This call may be made
// on non-local threads, which necessitate the use of the lock to prevent
- // the map(s) from being reallocated while they are copied. If |reset_max| is
- // true, then, just after we copy the DeathMap, we will set the max values to
- // zero in the active DeathMap (not the snapshot).
- void SnapshotMaps(bool reset_max,
- BirthMap* birth_map,
+ // the map(s) from being reallocated while they are copied.
+ void SnapshotMaps(BirthMap* birth_map,
DeathMap* death_map,
ParentChildSet* parent_child_set);
- // Using our lock to protect the iteration, Clear all birth and death data.
- void Reset();
-
// This method is called by the TLS system when a thread terminates.
// The argument may be NULL if this thread has never tracked a birth or death.
static void OnThreadTermination(void* thread_data);
diff --git a/base/tracked_objects_unittest.cc b/base/tracked_objects_unittest.cc
index e2ea362..7713091 100644
--- a/base/tracked_objects_unittest.cc
+++ b/base/tracked_objects_unittest.cc
@@ -138,7 +138,7 @@
ThreadData::BirthMap birth_map;
ThreadData::DeathMap death_map;
ThreadData::ParentChildSet parent_child_set;
- data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
+ data->SnapshotMaps(&birth_map, &death_map, &parent_child_set);
EXPECT_EQ(0u, birth_map.size());
EXPECT_EQ(0u, death_map.size());
EXPECT_EQ(0u, parent_child_set.size());
@@ -158,7 +158,7 @@
birth_map.clear();
death_map.clear();
parent_child_set.clear();
- data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
+ data->SnapshotMaps(&birth_map, &death_map, &parent_child_set);
EXPECT_EQ(0u, birth_map.size());
EXPECT_EQ(0u, death_map.size());
EXPECT_EQ(0u, parent_child_set.size());
@@ -182,7 +182,7 @@
ThreadData::BirthMap birth_map;
ThreadData::DeathMap death_map;
ThreadData::ParentChildSet parent_child_set;
- data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
+ data->SnapshotMaps(&birth_map, &death_map, &parent_child_set);
EXPECT_EQ(1u, birth_map.size()); // 1 birth location.
EXPECT_EQ(1, birth_map.begin()->second->birth_count()); // 1 birth.
EXPECT_EQ(0u, death_map.size()); // No deaths.
@@ -211,7 +211,7 @@
birth_map.clear();
death_map.clear();
parent_child_set.clear();
- data->SnapshotMaps(false, &birth_map, &death_map, &parent_child_set);
+ data->SnapshotMaps(&birth_map, &death_map, &parent_child_set);
EXPECT_EQ(1u, birth_map.size()); // 1 birth location.
EXPECT_EQ(2, birth_map.begin()->second->birth_count()); // 2 births.
EXPECT_EQ(1u, death_map.size()); // 1 location.
@@ -228,7 +228,7 @@
EXPECT_EQ(birth_map.begin()->second, death_map.begin()->first);
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
ASSERT_EQ(1u, process_data.tasks.size());
EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name);
@@ -317,7 +317,7 @@
TallyABirth(location, std::string());
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
EXPECT_EQ(0u, process_data.tasks.size());
EXPECT_EQ(0u, process_data.descendants.size());
EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
@@ -334,7 +334,7 @@
TallyABirth(location, kMainThreadName);
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
EXPECT_EQ(0u, process_data.tasks.size());
EXPECT_EQ(0u, process_data.descendants.size());
EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
@@ -351,7 +351,7 @@
TallyABirth(location, std::string());
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName,
kStillAlive, 1, 0, 0);
}
@@ -367,7 +367,7 @@
TallyABirth(location, kMainThreadName);
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
ExpectSimpleProcessData(process_data, kFunction, kMainThreadName, kStillAlive,
1, 0, 0);
}
@@ -399,7 +399,7 @@
ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
kMainThreadName, 1, 2, 4);
}
@@ -439,7 +439,7 @@
ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
kMainThreadName, 1, 2, 4);
}
@@ -473,76 +473,12 @@
ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, stopwatch);
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
EXPECT_EQ(0u, process_data.tasks.size());
EXPECT_EQ(0u, process_data.descendants.size());
EXPECT_EQ(base::GetCurrentProcId(), process_data.process_id);
}
-TEST_F(TrackedObjectsTest, LifeCycleToSnapshotWorkerThread) {
- if (!ThreadData::InitializeAndSetTrackingStatus(
- ThreadData::PROFILING_CHILDREN_ACTIVE)) {
- return;
- }
-
- const char kFunction[] = "LifeCycleToSnapshotWorkerThread";
- Location location(kFunction, kFile, kLineNumber, NULL);
- // Do not delete |birth|. We don't own it.
- Births* birth = ThreadData::TallyABirthIfActive(location);
- EXPECT_NE(reinterpret_cast<Births*>(NULL), birth);
-
- const unsigned int kTimePosted = 1;
- const unsigned int kStartOfRun = 5;
- const unsigned int kEndOfRun = 7;
- SetTestTime(kStartOfRun);
- TaskStopwatch stopwatch;
- stopwatch.Start();
- SetTestTime(kEndOfRun);
- stopwatch.Stop();
-
- ThreadData::TallyRunOnWorkerThreadIfTracking(
- birth, TrackedTime() + Duration::FromMilliseconds(kTimePosted), stopwatch);
-
- // Call for the ToSnapshot, but tell it to not reset the maxes after scanning.
- ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
- ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName,
- kWorkerThreadName, 1, 2, 4);
-
- // Call for the ToSnapshot, but tell it to reset the maxes after scanning.
- // We'll still get the same values, but the data will be reset (which we'll
- // see in a moment).
- ProcessDataSnapshot process_data_pre_reset;
- ThreadData::Snapshot(true, &process_data_pre_reset);
- ExpectSimpleProcessData(process_data, kFunction, kWorkerThreadName,
- kWorkerThreadName, 1, 2, 4);
-
- // Call for the ToSnapshot, and now we'll see the result of the last
- // translation, as the max will have been pushed back to zero.
- ProcessDataSnapshot process_data_post_reset;
- ThreadData::Snapshot(true, &process_data_post_reset);
- ASSERT_EQ(1u, process_data_post_reset.tasks.size());
- EXPECT_EQ(kFile, process_data_post_reset.tasks[0].birth.location.file_name);
- EXPECT_EQ(kFunction,
- process_data_post_reset.tasks[0].birth.location.function_name);
- EXPECT_EQ(kLineNumber,
- process_data_post_reset.tasks[0].birth.location.line_number);
- EXPECT_EQ(kWorkerThreadName,
- process_data_post_reset.tasks[0].birth.thread_name);
- EXPECT_EQ(1, process_data_post_reset.tasks[0].death_data.count);
- EXPECT_EQ(2, process_data_post_reset.tasks[0].death_data.run_duration_sum);
- EXPECT_EQ(0, process_data_post_reset.tasks[0].death_data.run_duration_max);
- EXPECT_EQ(2, process_data_post_reset.tasks[0].death_data.run_duration_sample);
- EXPECT_EQ(4, process_data_post_reset.tasks[0].death_data.queue_duration_sum);
- EXPECT_EQ(0, process_data_post_reset.tasks[0].death_data.queue_duration_max);
- EXPECT_EQ(4,
- process_data_post_reset.tasks[0].death_data.queue_duration_sample);
- EXPECT_EQ(kWorkerThreadName,
- process_data_post_reset.tasks[0].death_thread_name);
- EXPECT_EQ(0u, process_data_post_reset.descendants.size());
- EXPECT_EQ(base::GetCurrentProcId(), process_data_post_reset.process_id);
-}
-
TEST_F(TrackedObjectsTest, TwoLives) {
if (!ThreadData::InitializeAndSetTrackingStatus(
ThreadData::PROFILING_CHILDREN_ACTIVE)) {
@@ -581,7 +517,7 @@
ThreadData::TallyRunOnNamedThreadIfTracking(pending_task2, stopwatch2);
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
kMainThreadName, 2, 2, 4);
}
@@ -621,7 +557,7 @@
pending_task2.time_posted = kTimePosted; // Overwrite implied Now().
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
ASSERT_EQ(2u, process_data.tasks.size());
EXPECT_EQ(kFile, process_data.tasks[0].birth.location.file_name);
@@ -685,7 +621,7 @@
ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
kMainThreadName, 1, 6, 4);
}
@@ -728,7 +664,7 @@
ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
ExpectSimpleProcessData(process_data, kFunction, kMainThreadName,
kMainThreadName, 1, 13, 4);
}
@@ -781,7 +717,7 @@
ThreadData::TallyRunOnNamedThreadIfTracking(pending_task, task_stopwatch);
ProcessDataSnapshot process_data;
- ThreadData::Snapshot(false, &process_data);
+ ThreadData::Snapshot(&process_data);
// The order in which the two task follow is platform-dependent.
int t0 = (process_data.tasks[0].birth.location.line_number == kLineNumber) ?
diff --git a/base/value_conversions.h b/base/value_conversions.h
index fde9a26..452c587 100644
--- a/base/value_conversions.h
+++ b/base/value_conversions.h
@@ -24,6 +24,6 @@
BASE_EXPORT StringValue* CreateTimeDeltaValue(const TimeDelta& time);
BASE_EXPORT bool GetValueAsTimeDelta(const Value& value, TimeDelta* time);
-} // namespace
+} // namespace base
#endif // BASE_VALUE_CONVERSIONS_H_
diff --git a/base/version.cc b/base/version.cc
index 933356e..ede8a45 100644
--- a/base/version.cc
+++ b/base/version.cc
@@ -23,7 +23,7 @@
// is the resulting integer vector. Function returns true if all numbers were
// parsed successfully, false otherwise.
bool ParseVersionNumbers(const std::string& version_str,
- std::vector<uint16>* parsed) {
+ std::vector<uint32_t>* parsed) {
std::vector<std::string> numbers;
SplitString(version_str, '.', &numbers);
if (numbers.empty())
@@ -33,22 +33,18 @@
it != numbers.end(); ++it) {
if (StartsWithASCII(*it, "+", false))
return false;
- int num;
- if (!StringToInt(*it, &num))
- return false;
-
- if (num < 0)
- return false;
-
- const uint16 max = 0xFFFF;
- if (num > max)
+ unsigned int num;
+ if (!StringToUint(*it, &num))
return false;
// This throws out leading zeros for the first item only.
- if (it == numbers.begin() && IntToString(num) != *it)
+ if (it == numbers.begin() && UintToString(num) != *it)
return false;
- parsed->push_back(static_cast<uint16>(num));
+ // StringToUint returns unsigned int but Version fields are uint32_t.
+ static_assert(sizeof (uint32_t) == sizeof (unsigned int),
+ "uint32_t must be same as unsigned int");
+ parsed->push_back(num);
}
return true;
}
@@ -56,8 +52,8 @@
// Compares version components in |components1| with components in
// |components2|. Returns -1, 0 or 1 if |components1| is less than, equal to,
// or greater than |components2|, respectively.
-int CompareVersionComponents(const std::vector<uint16>& components1,
- const std::vector<uint16>& components2) {
+int CompareVersionComponents(const std::vector<uint32_t>& components1,
+ const std::vector<uint32_t>& components2) {
const size_t count = std::min(components1.size(), components2.size());
for (size_t i = 0; i < count; ++i) {
if (components1[i] > components2[i])
@@ -88,7 +84,7 @@
}
Version::Version(const std::string& version_str) {
- std::vector<uint16> parsed;
+ std::vector<uint32_t> parsed;
if (!ParseVersionNumbers(version_str, &parsed))
return;
@@ -127,7 +123,7 @@
return CompareTo(version);
}
- std::vector<uint16> parsed;
+ std::vector<uint32_t> parsed;
const bool success = ParseVersionNumbers(
wildcard_string.substr(0, wildcard_string.length() - 2), &parsed);
DCHECK(success);
diff --git a/base/version.h b/base/version.h
index b3012eb..814acaa 100644
--- a/base/version.h
+++ b/base/version.h
@@ -5,6 +5,7 @@
#ifndef BASE_VERSION_H_
#define BASE_VERSION_H_
+#include <stdint.h>
#include <string>
#include <vector>
@@ -57,10 +58,10 @@
// Return the string representation of this version.
const std::string GetString() const;
- const std::vector<uint16>& components() const { return components_; }
+ const std::vector<uint32_t>& components() const { return components_; }
private:
- std::vector<uint16> components_;
+ std::vector<uint32_t> components_;
};
} // namespace base
diff --git a/base/version_unittest.cc b/base/version_unittest.cc
index 46d8255..f40ed27 100644
--- a/base/version_unittest.cc
+++ b/base/version_unittest.cc
@@ -31,39 +31,44 @@
static const struct version_string {
const char* input;
size_t parts;
+ uint32_t firstpart;
bool success;
} cases[] = {
- {"", 0, false},
- {" ", 0, false},
- {"\t", 0, false},
- {"\n", 0, false},
- {" ", 0, false},
- {".", 0, false},
- {" . ", 0, false},
- {"0", 1, true},
- {"0.", 0, false},
- {"0.0", 2, true},
- {"65537.0", 0, false},
- {"-1.0", 0, false},
- {"1.-1.0", 0, false},
- {"1,--1.0", 0, false},
- {"+1.0", 0, false},
- {"1.+1.0", 0, false},
- {"1+1.0", 0, false},
- {"++1.0", 0, false},
- {"1.0a", 0, false},
- {"1.2.3.4.5.6.7.8.9.0", 10, true},
- {"02.1", 0, false},
- {"0.01", 2, true},
- {"f.1", 0, false},
- {"15.007.20011", 3, true},
+ {"", 0, 0, false},
+ {" ", 0, 0, false},
+ {"\t", 0, 0, false},
+ {"\n", 0, 0, false},
+ {" ", 0, 0, false},
+ {".", 0, 0, false},
+ {" . ", 0, 0, false},
+ {"0", 1, 0, true},
+ {"0.", 0, 0, false},
+ {"0.0", 2, 0, true},
+ {"4294967295.0", 2, 4294967295, true},
+ {"4294967296.0", 0, 0, false},
+ {"-1.0", 0, 0, false},
+ {"1.-1.0", 0, 0, false},
+ {"1,--1.0", 0, 0, false},
+ {"+1.0", 0, 0, false},
+ {"1.+1.0", 0, 0, false},
+ {"1+1.0", 0, 0, false},
+ {"++1.0", 0, 0, false},
+ {"1.0a", 0, 0, false},
+ {"1.2.3.4.5.6.7.8.9.0", 10, 1, true},
+ {"02.1", 0, 0, false},
+ {"0.01", 2, 0, true},
+ {"f.1", 0, 0, false},
+ {"15.007.20011", 3, 15, true},
+ {"15.5.28.130162", 4, 15, true},
};
for (size_t i = 0; i < arraysize(cases); ++i) {
Version version(cases[i].input);
EXPECT_EQ(cases[i].success, version.IsValid());
- if (cases[i].success)
+ if (cases[i].success) {
EXPECT_EQ(cases[i].parts, version.components().size());
+ EXPECT_EQ(cases[i].firstpart, version.components()[0]);
+ }
}
}
@@ -84,6 +89,7 @@
{"1.0.0", "1.0", 0},
{"1.0.3", "1.0.20", -1},
{"11.0.10", "15.007.20011", -1},
+ {"11.0.10", "15.5.28.130162", -1},
};
for (size_t i = 0; i < arraysize(cases); ++i) {
Version lhs(cases[i].lhs);
diff --git a/base/vlog.cc b/base/vlog.cc
index 434a70e..8612071 100644
--- a/base/vlog.cc
+++ b/base/vlog.cc
@@ -178,4 +178,4 @@
return false;
}
-} // namespace
+} // namespace logging
diff --git a/base/win/metro.cc b/base/win/metro.cc
index 6e443ba..7946698 100644
--- a/base/win/metro.cc
+++ b/base/win/metro.cc
@@ -4,10 +4,7 @@
#include "base/win/metro.h"
-#include "base/message_loop/message_loop.h"
#include "base/strings/string_util.h"
-#include "base/win/scoped_comptr.h"
-#include "base/win/windows_version.h"
namespace base {
namespace win {
@@ -73,38 +70,6 @@
return dest;
}
-bool IsParentalControlActivityLoggingOn() {
- // Query this info on Windows 7 and above.
- if (base::win::GetVersion() < base::win::VERSION_WIN7)
- return false;
-
- static bool parental_control_logging_required = false;
- static bool parental_control_status_determined = false;
-
- if (parental_control_status_determined)
- return parental_control_logging_required;
-
- parental_control_status_determined = true;
-
- ScopedComPtr<IWindowsParentalControlsCore> parent_controls;
- HRESULT hr = parent_controls.CreateInstance(
- __uuidof(WindowsParentalControls));
- if (FAILED(hr))
- return false;
-
- ScopedComPtr<IWPCSettings> settings;
- hr = parent_controls->GetUserSettings(NULL, settings.Receive());
- if (FAILED(hr))
- return false;
-
- unsigned long restrictions = 0;
- settings->GetRestrictions(&restrictions);
-
- parental_control_logging_required =
- (restrictions & WPCFLAG_LOGGING_REQUIRED) == WPCFLAG_LOGGING_REQUIRED;
- return parental_control_logging_required;
-}
-
// Metro driver exports for getting the launch type, initial url, initial
// search term, etc.
extern "C" {
diff --git a/base/win/metro.h b/base/win/metro.h
index 5894ef0..0696006 100644
--- a/base/win/metro.h
+++ b/base/win/metro.h
@@ -6,7 +6,6 @@
#define BASE_WIN_METRO_H_
#include <windows.h>
-#include <wpcapi.h>
#include "base/base_export.h"
#include "base/callback.h"
@@ -80,11 +79,6 @@
// copying the src to it.
BASE_EXPORT wchar_t* LocalAllocAndCopyString(const string16& src);
-// Returns true if Windows Parental control activity logging is enabled. This
-// feature is available on Windows Vista and beyond.
-// This function should ideally be called on the UI thread.
-BASE_EXPORT bool IsParentalControlActivityLoggingOn();
-
// Returns the type of launch and the activation params. For example if the
// the launch is for METRO_PROTOCOL then the params is a url.
BASE_EXPORT MetroLaunchType GetMetroLaunchParams(string16* params);
diff --git a/base/win/object_watcher.h b/base/win/object_watcher.h
index ecd0415..0ae2532 100644
--- a/base/win/object_watcher.h
+++ b/base/win/object_watcher.h
@@ -103,4 +103,4 @@
} // namespace win
} // namespace base
-#endif // BASE_OBJECT_WATCHER_H_
+#endif // BASE_WIN_OBJECT_WATCHER_H_
diff --git a/base/win/registry.cc b/base/win/registry.cc
index b39b749..d0df48a 100644
--- a/base/win/registry.cc
+++ b/base/win/registry.cc
@@ -210,7 +210,7 @@
}
HKEY RegKey::Take() {
- DCHECK(wow64access_ == 0);
+ DCHECK_EQ(wow64access_, 0u);
HKEY key = key_;
key_ = NULL;
return key;
diff --git a/base/win/scoped_bstr.h b/base/win/scoped_bstr.h
index d703f62..7c9f5df 100644
--- a/base/win/scoped_bstr.h
+++ b/base/win/scoped_bstr.h
@@ -94,4 +94,4 @@
} // namespace win
} // namespace base
-#endif // BASE_SCOPED_BSTR_H_
+#endif // BASE_WIN_SCOPED_BSTR_H_
diff --git a/base/win/scoped_comptr_unittest.cc b/base/win/scoped_comptr_unittest.cc
index 711c52f..d38752d 100644
--- a/base/win/scoped_comptr_unittest.cc
+++ b/base/win/scoped_comptr_unittest.cc
@@ -31,8 +31,8 @@
} // namespace
TEST(ScopedComPtrTest, ScopedComPtr) {
- EXPECT_TRUE(memcmp(&ScopedComPtr<IUnknown>::iid(), &IID_IUnknown,
- sizeof(IID)) == 0);
+ EXPECT_EQ(memcmp(&ScopedComPtr<IUnknown>::iid(), &IID_IUnknown, sizeof(IID)),
+ 0);
base::win::ScopedCOMInitializer com_initializer;
EXPECT_TRUE(com_initializer.succeeded());
diff --git a/base/win/scoped_handle.h b/base/win/scoped_handle.h
index db24f4b..97fd7a5 100644
--- a/base/win/scoped_handle.h
+++ b/base/win/scoped_handle.h
@@ -174,4 +174,4 @@
} // namespace win
} // namespace base
-#endif // BASE_SCOPED_HANDLE_WIN_H_
+#endif // BASE_WIN_SCOPED_HANDLE_H_
diff --git a/base/win/scoped_propvariant.h b/base/win/scoped_propvariant.h
index 711d51a..62cc6a6 100644
--- a/base/win/scoped_propvariant.h
+++ b/base/win/scoped_propvariant.h
@@ -41,8 +41,7 @@
}
const PROPVARIANT& get() const { return pv_; }
-
- const PROPVARIANT* operator&() const { return &pv_; }
+ const PROPVARIANT* ptr() const { return &pv_; }
private:
PROPVARIANT pv_;
diff --git a/base/win/scoped_variant.h b/base/win/scoped_variant.h
index b6e6579..322fcf7 100644
--- a/base/win/scoped_variant.h
+++ b/base/win/scoped_variant.h
@@ -122,9 +122,7 @@
// This support is necessary for the V_XYZ (e.g. V_BSTR) set of macros to
// work properly but still doesn't allow modifications since we want control
// over that.
- const VARIANT* operator&() const {
- return &var_;
- }
+ const VARIANT* ptr() const { return &var_; }
// Like other scoped classes (e.g scoped_refptr, ScopedComPtr, ScopedBstr)
// we support the assignment operator for the type we wrap.
@@ -161,6 +159,6 @@
};
} // namespace win
-} // namesoace base
+} // namespace base
#endif // BASE_WIN_SCOPED_VARIANT_H_
diff --git a/base/win/scoped_variant_unittest.cc b/base/win/scoped_variant_unittest.cc
index 1f017cf..284a6ef 100644
--- a/base/win/scoped_variant_unittest.cc
+++ b/base/win/scoped_variant_unittest.cc
@@ -72,41 +72,41 @@
TEST(ScopedVariantTest, ScopedVariant) {
ScopedVariant var;
EXPECT_TRUE(var.type() == VT_EMPTY);
- // V_BSTR(&var) = NULL; <- NOTE: Assignment like that is not supported
+ // V_BSTR(var.ptr()) = NULL; <- NOTE: Assignment like that is not supported.
ScopedVariant var_bstr(L"VT_BSTR");
- EXPECT_EQ(VT_BSTR, V_VT(&var_bstr));
- EXPECT_TRUE(V_BSTR(&var_bstr) != NULL); // can't use EXPECT_NE for BSTR
+ EXPECT_EQ(VT_BSTR, V_VT(var_bstr.ptr()));
+ EXPECT_TRUE(V_BSTR(var_bstr.ptr()) != NULL); // can't use EXPECT_NE for BSTR
var_bstr.Reset();
- EXPECT_NE(VT_BSTR, V_VT(&var_bstr));
+ EXPECT_NE(VT_BSTR, V_VT(var_bstr.ptr()));
var_bstr.Set(kTestString2);
- EXPECT_EQ(VT_BSTR, V_VT(&var_bstr));
+ EXPECT_EQ(VT_BSTR, V_VT(var_bstr.ptr()));
VARIANT tmp = var_bstr.Release();
- EXPECT_EQ(VT_EMPTY, V_VT(&var_bstr));
+ EXPECT_EQ(VT_EMPTY, V_VT(var_bstr.ptr()));
EXPECT_EQ(VT_BSTR, V_VT(&tmp));
EXPECT_EQ(0, lstrcmp(V_BSTR(&tmp), kTestString2));
var.Reset(tmp);
- EXPECT_EQ(VT_BSTR, V_VT(&var));
- EXPECT_EQ(0, lstrcmpW(V_BSTR(&var), kTestString2));
+ EXPECT_EQ(VT_BSTR, V_VT(var.ptr()));
+ EXPECT_EQ(0, lstrcmpW(V_BSTR(var.ptr()), kTestString2));
var_bstr.Swap(var);
- EXPECT_EQ(VT_EMPTY, V_VT(&var));
- EXPECT_EQ(VT_BSTR, V_VT(&var_bstr));
- EXPECT_EQ(0, lstrcmpW(V_BSTR(&var_bstr), kTestString2));
+ EXPECT_EQ(VT_EMPTY, V_VT(var.ptr()));
+ EXPECT_EQ(VT_BSTR, V_VT(var_bstr.ptr()));
+ EXPECT_EQ(0, lstrcmpW(V_BSTR(var_bstr.ptr()), kTestString2));
var_bstr.Reset();
// Test the Compare and Copy routines.
GiveMeAVariant(var_bstr.Receive());
- ScopedVariant var_bstr2(V_BSTR(&var_bstr));
+ ScopedVariant var_bstr2(V_BSTR(var_bstr.ptr()));
EXPECT_EQ(0, var_bstr.Compare(var_bstr2));
var_bstr2.Reset();
EXPECT_NE(0, var_bstr.Compare(var_bstr2));
var_bstr2.Reset(var_bstr.Copy());
EXPECT_EQ(0, var_bstr.Compare(var_bstr2));
var_bstr2.Reset();
- var_bstr2.Set(V_BSTR(&var_bstr));
+ var_bstr2.Set(V_BSTR(var_bstr.ptr()));
EXPECT_EQ(0, var_bstr.Compare(var_bstr2));
var_bstr2.Reset();
var_bstr.Reset();
@@ -119,7 +119,7 @@
var.Reset();
var.SetDate(date);
EXPECT_EQ(VT_DATE, var.type());
- EXPECT_EQ(date, V_DATE(&var));
+ EXPECT_EQ(date, V_DATE(var.ptr()));
// Simple setter tests. These do not require resetting the variant
// after each test since the variant type is not "leakable" (i.e. doesn't
@@ -128,75 +128,75 @@
// We need static cast here since char defaults to int (!?).
var.Set(static_cast<int8>('v'));
EXPECT_EQ(VT_I1, var.type());
- EXPECT_EQ('v', V_I1(&var));
+ EXPECT_EQ('v', V_I1(var.ptr()));
var.Set(static_cast<short>(123));
EXPECT_EQ(VT_I2, var.type());
- EXPECT_EQ(123, V_I2(&var));
+ EXPECT_EQ(123, V_I2(var.ptr()));
var.Set(static_cast<int32>(123));
EXPECT_EQ(VT_I4, var.type());
- EXPECT_EQ(123, V_I4(&var));
+ EXPECT_EQ(123, V_I4(var.ptr()));
var.Set(static_cast<int64>(123));
EXPECT_EQ(VT_I8, var.type());
- EXPECT_EQ(123, V_I8(&var));
+ EXPECT_EQ(123, V_I8(var.ptr()));
var.Set(static_cast<uint8>(123));
EXPECT_EQ(VT_UI1, var.type());
- EXPECT_EQ(123, V_UI1(&var));
+ EXPECT_EQ(123, V_UI1(var.ptr()));
var.Set(static_cast<unsigned short>(123));
EXPECT_EQ(VT_UI2, var.type());
- EXPECT_EQ(123, V_UI2(&var));
+ EXPECT_EQ(123, V_UI2(var.ptr()));
var.Set(static_cast<uint32>(123));
EXPECT_EQ(VT_UI4, var.type());
- EXPECT_EQ(123, V_UI4(&var));
+ EXPECT_EQ(123, V_UI4(var.ptr()));
var.Set(static_cast<uint64>(123));
EXPECT_EQ(VT_UI8, var.type());
- EXPECT_EQ(123, V_UI8(&var));
+ EXPECT_EQ(123, V_UI8(var.ptr()));
var.Set(123.123f);
EXPECT_EQ(VT_R4, var.type());
- EXPECT_EQ(123.123f, V_R4(&var));
+ EXPECT_EQ(123.123f, V_R4(var.ptr()));
var.Set(static_cast<double>(123.123));
EXPECT_EQ(VT_R8, var.type());
- EXPECT_EQ(123.123, V_R8(&var));
+ EXPECT_EQ(123.123, V_R8(var.ptr()));
var.Set(true);
EXPECT_EQ(VT_BOOL, var.type());
- EXPECT_EQ(VARIANT_TRUE, V_BOOL(&var));
+ EXPECT_EQ(VARIANT_TRUE, V_BOOL(var.ptr()));
var.Set(false);
EXPECT_EQ(VT_BOOL, var.type());
- EXPECT_EQ(VARIANT_FALSE, V_BOOL(&var));
+ EXPECT_EQ(VARIANT_FALSE, V_BOOL(var.ptr()));
// Com interface tests
var.Set(static_cast<IDispatch*>(NULL));
EXPECT_EQ(VT_DISPATCH, var.type());
- EXPECT_EQ(NULL, V_DISPATCH(&var));
+ EXPECT_EQ(NULL, V_DISPATCH(var.ptr()));
var.Reset();
var.Set(static_cast<IUnknown*>(NULL));
EXPECT_EQ(VT_UNKNOWN, var.type());
- EXPECT_EQ(NULL, V_UNKNOWN(&var));
+ EXPECT_EQ(NULL, V_UNKNOWN(var.ptr()));
var.Reset();
FakeComObject faker;
EXPECT_EQ(0, faker.ref_count());
var.Set(static_cast<IDispatch*>(&faker));
EXPECT_EQ(VT_DISPATCH, var.type());
- EXPECT_EQ(&faker, V_DISPATCH(&var));
+ EXPECT_EQ(&faker, V_DISPATCH(var.ptr()));
EXPECT_EQ(1, faker.ref_count());
var.Reset();
EXPECT_EQ(0, faker.ref_count());
var.Set(static_cast<IUnknown*>(&faker));
EXPECT_EQ(VT_UNKNOWN, var.type());
- EXPECT_EQ(&faker, V_UNKNOWN(&var));
+ EXPECT_EQ(&faker, V_UNKNOWN(var.ptr()));
EXPECT_EQ(1, faker.ref_count());
var.Reset();
EXPECT_EQ(0, faker.ref_count());
@@ -204,7 +204,7 @@
{
ScopedVariant disp_var(&faker);
EXPECT_EQ(VT_DISPATCH, disp_var.type());
- EXPECT_EQ(&faker, V_DISPATCH(&disp_var));
+ EXPECT_EQ(&faker, V_DISPATCH(disp_var.ptr()));
EXPECT_EQ(1, faker.ref_count());
}
EXPECT_EQ(0, faker.ref_count());
@@ -223,7 +223,7 @@
{
ScopedVariant unk_var(static_cast<IUnknown*>(&faker));
EXPECT_EQ(VT_UNKNOWN, unk_var.type());
- EXPECT_EQ(&faker, V_UNKNOWN(&unk_var));
+ EXPECT_EQ(&faker, V_UNKNOWN(unk_var.ptr()));
EXPECT_EQ(1, faker.ref_count());
}
EXPECT_EQ(0, faker.ref_count());
@@ -240,7 +240,7 @@
{
ScopedVariant number(123);
EXPECT_EQ(VT_I4, number.type());
- EXPECT_EQ(123, V_I4(&number));
+ EXPECT_EQ(123, V_I4(number.ptr()));
}
// SAFEARRAY tests
@@ -253,7 +253,7 @@
var.Set(sa);
EXPECT_TRUE(ScopedVariant::IsLeakableVarType(var.type()));
EXPECT_EQ(VT_ARRAY | VT_UI1, var.type());
- EXPECT_EQ(sa, V_ARRAY(&var));
+ EXPECT_EQ(sa, V_ARRAY(var.ptr()));
// The array is destroyed in the destructor of var.
}
diff --git a/base/win/startup_information.h b/base/win/startup_information.h
index 7cef81f..e7e21cb 100644
--- a/base/win/startup_information.h
+++ b/base/win/startup_information.h
@@ -45,5 +45,4 @@
} // namespace win
} // namespace base
-#endif // BASE_WIN_SCOPED_STARTUP_INFO_EX_H_
-
+#endif // BASE_WIN_STARTUP_INFORMATION_H__
diff --git a/base/win/win_util.cc b/base/win/win_util.cc
index 957f937..59ae375 100644
--- a/base/win/win_util.cc
+++ b/base/win/win_util.cc
@@ -70,6 +70,53 @@
return true;
}
+ // If the device is docked, the user is treating the device as a PC.
+ if (GetSystemMetrics(SM_SYSTEMDOCKED) != 0)
+ return true;
+
+ // To determine whether a keyboard is present on the device, we do the
+ // following:-
+ // 1. Check whether the device supports auto rotation. If it does then
+ // it possibly supports flipping from laptop to slate mode. If it
+ // does not support auto rotation, then we assume it is a desktop
+ // or a normal laptop and assume that there is a keyboard.
+
+ // 2. If the device supports auto rotation, then we get its platform role
+ // and check the system metric SM_CONVERTIBLESLATEMODE to see if it is
+ // being used in slate mode. If yes then we return false here to ensure
+ // that the OSK is displayed.
+
+ // 3. If step 1 and 2 fail then we check attached keyboards and return true
+ // if we find ACPI\* or HID\VID* keyboards.
+
+ typedef BOOL (WINAPI* GetAutoRotationState)(PAR_STATE state);
+
+ GetAutoRotationState get_rotation_state =
+ reinterpret_cast<GetAutoRotationState>(::GetProcAddress(
+ GetModuleHandle(L"user32.dll"), "GetAutoRotationState"));
+
+ if (get_rotation_state) {
+ AR_STATE auto_rotation_state = AR_ENABLED;
+ get_rotation_state(&auto_rotation_state);
+ if ((auto_rotation_state & AR_NOSENSOR) ||
+ (auto_rotation_state & AR_NOT_SUPPORTED)) {
+ // If there is no auto rotation sensor or rotation is not supported in
+ // the current configuration, then we can assume that this is a desktop
+ // or a traditional laptop.
+ return true;
+ }
+ }
+
+ // Check if the device is being used as a laptop or a tablet. This can be
+ // checked by first checking the role of the device and then the
+ // corresponding system metric (SM_CONVERTIBLESLATEMODE). If it is being used
+ // as a tablet then we want the OSK to show up.
+ POWER_PLATFORM_ROLE role = PowerDeterminePlatformRole();
+
+ if (((role == PlatformRoleMobile) || (role == PlatformRoleSlate)) &&
+ (GetSystemMetrics(SM_CONVERTIBLESLATEMODE) == 0))
+ return false;
+
const GUID KEYBOARD_CLASS_GUID =
{ 0x4D36E96B, 0xE325, 0x11CE,
{ 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18 } };
@@ -97,10 +144,9 @@
MAX_DEVICE_ID_LEN,
0);
if (status == CR_SUCCESS) {
- // To reduce the scope of the hack we only look for PNP, MSF and HID
- // keyboards.
- if (StartsWith(device_id, L"ACPI\\PNP", false) ||
- StartsWith(device_id, L"ACPI\\MSF", false) ||
+ // To reduce the scope of the hack we only look for ACPI and HID\\VID
+ // prefixes in the keyboard device ids.
+ if (StartsWith(device_id, L"ACPI", false) ||
StartsWith(device_id, L"HID\\VID", false)) {
keyboard_count++;
}
diff --git a/base/win/win_util_unittest.cc b/base/win/win_util_unittest.cc
index 8300c16..24141cd 100644
--- a/base/win/win_util_unittest.cc
+++ b/base/win/win_util_unittest.cc
@@ -49,9 +49,9 @@
TEST(BaseWinUtilTest, TestGetNonClientMetrics) {
NONCLIENTMETRICS_XP metrics = {0};
GetNonClientMetrics(&metrics);
- EXPECT_TRUE(metrics.cbSize > 0);
- EXPECT_TRUE(metrics.iScrollWidth > 0);
- EXPECT_TRUE(metrics.iScrollHeight > 0);
+ EXPECT_GT(metrics.cbSize, 0u);
+ EXPECT_GT(metrics.iScrollWidth, 0);
+ EXPECT_GT(metrics.iScrollHeight, 0);
}
} // namespace win