X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fchrome%2Fbrowser%2Fservices%2Fgcm%2Fgcm_profile_service.cc;h=018cbe6037ab0f223e1ba3fb8e3278963b96ba9e;hb=1afa4dd80ef85af7c90efaea6959db1d92330844;hp=0de6385d77b6fe0d6f1fa820c404316e224569b5;hpb=90762837333c13ccf56f2ad88e4481fc71e8d281;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/chrome/browser/services/gcm/gcm_profile_service.cc b/src/chrome/browser/services/gcm/gcm_profile_service.cc index 0de6385..018cbe6 100644 --- a/src/chrome/browser/services/gcm/gcm_profile_service.cc +++ b/src/chrome/browser/services/gcm/gcm_profile_service.cc @@ -4,12 +4,13 @@ #include "chrome/browser/services/gcm/gcm_profile_service.h" -#include +#include #include "base/logging.h" #include "base/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/pref_names.h" +#include "components/gcm_driver/gcm_driver.h" #include "components/pref_registry/pref_registry_syncable.h" #if defined(OS_ANDROID) @@ -43,23 +44,20 @@ namespace gcm { // in. It ensures that account tracker is taking class GCMProfileService::IdentityObserver : public IdentityProvider::Observer { public: - IdentityObserver(Profile* profile, GCMDriverDesktop* driver); - virtual ~IdentityObserver(); + IdentityObserver(Profile* profile, GCMDriver* driver); + ~IdentityObserver() override; // IdentityProvider::Observer: - virtual void OnActiveAccountLogin() OVERRIDE; - virtual void OnActiveAccountLogout() OVERRIDE; + void OnActiveAccountLogin() override; + void OnActiveAccountLogout() override; 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& account_tokens); - private: + void StartAccountTracker(); + Profile* profile_; - GCMDriverDesktop* driver_; + GCMDriver* driver_; scoped_ptr identity_provider_; scoped_ptr gcm_account_tracker_; @@ -73,7 +71,7 @@ class GCMProfileService::IdentityObserver : public IdentityProvider::Observer { }; GCMProfileService::IdentityObserver::IdentityObserver(Profile* profile, - GCMDriverDesktop* driver) + GCMDriver* driver) : profile_(profile), driver_(driver), weak_ptr_factory_(this) { identity_provider_.reset(new ProfileIdentityProvider( SigninManagerFactory::GetForProfile(profile), @@ -82,6 +80,7 @@ GCMProfileService::IdentityObserver::IdentityObserver(Profile* profile, identity_provider_->AddObserver(this); OnActiveAccountLogin(); + StartAccountTracker(); } GCMProfileService::IdentityObserver::~IdentityObserver() { @@ -95,30 +94,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_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 @@ -130,10 +113,20 @@ std::string GCMProfileService::IdentityObserver::SignedInUserName() const { return driver_->IsStarted() ? account_id_ : std::string(); } -void GCMProfileService::IdentityObserver::AccountsUpdated( - const std::map& account_tokens) { - driver_->SetAccountsForCheckin(account_tokens); +void GCMProfileService::IdentityObserver::StartAccountTracker() { + if (gcm_account_tracker_) + return; + + scoped_ptr 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 @@ -178,8 +171,7 @@ GCMProfileService::GCMProfileService( driver_->AddConnectionObserver(chromeos_connection_observer_.get()); #endif - identity_observer_.reset(new IdentityObserver( - profile, static_cast(driver_.get()))); + identity_observer_.reset(new IdentityObserver(profile, driver_.get())); } #endif // defined(OS_ANDROID) @@ -191,24 +183,6 @@ GCMProfileService::GCMProfileService() GCMProfileService::~GCMProfileService() { } -void GCMProfileService::AddAppHandler(const std::string& app_id, - GCMAppHandler* handler) { - if (driver_) - driver_->AddAppHandler(app_id, handler); -} - -void GCMProfileService::RemoveAppHandler(const std::string& app_id) { - if (driver_) - driver_->RemoveAppHandler(app_id); -} - -void GCMProfileService::Register(const std::string& app_id, - const std::vector& sender_ids, - const GCMDriver::RegisterCallback& callback) { - if (driver_) - driver_->Register(app_id, sender_ids, callback); -} - void GCMProfileService::Shutdown() { #if !defined(OS_ANDROID) identity_observer_.reset(); @@ -234,6 +208,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