Chromium Code Reviews| 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 3e549a75d447f53b07669601e2cbc5037c61dbd1..9306408008eb0e80cb07b54e6eb7e3370456e0ff 100644 |
| --- a/chrome/browser/services/gcm/gcm_profile_service.cc |
| +++ b/chrome/browser/services/gcm/gcm_profile_service.cc |
| @@ -4,6 +4,8 @@ |
| #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| +#include <map> |
| + |
| #include "base/logging.h" |
| #include "base/prefs/pref_service.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -13,7 +15,10 @@ |
| #if defined(OS_ANDROID) |
| #include "components/gcm_driver/gcm_driver_android.h" |
| #else |
| +#include "base/bind.h" |
| #include "base/files/file_path.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "chrome/browser/services/gcm/gcm_account_tracker.h" |
| #include "chrome/browser/services/gcm/gcm_desktop_utils.h" |
| #include "chrome/browser/signin/profile_identity_provider.h" |
| #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| @@ -21,7 +26,9 @@ |
| #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| #include "chrome/common/chrome_constants.h" |
| #include "components/gcm_driver/gcm_client_factory.h" |
| +#include "components/gcm_driver/gcm_driver_desktop.h" |
| #include "components/signin/core/browser/signin_manager.h" |
| +#include "google_apis/gaia/account_tracker.h" |
| #include "google_apis/gaia/identity_provider.h" |
| #include "net/url_request/url_request_context_getter.h" |
| #endif |
| @@ -29,9 +36,11 @@ |
| namespace gcm { |
| #if !defined(OS_ANDROID) |
| +// Identity observer only has actual work to do when the user is acutally signed |
|
Nicolas Zea
2014/07/16 20:53:54
nit: acutally
fgorski
2014/07/17 03:35:34
Done.
|
| +// in. It ensures that account tracker is taking |
| class GCMProfileService::IdentityObserver : public IdentityProvider::Observer { |
| public: |
| - IdentityObserver(Profile* profile, GCMDriver* driver); |
| + IdentityObserver(Profile* profile, GCMDriverDesktop* driver); |
| virtual ~IdentityObserver(); |
| // IdentityProvider::Observer: |
| @@ -40,20 +49,29 @@ class GCMProfileService::IdentityObserver : public IdentityProvider::Observer { |
| std::string SignedInUserName() const; |
| + // Called to inform IdentityObserver that a list of accounts was updated. |
| + // |account_tokens| maps email addresses to OAuth2 access tokens. |
| + void AccountsUpdated( |
| + const std::map<std::string, std::string>& account_tokens); |
| + |
| private: |
| - GCMDriver* driver_; |
| + Profile* profile_; |
| + GCMDriverDesktop* driver_; |
| scoped_ptr<IdentityProvider> identity_provider_; |
| + scoped_ptr<GCMAccountTracker> gcm_account_tracker_; |
| // The account ID that this service is responsible for. Empty when the service |
| // is not running. |
| std::string account_id_; |
| + base::WeakPtrFactory<GCMProfileService::IdentityObserver> weak_ptr_factory_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(IdentityObserver); |
| }; |
| GCMProfileService::IdentityObserver::IdentityObserver(Profile* profile, |
| - GCMDriver* driver) |
| - : driver_(driver) { |
| + GCMDriverDesktop* driver) |
| + : profile_(profile), driver_(driver), weak_ptr_factory_(this) { |
| identity_provider_.reset(new ProfileIdentityProvider( |
| SigninManagerFactory::GetForProfile(profile), |
| ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
| @@ -64,6 +82,8 @@ GCMProfileService::IdentityObserver::IdentityObserver(Profile* profile, |
| } |
| GCMProfileService::IdentityObserver::~IdentityObserver() { |
| + if (gcm_account_tracker_) |
| + gcm_account_tracker_->Shutdown(); |
| identity_provider_->RemoveObserver(this); |
| } |
| @@ -75,15 +95,37 @@ void GCMProfileService::IdentityObserver::OnActiveAccountLogin() { |
| 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() { |
| + if (gcm_account_tracker_) |
|
Nicolas Zea
2014/07/16 20:53:54
Shouldn't we always have an account tracker at thi
fgorski
2014/07/17 03:35:34
Replacing with DCHECK and starting trybots.
|
| + gcm_account_tracker_->Stop(); |
| + // TODO(fgorski): If we purge here, what should happen when we get |
| + // OnActiveAccountLogin() right after that? |
| driver_->Purge(); |
| } |
| std::string GCMProfileService::IdentityObserver::SignedInUserName() const { |
| return driver_->IsStarted() ? account_id_ : std::string(); |
| } |
| + |
| +void GCMProfileService::IdentityObserver::AccountsUpdated( |
| + const std::map<std::string, std::string>& account_tokens) { |
| + driver_->SetAccountsForCheckin(account_tokens); |
| +} |
| #endif // !defined(OS_ANDROID) |
| // static |
| @@ -122,7 +164,8 @@ GCMProfileService::GCMProfileService( |
| profile_->GetPath().Append(chrome::kGCMStoreDirname), |
| profile_->GetRequestContext()); |
| - identity_observer_.reset(new IdentityObserver(profile, driver_.get())); |
| + identity_observer_.reset(new IdentityObserver( |
| + profile, static_cast<gcm::GCMDriverDesktop*>(driver_.get()))); |
| } |
| #endif // defined(OS_ANDROID) |