Chromium Code Reviews| 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..2a07cc8984236b3fa536a347618e6de4cf0b047c 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); |
|
Dmitry Titov
2014/03/04 02:47:51
Note: If you rename GCMClient::Load -> Start, you
jianli
2014/03/04 05:14:26
Yes, will rename all these if we proceed with the
|
| + 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,28 @@ 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 signed in yet. |
| + if (username_.empty()) |
| + return; |
| + username_.clear(); |
|
fgorski
2014/03/04 20:07:49
Seems that clearing username could be a part of Re
jianli
2014/03/04 20:52:26
Done.
|
| + |
| + 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 +801,19 @@ 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(); |
| + 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,21 @@ 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. |
| + username_.clear(); |
| + |
| + // 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, |