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

Unified Diff: chrome/browser/services/gcm/gcm_profile_service.cc

Issue 330733002: Move IdentityProvider usage from GCMDriverDesktop to GCMProfileService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch Created 6 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
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 424f5909fcc43c86e851b7da12966e20ade79f4f..b00a74e8194896503c17d5c559326b749a331216 100644
--- a/chrome/browser/services/gcm/gcm_profile_service.cc
+++ b/chrome/browser/services/gcm/gcm_profile_service.cc
@@ -58,12 +58,16 @@ GCMProfileService::GCMProfileService(
driver_ = CreateGCMDriverDesktop(
gcm_client_factory.Pass(),
- scoped_ptr<IdentityProvider>(new ProfileIdentityProvider(
- SigninManagerFactory::GetForProfile(profile_),
- ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
- LoginUIServiceFactory::GetForProfile(profile_))),
profile_->GetPath().Append(chrome::kGCMStoreDirname),
profile_->GetRequestContext());
+
+ identity_provider_.reset(new ProfileIdentityProvider(
+ SigninManagerFactory::GetForProfile(profile_),
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile_),
+ LoginUIServiceFactory::GetForProfile(profile_)));
+ identity_provider_->AddObserver(this);
+
+ OnActiveAccountLogin();
}
#endif // defined(OS_ANDROID)
@@ -96,6 +100,41 @@ void GCMProfileService::Shutdown() {
driver_->Shutdown();
driver_.reset();
}
+
+#if !defined(OS_ANDROID)
+ if (identity_provider_) {
+ identity_provider_->RemoveObserver(this);
+ identity_provider_.reset();
+ }
+#endif // !defined(OS_ANDROID)
+}
+
+#if !defined(OS_ANDROID)
+void GCMProfileService::OnActiveAccountLogin() {
+ if (!driver_)
+ return;
+
+ // This might be called multiple times when the password changes.
+ std::string account_id = identity_provider_->GetActiveAccountId();
bartfab (slow) 2014/06/13 11:27:21 Nit: const.
jianli 2014/06/13 18:04:48 Done.
+ if (account_id == account_id_)
+ return;
+ account_id_ = account_id;
+
+ driver_->SignIn();
+}
+
+void GCMProfileService::OnActiveAccountLogout() {
+ if (driver_)
+ driver_->Purge();
+}
+#endif // !defined(OS_ANDROID)
+
+std::string GCMProfileService::SignedInUserName() const {
+#if !defined(OS_ANDROID)
+ if (driver_.get() && driver_->IsStarted())
bartfab (slow) 2014/06/13 11:27:21 Nit: scoped_ptr is testable. No need for .get():
jianli 2014/06/13 18:04:48 Done.
+ return account_id_;
+#endif // !defined(OS_ANDROID)
+ return std::string();
}
void GCMProfileService::SetDriverForTesting(GCMDriver* driver) {

Powered by Google App Engine
This is Rietveld 408576698