summaryrefslogtreecommitdiffstats
path: root/google_apis
diff options
context:
space:
mode:
authorjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-05 00:57:15 +0000
committerjianli@chromium.org <jianli@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-03-05 00:57:15 +0000
commit21fee54816f721c9fd0a91056caa4baa7156aac3 (patch)
treec70ba3e7c627eca77ebcc76dc4b4830efa355138 /google_apis
parent4bf858f802b04c1e7a4de9ed8fd601a315aa5ce0 (diff)
downloadchromium_src-21fee54816f721c9fd0a91056caa4baa7156aac3.zip
chromium_src-21fee54816f721c9fd0a91056caa4baa7156aac3.tar.gz
chromium_src-21fee54816f721c9fd0a91056caa4baa7156aac3.tar.bz2
[GCM] Stop/restart GCM when the state is forced off/on
BUG=348642 TEST=new tests added R=dimich@chromium.org, fgorski@chromium.org, tim@chromium.org Review URL: https://codereview.chromium.org/183013007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@254893 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'google_apis')
-rw-r--r--google_apis/gcm/engine/gcm_store.h3
-rw-r--r--google_apis/gcm/engine/gcm_store_impl.cc12
-rw-r--r--google_apis/gcm/engine/gcm_store_impl.h3
-rw-r--r--google_apis/gcm/engine/gcm_store_impl_unittest.cc17
-rw-r--r--google_apis/gcm/gcm_client.h4
-rw-r--r--google_apis/gcm/gcm_client_impl.cc11
-rw-r--r--google_apis/gcm/gcm_client_impl.h1
7 files changed, 48 insertions, 3 deletions
diff --git a/google_apis/gcm/engine/gcm_store.h b/google_apis/gcm/engine/gcm_store.h
index d725118..4387042 100644
--- a/google_apis/gcm/engine/gcm_store.h
+++ b/google_apis/gcm/engine/gcm_store.h
@@ -68,6 +68,9 @@ class GCM_EXPORT GCMStore {
// caller.
virtual void Load(const LoadCallback& callback) = 0;
+ // Close the persistent store.
+ virtual void Close() = 0;
+
// Clears the GCM store of all data.
virtual void Destroy(const UpdateCallback& callback) = 0;
diff --git a/google_apis/gcm/engine/gcm_store_impl.cc b/google_apis/gcm/engine/gcm_store_impl.cc
index 31b258f..91d3e70 100644
--- a/google_apis/gcm/engine/gcm_store_impl.cc
+++ b/google_apis/gcm/engine/gcm_store_impl.cc
@@ -96,6 +96,7 @@ class GCMStoreImpl::Backend
// Blocking implementations of GCMStoreImpl methods.
void Load(const LoadCallback& callback);
+ void Close();
void Destroy(const UpdateCallback& callback);
void SetDeviceCredentials(uint64 device_android_id,
uint64 device_security_token,
@@ -213,6 +214,11 @@ void GCMStoreImpl::Backend::Load(const LoadCallback& callback) {
return;
}
+void GCMStoreImpl::Backend::Close() {
+ DVLOG(1) << "Closing GCM store.";
+ db_.reset();
+}
+
void GCMStoreImpl::Backend::Destroy(const UpdateCallback& callback) {
DVLOG(1) << "Destroying GCM store.";
db_.reset();
@@ -634,6 +640,12 @@ void GCMStoreImpl::Load(const LoadCallback& callback) {
callback)));
}
+void GCMStoreImpl::Close() {
+ blocking_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&GCMStoreImpl::Backend::Close, backend_));
+}
+
void GCMStoreImpl::Destroy(const UpdateCallback& callback) {
blocking_task_runner_->PostTask(
FROM_HERE,
diff --git a/google_apis/gcm/engine/gcm_store_impl.h b/google_apis/gcm/engine/gcm_store_impl.h
index b8550da..88ed164 100644
--- a/google_apis/gcm/engine/gcm_store_impl.h
+++ b/google_apis/gcm/engine/gcm_store_impl.h
@@ -31,6 +31,9 @@ class GCM_EXPORT GCMStoreImpl : public GCMStore {
// Load the directory and pass the initial state back to caller.
virtual void Load(const LoadCallback& callback) OVERRIDE;
+ // Closes the GCM store.
+ virtual void Close() OVERRIDE;
+
// Clears the GCM store of all data and destroys any LevelDB files associated
// with this store.
// WARNING: this will permanently destroy any pending outgoing messages
diff --git a/google_apis/gcm/engine/gcm_store_impl_unittest.cc b/google_apis/gcm/engine/gcm_store_impl_unittest.cc
index a7c3d38..0a34307 100644
--- a/google_apis/gcm/engine/gcm_store_impl_unittest.cc
+++ b/google_apis/gcm/engine/gcm_store_impl_unittest.cc
@@ -465,6 +465,23 @@ TEST_F(GCMStoreImplTest, AddMessageAfterDestroy) {
}
}
+TEST_F(GCMStoreImplTest, ReloadAfterClose) {
+ scoped_ptr<GCMStore> gcm_store(BuildGCMStore());
+ scoped_ptr<GCMStore::LoadResult> load_result;
+ gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback,
+ base::Unretained(this),
+ &load_result));
+ PumpLoop();
+
+ gcm_store->Close();
+ PumpLoop();
+
+ gcm_store->Load(base::Bind(&GCMStoreImplTest::LoadCallback,
+ base::Unretained(this),
+ &load_result));
+ PumpLoop();
+}
+
} // namespace
} // namespace gcm
diff --git a/google_apis/gcm/gcm_client.h b/google_apis/gcm/gcm_client.h
index 15f67cf..a25cb12 100644
--- a/google_apis/gcm/gcm_client.h
+++ b/google_apis/gcm/gcm_client.h
@@ -153,8 +153,12 @@ class GCM_EXPORT GCMClient {
// Loads the data from the persistent store. This will automatically kick off
// the check-in if the check-in info is not found in the store.
+ // TODO(jianli): consider renaming this name to Start.
virtual void Load() = 0;
+ // Stops using the GCM service. This will not erase the persisted data.
+ virtual void Stop() = 0;
+
// Checks out of the GCM service. This will erase all the cached and persisted
// data.
virtual void CheckOut() = 0;
diff --git a/google_apis/gcm/gcm_client_impl.cc b/google_apis/gcm/gcm_client_impl.cc
index 640977a..aa12ee8 100644
--- a/google_apis/gcm/gcm_client_impl.cc
+++ b/google_apis/gcm/gcm_client_impl.cc
@@ -286,14 +286,19 @@ void GCMClientImpl::SetDeviceCredentialsCallback(bool success) {
DCHECK(success);
}
-void GCMClientImpl::CheckOut() {
+void GCMClientImpl::Stop() {
device_checkin_info_.Reset();
mcs_client_.reset();
- gcm_store_->Destroy(base::Bind(&GCMClientImpl::OnGCMStoreDestroyed,
- weak_ptr_factory_.GetWeakPtr()));
checkin_request_.reset();
pending_registrations_.clear();
state_ = INITIALIZED;
+ gcm_store_->Close();
+}
+
+void GCMClientImpl::CheckOut() {
+ Stop();
+ gcm_store_->Destroy(base::Bind(&GCMClientImpl::OnGCMStoreDestroyed,
+ weak_ptr_factory_.GetWeakPtr()));
}
void GCMClientImpl::Register(const std::string& app_id,
diff --git a/google_apis/gcm/gcm_client_impl.h b/google_apis/gcm/gcm_client_impl.h
index 72b86ba..247360a 100644
--- a/google_apis/gcm/gcm_client_impl.h
+++ b/google_apis/gcm/gcm_client_impl.h
@@ -56,6 +56,7 @@ class GCM_EXPORT GCMClientImpl : public GCMClient {
url_request_context_getter,
Delegate* delegate) OVERRIDE;
virtual void Load() OVERRIDE;
+ virtual void Stop() OVERRIDE;
virtual void CheckOut() OVERRIDE;
virtual void Register(const std::string& app_id,
const std::string& cert,