diff options
author | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-30 23:54:35 +0000 |
---|---|---|
committer | mbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-30 23:54:35 +0000 |
commit | 4f470ec4e08cf042997d68c55bb7aeeeeaa1209c (patch) | |
tree | bb0f13c32bb3f27849a8f694720e0664b0550fda /chrome/browser | |
parent | 9b6b8dbb54aeec5b4f271a7b5aed18c45664f911 (diff) | |
download | chromium_src-4f470ec4e08cf042997d68c55bb7aeeeeaa1209c.zip chromium_src-4f470ec4e08cf042997d68c55bb7aeeeeaa1209c.tar.gz chromium_src-4f470ec4e08cf042997d68c55bb7aeeeeaa1209c.tar.bz2 |
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
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser.vcproj | 8 | ||||
-rw-r--r-- | chrome/browser/browser_main.cc | 4 | ||||
-rw-r--r-- | chrome/browser/browser_process.h | 2 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 3 | ||||
-rw-r--r-- | chrome/browser/browser_process_impl.h | 7 | ||||
-rw-r--r-- | chrome/browser/profile_manager.cc | 50 | ||||
-rw-r--r-- | chrome/browser/profile_manager.h | 16 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_service.cc | 17 | ||||
-rw-r--r-- | chrome/browser/safe_browsing/safe_browsing_service.h | 10 | ||||
-rw-r--r-- | chrome/browser/suspend_controller.cc | 83 | ||||
-rw-r--r-- | chrome/browser/suspend_controller.h | 40 |
11 files changed, 88 insertions, 152 deletions
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index 7d79e5d..31426e8 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -2263,14 +2263,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 ff87093..da13f65 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.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; 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 3a6fff3..193ac18 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::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)); } } 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__ - |