summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-01 00:52:40 +0000
committermbelshe@google.com <mbelshe@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-01 00:52:40 +0000
commit3abd6bbdfb0a6d8367a2c56d4846e3d70d9da660 (patch)
treec6b872305f258a653ac0203eeb25b5b08ae2eb00
parent4f470ec4e08cf042997d68c55bb7aeeeeaa1209c (diff)
downloadchromium_src-3abd6bbdfb0a6d8367a2c56d4846e3d70d9da660.zip
chromium_src-3abd6bbdfb0a6d8367a2c56d4846e3d70d9da660.tar.gz
chromium_src-3abd6bbdfb0a6d8367a2c56d4846e3d70d9da660.tar.bz2
Rollback
Review URL: http://codereview.chromium.org/13009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6127 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/plugin/plugin_main.cc4
-rw-r--r--chrome/renderer/renderer_main.cc4
-rw-r--r--chrome/views/widget_win.h4
15 files changed, 154 insertions, 104 deletions
diff --git a/base/system_monitor.h b/base/system_monitor.h
index 32bd732..7a2d4d5 100644
--- a/base/system_monitor.h
+++ b/base/system_monitor.h
@@ -20,10 +20,8 @@ class SystemMonitor {
return Singleton<SystemMonitor>::get();
}
- // 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.
+ // To start the System Monitor within an application
+ // use this call.
static void Start();
//
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index 31426e8..7d79e5d 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -2263,6 +2263,14 @@
>
</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 da13f65..ff87093 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -16,7 +16,6 @@
#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"
@@ -289,9 +288,6 @@ 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 7cf77cf..75e20e4 100644
--- a/chrome/browser/browser_process.h
+++ b/chrome/browser/browser_process.h
@@ -122,6 +122,8 @@ 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 3d3e8a5..d4aabe7 100644
--- a/chrome/browser/browser_process_impl.cc
+++ b/chrome/browser/browser_process_impl.cc
@@ -22,6 +22,7 @@
#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"
@@ -127,6 +128,8 @@ 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 6f51102..fa5e969 100644
--- a/chrome/browser/browser_process_impl.h
+++ b/chrome/browser/browser_process_impl.h
@@ -167,6 +167,11 @@ 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:
@@ -238,6 +243,8 @@ 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 23ad108..d8c5099 100644
--- a/chrome/browser/profile_manager.cc
+++ b/chrome/browser/profile_manager.cc
@@ -21,8 +21,6 @@
#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"
@@ -41,16 +39,9 @@ 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) {
@@ -224,47 +215,6 @@ 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 72f1d63..5c3ad89 100644
--- a/chrome/browser/profile_manager.h
+++ b/chrome/browser/profile_manager.h
@@ -12,9 +12,6 @@
#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"
@@ -60,8 +57,7 @@ class AvailableProfile {
DISALLOW_EVIL_CONSTRUCTORS(AvailableProfile);
};
-class ProfileManager : public NonThreadSafe,
- public base::SystemMonitor::PowerObserver {
+class ProfileManager {
public:
ProfileManager();
virtual ~ProfileManager();
@@ -126,11 +122,6 @@ class ProfileManager : public NonThreadSafe,
// 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.
@@ -166,11 +157,6 @@ class ProfileManager : public NonThreadSafe,
// 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 193ac18..3a6fff3 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc
@@ -12,7 +12,6 @@
#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"
@@ -35,16 +34,9 @@ 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.
@@ -670,17 +662,18 @@ void SafeBrowsingService::CacheHashResults(
GetDatabase()->CacheHashResults(prefixes, full_hashes);
}
-void SafeBrowsingService::OnSuspend(base::SystemMonitor*) {
+void SafeBrowsingService::OnSuspend() {
}
// 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() {
+ DCHECK(MessageLoop::current() == io_loop_);
if (enabled_) {
- ChromeThread::GetMessageLoop(ChromeThread::DB)->PostTask(FROM_HERE,
- NewRunnableMethod(this, &SafeBrowsingService::HandleResume));
+ db_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 c3125e5..761acb2 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.h
+++ b/chrome/browser/safe_browsing/safe_browsing_service.h
@@ -16,7 +16,6 @@
#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"
@@ -32,8 +31,7 @@ class SafeBrowsingProtocolManager;
// Construction needs to happen on the main thread.
class SafeBrowsingService
- : public base::RefCountedThreadSafe<SafeBrowsingService>,
- public base::SystemMonitor::PowerObserver {
+ : public base::RefCountedThreadSafe<SafeBrowsingService> {
public:
// Users of this service implement this interface to be notified
// asynchronously of the result.
@@ -171,12 +169,10 @@ 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 OnPowerStateChange(base::SystemMonitor*) {};
- void OnSuspend(base::SystemMonitor*);
- void OnResume(base::SystemMonitor*);
+ void OnSuspend();
+ void OnResume();
bool new_safe_browsing() const { return new_safe_browsing_; }
diff --git a/chrome/browser/suspend_controller.cc b/chrome/browser/suspend_controller.cc
new file mode 100644
index 0000000..9eb9eab
--- /dev/null
+++ b/chrome/browser/suspend_controller.cc
@@ -0,0 +1,83 @@
+// 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
new file mode 100644
index 0000000..c151d0c
--- /dev/null
+++ b/chrome/browser/suspend_controller.h
@@ -0,0 +1,40 @@
+// 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/plugin/plugin_main.cc b/chrome/plugin/plugin_main.cc
index 84aa0b5..3fcdc91 100644
--- a/chrome/plugin/plugin_main.cc
+++ b/chrome/plugin/plugin_main.cc
@@ -4,7 +4,6 @@
#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"
@@ -21,9 +20,6 @@ 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();
diff --git a/chrome/renderer/renderer_main.cc b/chrome/renderer/renderer_main.cc
index 5d633f6..21da042 100644
--- a/chrome/renderer/renderer_main.cc
+++ b/chrome/renderer/renderer_main.cc
@@ -7,7 +7,6 @@
#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"
@@ -54,9 +53,6 @@ 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/views/widget_win.h b/chrome/views/widget_win.h
index 6b4d606..9e402e8 100644
--- a/chrome/views/widget_win.h
+++ b/chrome/views/widget_win.h
@@ -9,7 +9,6 @@
#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"
@@ -411,9 +410,6 @@ 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;
}