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 | |
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
27 files changed, 195 insertions, 184 deletions
diff --git a/app/app.gyp b/app/app.gyp index 78f9978..4ddfb8a 100644 --- a/app/app.gyp +++ b/app/app.gyp @@ -105,6 +105,9 @@ 'gfx/text_elider.h', 'gtk_dnd_util.cc', 'gtk_dnd_util.h', + 'hi_res_timer_manager_posix.cc', + 'hi_res_timer_manager_win.cc', + 'hi_res_timer_manager.h', 'l10n_util.cc', 'l10n_util.h', 'l10n_util_mac.h', @@ -134,6 +137,10 @@ 'sql/statement.h', 'sql/transaction.cc', 'sql/transaction.h', + 'system_monitor.cc', + 'system_monitor.h', + 'system_monitor_posix.cc', + 'system_monitor_win.cc', 'table_model.cc', 'table_model.h', 'table_model_observer.h', @@ -244,6 +251,7 @@ 'l10n_util_unittest.cc', 'os_exchange_data_win_unittest.cc', 'run_all_unittests.cc', + 'system_monitor_unittest.cc', 'test_suite.h', 'sql/connection_unittest.cc', 'sql/statement_unittest.cc', diff --git a/app/hi_res_timer_manager.h b/app/hi_res_timer_manager.h new file mode 100644 index 0000000..17a0522 --- /dev/null +++ b/app/hi_res_timer_manager.h @@ -0,0 +1,29 @@ +// Copyright (c) 2009 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 APP_HI_RES_TIMER_MANAGER_H_ +#define APP_HI_RES_TIMER_MANAGER_H_ + +#include "app/system_monitor.h" + +// Ensures that the Windows high resolution timer is only used +// when not running on battery power. +class HighResolutionTimerManager : public SystemMonitor::PowerObserver { + public: + HighResolutionTimerManager(); + virtual ~HighResolutionTimerManager(); + + // SystemMonitor::PowerObserver: + void OnPowerStateChange(bool on_battery_power); + + private: + // Enable or disable the faster multimedia timer. + void UseHiResClock(bool use); + + bool hi_res_clock_used_; + + DISALLOW_COPY_AND_ASSIGN(HighResolutionTimerManager); +}; + +#endif // APP_HI_RES_TIMER_MANAGER_H_ diff --git a/app/hi_res_timer_manager_posix.cc b/app/hi_res_timer_manager_posix.cc new file mode 100644 index 0000000..f0562fd --- /dev/null +++ b/app/hi_res_timer_manager_posix.cc @@ -0,0 +1,19 @@ +// Copyright (c) 2009 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 "app/hi_res_timer_manager.h" + +// On POSIX we don't need to do anything special with the system timer. + +HighResolutionTimerManager::HighResolutionTimerManager() { +} + +HighResolutionTimerManager::~HighResolutionTimerManager() { +} + +void HighResolutionTimerManager::OnPowerStateChange(bool on_battery_power) { +} + +void HighResolutionTimerManager::UseHiResClock(bool use) { +} diff --git a/app/hi_res_timer_manager_win.cc b/app/hi_res_timer_manager_win.cc new file mode 100644 index 0000000..b7cee1d --- /dev/null +++ b/app/hi_res_timer_manager_win.cc @@ -0,0 +1,31 @@ +// Copyright (c) 2009 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 "app/hi_res_timer_manager.h" + +#include "base/time.h" + +HighResolutionTimerManager::HighResolutionTimerManager() + : hi_res_clock_used_(false) { + SystemMonitor* system_monitor = SystemMonitor::Get(); + system_monitor->AddObserver(this); + UseHiResClock(!system_monitor->BatteryPower()); +} + +HighResolutionTimerManager::~HighResolutionTimerManager() { + SystemMonitor::Get()->RemoveObserver(this); + UseHiResClock(false); +} + +void HighResolutionTimerManager::OnPowerStateChange(bool on_battery_power) { + UseHiResClock(!on_battery_power); +} + +void HighResolutionTimerManager::UseHiResClock(bool use) { + if (use == hi_res_clock_used_) + return; + bool result = base::Time::UseHighResolutionTimer(use); + DCHECK(result); + hi_res_clock_used_ = use; +} diff --git a/base/system_monitor.cc b/app/system_monitor.cc index 44cdce5..b0e715a 100644 --- a/base/system_monitor.cc +++ b/app/system_monitor.cc @@ -1,13 +1,14 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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/system_monitor.h" +#include "app/system_monitor.h" + #include "base/logging.h" #include "base/message_loop.h" -#include "base/singleton.h" +#include "base/time.h" -namespace base { +static SystemMonitor* g_system_monitor = NULL; #if defined(ENABLE_BATTERY_MONITORING) // The amount of time (in ms) to wait before running the initial @@ -16,9 +17,28 @@ static int kDelayedBatteryCheckMs = 10 * 1000; #endif // defined(ENABLE_BATTERY_MONITORING) SystemMonitor::SystemMonitor() - : battery_in_use_(false), + : observer_list_(new ObserverListThreadSafe<PowerObserver>()), + battery_in_use_(false), suspended_(false) { - observer_list_ = new ObserverListThreadSafe<PowerObserver>(); + DCHECK(!g_system_monitor); + g_system_monitor = this; + + DCHECK(MessageLoop::current()); +#if defined(ENABLE_BATTERY_MONITORING) + delayed_battery_check_.Start( + base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this, + &SystemMonitor::BatteryCheck); +#endif // defined(ENABLE_BATTERY_MONITORING) +} + +SystemMonitor::~SystemMonitor() { + DCHECK_EQ(this, g_system_monitor); + g_system_monitor = NULL; +} + +// static +SystemMonitor* SystemMonitor::Get() { + return g_system_monitor; } void SystemMonitor::ProcessPowerMessage(PowerEvent event_id) { @@ -73,26 +93,6 @@ void SystemMonitor::NotifyResume() { observer_list_->Notify(&PowerObserver::OnResume); } -// static -SystemMonitor* SystemMonitor::Get() { - // Uses the LeakySingletonTrait because cleanup is optional. - return - Singleton<SystemMonitor, LeakySingletonTraits<SystemMonitor> >::get(); -} - -// static -void SystemMonitor::Start() { -#if defined(ENABLE_BATTERY_MONITORING) - DCHECK(MessageLoop::current()); // Can't call start too early. - SystemMonitor* monitor = Get(); - monitor->delayed_battery_check_.Start( - TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), monitor, - &SystemMonitor::BatteryCheck); -#endif // defined(ENABLE_BATTERY_MONITORING) -} - void SystemMonitor::BatteryCheck() { ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); } - -} // namespace base diff --git a/base/system_monitor.h b/app/system_monitor.h index 71d8436..abafe4f 100644 --- a/base/system_monitor.h +++ b/app/system_monitor.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_SYSTEM_MONITOR_H_ -#define BASE_SYSTEM_MONITOR_H_ +#ifndef APP_SYSTEM_MONITOR_H_ +#define APP_SYSTEM_MONITOR_H_ #include "build/build_config.h" @@ -20,23 +20,18 @@ #include "base/timer.h" #endif // defined(ENABLE_BATTERY_MONITORING) -namespace base { - // Class for monitoring various system-related subsystems // such as power management, network status, etc. // TODO(mbelshe): Add support beyond just power management. class SystemMonitor { public: - // Retrieves the Singleton. - static SystemMonitor* Get(); + // Create SystemMonitor. Only one SystemMonitor instance per application + // is allowed. + SystemMonitor(); + ~SystemMonitor(); - // Start the System Monitor within a process. This method - // is provided so that the battery check can be deferred. - // The MessageLoop must be started before calling this - // method. - // This is a no-op on platforms for which ENABLE_BATTERY_MONITORING is - // disabled. - static void Start(); + // Get the application-wide SystemMonitor (if not present, returns NULL). + static SystemMonitor* Get(); // // Power-related APIs @@ -94,10 +89,6 @@ class SystemMonitor { // Cross-platform handling of a power event. void ProcessPowerMessage(PowerEvent event_id); - // Constructor. - // Don't use this; access SystemMonitor via the Singleton. - SystemMonitor(); - private: // Platform-specific method to check whether the system is currently // running on battery power. Returns true if running on batteries, @@ -124,6 +115,4 @@ class SystemMonitor { DISALLOW_COPY_AND_ASSIGN(SystemMonitor); }; -} - -#endif // BASE_SYSTEM_MONITOR_H_ +#endif // APP_SYSTEM_MONITOR_H_ diff --git a/base/system_monitor_posix.cc b/app/system_monitor_posix.cc index a4a118c..5ac7a12 100644 --- a/base/system_monitor_posix.cc +++ b/app/system_monitor_posix.cc @@ -1,14 +1,10 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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/system_monitor.h" - -namespace base { +#include "app/system_monitor.h" bool SystemMonitor::IsBatteryPower() { NOTIMPLEMENTED(); return false; } - -} // namespace base diff --git a/base/system_monitor_unittest.cc b/app/system_monitor_unittest.cc index 7ba3a6b..5b107aa 100644 --- a/base/system_monitor_unittest.cc +++ b/app/system_monitor_unittest.cc @@ -2,16 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/system_monitor.h" +#include "app/system_monitor.h" #include "testing/gtest/include/gtest/gtest.h" -class PowerTest : public base::SystemMonitor::PowerObserver { +class PowerTest : public SystemMonitor::PowerObserver { public: PowerTest() : battery_(false), power_state_changes_(0), suspends_(0), - resumes_(0) {}; + resumes_(0) { + } // PowerObserver callbacks. void OnPowerStateChange(bool on_battery_power) { @@ -47,40 +48,40 @@ TEST(SystemMonitor, PowerNotifications) { // Initialize time() since it registers as a SystemMonitor observer. base::Time now = base::Time::Now(); - base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); + SystemMonitor system_monitor; PowerTest test[kObservers]; for (int index = 0; index < kObservers; ++index) - system_monitor->AddObserver(&test[index]); + system_monitor.AddObserver(&test[index]); // Send a bunch of power changes. Since the battery power hasn't // actually changed, we shouldn't get notifications. for (int index = 0; index < 5; index++) { - system_monitor->ProcessPowerMessage(base::SystemMonitor::POWER_STATE_EVENT); + system_monitor.ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); EXPECT_EQ(test[0].power_state_changes(), 0); } // Sending resume when not suspended should have no effect. - system_monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT); + system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); loop.RunAllPending(); EXPECT_EQ(test[0].resumes(), 0); // Pretend we suspended. - system_monitor->ProcessPowerMessage(base::SystemMonitor::SUSPEND_EVENT); + system_monitor.ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT); loop.RunAllPending(); EXPECT_EQ(test[0].suspends(), 1); // Send a second suspend notification. This should be suppressed. - system_monitor->ProcessPowerMessage(base::SystemMonitor::SUSPEND_EVENT); + system_monitor.ProcessPowerMessage(SystemMonitor::SUSPEND_EVENT); loop.RunAllPending(); EXPECT_EQ(test[0].suspends(), 1); // Pretend we were awakened. - system_monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT); + system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); loop.RunAllPending(); EXPECT_EQ(test[0].resumes(), 1); // Send a duplicate resume notification. This should be suppressed. - system_monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT); + system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); loop.RunAllPending(); EXPECT_EQ(test[0].resumes(), 1); } diff --git a/base/system_monitor_win.cc b/app/system_monitor_win.cc index 8a2d8c9..c9347dc 100644 --- a/base/system_monitor_win.cc +++ b/app/system_monitor_win.cc @@ -1,10 +1,8 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2009 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/system_monitor.h" - -namespace base { +#include "app/system_monitor.h" void SystemMonitor::ProcessWmPowerBroadcastMessage(int event_id) { PowerEvent power_event; @@ -46,7 +44,3 @@ bool SystemMonitor::IsBatteryPower() { } return (status.ACLineStatus == 0); } - - - -} // namespace base diff --git a/base/base.gyp b/base/base.gyp index 7238928..23b85b1 100644 --- a/base/base.gyp +++ b/base/base.gyp @@ -321,10 +321,6 @@ 'sys_string_conversions_linux.cc', 'sys_string_conversions_mac.mm', 'sys_string_conversions_win.cc', - 'system_monitor.cc', - 'system_monitor.h', - 'system_monitor_posix.cc', - 'system_monitor_win.cc', 'task.h', 'thread.cc', 'thread.h', @@ -654,7 +650,6 @@ 'sys_info_unittest.cc', 'sys_string_conversions_mac_unittest.mm', 'sys_string_conversions_unittest.cc', - 'system_monitor_unittest.cc', 'task_unittest.cc', 'thread_collision_warner_unittest.cc', 'thread_local_storage_unittest.cc', diff --git a/base/test/test_suite.h b/base/test/test_suite.h index 44e8511..2566b1a 100644 --- a/base/test/test_suite.h +++ b/base/test/test_suite.h @@ -182,10 +182,10 @@ class TestSuite { CHECK(base::EnableInProcessStackDumping()); #if defined(OS_WIN) - // For unit tests we turn on the high resolution timer and disable - // base::Time's use of SystemMonitor. Tests create and destroy the message - // loop, which causes a crash with SystemMonitor (http://crbug.com/12187). - base::Time::EnableHiResClockForTests(); + // Make sure we run with high resolution timer to minimize differences + // between production code and test code. + bool result = base::Time::UseHighResolutionTimer(true); + CHECK(result); // In some cases, we do not want to see standard error dialogs. if (!IsDebuggerPresent() && diff --git a/base/time.h b/base/time.h index 8cd752a..33ab227 100644 --- a/base/time.h +++ b/base/time.h @@ -242,12 +242,9 @@ class Time { static Time FromFileTime(FILETIME ft); FILETIME ToFileTime() const; - // Monitor system power state and disable high resolution timer when we're - // on battery. See time_win.cc for more details. - static void StartSystemMonitorObserver(); - - // Enable high resolution timer unconditionally. Only for test code. - static void EnableHiResClockForTests(); + // Enable or disable Windows high resolution timer. For more details + // see comments in time_win.cc. Returns true on success. + static bool UseHighResolutionTimer(bool use); #endif // Converts an exploded structure representing either the local time or UTC diff --git a/base/time_win.cc b/base/time_win.cc index 9fdcab1..eedf468 100644 --- a/base/time_win.cc +++ b/base/time_win.cc @@ -45,7 +45,6 @@ #include "base/logging.h" #include "base/cpu.h" #include "base/singleton.h" -#include "base/system_monitor.h" using base::Time; using base::TimeDelta; @@ -88,65 +87,6 @@ void InitializeClock() { initial_time = CurrentWallclockMicroseconds(); } -class HighResolutionTimerManager : public base::SystemMonitor::PowerObserver { - public: - ~HighResolutionTimerManager() { - StopMonitoring(); - UseHiResClock(false); - } - - void Enable() { - StopMonitoring(); - UseHiResClock(true); - } - - void StartMonitoring() { - if (is_monitoring_) - return; - is_monitoring_ = true; - base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); - system_monitor->AddObserver(this); - UseHiResClock(!system_monitor->BatteryPower()); - } - - void StopMonitoring() { - if (!is_monitoring_) - return; - is_monitoring_ = false; - base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); - if (system_monitor) - system_monitor->RemoveObserver(this); - } - - // Interfaces for monitoring Power changes. - void OnPowerStateChange(bool on_battery_power) { - UseHiResClock(!on_battery_power); - } - - private: - HighResolutionTimerManager() - : is_monitoring_(false), - hi_res_clock_enabled_(false) { - } - friend struct DefaultSingletonTraits<HighResolutionTimerManager>; - - // Enable or disable the faster multimedia timer. - void UseHiResClock(bool enabled) { - if (enabled == hi_res_clock_enabled_) - return; - if (enabled) - timeBeginPeriod(1); - else - timeEndPeriod(1); - hi_res_clock_enabled_ = enabled; - } - - bool is_monitoring_; - bool hi_res_clock_enabled_; - - DISALLOW_COPY_AND_ASSIGN(HighResolutionTimerManager); -}; - } // namespace // Time ----------------------------------------------------------------------- @@ -208,13 +148,18 @@ FILETIME Time::ToFileTime() const { } // static -void Time::StartSystemMonitorObserver() { - Singleton<HighResolutionTimerManager>()->StartMonitoring(); -} - -// static -void Time::EnableHiResClockForTests() { - Singleton<HighResolutionTimerManager>()->Enable(); +bool Time::UseHighResolutionTimer(bool use) { + // TODO(mbelshe): Make sure that switching the system timer resolution + // doesn't break Timer firing order etc. An example test would be to have + // two threads. One would have a bunch of timers, and another would turn the + // high resolution timer on and off. + + MMRESULT result; + if (use) + result = timeBeginPeriod(1); + else + result = timeEndPeriod(1); + return (result == TIMERR_NOERROR); } // static 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()); diff --git a/chrome_frame/test/net/fake_external_tab.cc b/chrome_frame/test/net/fake_external_tab.cc index cc31331..2ea35d9 100644 --- a/chrome_frame/test/net/fake_external_tab.cc +++ b/chrome_frame/test/net/fake_external_tab.cc @@ -255,7 +255,7 @@ void CFUrlRequestUnittestRunner::Initialize() { // directly because it will attempt to initialize some things such as // ICU that have already been initialized for this process. InitializeLogging(); - base::Time::EnableHiResClockForTests(); + base::Time::UseHighResolutionTimer(true); #if !defined(PURIFY) && defined(OS_WIN) logging::SetLogAssertHandler(UnitTestAssertHandler); diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 79956a8..892d47f 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -8,6 +8,7 @@ #include "app/gfx/native_theme_win.h" #include "app/gfx/path.h" #include "app/l10n_util_win.h" +#include "app/system_monitor.h" #include "app/win_util.h" #include "base/string_util.h" #include "base/win_util.h" @@ -770,7 +771,7 @@ void WidgetWin::OnPaint(HDC dc) { } LRESULT WidgetWin::OnPowerBroadcast(DWORD power_event, DWORD data) { - base::SystemMonitor* monitor = base::SystemMonitor::Get(); + SystemMonitor* monitor = SystemMonitor::Get(); if (monitor) monitor->ProcessWmPowerBroadcastMessage(power_event); SetMsgHandled(FALSE); diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h index 3f06ca3..43c4357 100644 --- a/views/widget/widget_win.h +++ b/views/widget/widget_win.h @@ -13,7 +13,6 @@ #include "app/win/window_impl.h" #include "base/message_loop.h" #include "base/scoped_comptr_win.h" -#include "base/system_monitor.h" #include "views/focus/focus_manager.h" #include "views/layout_manager.h" #include "views/widget/widget.h" |