summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-14 19:07:32 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-14 19:07:32 +0000
commit322f7f7005061fee5e3b691e6aee318ea93a7eb8 (patch)
tree4d743cbbbee965d8b087171b9ee315f2ffc93865
parenta618550847f7c09eea7bb27e43bb226f330e5525 (diff)
downloadchromium_src-322f7f7005061fee5e3b691e6aee318ea93a7eb8.zip
chromium_src-322f7f7005061fee5e3b691e6aee318ea93a7eb8.tar.gz
chromium_src-322f7f7005061fee5e3b691e6aee318ea93a7eb8.tar.bz2
Change to integrate SystemMonitor changes into chrome.
This enables the dynamic detection of battery status changes so that we can turn on/off the hi-res timer. Review URL: http://codereview.chromium.org/10264 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5489 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/system_monitor.h6
-rw-r--r--chrome/browser/browser.vcproj8
-rw-r--r--chrome/browser/browser_main.cc4
-rw-r--r--chrome/browser/browser_process.h2
-rw-r--r--chrome/browser/browser_process_impl.cc3
-rw-r--r--chrome/browser/browser_process_impl.h7
-rw-r--r--chrome/browser/profile_manager.cc50
-rw-r--r--chrome/browser/profile_manager.h16
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_service.cc17
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_service.h10
-rw-r--r--chrome/browser/suspend_controller.cc83
-rw-r--r--chrome/browser/suspend_controller.h40
-rw-r--r--chrome/renderer/renderer_main.cc4
-rw-r--r--chrome/test/testing_browser_process.h2
-rw-r--r--chrome/views/container_win.h4
15 files changed, 100 insertions, 156 deletions
diff --git a/base/system_monitor.h b/base/system_monitor.h
index 7a2d4d5..4756e6733 100644
--- a/base/system_monitor.h
+++ b/base/system_monitor.h
@@ -20,8 +20,10 @@ class SystemMonitor {
return Singleton<SystemMonitor>::get();
}
- // To start the System Monitor within an application
- // use this call.
+ // Start the System Monitor within a process. This method
+ // is provided so tht the battery check can be deferred.
+ // The MessageLoop must be started before calling this
+ // method.
static void Start();
//
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index 6f54f24..70d8460 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -2267,14 +2267,6 @@
>
</File>
<File
- RelativePath=".\suspend_controller.cc"
- >
- </File>
- <File
- RelativePath=".\suspend_controller.h"
- >
- </File>
- <File
RelativePath=".\toolbar_model.cc"
>
</File>
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 6aba314..5335921 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -15,6 +15,7 @@
#include "base/process_util.h"
#include "base/registry.h"
#include "base/string_util.h"
+#include "base/system_monitor.h"
#include "base/tracked_objects.h"
#include "base/win_util.h"
#include "chrome/app/result_codes.h"
@@ -270,6 +271,9 @@ int BrowserMain(CommandLine &parsed_command_line,
MessageLoop main_message_loop(MessageLoop::TYPE_UI);
+ // Initialize the SystemMonitor
+ base::SystemMonitor::Start();
+
// Initialize statistical testing infrastructure.
FieldTrialList field_trial;
diff --git a/chrome/browser/browser_process.h b/chrome/browser/browser_process.h
index 75e20e4..7cf77cf 100644
--- a/chrome/browser/browser_process.h
+++ b/chrome/browser/browser_process.h
@@ -122,8 +122,6 @@ class BrowserProcess {
virtual MemoryModel memory_model() = 0;
- virtual SuspendController* suspend_controller() = 0;
-
#if defined(OS_WIN)
DownloadRequestManager* download_request_manager() {
ResourceDispatcherHost* rdh = resource_dispatcher_host();
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc
index d4aabe7..3d3e8a5 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -22,7 +22,6 @@
#include "chrome/browser/resource_dispatcher_host.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
#include "chrome/browser/debugger/debugger_wrapper.h"
-#include "chrome/browser/suspend_controller.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/clipboard_service.h"
@@ -128,8 +127,6 @@ BrowserProcessImpl::BrowserProcessImpl(CommandLine& command_line)
memory_model_ = MEDIUM_MEMORY_MODEL;
}
- suspend_controller_ = new SuspendController();
-
shutdown_event_ = ::CreateEvent(NULL, TRUE, FALSE, NULL);
}
diff --git a/chrome/browser/browser_process_impl.h b/chrome/browser/browser_process_impl.h
index fa5e969..6f51102 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -167,11 +167,6 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe {
return memory_model_;
}
- virtual SuspendController* suspend_controller() {
- DCHECK(CalledOnValidThread());
- return suspend_controller_.get();
- }
-
virtual HANDLE shutdown_event() { return shutdown_event_; }
private:
@@ -243,8 +238,6 @@ class BrowserProcessImpl : public BrowserProcess, public NonThreadSafe {
MemoryModel memory_model_;
- scoped_refptr<SuspendController> suspend_controller_;
-
bool checked_for_new_frames_;
bool using_new_frames_;
diff --git a/chrome/browser/profile_manager.cc b/chrome/browser/profile_manager.cc
index d8c5099..23ad108 100644
--- a/chrome/browser/profile_manager.cc
+++ b/chrome/browser/profile_manager.cc
@@ -21,6 +21,8 @@
#include "chrome/common/logging_chrome.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
+#include "net/url_request/url_request_job.h"
+#include "net/url_request/url_request_job_tracker.h"
#include "generated_resources.h"
@@ -39,9 +41,16 @@ void ProfileManager::ShutdownSessionServices() {
}
ProfileManager::ProfileManager() {
+ base::SystemMonitor* monitor = base::SystemMonitor::Get();
+ if (monitor)
+ monitor->AddObserver(this);
}
ProfileManager::~ProfileManager() {
+ base::SystemMonitor* monitor = base::SystemMonitor::Get();
+ if (monitor)
+ monitor->RemoveObserver(this);
+
// Destroy all profiles that we're keeping track of.
for (ProfileVector::const_iterator iter = profiles_.begin();
iter != profiles_.end(); ++iter) {
@@ -215,6 +224,47 @@ Profile* ProfileManager::GetProfileByID(const std::wstring& id) const {
return NULL;
}
+void ProfileManager::OnSuspend(base::SystemMonitor* monitor) {
+ DCHECK(CalledOnValidThread());
+
+ ProfileManager::const_iterator it = begin();
+ while(it != end()) {
+ g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ NewRunnableFunction(&ProfileManager::SuspendProfile, *it));
+ it++;
+ }
+}
+
+void ProfileManager::OnResume(base::SystemMonitor* monitor) {
+ DCHECK(CalledOnValidThread());
+ ProfileManager::const_iterator it = begin();
+ while (it != end()) {
+ g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
+ NewRunnableFunction(&ProfileManager::ResumeProfile, *it));
+ it++;
+ }
+}
+
+void ProfileManager::SuspendProfile(Profile* profile) {
+ DCHECK(profile);
+ DCHECK(MessageLoop::current() ==
+ ChromeThread::GetMessageLoop(ChromeThread::IO));
+
+ URLRequestJobTracker::JobIterator it = g_url_request_job_tracker.begin();
+ for (;it != g_url_request_job_tracker.end(); ++it)
+ (*it)->Kill();
+
+ profile->GetRequestContext()->http_transaction_factory()->Suspend(true);
+}
+
+void ProfileManager::ResumeProfile(Profile* profile) {
+ DCHECK(profile);
+ DCHECK(MessageLoop::current() ==
+ ChromeThread::GetMessageLoop(ChromeThread::IO));
+ profile->GetRequestContext()->http_transaction_factory()->Suspend(false);
+}
+
+
// static
bool ProfileManager::IsProfile(const std::wstring& path) {
diff --git a/chrome/browser/profile_manager.h b/chrome/browser/profile_manager.h
index 5c3ad89..72f1d63 100644
--- a/chrome/browser/profile_manager.h
+++ b/chrome/browser/profile_manager.h
@@ -12,6 +12,9 @@
#include <vector>
#include "base/basictypes.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"
@@ -57,7 +60,8 @@ class AvailableProfile {
DISALLOW_EVIL_CONSTRUCTORS(AvailableProfile);
};
-class ProfileManager {
+class ProfileManager : public NonThreadSafe,
+ public base::SystemMonitor::PowerObserver {
public:
ProfileManager();
virtual ~ProfileManager();
@@ -122,6 +126,11 @@ class ProfileManager {
// Creates a new window with the given profile.
void NewWindowWithProfile(Profile* profile);
+ // PowerObserver notifications
+ void OnPowerStateChange(base::SystemMonitor*) {}
+ void OnSuspend(base::SystemMonitor*);
+ void OnResume(base::SystemMonitor*);
+
// ------------------ static utility functions -------------------
// Returns the path to the profile directory based on the user data directory.
@@ -157,6 +166,11 @@ class ProfileManager {
// or NULL if no match is found.
AvailableProfile* GetAvailableProfileByID(const std::wstring& id);
+ // Hooks to suspend/resume per-profile network traffic.
+ // These must be called on the IO thread.
+ static void SuspendProfile(Profile*);
+ static void ResumeProfile(Profile*);
+
// We keep a simple vector of profiles rather than something fancier
// because we expect there to be a small number of profiles active.
ProfileVector profiles_;
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc
index e38bcc4..2474c4e 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc
@@ -12,6 +12,7 @@
#include "base/path_service.h"
#include "base/string_util.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/profile_manager.h"
#include "chrome/browser/safe_browsing/protocol_manager.h"
#include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h"
@@ -34,9 +35,16 @@ SafeBrowsingService::SafeBrowsingService()
resetting_(false),
database_loaded_(false) {
new_safe_browsing_ = CommandLine().HasSwitch(switches::kUseNewSafeBrowsing);
+ base::SystemMonitor* monitor = base::SystemMonitor::Get();
+ DCHECK(monitor);
+ if (monitor)
+ monitor->AddObserver(this);
}
SafeBrowsingService::~SafeBrowsingService() {
+ base::SystemMonitor* monitor = base::SystemMonitor::Get();
+ if (monitor)
+ monitor->RemoveObserver(this);
}
// Only called on the UI thread.
@@ -655,18 +663,17 @@ void SafeBrowsingService::CacheHashResults(
GetDatabase()->CacheHashResults(prefixes, full_hashes);
}
-void SafeBrowsingService::OnSuspend() {
+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() {
- DCHECK(MessageLoop::current() == io_loop_);
+void SafeBrowsingService::OnResume(base::SystemMonitor*) {
if (enabled_) {
- db_thread_->message_loop()->PostTask(FROM_HERE,
- NewRunnableMethod(this, &SafeBrowsingService::HandleResume));
+ ChromeThread::GetMessageLoop(ChromeThread::DB)->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 761acb2..c3125e5 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.h
+++ b/chrome/browser/safe_browsing/safe_browsing_service.h
@@ -16,6 +16,7 @@
#include "base/hash_tables.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
+#include "base/system_monitor.h"
#include "base/thread.h"
#include "base/time.h"
#include "chrome/browser/safe_browsing/safe_browsing_util.h"
@@ -31,7 +32,8 @@ class SafeBrowsingProtocolManager;
// Construction needs to happen on the main thread.
class SafeBrowsingService
- : public base::RefCountedThreadSafe<SafeBrowsingService> {
+ : public base::RefCountedThreadSafe<SafeBrowsingService>,
+ public base::SystemMonitor::PowerObserver {
public:
// Users of this service implement this interface to be notified
// asynchronously of the result.
@@ -169,10 +171,12 @@ class SafeBrowsingService
// the current page is 'safe'.
void LogPauseDelay(base::TimeDelta time);
+ // 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 OnSuspend();
- void OnResume();
+ void OnPowerStateChange(base::SystemMonitor*) {};
+ void OnSuspend(base::SystemMonitor*);
+ void OnResume(base::SystemMonitor*);
bool new_safe_browsing() const { return new_safe_browsing_; }
diff --git a/chrome/browser/suspend_controller.cc b/chrome/browser/suspend_controller.cc
deleted file mode 100644
index 9eb9eab..0000000
--- a/chrome/browser/suspend_controller.cc
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright (c) 2006-2008 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 "chrome/browser/suspend_controller.h"
-
-#include "base/logging.h"
-#include "base/message_loop.h"
-#include "base/task.h"
-#include "base/thread.h"
-#include "chrome/browser/browser_process.h"
-#include "chrome/browser/profile.h"
-#include "chrome/browser/resource_dispatcher_host.h"
-#include "chrome/browser/safe_browsing/safe_browsing_service.h"
-#include "net/url_request/url_request_job.h"
-#include "net/url_request/url_request_job_tracker.h"
-
-// Static member.
-bool SuspendController::is_suspended_ = false;
-
-// Static method.
-void SuspendController::OnSuspend(Profile* profile) {
- if (is_suspended_)
- return;
- is_suspended_ = true;
-
- LOG(INFO) << "Received APM suspend message";
-
- SuspendController* controller = g_browser_process->suspend_controller();
-
- MessageLoop* io_loop = g_browser_process->io_thread()->message_loop();
- io_loop->PostTask(FROM_HERE,
- NewRunnableMethod(controller,
- &SuspendController::StopRequests,
- profile));
-
- ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host();
- SafeBrowsingService* safe_browsing_service = rdh->safe_browsing_service();
- io_loop->PostTask(FROM_HERE,
- NewRunnableMethod(safe_browsing_service,
- &SafeBrowsingService::OnSuspend));
-}
-
-// Static method.
-void SuspendController::OnResume(Profile* profile) {
- if (!is_suspended_)
- return;
- is_suspended_ = false;
-
- LOG(INFO) << "Received APM resume message";
-
- SuspendController* controller = g_browser_process->suspend_controller();
-
- MessageLoop* io_loop = g_browser_process->io_thread()->message_loop();
- io_loop->PostTask(FROM_HERE,
- NewRunnableMethod(controller,
- &SuspendController::AllowNewRequests,
- profile));
-
- ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host();
- SafeBrowsingService* safe_browsing_service = rdh->safe_browsing_service();
- io_loop->PostTask(FROM_HERE,
- NewRunnableMethod(safe_browsing_service,
- &SafeBrowsingService::OnResume));
-}
-
-void SuspendController::StopRequests(Profile* profile) {
- // Cancel all requests and stop creating new ones.
- URLRequestJobTracker::JobIterator it = g_url_request_job_tracker.begin();
- for (;it != g_url_request_job_tracker.end(); ++it) {
- URLRequestJob* job = const_cast<URLRequestJob*>(*it);
- job->Kill();
- }
-
- // Close the network session.
- profile->GetRequestContext()->http_transaction_factory()->Suspend(true);
-}
-
-void SuspendController::AllowNewRequests(Profile* profile) {
- // Re-enable the network session.
- profile->GetRequestContext()->http_transaction_factory()->Suspend(false);
-}
-
diff --git a/chrome/browser/suspend_controller.h b/chrome/browser/suspend_controller.h
deleted file mode 100644
index c151d0c..0000000
--- a/chrome/browser/suspend_controller.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright (c) 2006-2008 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.
-
-// The SuspendController keeps track of actions related to the computer going
-// into power savings mode. Its purpose right now is to close all network
-// requests and prevent creation of new requests until the computer resumes.
-
-#ifndef CHROME_BROWSER_SUSPEND_CONTROLLER_H__
-#define CHROME_BROWSER_SUSPEND_CONTROLLER_H__
-
-#include "base/basictypes.h"
-#include "chrome/browser/profile.h"
-
-class Profile;
-
-// The browser process owns the only instance of this class.
-class SuspendController : public base::RefCountedThreadSafe<SuspendController> {
- public:
- SuspendController() {}
- ~SuspendController() {}
-
- // Called when the system is going to be suspended.
- static void OnSuspend(Profile* profile);
-
- // Called when the system has been resumed.
- static void OnResume(Profile* profile);
-
- private:
- // Run on the io_thread.
- void StopRequests(Profile* profile);
- void AllowNewRequests(Profile* profile);
-
- static bool is_suspended_;
-
- DISALLOW_EVIL_CONSTRUCTORS(SuspendController);
-};
-
-#endif // CHROME_BROWSER_SUSPEND_CONTROLLER_H__
-
diff --git a/chrome/renderer/renderer_main.cc b/chrome/renderer/renderer_main.cc
index 21da042..5d633f6 100644
--- a/chrome/renderer/renderer_main.cc
+++ b/chrome/renderer/renderer_main.cc
@@ -7,6 +7,7 @@
#include "base/path_service.h"
#include "base/platform_thread.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"
@@ -53,6 +54,9 @@ int RendererMain(CommandLine &parsed_command_line,
std::wstring app_name = chrome::kBrowserAppName;
PlatformThread::SetName(WideToASCII(app_name + L"_RendererMain").c_str());
+ // Initialize the SystemMonitor
+ base::SystemMonitor::Start();
+
CoInitialize(NULL);
DLOG(INFO) << "Started renderer with " <<
diff --git a/chrome/test/testing_browser_process.h b/chrome/test/testing_browser_process.h
index 3220c05..c00acd7d 100644
--- a/chrome/test/testing_browser_process.h
+++ b/chrome/test/testing_browser_process.h
@@ -118,8 +118,6 @@ class TestingBrowserProcess : public BrowserProcess {
virtual MemoryModel memory_model() { return HIGH_MEMORY_MODEL; }
- virtual SuspendController* suspend_controller() { return NULL; }
-
virtual HANDLE shutdown_event() { return shutdown_event_; }
private:
diff --git a/chrome/views/container_win.h b/chrome/views/container_win.h
index 84309b9..8a9d9a1 100644
--- a/chrome/views/container_win.h
+++ b/chrome/views/container_win.h
@@ -9,6 +9,7 @@
#include <atlcrack.h>
#include "base/message_loop.h"
+#include "base/system_monitor.h"
#include "chrome/views/focus_manager.h"
#include "chrome/views/layout_manager.h"
#include "chrome/views/container.h"
@@ -416,6 +417,9 @@ class ContainerWin : public Container,
virtual LRESULT OnNotify(int w_param, NMHDR* l_param);
virtual void OnPaint(HDC dc);
virtual LRESULT OnPowerBroadcast(DWORD power_event, DWORD data) {
+ base::SystemMonitor* monitor = base::SystemMonitor::Get();
+ if (monitor)
+ monitor->ProcessWmPowerBroadcastMessage(power_event);
SetMsgHandled(FALSE);
return 0;
}