summaryrefslogtreecommitdiffstats
path: root/chrome/browser/profile_manager.cc
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 /chrome/browser/profile_manager.cc
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
Diffstat (limited to 'chrome/browser/profile_manager.cc')
-rw-r--r--chrome/browser/profile_manager.cc50
1 files changed, 50 insertions, 0 deletions
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) {