Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4736)

Unified Diff: chrome/browser/services/gcm/gcm_driver.cc

Issue 296053011: Start and stop the GCM service on demand (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/services/gcm/gcm_driver.cc
diff --git a/chrome/browser/services/gcm/gcm_driver.cc b/chrome/browser/services/gcm/gcm_driver.cc
index 59860c01a787ff6c2864652392293705e62c5cdf..96c21f45201fe1991ddaa33265ba1ecfc5235671 100644
--- a/chrome/browser/services/gcm/gcm_driver.cc
+++ b/chrome/browser/services/gcm/gcm_driver.cc
@@ -475,6 +475,10 @@ void GCMDriver::RemoveAppHandler(const std::string& app_id) {
DCHECK(!app_id.empty());
app_handlers_.erase(app_id);
+
+ // Stops the GCM service when no app intends to consume it.
+ if (app_handlers_.empty())
+ Stop();
}
void GCMDriver::Register(const std::string& app_id,
@@ -681,6 +685,10 @@ GCMClient::Result GCMDriver::EnsureStarted() {
if (!gcm_enabled_)
return GCMClient::GCM_DISABLED;
+ // Have any app requested the service?
+ if (app_handlers_.empty())
+ return GCMClient::UNKNOWN_ERROR;
+
// Is the user signed in?
const std::string account_id = identity_provider_->GetActiveAccountId();
if (account_id.empty())
« no previous file with comments | « chrome/browser/services/gcm/fake_gcm_app_handler.cc ('k') | chrome/browser/services/gcm/gcm_driver_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698