| 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 return new base::win::MemoryPressureMonitor(moderate_threshold_mb, |
| 324 critical_threshold_mb); |
| 325 } |
| 326 |
| 327 // In absence of valid switches use the automatic defaults. |
| 328 return new base::win::MemoryPressureMonitor(); |
| 329 } |
| 330 #endif // defined(OS_WIN) |
| 331 |
| 302 } // namespace | 332 } // namespace |
| 303 | 333 |
| 304 // The currently-running BrowserMainLoop. There can be one or zero. | 334 // The currently-running BrowserMainLoop. There can be one or zero. |
| 305 BrowserMainLoop* g_current_browser_main_loop = NULL; | 335 BrowserMainLoop* g_current_browser_main_loop = NULL; |
| 306 | 336 |
| 307 // This is just to be able to keep ShutdownThreadsAndCleanUp out of | 337 // This is just to be able to keep ShutdownThreadsAndCleanUp out of |
| 308 // the public interface of BrowserMainLoop. | 338 // the public interface of BrowserMainLoop. |
| 309 class BrowserShutdownImpl { | 339 class BrowserShutdownImpl { |
| 310 public: | 340 public: |
| 311 static void ImmediateShutdownAndExitProcess() { | 341 static void ImmediateShutdownAndExitProcess() { |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 result_code_ = parts_->PreCreateThreads(); | 636 result_code_ = parts_->PreCreateThreads(); |
| 607 } | 637 } |
| 608 | 638 |
| 609 #if defined(OS_CHROMEOS) | 639 #if defined(OS_CHROMEOS) |
| 610 if (chromeos::switches::MemoryPressureHandlingEnabled()) { | 640 if (chromeos::switches::MemoryPressureHandlingEnabled()) { |
| 611 memory_pressure_monitor_.reset(new base::MemoryPressureMonitorChromeOS( | 641 memory_pressure_monitor_.reset(new base::MemoryPressureMonitorChromeOS( |
| 612 chromeos::switches::GetMemoryPressureThresholds())); | 642 chromeos::switches::GetMemoryPressureThresholds())); |
| 613 } | 643 } |
| 614 #elif defined(OS_MACOSX) && !defined(OS_IOS) | 644 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
| 615 memory_pressure_monitor_.reset(new base::MemoryPressureMonitorMac()); | 645 memory_pressure_monitor_.reset(new base::MemoryPressureMonitorMac()); |
| 646 #elif defined(OS_WIN) |
| 647 memory_pressure_monitor_.reset(CreateWinMemoryPressureMonitor( |
| 648 parsed_command_line_)); |
| 616 #endif | 649 #endif |
| 617 | 650 |
| 618 #if defined(ENABLE_PLUGINS) | 651 #if defined(ENABLE_PLUGINS) |
| 619 // Prior to any processing happening on the io thread, we create the | 652 // Prior to any processing happening on the io thread, we create the |
| 620 // plugin service as it is predominantly used from the io thread, | 653 // plugin service as it is predominantly used from the io thread, |
| 621 // but must be created on the main thread. The service ctor is | 654 // but must be created on the main thread. The service ctor is |
| 622 // inexpensive and does not invoke the io_thread() accessor. | 655 // inexpensive and does not invoke the io_thread() accessor. |
| 623 { | 656 { |
| 624 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads:PluginService"); | 657 TRACE_EVENT0("startup", "BrowserMainLoop::CreateThreads:PluginService"); |
| 625 PluginService::GetInstance()->Init(); | 658 PluginService::GetInstance()->Init(); |
| (...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1310 | 1343 |
| 1311 void BrowserMainLoop::EndStartupTracing() { | 1344 void BrowserMainLoop::EndStartupTracing() { |
| 1312 is_tracing_startup_ = false; | 1345 is_tracing_startup_ = false; |
| 1313 TracingController::GetInstance()->DisableRecording( | 1346 TracingController::GetInstance()->DisableRecording( |
| 1314 TracingController::CreateFileSink( | 1347 TracingController::CreateFileSink( |
| 1315 startup_trace_file_, | 1348 startup_trace_file_, |
| 1316 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); | 1349 base::Bind(OnStoppedStartupTracing, startup_trace_file_))); |
| 1317 } | 1350 } |
| 1318 | 1351 |
| 1319 } // namespace content | 1352 } // namespace content |
| OLD | NEW |