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

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: 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 a855a18eeb09066ada4fe2961226ec6ca1a21c29..c1ba9437bf7726a716d69a6efdcb246a29ce1c85 100644
--- a/chrome/browser/services/gcm/gcm_driver.cc
+++ b/chrome/browser/services/gcm/gcm_driver.cc
@@ -489,6 +489,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,
@@ -700,6 +704,10 @@ GCMClient::Result GCMDriver::EnsureStarted() {
if (!gcm_enabled_)
return GCMClient::GCM_DISABLED;
+ // Has any app requested the service?
Nicolas Zea 2014/05/22 17:06:31 nit: has -> Have
jianli 2014/05/22 18:09:26 Done.
+ 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())

Powered by Google App Engine
This is Rietveld 408576698