Chromium Code Reviews| Index: chrome/browser/signin/signin_tracker.cc |
| diff --git a/chrome/browser/signin/signin_tracker.cc b/chrome/browser/signin/signin_tracker.cc |
| index b356efb3318b90e24204555a7b26b0e9a9232e4d..93972917f8f65e344a9920594ac31a1a3f0d96f5 100644 |
| --- a/chrome/browser/signin/signin_tracker.cc |
| +++ b/chrome/browser/signin/signin_tracker.cc |
| @@ -6,31 +6,26 @@ |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/signin/profile_oauth2_token_service.h" |
| +#include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| #include "chrome/browser/signin/signin_manager.h" |
| #include "chrome/browser/signin/signin_manager_factory.h" |
| -#include "chrome/browser/signin/token_service.h" |
| -#include "chrome/browser/signin/token_service_factory.h" |
| #include "content/public/browser/notification_details.h" |
| #include "content/public/browser/notification_source.h" |
| #include "google_apis/gaia/gaia_constants.h" |
| -static const char* kSignedInServices[] = { |
| - GaiaConstants::kSyncService, |
| - GaiaConstants::kGaiaOAuth2LoginRefreshToken |
| -}; |
| -static const int kNumSignedInServices = |
| - arraysize(kSignedInServices); |
| - |
| -// Helper to check if the given token service is relevant for sync. |
| SigninTracker::SigninTracker(Profile* profile, Observer* observer) |
| : state_(WAITING_FOR_GAIA_VALIDATION), |
| profile_(profile), |
| observer_(observer), |
| credentials_valid_(false) { |
| + DCHECK(profile_); |
| Initialize(); |
|
Andrew T Wilson (Slow)
2013/08/19 15:23:06
I'm guessing it's an error to call this if the OAu
|
| } |
| SigninTracker::~SigninTracker() { |
| + ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)-> |
| + RemoveObserver(this); |
| } |
| void SigninTracker::Initialize() { |
| @@ -42,16 +37,8 @@ void SigninTracker::Initialize() { |
| registrar_.Add(this, |
| chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED, |
| content::Source<Profile>(profile_)); |
| - TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); |
| - registrar_.Add(this, |
| - chrome::NOTIFICATION_TOKEN_AVAILABLE, |
| - content::Source<TokenService>(token_service)); |
| - registrar_.Add(this, |
| - chrome::NOTIFICATION_TOKEN_REQUEST_FAILED, |
| - content::Source<TokenService>(token_service)); |
| - if (state_ == SERVICES_INITIALIZING) |
| - HandleServiceStateChange(); |
|
Andrew T Wilson (Slow)
2013/08/19 15:23:06
I guess we no longer support initializing in an in
Roger Tawa OOO till Jul 10th
2013/08/29 19:28:41
I noticed this was true while making this change.
|
| + ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->AddObserver(this); |
| } |
| void SigninTracker::Observe(int type, |
| @@ -73,27 +60,21 @@ void SigninTracker::Observe(int type, |
| observer_->SigninFailed(error); |
| break; |
| } |
| - case chrome::NOTIFICATION_TOKEN_AVAILABLE: |
| - // A new token is available - check to see if we're all signed in now. |
| - HandleServiceStateChange(); |
| - break; |
| - case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: |
| - if (state_ == SERVICES_INITIALIZING) { |
| - const TokenService::TokenRequestFailedDetails& token_details = |
| - *(content::Details<const TokenService::TokenRequestFailedDetails>( |
| - details).ptr()); |
| - for (int i = 0; i < kNumSignedInServices; ++i) { |
| - if (token_details.service() == kSignedInServices[i]) { |
| - // We got an error loading one of our tokens, so notify our |
| - // observer. |
| - state_ = WAITING_FOR_GAIA_VALIDATION; |
| - observer_->SigninFailed(token_details.error()); |
| - } |
| - } |
| - } |
| - break; |
| default: |
| - NOTREACHED(); |
| + NOTREACHED() << "Invalid type=" << type; |
| + } |
| +} |
| + |
| +void SigninTracker::OnRefreshTokenAvailable(const std::string& account_id) { |
| + HandleServiceStateChange(); |
| +} |
| + |
| +void SigninTracker::OnRefreshTokenRevoked(const std::string& account_id, |
| + const GoogleServiceAuthError& error) { |
| + if (state_ == SERVICES_INITIALIZING) { |
| + // We got an error loading one of our tokens, so notify our observer. |
| + state_ = WAITING_FOR_GAIA_VALIDATION; |
| + observer_->SigninFailed(error); |
| } |
| } |
| @@ -121,15 +102,8 @@ void SigninTracker::HandleServiceStateChange() { |
| // static |
| bool SigninTracker::AreServiceTokensLoaded(Profile* profile) { |
| - // See if we have all of the tokens required. |
| - TokenService* token_service = TokenServiceFactory::GetForProfile(profile); |
| - for (int i = 0; i < kNumSignedInServices; ++i) { |
| - if (!token_service->HasTokenForService(kSignedInServices[i])) { |
| - // Don't have a token for one of our signed-in services. |
| - return false; |
| - } |
| - } |
| - return true; |
| + return ProfileOAuth2TokenServiceFactory::GetForProfile(profile)-> |
| + RefreshTokenIsAvailable(); |
| } |
| // static |