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

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

Issue 183013007: [GCM] Stop/restart GCM when the state is forced off/on (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch to land Created 6 years, 10 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_profile_service.cc
diff --git a/chrome/browser/services/gcm/gcm_profile_service.cc b/chrome/browser/services/gcm/gcm_profile_service.cc
index c215192c8df17f593250d6d4f9d6306a0d3b5f73..4cb54bd080371b6da2cf0eddcba839799136a156 100644
--- a/chrome/browser/services/gcm/gcm_profile_service.cc
+++ b/chrome/browser/services/gcm/gcm_profile_service.cc
@@ -265,6 +265,7 @@ class GCMProfileService::IOWorker
url_request_context_getter);
void Reset();
void Load(const base::WeakPtr<GCMProfileService>& service);
+ void Stop();
void CheckOut();
void Register(const std::string& app_id,
const std::vector<std::string>& sender_ids,
@@ -426,6 +427,12 @@ void GCMProfileService::IOWorker::Load(
gcm_client_->Load();
}
+void GCMProfileService::IOWorker::Stop() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
+
+ gcm_client_->Stop();
+}
+
void GCMProfileService::IOWorker::CheckOut() {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
@@ -559,6 +566,27 @@ void GCMProfileService::Initialize(
EnsureLoaded();
}
+void GCMProfileService::Start() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ EnsureLoaded();
+}
+
+void GCMProfileService::Stop() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ // No need to stop GCM service if not started yet.
+ if (username_.empty())
+ return;
+
+ RemoveCachedData();
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO,
+ FROM_HERE,
+ base::Bind(&GCMProfileService::IOWorker::Stop, io_worker_));
+}
+
void GCMProfileService::Register(const std::string& app_id,
const std::vector<std::string>& sender_ids,
const std::string& cert,
@@ -772,18 +800,20 @@ void GCMProfileService::EnsureLoaded() {
weak_ptr_factory_.GetWeakPtr()));
}
-void GCMProfileService::CheckOut() {
- DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
-
- // We still proceed with the check-out logic even if the check-in is not
- // initiated in the current session. This will make sure that all the
- // persisted data written previously will get purged.
- username_.clear();
-
+void GCMProfileService::RemoveCachedData() {
// Remove all the queued tasks since they no longer make sense after
- // check-out.
+ // GCM service is stopped.
weak_ptr_factory_.InvalidateWeakPtrs();
+ username_.clear();
+ gcm_client_ready_ = false;
+ delayed_task_controller_.reset();
+ register_callbacks_.clear();
+ send_callbacks_.clear();
+ registration_info_map_.clear();
+}
+
+void GCMProfileService::RemovePersistedData() {
// Remove persisted data from app's state store.
for (RegistrationInfoMap::const_iterator iter =
registration_info_map_.begin();
@@ -793,12 +823,20 @@ void GCMProfileService::CheckOut() {
// Remove persisted data from prefs store.
profile_->GetPrefs()->ClearPref(prefs::kGCMRegisteredAppIDs);
+}
- gcm_client_ready_ = false;
- delayed_task_controller_.reset();
- register_callbacks_.clear();
- send_callbacks_.clear();
- registration_info_map_.clear();
+void GCMProfileService::CheckOut() {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ // We still proceed with the check-out logic even if the check-in is not
+ // initiated in the current session. This will make sure that all the
+ // persisted data written previously will get purged.
+
+ // This has to be done before removing the cached data since we need to do
+ // the lookup based on the cached data.
+ RemovePersistedData();
+
+ RemoveCachedData();
content::BrowserThread::PostTask(
content::BrowserThread::IO,
« no previous file with comments | « chrome/browser/services/gcm/gcm_profile_service.h ('k') | chrome/browser/services/gcm/gcm_profile_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698