A new copy of the old system monitor changelist.
Review URL: http://codereview.chromium.org/12817 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6126 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
base
chrome
@ -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 that the battery check can be deferred.
|
||||
// The MessageLoop must be started before calling this
|
||||
// method.
|
||||
static void Start();
|
||||
|
||||
//
|
||||
|
@ -2262,14 +2262,6 @@
|
||||
RelativePath=".\ssl_blocking_page.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\suspend_controller.cc"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\suspend_controller.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\toolbar_model.cc"
|
||||
>
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "base/registry.h"
|
||||
#include "base/string_piece.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"
|
||||
@ -288,6 +289,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;
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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_;
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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_;
|
||||
|
@ -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::kUseOldSafeBrowsing);
|
||||
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.
|
||||
@ -662,18 +670,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));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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_; }
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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__
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "base/command_line.h"
|
||||
#include "base/message_loop.h"
|
||||
#include "base/system_monitor.h"
|
||||
#include "chrome/common/chrome_constants.h"
|
||||
#include "chrome/common/chrome_switches.h"
|
||||
#include "chrome/common/logging_chrome.h"
|
||||
@ -20,6 +21,9 @@ int PluginMain(CommandLine &parsed_command_line,
|
||||
std::wstring app_name = chrome::kBrowserAppName;
|
||||
PlatformThread::SetName(WideToASCII(app_name + L"_PluginMain").c_str());
|
||||
|
||||
// Initialize the SystemMonitor
|
||||
base::SystemMonitor::Start();
|
||||
|
||||
CoInitialize(NULL);
|
||||
DLOG(INFO) << "Started plugin with " <<
|
||||
parsed_command_line.command_line_string();
|
||||
|
@ -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 " <<
|
||||
|
@ -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/widget.h"
|
||||
@ -410,6 +411,9 @@ class WidgetWin : public Widget,
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user