summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorfgorski@chromium.org <fgorski@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-20 22:34:28 +0000
committerfgorski@chromium.org <fgorski@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-20 22:35:45 +0000
commit72d4f258d30da752436236e7b0590d55f8863576 (patch)
treeeea89876cce5fbedee8c07125e8ce0a442b09eb5 /components
parent55699f3922240d6fb09ae7cda583687971111670 (diff)
downloadchromium_src-72d4f258d30da752436236e7b0590d55f8863576.zip
chromium_src-72d4f258d30da752436236e7b0590d55f8863576.tar.gz
chromium_src-72d4f258d30da752436236e7b0590d55f8863576.tar.bz2
[GCM] Exposing persistence of account mappings in GCM Driver
* Enables GCMAccountMapper (patches to come) to persist AccountMappings in GCMStore by calling GCMDriver. * Passes UpdateAccountMapping and RemoveAccountMapping through: * GCMDriverDesktop * GCMDriverDesktop::IOWorker * GCMClientImpl BUG=374969 Review URL: https://codereview.chromium.org/445683003 Cr-Commit-Position: refs/heads/master@{#290928} git-svn-id: svn://svn.chromium.org/chrome/trunk/src@290928 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'components')
-rw-r--r--components/gcm_driver/fake_gcm_client.cc7
-rw-r--r--components/gcm_driver/fake_gcm_client.h3
-rw-r--r--components/gcm_driver/fake_gcm_driver.cc7
-rw-r--r--components/gcm_driver/fake_gcm_driver.h5
-rw-r--r--components/gcm_driver/gcm_client.h8
-rw-r--r--components/gcm_driver/gcm_client_impl.cc18
-rw-r--r--components/gcm_driver/gcm_client_impl.h7
-rw-r--r--components/gcm_driver/gcm_driver.h8
-rw-r--r--components/gcm_driver/gcm_driver_android.cc7
-rw-r--r--components/gcm_driver/gcm_driver_android.h3
-rw-r--r--components/gcm_driver/gcm_driver_desktop.cc40
-rw-r--r--components/gcm_driver/gcm_driver_desktop.h3
12 files changed, 114 insertions, 2 deletions
diff --git a/components/gcm_driver/fake_gcm_client.cc b/components/gcm_driver/fake_gcm_client.cc
index 6a5639c..9110d1b 100644
--- a/components/gcm_driver/fake_gcm_client.cc
+++ b/components/gcm_driver/fake_gcm_client.cc
@@ -119,6 +119,13 @@ void FakeGCMClient::SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens) {
}
+void FakeGCMClient::UpdateAccountMapping(
+ const AccountMapping& account_mapping) {
+}
+
+void FakeGCMClient::RemoveAccountMapping(const std::string& account_id) {
+}
+
void FakeGCMClient::PerformDelayedLoading() {
DCHECK(ui_thread_->RunsTasksOnCurrentThread());
diff --git a/components/gcm_driver/fake_gcm_client.h b/components/gcm_driver/fake_gcm_client.h
index 5ba863e..0d22dd6 100644
--- a/components/gcm_driver/fake_gcm_client.h
+++ b/components/gcm_driver/fake_gcm_client.h
@@ -58,6 +58,9 @@ class FakeGCMClient : public GCMClient {
virtual GCMStatistics GetStatistics() const OVERRIDE;
virtual void SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens) OVERRIDE;
+ virtual void UpdateAccountMapping(
+ const AccountMapping& account_mapping) OVERRIDE;
+ virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE;
// Initiate the loading that has been delayed.
// Called on UI thread.
diff --git a/components/gcm_driver/fake_gcm_driver.cc b/components/gcm_driver/fake_gcm_driver.cc
index 0b98775..573140e 100644
--- a/components/gcm_driver/fake_gcm_driver.cc
+++ b/components/gcm_driver/fake_gcm_driver.cc
@@ -70,4 +70,11 @@ void FakeGCMDriver::SendImpl(const std::string& app_id,
const GCMClient::OutgoingMessage& message) {
}
+void FakeGCMDriver::UpdateAccountMapping(
+ const AccountMapping& account_mapping) {
+}
+
+void FakeGCMDriver::RemoveAccountMapping(const std::string& account_id) {
+}
+
} // namespace gcm
diff --git a/components/gcm_driver/fake_gcm_driver.h b/components/gcm_driver/fake_gcm_driver.h
index f5b0a43..cfe6255 100644
--- a/components/gcm_driver/fake_gcm_driver.h
+++ b/components/gcm_driver/fake_gcm_driver.h
@@ -21,8 +21,6 @@ class FakeGCMDriver : public GCMDriver {
virtual void AddAppHandler(const std::string& app_id,
GCMAppHandler* handler) OVERRIDE;
virtual void RemoveAppHandler(const std::string& app_id) OVERRIDE;
-
- // GCMDriver implementation:
virtual void OnSignedIn() OVERRIDE;
virtual void Purge() OVERRIDE;
virtual void Enable() OVERRIDE;
@@ -34,6 +32,9 @@ class FakeGCMDriver : public GCMDriver {
bool clear_logs) OVERRIDE;
virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) OVERRIDE;
+ virtual void UpdateAccountMapping(
+ const AccountMapping& account_mapping) OVERRIDE;
+ virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE;
protected:
// GCMDriver implementation:
diff --git a/components/gcm_driver/gcm_client.h b/components/gcm_driver/gcm_client.h
index e5082c5..8a7f7b2 100644
--- a/components/gcm_driver/gcm_client.h
+++ b/components/gcm_driver/gcm_client.h
@@ -30,6 +30,7 @@ class URLRequestContextGetter;
namespace gcm {
class Encryptor;
+struct AccountMapping;
// Interface that encapsulates the network communications with the Google Cloud
// Messaging server. This interface is not supposed to be thread-safe.
@@ -276,6 +277,13 @@ class GCMClient {
// |account_tokens| maps email addresses to OAuth2 access tokens.
virtual void SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens) = 0;
+
+ // Persists the |account_mapping| in the store.
+ virtual void UpdateAccountMapping(const AccountMapping& account_mapping) = 0;
+
+ // Removes the account mapping related to |account_id| from the persistent
+ // store.
+ virtual void RemoveAccountMapping(const std::string& account_id) = 0;
};
} // namespace gcm
diff --git a/components/gcm_driver/gcm_client_impl.cc b/components/gcm_driver/gcm_client_impl.cc
index b5240f9..02ea232 100644
--- a/components/gcm_driver/gcm_client_impl.cc
+++ b/components/gcm_driver/gcm_client_impl.cc
@@ -469,6 +469,20 @@ void GCMClientImpl::SetAccountsForCheckin(
}
}
+void GCMClientImpl::UpdateAccountMapping(
+ const AccountMapping& account_mapping) {
+ gcm_store_->AddAccountMapping(account_mapping,
+ base::Bind(&GCMClientImpl::DefaultStoreCallback,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
+void GCMClientImpl::RemoveAccountMapping(const std::string& account_id) {
+ gcm_store_->RemoveAccountMapping(
+ account_id,
+ base::Bind(&GCMClientImpl::DefaultStoreCallback,
+ weak_ptr_factory_.GetWeakPtr()));
+}
+
void GCMClientImpl::StartCheckin() {
// Make sure no checkin is in progress.
if (checkin_request_.get())
@@ -584,6 +598,10 @@ void GCMClientImpl::UpdateRegistrationCallback(bool success) {
DCHECK(success);
}
+void GCMClientImpl::DefaultStoreCallback(bool success) {
+ DCHECK(success);
+}
+
void GCMClientImpl::Stop() {
weak_ptr_factory_.InvalidateWeakPtrs();
device_checkin_info_.Reset();
diff --git a/components/gcm_driver/gcm_client_impl.h b/components/gcm_driver/gcm_client_impl.h
index 10d89b7..48bfa6a 100644
--- a/components/gcm_driver/gcm_client_impl.h
+++ b/components/gcm_driver/gcm_client_impl.h
@@ -105,6 +105,9 @@ class GCMClientImpl
virtual GCMStatistics GetStatistics() const OVERRIDE;
virtual void SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens) OVERRIDE;
+ virtual void UpdateAccountMapping(
+ const AccountMapping& account_mapping) OVERRIDE;
+ virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE;
// GCMStatsRecorder::Delegate implemenation.
virtual void OnActivityRecorded() OVERRIDE;
@@ -222,6 +225,10 @@ class GCMClientImpl
// Callback for persisting registration info in the |gcm_store_|.
void UpdateRegistrationCallback(bool success);
+ // Callback for all store operations that do not try to recover, if write in
+ // |gcm_store_| fails.
+ void DefaultStoreCallback(bool success);
+
// Completes the registration request.
void OnRegisterCompleted(const std::string& app_id,
const std::vector<std::string>& sender_ids,
diff --git a/components/gcm_driver/gcm_driver.h b/components/gcm_driver/gcm_driver.h
index f75a8e3..c4646ed 100644
--- a/components/gcm_driver/gcm_driver.h
+++ b/components/gcm_driver/gcm_driver.h
@@ -18,6 +18,7 @@
namespace gcm {
class GCMAppHandler;
+struct AccountMapping;
// Bridge between GCM users in Chrome and the platform-specific implementation.
class GCMDriver {
@@ -110,6 +111,13 @@ class GCMDriver {
virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) = 0;
+ // Updates the |account_mapping| information in persistent store.
+ virtual void UpdateAccountMapping(const AccountMapping& account_mapping) = 0;
+
+ // Removes the account mapping information reated to |account_id| from
+ // persistent store.
+ virtual void RemoveAccountMapping(const std::string& account_id) = 0;
+
protected:
// Ensures that the GCM service starts (if necessary conditions are met).
virtual GCMClient::Result EnsureStarted() = 0;
diff --git a/components/gcm_driver/gcm_driver_android.cc b/components/gcm_driver/gcm_driver_android.cc
index ae643cd..a6ab94a 100644
--- a/components/gcm_driver/gcm_driver_android.cc
+++ b/components/gcm_driver/gcm_driver_android.cc
@@ -129,6 +129,13 @@ void GCMDriverAndroid::SetGCMRecording(const GetGCMStatisticsCallback& callback,
NOTIMPLEMENTED();
}
+void GCMDriverAndroid::UpdateAccountMapping(
+ const AccountMapping& account_mapping) {
+}
+
+void GCMDriverAndroid::RemoveAccountMapping(const std::string& account_id) {
+}
+
GCMClient::Result GCMDriverAndroid::EnsureStarted() {
// TODO(johnme): Maybe we should check if GMS is available?
return GCMClient::SUCCESS;
diff --git a/components/gcm_driver/gcm_driver_android.h b/components/gcm_driver/gcm_driver_android.h
index a351f8f..8c5aadf 100644
--- a/components/gcm_driver/gcm_driver_android.h
+++ b/components/gcm_driver/gcm_driver_android.h
@@ -55,6 +55,9 @@ class GCMDriverAndroid : public GCMDriver {
bool clear_logs) OVERRIDE;
virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) OVERRIDE;
+ virtual void UpdateAccountMapping(
+ const AccountMapping& account_mapping) OVERRIDE;
+ virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE;
protected:
// GCMDriver implementation:
diff --git a/components/gcm_driver/gcm_driver_desktop.cc b/components/gcm_driver/gcm_driver_desktop.cc
index d879426..1303152 100644
--- a/components/gcm_driver/gcm_driver_desktop.cc
+++ b/components/gcm_driver/gcm_driver_desktop.cc
@@ -16,6 +16,7 @@
#include "components/gcm_driver/gcm_app_handler.h"
#include "components/gcm_driver/gcm_client_factory.h"
#include "components/gcm_driver/system_encryptor.h"
+#include "google_apis/gcm/engine/account_mapping.h"
#include "net/base/ip_endpoint.h"
#include "net/url_request/url_request_context_getter.h"
@@ -136,6 +137,8 @@ class GCMDriverDesktop::IOWorker : public GCMClient::Delegate {
void SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens);
+ void UpdateAccountMapping(const AccountMapping& account_mapping);
+ void RemoveAccountMapping(const std::string& account_id);
// For testing purpose. Can be called from UI thread. Use with care.
GCMClient* gcm_client_for_testing() const { return gcm_client_.get(); }
@@ -369,6 +372,22 @@ void GCMDriverDesktop::IOWorker::SetAccountsForCheckin(
gcm_client_->SetAccountsForCheckin(account_tokens);
}
+void GCMDriverDesktop::IOWorker::UpdateAccountMapping(
+ const AccountMapping& account_mapping) {
+ DCHECK(io_thread_->RunsTasksOnCurrentThread());
+
+ if (gcm_client_.get())
+ gcm_client_->UpdateAccountMapping(account_mapping);
+}
+
+void GCMDriverDesktop::IOWorker::RemoveAccountMapping(
+ const std::string& account_id) {
+ DCHECK(io_thread_->RunsTasksOnCurrentThread());
+
+ if (gcm_client_.get())
+ gcm_client_->RemoveAccountMapping(account_id);
+}
+
GCMDriverDesktop::GCMDriverDesktop(
scoped_ptr<GCMClientFactory> gcm_client_factory,
const GCMClient::ChromeBuildInfo& chrome_build_info,
@@ -605,6 +624,27 @@ void GCMDriverDesktop::SetGCMRecording(const GetGCMStatisticsCallback& callback,
recording));
}
+void GCMDriverDesktop::UpdateAccountMapping(
+ const AccountMapping& account_mapping) {
+ DCHECK(ui_thread_->RunsTasksOnCurrentThread());
+
+ io_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&GCMDriverDesktop::IOWorker::UpdateAccountMapping,
+ base::Unretained(io_worker_.get()),
+ account_mapping));
+}
+
+void GCMDriverDesktop::RemoveAccountMapping(const std::string& account_id) {
+ DCHECK(ui_thread_->RunsTasksOnCurrentThread());
+
+ io_thread_->PostTask(
+ FROM_HERE,
+ base::Bind(&GCMDriverDesktop::IOWorker::RemoveAccountMapping,
+ base::Unretained(io_worker_.get()),
+ account_id));
+}
+
void GCMDriverDesktop::SetAccountsForCheckin(
const std::map<std::string, std::string>& account_tokens) {
DCHECK(ui_thread_->RunsTasksOnCurrentThread());
diff --git a/components/gcm_driver/gcm_driver_desktop.h b/components/gcm_driver/gcm_driver_desktop.h
index 91a0399..8eba9683 100644
--- a/components/gcm_driver/gcm_driver_desktop.h
+++ b/components/gcm_driver/gcm_driver_desktop.h
@@ -64,6 +64,9 @@ class GCMDriverDesktop : public GCMDriver {
bool clear_logs) OVERRIDE;
virtual void SetGCMRecording(const GetGCMStatisticsCallback& callback,
bool recording) OVERRIDE;
+ virtual void UpdateAccountMapping(
+ const AccountMapping& account_mapping) OVERRIDE;
+ virtual void RemoveAccountMapping(const std::string& account_id) OVERRIDE;
// GCMDriverDesktop specific implementation.
// Sets a list of accounts with OAuth2 tokens for the next checkin.