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 f8bcf72ca257ff456ac811bc5008b1cbcbc455d9..0bdf6eb2c209536db2afe2776ff8038657328f36 100644 |
--- a/chrome/browser/services/gcm/gcm_driver.cc |
+++ b/chrome/browser/services/gcm/gcm_driver.cc |
@@ -382,16 +382,15 @@ void GCMDriver::IOWorker::SetGCMRecording(bool recording) { |
base::Bind(&GCMDriver::GetGCMStatisticsFinished, service_, stats)); |
} |
-GCMDriver::GCMDriver(scoped_ptr<IdentityProvider> identity_provider) |
+GCMDriver::GCMDriver( |
+ scoped_ptr<GCMClientFactory> gcm_client_factory, |
+ scoped_ptr<IdentityProvider> identity_provider, |
+ const base::FilePath& store_path, |
+ const scoped_refptr<net::URLRequestContextGetter>& request_context) |
: identity_provider_(identity_provider.Pass()), |
+ gcm_enabled_(true), |
gcm_client_ready_(false), |
weak_ptr_factory_(this) { |
-} |
- |
-GCMDriver::~GCMDriver() { |
-} |
- |
-void GCMDriver::Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory) { |
// Get the list of available accounts. |
std::vector<std::string> account_ids; |
#if !defined(OS_ANDROID) |
@@ -408,23 +407,42 @@ void GCMDriver::Initialize(scoped_ptr<GCMClientFactory> gcm_client_factory) { |
base::Bind(&GCMDriver::IOWorker::Initialize, |
base::Unretained(io_worker_.get()), |
base::Passed(&gcm_client_factory), |
- GetStorePath(), |
+ store_path, |
account_ids, |
- GetURLRequestContextGetter())); |
- |
- // Start the GCM service if the rollout signal indicates yes. |
- if (ShouldStartAutomatically()) |
- EnsureStarted(); |
+ request_context)); |
identity_provider_->AddObserver(this); |
} |
-void GCMDriver::Start() { |
+GCMDriver::GCMDriver() |
+ : gcm_enabled_(true), |
+ gcm_client_ready_(false), |
+ weak_ptr_factory_(this) { |
+} |
+ |
+GCMDriver::~GCMDriver() { |
+} |
+ |
+void GCMDriver::Enable() { |
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
+ if (gcm_enabled_) |
+ return; |
+ gcm_enabled_ = true; |
+ |
EnsureStarted(); |
} |
+void GCMDriver::Disable() { |
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
+ |
+ if (!gcm_enabled_) |
+ return; |
+ gcm_enabled_ = false; |
+ |
+ Stop(); |
+} |
+ |
void GCMDriver::Stop() { |
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
@@ -441,7 +459,7 @@ void GCMDriver::Stop() { |
base::Unretained(io_worker_.get()))); |
} |
-void GCMDriver::ShutdownService() { |
+void GCMDriver::Shutdown() { |
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
identity_provider_->RemoveObserver(this); |
for (GCMAppHandlerMap::const_iterator iter = app_handlers_.begin(); |
@@ -462,6 +480,9 @@ void GCMDriver::AddAppHandler(const std::string& app_id, |
DCHECK(app_handlers_.find(app_id) == app_handlers_.end()); |
app_handlers_[app_id] = handler; |
+ |
+ // Ensures that the GCM service is started when there is an interest. |
+ EnsureStarted(); |
} |
void GCMDriver::RemoveAppHandler(const std::string& app_id) { |
@@ -667,7 +688,7 @@ void GCMDriver::SetGCMRecording(const GetGCMStatisticsCallback& callback, |
} |
void GCMDriver::OnActiveAccountLogin() { |
- if (ShouldStartAutomatically()) |
+ if (gcm_enabled_) |
EnsureStarted(); |
} |
@@ -859,4 +880,10 @@ void GCMDriver::GetGCMStatisticsFinished(GCMClient::GCMStatistics stats) { |
LOG(WARNING) << "request_gcm_statistics_callback_ is NULL."; |
} |
+std::string GCMDriver::SignedInUserName() const { |
+ if (IsStarted()) |
+ return identity_provider_->GetActiveUsername(); |
+ return std::string(); |
+} |
+ |
} // namespace gcm |