Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/browser_main_loop.h" | 5 #include "content/browser/browser_main_loop.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
| 12 #include "base/metrics/histogram.h" | 12 #include "base/metrics/histogram.h" |
| 13 #include "base/pending_task.h" | 13 #include "base/pending_task.h" |
| 14 #include "base/power_monitor/power_monitor.h" | 14 #include "base/power_monitor/power_monitor.h" |
| 15 #include "base/power_monitor/power_monitor_device_source.h" | 15 #include "base/power_monitor/power_monitor_device_source.h" |
| 16 #include "base/process/process_metrics.h" | 16 #include "base/process/process_metrics.h" |
| 17 #include "base/profiler/scoped_profile.h" | 17 #include "base/profiler/scoped_profile.h" |
| 18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_split.h" | |
| 20 #include "base/system_monitor/system_monitor.h" | 21 #include "base/system_monitor/system_monitor.h" |
| 21 #include "base/thread_task_runner_handle.h" | 22 #include "base/thread_task_runner_handle.h" |
| 22 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
| 23 #include "base/timer/hi_res_timer_manager.h" | 24 #include "base/timer/hi_res_timer_manager.h" |
| 24 #include "base/trace_event/memory_dump_manager.h" | 25 #include "base/trace_event/memory_dump_manager.h" |
| 25 #include "base/trace_event/trace_event.h" | 26 #include "base/trace_event/trace_event.h" |
| 26 #include "content/browser/browser_thread_impl.h" | 27 #include "content/browser/browser_thread_impl.h" |
| 27 #include "content/browser/device_sensors/device_inertial_sensor_service.h" | 28 #include "content/browser/device_sensors/device_inertial_sensor_service.h" |
| 28 #include "content/browser/download/save_file_manager.h" | 29 #include "content/browser/download/save_file_manager.h" |
| 29 #include "content/browser/gamepad/gamepad_service.h" | 30 #include "content/browser/gamepad/gamepad_service.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 #include "content/browser/cocoa/system_hotkey_helper_mac.h" | 95 #include "content/browser/cocoa/system_hotkey_helper_mac.h" |
| 95 #include "content/browser/compositor/browser_compositor_view_mac.h" | 96 #include "content/browser/compositor/browser_compositor_view_mac.h" |
| 96 #include "content/browser/theme_helper_mac.h" | 97 #include "content/browser/theme_helper_mac.h" |
| 97 #endif | 98 #endif |
| 98 | 99 |
| 99 #if defined(OS_WIN) | 100 #if defined(OS_WIN) |
| 100 #include <windows.h> | 101 #include <windows.h> |
| 101 #include <commctrl.h> | 102 #include <commctrl.h> |
| 102 #include <shellapi.h> | 103 #include <shellapi.h> |
| 103 | 104 |
| 105 #include "base/win/memory_pressure_monitor.h" | |
| 104 #include "content/browser/system_message_window_win.h" | 106 #include "content/browser/system_message_window_win.h" |
| 105 #include "content/common/sandbox_win.h" | 107 #include "content/common/sandbox_win.h" |
| 106 #include "net/base/winsock_init.h" | 108 #include "net/base/winsock_init.h" |
| 107 #include "ui/base/l10n/l10n_util_win.h" | 109 #include "ui/base/l10n/l10n_util_win.h" |
| 108 #endif | 110 #endif |
| 109 | 111 |
| 110 #if defined(OS_CHROMEOS) | 112 #if defined(OS_CHROMEOS) |
| 111 #include "base/chromeos/memory_pressure_monitor_chromeos.h" | 113 #include "base/chromeos/memory_pressure_monitor_chromeos.h" |
| 112 #include "chromeos/chromeos_switches.h" | 114 #include "chromeos/chromeos_switches.h" |
| 113 #endif | 115 #endif |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 NOINLINE void ResetThread_IndexedDb(scoped_ptr<base::Thread> thread) { | 294 NOINLINE void ResetThread_IndexedDb(scoped_ptr<base::Thread> thread) { |
| 293 volatile int inhibit_comdat = __LINE__; | 295 volatile int inhibit_comdat = __LINE__; |
| 294 ALLOW_UNUSED_LOCAL(inhibit_comdat); | 296 ALLOW_UNUSED_LOCAL(inhibit_comdat); |
| 295 thread.reset(); | 297 thread.reset(); |
| 296 } | 298 } |
| 297 #endif | 299 #endif |
| 298 | 300 |
| 299 MSVC_POP_WARNING() | 301 MSVC_POP_WARNING() |
| 300 MSVC_ENABLE_OPTIMIZE(); | 302 MSVC_ENABLE_OPTIMIZE(); |
| 301 | 303 |
| 304 #if defined(OS_WIN) | |
| 305 // Creates a memory pressure monitor using automatic thresholds, or those | |
| 306 // specified on the command-line. Ownership is passed to the caller. | |
| 307 base::win::MemoryPressureMonitor* CreateWinMemoryPressureMonitor( | |
| 308 const base::CommandLine& parsed_command_line) { | |
| 309 std::vector<std::string> thresholds; | |
| 310 base::SplitString( | |
| 311 parsed_command_line.GetSwitchValueASCII( | |
| 312 switches::kMemoryPressureThresholdsMb), | |
| 313 ',', | |
| 314 &thresholds); | |
| 315 | |
| 316 int moderate_threshold_mb = 0; | |
| 317 int critical_threshold_mb = 0; | |
| 318 if (thresholds.size() == 2 && | |
| 319 base::StringToInt(thresholds[0], &moderate_threshold_mb) && | |
| 320 base::StringToInt(thresholds[1], &critical_threshold_mb) && | |
| 321 moderate_threshold_mb >= critical_threshold_mb && | |
| 322 critical_threshold_mb >= 0) { | |
| 323 VLOG(0) << "Using custom thresholds for MemoryPressureMonitor (moderate=" | |
|
grt (UTC plus 2)
2015/05/07 02:12:12
this sort of always-on logging (VLOG vs DVLOG) is
chrisha
2015/05/07 21:17:36
Removed.
| |
| 324 << moderate_threshold_mb << "MB, critical=" | |
| 325 << critical_threshold_mb << "MB)"; | |
| 326 return new base::win::MemoryPressureMonitor(moderate_threshold_mb, | |
| 327 critical_threshold_mb); | |
| 328 } | |
| 329 | |
| 330 // In absence of valid switches use the automatic defaults. | |
| 331 return new base::win::MemoryPressureMonitor(); | |
| 332 } | |
| 333 #endif // defined(OS_WIN) | |
| 334 | |
| 302 } // namespace | 335 } // namespace |
| 303 | 336 |
| 304 // The currently-running BrowserMainLoop. There can be one or zero. | 337 // The currently-running BrowserMainLoop. There can be one or zero. |
| 305 BrowserMainLoop* g_current_browser_main_loop = NULL; | 338 BrowserMainLoop* g_current_browser_main_loop = NULL; |
| 306 | 339 |
| 307 // This is just to be able to keep ShutdownThreadsAndCleanUp out of | 340 // This is just to be able to keep ShutdownThreadsAndCleanUp out of |
| 308 // the public interface of BrowserMainLoop. | 341 // the public interface of BrowserMainLoop. |
| 309 class BrowserShutdownImpl { | 342 class BrowserShutdownImpl { |
| 310 public: | 343 public: |
| 311 static void ImmediateShutdownAndExitProcess() { | 344 static void ImmediateShutdownAndExitProcess() { |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 result_code_ = parts_->PreCreateThreads(); | 639 result_code_ = parts_->PreCreateThreads(); |
| 607 } | 640 } |
| 608 | 641 |
| 609 #if defined(OS_CHROMEOS) | 642 #if defined(OS_CHROMEOS) |
| 610 if (chromeos::switches::MemoryPressureHandlingEnabled()) { | 643 if (chromeos::switches::MemoryPressureHandlingEnabled()) { |
| 611 memory_pressure_monitor_.reset(new base::MemoryPressureMonitorChromeOS( | 644 memory_pressure_monitor_.reset(new base::MemoryPressureMonitorChromeOS( |
| 612 chromeos::switches::GetMemoryPressureThresholds())); | 645 chromeos::switches::GetMemoryPressureThresholds())); |
| 613 } | 646 } |
| 614 #elif defined(OS_MACOSX) && !defined(OS_IOS) | 647 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
| 615 memory_pressure_monitor_.reset(new base::MemoryPressureMonitorMac()); | 648 memory_pressure_monitor_.reset(new base::MemoryPressureMonitorMac()); |
| 649 #elif defined(OS_WIN) | |
| 650 memory_pressure_monitor_.reset(CreateWinMemoryPressureMonitor( | |
| 651 parsed_command_line_)); | |
| 616 #endif | 652 #endif |
| 617 | 653 |
| 618 #if defined(ENABLE_PLUGINS) | 654 #if defined(ENABLE_PLUGINS) |
| 619 // Prior to any processing happening on the io thread, we create the | 655 // Prior to any processing happening on the io thread, we create the |
| 620 // plugin service as it is predominantly used from the io thread, | 656 // plugin service as it is predominantly used from the io thread, |
| 621 // but must be created on the main thread. The service ctor is | 657 // but must be created on the main thread. The service ctor is |
| 622 // inexpensive and does not invoke the io_thread() accessor. | 658 // inexpensive and does not invoke the io_thread() accessor. |
| 623 { | 659 { |
| 624 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads:PluginService"); | 660 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads:PluginService"); |
| 625 PluginService::GetInstance()->Init(); | 661 PluginService::GetInstance()->Init(); |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1310 | 1346 |
| 1311 void BrowserMainLoop::EndStartupTracing() { | 1347 void BrowserMainLoop::EndStartupTracing() { |
| 1312 is_tracing_startup_ = false; | 1348 is_tracing_startup_ = false; |
| 1313 TracingController::GetInstance()->DisableRecording( | 1349 TracingController::GetInstance()->DisableRecording( |
| 1314 TracingController::CreateFileSink( | 1350 TracingController::CreateFileSink( |
| 1315 startup_trace_file_, | 1351 startup_trace_file_, |
| 1316 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); | 1352 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); |
| 1317 } | 1353 } |
| 1318 | 1354 |
| 1319 } // namespace content | 1355 } // namespace content |
| OLD | NEW |