diff options
-rw-r--r-- | base/system_monitor.cc | 6 | ||||
-rw-r--r-- | base/system_monitor.h | 10 | ||||
-rw-r--r-- | base/system_monitor_unittest.cc | 32 | ||||
-rw-r--r-- | base/time_win.cc | 22 | ||||
-rw-r--r-- | chrome/browser/profile_manager.cc | 16 | ||||
-rw-r--r-- | chrome/browser/profile_manager.h | 7 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_service.cc | 18 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_service.h | 6 |
8 files changed, 55 insertions, 62 deletions
diff --git a/base/system_monitor.cc b/base/system_monitor.cc index cf946a7..44cdce5 100644 --- a/base/system_monitor.cc +++ b/base/system_monitor.cc @@ -60,17 +60,17 @@ void SystemMonitor::RemoveObserver(PowerObserver* obs) { void SystemMonitor::NotifyPowerStateChange() { LOG(INFO) << L"PowerStateChange: " << (BatteryPower() ? L"On" : L"Off") << L" battery"; - observer_list_->Notify(&PowerObserver::OnPowerStateChange, this); + observer_list_->Notify(&PowerObserver::OnPowerStateChange, BatteryPower()); } void SystemMonitor::NotifySuspend() { LOG(INFO) << L"Power Suspending"; - observer_list_->Notify(&PowerObserver::OnSuspend, this); + observer_list_->Notify(&PowerObserver::OnSuspend); } void SystemMonitor::NotifyResume() { LOG(INFO) << L"Power Resuming"; - observer_list_->Notify(&PowerObserver::OnResume, this); + observer_list_->Notify(&PowerObserver::OnResume); } // static diff --git a/base/system_monitor.h b/base/system_monitor.h index aeec42b..71d8436 100644 --- a/base/system_monitor.h +++ b/base/system_monitor.h @@ -1,4 +1,4 @@ -// 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. @@ -44,7 +44,7 @@ class SystemMonitor { // Is the computer currently on battery power. // Can be called on any thread. - bool BatteryPower() { + bool BatteryPower() const { // Using a lock here is not necessary for just a bool. return battery_in_use_; } @@ -65,13 +65,13 @@ class SystemMonitor { public: // Notification of a change in power status of the computer, such // as from switching between battery and A/C power. - virtual void OnPowerStateChange(SystemMonitor*) = 0; + virtual void OnPowerStateChange(bool on_battery_power) {} // Notification that the system is suspending. - virtual void OnSuspend(SystemMonitor*) = 0; + virtual void OnSuspend() {} // Notification that the system is resuming. - virtual void OnResume(SystemMonitor*) = 0; + virtual void OnResume() {} }; // Add a new observer. diff --git a/base/system_monitor_unittest.cc b/base/system_monitor_unittest.cc index 0ca8d61..ff39d87 100644 --- a/base/system_monitor_unittest.cc +++ b/base/system_monitor_unittest.cc @@ -1,4 +1,4 @@ -// 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. @@ -14,9 +14,17 @@ class PowerTest : public base::SystemMonitor::PowerObserver { resumes_(0) {}; // PowerObserver callbacks. - void OnPowerStateChange(base::SystemMonitor*) { power_state_changes_++; }; - void OnSuspend(base::SystemMonitor*) { suspends_++; }; - void OnResume(base::SystemMonitor*) { resumes_++; }; + void OnPowerStateChange(bool on_battery_power) { + power_state_changes_++; + } + + void OnSuspend() { + suspends_++; + } + + void OnResume() { + resumes_++; + } // Test status counts. bool battery() { return battery_; } @@ -39,40 +47,40 @@ TEST(SystemMonitor, PowerNotifications) { // Initialize time() since it registers as a SystemMonitor observer. base::Time now = base::Time::Now(); - base::SystemMonitor* monitor = base::SystemMonitor::Get(); + base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); PowerTest test[kObservers]; for (int index = 0; index < kObservers; ++index) - 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++) { - monitor->ProcessPowerMessage(base::SystemMonitor::POWER_STATE_EVENT); + system_monitor->ProcessPowerMessage(base::SystemMonitor::POWER_STATE_EVENT); EXPECT_EQ(test[0].power_state_changes(), 0); } // Sending resume when not suspended should have no effect. - monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT); + system_monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT); loop.RunAllPending(); EXPECT_EQ(test[0].resumes(), 0); // Pretend we suspended. - monitor->ProcessPowerMessage(base::SystemMonitor::SUSPEND_EVENT); + system_monitor->ProcessPowerMessage(base::SystemMonitor::SUSPEND_EVENT); loop.RunAllPending(); EXPECT_EQ(test[0].suspends(), 1); // Send a second suspend notification. This should be suppressed. - monitor->ProcessPowerMessage(base::SystemMonitor::SUSPEND_EVENT); + system_monitor->ProcessPowerMessage(base::SystemMonitor::SUSPEND_EVENT); loop.RunAllPending(); EXPECT_EQ(test[0].suspends(), 1); // Pretend we were awakened. - monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT); + system_monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT); loop.RunAllPending(); EXPECT_EQ(test[0].resumes(), 1); // Send a duplicate resume notification. This should be suppressed. - monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT); + system_monitor->ProcessPowerMessage(base::SystemMonitor::RESUME_EVENT); loop.RunAllPending(); EXPECT_EQ(test[0].resumes(), 1); } diff --git a/base/time_win.cc b/base/time_win.cc index c134a9e..9fdcab1 100644 --- a/base/time_win.cc +++ b/base/time_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-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. @@ -104,29 +104,25 @@ class HighResolutionTimerManager : public base::SystemMonitor::PowerObserver { if (is_monitoring_) return; is_monitoring_ = true; - base::SystemMonitor* system = base::SystemMonitor::Get(); - DCHECK(system); - system->AddObserver(this); - UseHiResClock(!system->BatteryPower()); + 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* monitor = base::SystemMonitor::Get(); - if (monitor) - monitor->RemoveObserver(this); + base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); + if (system_monitor) + system_monitor->RemoveObserver(this); } // Interfaces for monitoring Power changes. - void OnPowerStateChange(base::SystemMonitor* system) { - UseHiResClock(!system->BatteryPower()); + void OnPowerStateChange(bool on_battery_power) { + UseHiResClock(!on_battery_power); } - void OnSuspend(base::SystemMonitor* system) {} - void OnResume(base::SystemMonitor* system) {} - private: HighResolutionTimerManager() : is_monitoring_(false), diff --git a/chrome/browser/profile_manager.cc b/chrome/browser/profile_manager.cc index c25322a..b24b7b2 100644 --- a/chrome/browser/profile_manager.cc +++ b/chrome/browser/profile_manager.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-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. @@ -41,15 +41,13 @@ void ProfileManager::ShutdownSessionServices() { } ProfileManager::ProfileManager() { - base::SystemMonitor* monitor = base::SystemMonitor::Get(); - if (monitor) - monitor->AddObserver(this); + base::SystemMonitor::Get()->AddObserver(this); } ProfileManager::~ProfileManager() { - base::SystemMonitor* monitor = base::SystemMonitor::Get(); - if (monitor) - monitor->RemoveObserver(this); + base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); + if (system_monitor) + system_monitor->RemoveObserver(this); // Destroy all profiles that we're keeping track of. for (ProfileVector::const_iterator iter = profiles_.begin(); @@ -227,7 +225,7 @@ Profile* ProfileManager::GetProfileByID(const std::wstring& id) const { return NULL; } -void ProfileManager::OnSuspend(base::SystemMonitor* monitor) { +void ProfileManager::OnSuspend() { DCHECK(CalledOnValidThread()); ProfileManager::const_iterator it = begin(); @@ -238,7 +236,7 @@ void ProfileManager::OnSuspend(base::SystemMonitor* monitor) { } } -void ProfileManager::OnResume(base::SystemMonitor* monitor) { +void ProfileManager::OnResume() { DCHECK(CalledOnValidThread()); ProfileManager::const_iterator it = begin(); while (it != end()) { diff --git a/chrome/browser/profile_manager.h b/chrome/browser/profile_manager.h index 466fb2f..56b9998 100644 --- a/chrome/browser/profile_manager.h +++ b/chrome/browser/profile_manager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-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. @@ -129,9 +129,8 @@ class ProfileManager : public NonThreadSafe, void NewWindowWithProfile(Profile* profile); // PowerObserver notifications - void OnPowerStateChange(base::SystemMonitor*) {} - void OnSuspend(base::SystemMonitor*); - void OnResume(base::SystemMonitor*); + void OnSuspend(); + void OnResume(); // ------------------ static utility functions ------------------- diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc index d3d0920..834d1cc 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.cc +++ b/chrome/browser/safe_browsing/safe_browsing_service.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-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. // @@ -38,16 +38,13 @@ SafeBrowsingService::SafeBrowsingService() resetting_(false), database_loaded_(false), update_in_progress_(false) { - base::SystemMonitor* monitor = base::SystemMonitor::Get(); - DCHECK(monitor); - if (monitor) - monitor->AddObserver(this); + base::SystemMonitor::Get()->AddObserver(this); } SafeBrowsingService::~SafeBrowsingService() { - base::SystemMonitor* monitor = base::SystemMonitor::Get(); - if (monitor) - monitor->RemoveObserver(this); + base::SystemMonitor* system_monitor = base::SystemMonitor::Get(); + if (system_monitor) + system_monitor->RemoveObserver(this); } // Only called on the UI thread. @@ -663,14 +660,11 @@ void SafeBrowsingService::CacheHashResults( GetDatabase()->CacheHashResults(prefixes, full_hashes); } -void SafeBrowsingService::OnSuspend(base::SystemMonitor*) { -} - // Tell the SafeBrowsing database not to do expensive disk operations for a few // minutes after waking up. It's quite likely that the act of resuming from a // low power state will involve much disk activity, which we don't want to // exacerbate. -void SafeBrowsingService::OnResume(base::SystemMonitor*) { +void SafeBrowsingService::OnResume() { if (enabled_) { safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &SafeBrowsingService::HandleResume)); diff --git a/chrome/browser/safe_browsing/safe_browsing_service.h b/chrome/browser/safe_browsing/safe_browsing_service.h index cc5651f..76b7f8c 100644 --- a/chrome/browser/safe_browsing/safe_browsing_service.h +++ b/chrome/browser/safe_browsing/safe_browsing_service.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-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. // @@ -169,9 +169,7 @@ class SafeBrowsingService // PowerObserver notifications // We defer SafeBrowsing work for a short duration when the computer comes // out of a suspend state to avoid thrashing the disk. - void OnPowerStateChange(base::SystemMonitor*) {} - void OnSuspend(base::SystemMonitor*); - void OnResume(base::SystemMonitor*); + void OnResume(); // Report any pages that contain malware sub-resources to the SafeBrowsing // service. |