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

Unified Diff: components/gcm_driver/gcm_client_impl.cc

Issue 1183843002: Do not create GCM store if it is not needed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback + fix test Created 5 years, 6 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
« no previous file with comments | « no previous file | components/gcm_driver/gcm_client_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/gcm_driver/gcm_client_impl.cc
diff --git a/components/gcm_driver/gcm_client_impl.cc b/components/gcm_driver/gcm_client_impl.cc
index 1c3f8bfe7444738f4948f5a9cf4380d671552b47..2ef645e2767807d55155472d6c2585de708ef519 100644
--- a/components/gcm_driver/gcm_client_impl.cc
+++ b/components/gcm_driver/gcm_client_impl.cc
@@ -361,8 +361,14 @@ void GCMClientImpl::Start(StartMode start_mode) {
return;
// Once the loading is completed, the check-in will be initiated.
- gcm_store_->Load(base::Bind(&GCMClientImpl::OnLoadCompleted,
- weak_ptr_factory_.GetWeakPtr()));
+ // If we're in lazy start mode, don't create a new store since none is really
+ // using GCM functionality yet.
+ gcm_store_->Load(
+ (start_mode == IMMEDIATE_START) ?
+ GCMStore::CREATE_IF_MISSING :
+ GCMStore::DO_NOT_CREATE,
+ base::Bind(&GCMClientImpl::OnLoadCompleted,
+ weak_ptr_factory_.GetWeakPtr()));
state_ = LOADING;
}
@@ -370,7 +376,15 @@ void GCMClientImpl::OnLoadCompleted(scoped_ptr<GCMStore::LoadResult> result) {
DCHECK_EQ(LOADING, state_);
if (!result->success) {
- ResetStore();
+ if (result->store_does_not_exist) {
+ // In the case that the store does not exist, set |state| back to
+ // INITIALIZED such that store loading could be triggered again when
+ // Start() is called with IMMEDIATE_START.
+ state_ = INITIALIZED;
+ } else {
+ // Otherwise, destroy the store to try again.
+ ResetStore();
+ }
return;
}
gcm_store_reset_ = false;
« no previous file with comments | « no previous file | components/gcm_driver/gcm_client_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698