diff options
author | fgorski <fgorski@chromium.org> | 2014-09-24 16:40:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-09-24 23:46:24 +0000 |
commit | d578c18be6220adb21d8e1261c9196cc27c4a879 (patch) | |
tree | 0c23376ecd4755e7b0a784053677b69e2d93738c /components | |
parent | 9e2bd7aff70c6ead6e8d66bc370bf61dea076a56 (diff) | |
download | chromium_src-d578c18be6220adb21d8e1261c9196cc27c4a879.zip chromium_src-d578c18be6220adb21d8e1261c9196cc27c4a879.tar.gz chromium_src-d578c18be6220adb21d8e1261c9196cc27c4a879.tar.bz2 |
Loading the account mappings from store to the driver.
This is to make sure the starting list of account
mapping properly reflects the mappings present in the
previous Chrome session.
BUG=374969
Review URL: https://codereview.chromium.org/600053002
Cr-Commit-Position: refs/heads/master@{#296567}
Diffstat (limited to 'components')
-rw-r--r-- | components/gcm_driver/BUILD.gn | 4 | ||||
-rw-r--r-- | components/gcm_driver/fake_gcm_client.cc | 3 | ||||
-rw-r--r-- | components/gcm_driver/gcm_client.h | 5 | ||||
-rw-r--r-- | components/gcm_driver/gcm_client_impl.cc | 14 | ||||
-rw-r--r-- | components/gcm_driver/gcm_client_impl.h | 2 | ||||
-rw-r--r-- | components/gcm_driver/gcm_client_impl_unittest.cc | 8 | ||||
-rw-r--r-- | components/gcm_driver/gcm_driver_desktop.cc | 12 | ||||
-rw-r--r-- | components/gcm_driver/gcm_driver_desktop.h | 3 |
8 files changed, 37 insertions, 14 deletions
diff --git a/components/gcm_driver/BUILD.gn b/components/gcm_driver/BUILD.gn index 9e4f3d7..92330f8 100644 --- a/components/gcm_driver/BUILD.gn +++ b/components/gcm_driver/BUILD.gn @@ -11,6 +11,8 @@ static_library("gcm_driver") { "default_gcm_app_handler.h", "gcm_activity.cc", "gcm_activity.h", + "gcm_account_mapper.cc", + "gcm_account_mapper.h", "gcm_app_handler.cc", "gcm_app_handler.h", "gcm_backoff_policy.cc", @@ -51,6 +53,8 @@ static_library("gcm_driver") { if (is_android) { sources -= [ + "gcm_account_mapper.cc", + "gcm_account_mapper.h", "gcm_channel_status_request.cc", "gcm_channel_status_request.h", "gcm_channel_status_syncer.cc", diff --git a/components/gcm_driver/fake_gcm_client.cc b/components/gcm_driver/fake_gcm_client.cc index 9110d1b..91d0ecb7 100644 --- a/components/gcm_driver/fake_gcm_client.cc +++ b/components/gcm_driver/fake_gcm_client.cc @@ -11,6 +11,7 @@ #include "base/sys_byteorder.h" #include "base/time/time.h" #include "google_apis/gcm/base/encryptor.h" +#include "google_apis/gcm/engine/account_mapping.h" #include "net/base/ip_endpoint.h" namespace gcm { @@ -179,7 +180,7 @@ std::string FakeGCMClient::GetRegistrationIdFromSenderIds( } void FakeGCMClient::CheckinFinished() { - delegate_->OnGCMReady(); + delegate_->OnGCMReady(std::vector<AccountMapping>()); delegate_->OnConnected(net::IPEndPoint()); } diff --git a/components/gcm_driver/gcm_client.h b/components/gcm_driver/gcm_client.h index abf2fd5..740a3c7 100644 --- a/components/gcm_driver/gcm_client.h +++ b/components/gcm_driver/gcm_client.h @@ -201,7 +201,10 @@ class GCMClient { // Called when the GCM becomes ready. To get to this state, GCMClient // finished loading from the GCM store and retrieved the device check-in // from the server if it hadn't yet. - virtual void OnGCMReady() = 0; + // |account_mappings|: a persisted list of accounts mapped to this GCM + // client. + virtual void OnGCMReady( + const std::vector<AccountMapping>& account_mappings) = 0; // Called when activities are being recorded and a new activity has just // been recorded. diff --git a/components/gcm_driver/gcm_client_impl.cc b/components/gcm_driver/gcm_client_impl.cc index d1fc7a0..57a665a 100644 --- a/components/gcm_driver/gcm_client_impl.cc +++ b/components/gcm_driver/gcm_client_impl.cc @@ -321,11 +321,16 @@ void GCMClientImpl::OnLoadCompleted(scoped_ptr<GCMStore::LoadResult> result) { device_checkin_info_.accounts_set = true; last_checkin_time_ = result->last_checkin_time; gservices_settings_.UpdateFromLoadResult(*result); + // Taking over the value of account_mappings before passing the ownership of + // load result to InitializeMCSClient. + std::vector<AccountMapping> account_mappings; + account_mappings.swap(result->account_mappings); + InitializeMCSClient(result.Pass()); if (device_checkin_info_.IsValid()) { SchedulePeriodicCheckin(); - OnReady(); + OnReady(account_mappings); return; } @@ -379,14 +384,15 @@ void GCMClientImpl::OnFirstTimeDeviceCheckinCompleted( base::Bind(&GCMClientImpl::SetDeviceCredentialsCallback, weak_ptr_factory_.GetWeakPtr())); - OnReady(); + OnReady(std::vector<AccountMapping>()); } -void GCMClientImpl::OnReady() { +void GCMClientImpl::OnReady( + const std::vector<AccountMapping>& account_mappings) { state_ = READY; StartMCSLogin(); - delegate_->OnGCMReady(); + delegate_->OnGCMReady(account_mappings); } void GCMClientImpl::StartMCSLogin() { diff --git a/components/gcm_driver/gcm_client_impl.h b/components/gcm_driver/gcm_client_impl.h index 48bfa6a..8e43f6d 100644 --- a/components/gcm_driver/gcm_client_impl.h +++ b/components/gcm_driver/gcm_client_impl.h @@ -198,7 +198,7 @@ class GCMClientImpl void ResetState(); // Sets state to ready. This will initiate the MCS login and notify the // delegates. - void OnReady(); + void OnReady(const std::vector<AccountMapping>& account_mappings); // Starts a first time device checkin. void StartCheckin(); diff --git a/components/gcm_driver/gcm_client_impl_unittest.cc b/components/gcm_driver/gcm_client_impl_unittest.cc index c0d3e82..62416c9 100644 --- a/components/gcm_driver/gcm_client_impl_unittest.cc +++ b/components/gcm_driver/gcm_client_impl_unittest.cc @@ -258,7 +258,8 @@ class GCMClientImplTest : public testing::Test, const gcm::GCMClient::SendErrorDetails& send_error_details) OVERRIDE; virtual void OnSendAcknowledged(const std::string& app_id, const std::string& message_id) OVERRIDE; - virtual void OnGCMReady() OVERRIDE; + virtual void OnGCMReady( + const std::vector<AccountMapping>& account_mappings) OVERRIDE; virtual void OnActivityRecorded() OVERRIDE {} virtual void OnConnected(const net::IPEndPoint& ip_endpoint) OVERRIDE {} virtual void OnDisconnected() OVERRIDE {} @@ -490,9 +491,12 @@ void GCMClientImplTest::ReceiveOnMessageSentToMCS( gcm_client_->OnMessageSentToMCS(0LL, app_id, message_id, status); } -void GCMClientImplTest::OnGCMReady() { +void GCMClientImplTest::OnGCMReady( + const std::vector<AccountMapping>& account_mappings) { last_event_ = LOADING_COMPLETED; QuitLoop(); + // TODO(fgorski): Add scenario verifying contents of account_mappings, when + // the list is not empty. } void GCMClientImplTest::OnMessageReceived( diff --git a/components/gcm_driver/gcm_driver_desktop.cc b/components/gcm_driver/gcm_driver_desktop.cc index 82ca4b3..b2d2e55 100644 --- a/components/gcm_driver/gcm_driver_desktop.cc +++ b/components/gcm_driver/gcm_driver_desktop.cc @@ -50,7 +50,8 @@ class GCMDriverDesktop::IOWorker : public GCMClient::Delegate { const GCMClient::SendErrorDetails& send_error_details) OVERRIDE; virtual void OnSendAcknowledged(const std::string& app_id, const std::string& message_id) OVERRIDE; - virtual void OnGCMReady() OVERRIDE; + virtual void OnGCMReady( + const std::vector<AccountMapping>& account_mappings) OVERRIDE; virtual void OnActivityRecorded() OVERRIDE; virtual void OnConnected(const net::IPEndPoint& ip_endpoint) OVERRIDE; virtual void OnDisconnected() OVERRIDE; @@ -201,10 +202,12 @@ void GCMDriverDesktop::IOWorker::OnSendAcknowledged( &GCMDriverDesktop::SendAcknowledged, service_, app_id, message_id)); } -void GCMDriverDesktop::IOWorker::OnGCMReady() { +void GCMDriverDesktop::IOWorker::OnGCMReady( + const std::vector<AccountMapping>& account_mappings) { ui_thread_->PostTask( FROM_HERE, - base::Bind(&GCMDriverDesktop::GCMClientReady, service_)); + base::Bind( + &GCMDriverDesktop::GCMClientReady, service_, account_mappings)); } void GCMDriverDesktop::IOWorker::OnActivityRecorded() { @@ -714,7 +717,8 @@ void GCMDriverDesktop::SendAcknowledged(const std::string& app_id, GetAppHandler(app_id)->OnSendAcknowledged(app_id, message_id); } -void GCMDriverDesktop::GCMClientReady() { +void GCMDriverDesktop::GCMClientReady( + const std::vector<AccountMapping>& account_mappings) { DCHECK(ui_thread_->RunsTasksOnCurrentThread()); delayed_task_controller_->SetReady(); diff --git a/components/gcm_driver/gcm_driver_desktop.h b/components/gcm_driver/gcm_driver_desktop.h index 0ef9495..c1900ed 100644 --- a/components/gcm_driver/gcm_driver_desktop.h +++ b/components/gcm_driver/gcm_driver_desktop.h @@ -129,7 +129,8 @@ class GCMDriverDesktop : public GCMDriver { const GCMClient::SendErrorDetails& send_error_details); void SendAcknowledged(const std::string& app_id, const std::string& message_id); - void GCMClientReady(); + void GCMClientReady( + const std::vector<AccountMapping>& account_mappings); void OnConnected(const net::IPEndPoint& ip_endpoint); void OnDisconnected(); |