diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-26 19:48:34 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-26 19:48:34 +0000 |
commit | 097ae5a93a863b604fd6dbd939bed0c2be1afed2 (patch) | |
tree | 61177362b1c1bd2d1b2438acc50ccb2c061b176e /chrome | |
parent | 902c971382790170852fe5b5d22d1b79adb31056 (diff) | |
download | chromium_src-097ae5a93a863b604fd6dbd939bed0c2be1afed2.zip chromium_src-097ae5a93a863b604fd6dbd939bed0c2be1afed2.tar.gz chromium_src-097ae5a93a863b604fd6dbd939bed0c2be1afed2.tar.bz2 |
Make SystemMonitor not a Singleton and move it out of base
SystemMonitor makes an assumption that through its lifetime a MessageLoop exists and stays the same. It is difficult and error-prone to satisfy that when it is a Singleton. It has caused problems in the past.
Additionally, extract HighResoltionTimerManager out of time_win.cc, eliminating yet another Singleton.
TEST=none
BUG=none
Review URL: http://codereview.chromium.org/431008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@33214 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_main.cc | 12 | ||||
-rw-r--r-- | chrome/browser/profile_manager.cc | 4 | ||||
-rw-r--r-- | chrome/browser/profile_manager.h | 4 | ||||
-rw-r--r-- | chrome/browser/tabs/tab_strip_model_unittest.cc | 5 | ||||
-rwxr-xr-x | chrome/chrome.gyp | 2 | ||||
-rw-r--r-- | chrome/nacl/nacl_main.cc | 7 | ||||
-rw-r--r-- | chrome/plugin/plugin_main.cc | 7 | ||||
-rw-r--r-- | chrome/profile_import/profile_import_main.cc | 1 | ||||
-rw-r--r-- | chrome/renderer/renderer_main.cc | 7 | ||||
-rw-r--r-- | chrome/utility/utility_main.cc | 7 | ||||
-rw-r--r-- | chrome/worker/worker_main.cc | 7 |
11 files changed, 35 insertions, 28 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index a452dab..28ba351 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -6,8 +6,10 @@ #include <algorithm> +#include "app/hi_res_timer_manager.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "app/system_monitor.h" #include "base/command_line.h" #include "base/field_trial.h" #include "base/file_util.h" @@ -19,7 +21,6 @@ #include "base/string_piece.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" -#include "base/system_monitor.h" #include "base/time.h" #include "base/tracked_objects.h" #include "base/values.h" @@ -340,13 +341,8 @@ int BrowserMain(const MainFunctionParams& parameters) { MessageLoop main_message_loop(MessageLoop::TYPE_UI); - // Initialize the SystemMonitor - base::SystemMonitor::Start(); -#if defined(OS_WIN) - // We want to monitor system power state to adjust our high resolution - // timer settings. But it's necessary only on Windows. - base::Time::StartSystemMonitorObserver(); -#endif // defined(OS_WIN) + SystemMonitor system_monitor; + HighResolutionTimerManager hi_res_timer_manager; // Initialize statistical testing infrastructure. FieldTrialList field_trial; diff --git a/chrome/browser/profile_manager.cc b/chrome/browser/profile_manager.cc index 2a20bdc..9b66e39 100644 --- a/chrome/browser/profile_manager.cc +++ b/chrome/browser/profile_manager.cc @@ -42,11 +42,11 @@ void ProfileManager::ShutdownSessionServices() { } ProfileManager::ProfileManager() { - base::SystemMonitor::Get()->AddObserver(this); + SystemMonitor::Get()->AddObserver(this); } ProfileManager::~ProfileManager() { - base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); + SystemMonitor* system_monitor = SystemMonitor::Get(); if (system_monitor) system_monitor->RemoveObserver(this); diff --git a/chrome/browser/profile_manager.h b/chrome/browser/profile_manager.h index ecbbfc8..b52c7db 100644 --- a/chrome/browser/profile_manager.h +++ b/chrome/browser/profile_manager.h @@ -11,11 +11,11 @@ #include <string> #include <vector> +#include "app/system_monitor.h" #include "base/basictypes.h" #include "base/file_path.h" #include "base/message_loop.h" #include "base/non_thread_safe.h" -#include "base/system_monitor.h" #include "base/values.h" #include "chrome/browser/profile.h" @@ -63,7 +63,7 @@ class AvailableProfile { }; class ProfileManager : public NonThreadSafe, - public base::SystemMonitor::PowerObserver { + public SystemMonitor::PowerObserver { public: ProfileManager(); virtual ~ProfileManager(); diff --git a/chrome/browser/tabs/tab_strip_model_unittest.cc b/chrome/browser/tabs/tab_strip_model_unittest.cc index 70331f9..00afd03 100644 --- a/chrome/browser/tabs/tab_strip_model_unittest.cc +++ b/chrome/browser/tabs/tab_strip_model_unittest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/system_monitor.h" #include "base/file_util.h" #include "base/path_service.h" #include "base/string_util.h" @@ -151,6 +152,10 @@ class TabStripModelTest : public RenderViewHostTestHarness { std::wstring test_dir_; std::wstring profile_path_; std::map<TabContents*, int> foo_; + + // ProfileManager requires a SystemMonitor. + SystemMonitor system_monitor; + ProfileManager pm_; }; diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index c921070..c73946e 100755 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -739,6 +739,8 @@ ], }, { # else: OS != "win" 'sources!': [ + 'common/hi_res_timer_manager.cc', + 'common/hi_res_timer_manager.h', 'common/temp_scaffolding_stubs.h', ], }], diff --git a/chrome/nacl/nacl_main.cc b/chrome/nacl/nacl_main.cc index 0516495..5271cf4 100644 --- a/chrome/nacl/nacl_main.cc +++ b/chrome/nacl/nacl_main.cc @@ -10,10 +10,11 @@ #include "sandbox/src/sandbox.h" #endif +#include "app/hi_res_timer_manager.h" +#include "app/system_monitor.h" #include "base/command_line.h" #include "base/message_loop.h" #include "base/string_util.h" -#include "base/system_monitor.h" #include "chrome/common/child_process.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" @@ -28,8 +29,8 @@ int NaClMain(const MainFunctionParams& parameters) { std::wstring app_name = chrome::kBrowserAppName; PlatformThread::SetName(WideToASCII(app_name + L"_NaClMain").c_str()); - // Initialize the SystemMonitor - base::SystemMonitor::Start(); + SystemMonitor system_monitor; + HighResolutionTimerManager hi_res_timer_manager; #if defined(OS_WIN) const CommandLine& parsed_command_line = parameters.command_line_; diff --git a/chrome/plugin/plugin_main.cc b/chrome/plugin/plugin_main.cc index 0b67360..9794305 100644 --- a/chrome/plugin/plugin_main.cc +++ b/chrome/plugin/plugin_main.cc @@ -4,13 +4,14 @@ #include "build/build_config.h" +#include "app/hi_res_timer_manager.h" +#include "app/system_monitor.h" #if defined(OS_WIN) #include "app/win_util.h" #endif #include "base/command_line.h" #include "base/message_loop.h" #include "base/string_util.h" -#include "base/system_monitor.h" #include "chrome/common/child_process.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" @@ -89,8 +90,8 @@ int PluginMain(const MainFunctionParams& parameters) { std::wstring app_name = chrome::kBrowserAppName; PlatformThread::SetName(WideToASCII(app_name + L"_PluginMain").c_str()); - // Initialize the SystemMonitor - base::SystemMonitor::Start(); + SystemMonitor system_monitor; + HighResolutionTimerManager high_resolution_timer_manager; #if defined(OS_MACOSX) TrimInterposeEnvironment(); diff --git a/chrome/profile_import/profile_import_main.cc b/chrome/profile_import/profile_import_main.cc index 11b1aed..546df18 100644 --- a/chrome/profile_import/profile_import_main.cc +++ b/chrome/profile_import/profile_import_main.cc @@ -5,7 +5,6 @@ #include "base/command_line.h" #include "base/message_loop.h" #include "base/string_util.h" -#include "base/system_monitor.h" #include "chrome/common/child_process.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" diff --git a/chrome/renderer/renderer_main.cc b/chrome/renderer/renderer_main.cc index 1531c40..c8f89c9 100644 --- a/chrome/renderer/renderer_main.cc +++ b/chrome/renderer/renderer_main.cc @@ -2,8 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/hi_res_timer_manager.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" +#include "app/system_monitor.h" #include "base/command_line.h" #include "base/field_trial.h" #include "base/histogram.h" @@ -14,7 +16,6 @@ #include "base/scoped_nsautorelease_pool.h" #include "base/stats_counters.h" #include "base/string_util.h" -#include "base/system_monitor.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_counters.h" #include "chrome/common/chrome_switches.h" @@ -88,8 +89,8 @@ int RendererMain(const MainFunctionParams& parameters) { std::wstring app_name = chrome::kBrowserAppName; PlatformThread::SetName(WideToASCII(app_name + L"_RendererMain").c_str()); - // Initialize the SystemMonitor - base::SystemMonitor::Start(); + SystemMonitor system_monitor; + HighResolutionTimerManager hi_res_timer_manager; platform.PlatformInitialize(); diff --git a/chrome/utility/utility_main.cc b/chrome/utility/utility_main.cc index b2eaa46..690d47b1 100644 --- a/chrome/utility/utility_main.cc +++ b/chrome/utility/utility_main.cc @@ -3,10 +3,11 @@ // found in the LICENSE file. #include "app/app_switches.h" +#include "app/hi_res_timer_manager.h" +#include "app/system_monitor.h" #include "base/command_line.h" #include "base/message_loop.h" #include "base/string_util.h" -#include "base/system_monitor.h" #include "chrome/common/child_process.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" @@ -27,8 +28,8 @@ int UtilityMain(const MainFunctionParams& parameters) { std::wstring app_name = chrome::kBrowserAppName; PlatformThread::SetName(WideToASCII(app_name + L"_UtilityMain").c_str()); - // Initialize the SystemMonitor - base::SystemMonitor::Start(); + SystemMonitor system_monitor; + HighResolutionTimerManager hi_res_timer_manager; ChildProcess utility_process; utility_process.set_main_thread(new UtilityThread()); diff --git a/chrome/worker/worker_main.cc b/chrome/worker/worker_main.cc index b157dbe..a91ac74 100644 --- a/chrome/worker/worker_main.cc +++ b/chrome/worker/worker_main.cc @@ -2,10 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "app/hi_res_timer_manager.h" +#include "app/system_monitor.h" #include "base/command_line.h" #include "base/message_loop.h" #include "base/string_util.h" -#include "base/system_monitor.h" #include "chrome/common/child_process.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_switches.h" @@ -25,8 +26,8 @@ int WorkerMain(const MainFunctionParams& parameters) { std::wstring app_name = chrome::kBrowserAppName; PlatformThread::SetName(WideToASCII(app_name + L"_WorkerMain").c_str()); - // Initialize the SystemMonitor - base::SystemMonitor::Start(); + SystemMonitor system_monitor; + HighResolutionTimerManager hi_res_timer_manager; ChildProcess worker_process; worker_process.set_main_thread(new WorkerThread()); |