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

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

Issue 618003002: [GCM] Handling connection events in GCMAccountTracker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing the test failing on a mac Created 6 years, 2 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 491ca87a4f1ae9458675e1593b016bc27a811d2d..8cf374b299a4662d4efce113681c4df755e418a5 100644
--- a/chrome/browser/services/gcm/gcm_profile_service.cc
+++ b/chrome/browser/services/gcm/gcm_profile_service.cc
@@ -52,13 +52,9 @@ class GCMProfileService::IdentityObserver : public IdentityProvider::Observer {
std::string SignedInUserName() const;
- // Called to inform IdentityObserver that a list of accounts was updated.
- // |account_tokens| is a list of email addresses, account IDs and OAuth2
- // access tokens.
- void AccountsUpdated(
- const std::vector<GCMClient::AccountTokenInfo>& account_tokens);
-
private:
+ void StartAccountTracker();
+
Profile* profile_;
GCMDriver* driver_;
scoped_ptr<IdentityProvider> identity_provider_;
@@ -83,6 +79,7 @@ GCMProfileService::IdentityObserver::IdentityObserver(Profile* profile,
identity_provider_->AddObserver(this);
OnActiveAccountLogin();
+ StartAccountTracker();
}
GCMProfileService::IdentityObserver::~IdentityObserver() {
@@ -96,30 +93,14 @@ void GCMProfileService::IdentityObserver::OnActiveAccountLogin() {
const std::string account_id = identity_provider_->GetActiveAccountId();
if (account_id == account_id_)
return;
- account_id_ = account_id;
+ account_id_ = account_id;
driver_->OnSignedIn();
-
- if (!gcm_account_tracker_) {
- scoped_ptr<gaia::AccountTracker> gaia_account_tracker(
- new gaia::AccountTracker(identity_provider_.get(),
- profile_->GetRequestContext()));
-
- gcm_account_tracker_.reset(new GCMAccountTracker(
- gaia_account_tracker.Pass(),
- base::Bind(&GCMProfileService::IdentityObserver::AccountsUpdated,
- weak_ptr_factory_.GetWeakPtr())));
- }
-
- gcm_account_tracker_->Start();
}
void GCMProfileService::IdentityObserver::OnActiveAccountLogout() {
account_id_.clear();
- // Check is necessary to not crash browser_tests.
- if (gcm_account_tracker_)
- gcm_account_tracker_->Stop();
// When sign-in enforcement is not dropped, OnSignedOut will also clear all
// the GCM data and a new GCM ID will be retrieved after the user signs in
// again. Otherwise, the user sign-out will not affect the existing GCM
@@ -131,10 +112,20 @@ std::string GCMProfileService::IdentityObserver::SignedInUserName() const {
return driver_->IsStarted() ? account_id_ : std::string();
}
-void GCMProfileService::IdentityObserver::AccountsUpdated(
- const std::vector<GCMClient::AccountTokenInfo>& account_tokens) {
- driver_->SetAccountTokens(account_tokens);
+void GCMProfileService::IdentityObserver::StartAccountTracker() {
+ if (gcm_account_tracker_)
+ return;
+
+ scoped_ptr<gaia::AccountTracker> gaia_account_tracker(
+ new gaia::AccountTracker(identity_provider_.get(),
+ profile_->GetRequestContext()));
+
+ gcm_account_tracker_.reset(
+ new GCMAccountTracker(gaia_account_tracker.Pass(), driver_));
+
+ gcm_account_tracker_->Start();
}
+
#endif // !defined(OS_ANDROID)
// static
@@ -234,6 +225,10 @@ std::string GCMProfileService::SignedInUserName() const {
void GCMProfileService::SetDriverForTesting(GCMDriver* driver) {
driver_.reset(driver);
+#if !defined(OS_ANDROID)
+ if (identity_observer_)
+ identity_observer_.reset(new IdentityObserver(profile_, driver));
+#endif // !defined(OS_ANDROID)
}
} // namespace gcm

Powered by Google App Engine
This is Rietveld 408576698