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

Unified Diff: chrome/browser/signin/signin_tracker.cc

Issue 19567004: Convert SigninTracker to use OAuth2TokenService notifications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Filip's review comments Created 7 years, 4 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/signin/signin_tracker.cc
diff --git a/chrome/browser/signin/signin_tracker.cc b/chrome/browser/signin/signin_tracker.cc
index b356efb3318b90e24204555a7b26b0e9a9232e4d..850aa9042bda3dc531d75932d5a955921a21ce7f 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();
}
SigninTracker::~SigninTracker() {
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile_)->
+ RemoveObserver(this);
}
void SigninTracker::Initialize() {
@@ -42,16 +37,10 @@ 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();
+ OAuth2TokenService* token_service =
+ ProfileOAuth2TokenServiceFactory::GetForProfile(profile_);
+ token_service->AddObserver(this);
}
void SigninTracker::Observe(int type,
@@ -73,27 +62,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) {
+ if (state_ == SERVICES_INITIALIZING) {
+ // We got an error loading one of our tokens, so notify our observer.
+ state_ = WAITING_FOR_GAIA_VALIDATION;
+ observer_->SigninFailed(
+ GoogleServiceAuthError(GoogleServiceAuthError::REQUEST_CANCELED));
}
}
@@ -121,15 +104,10 @@ 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;
+ // SigninTracker only tracks the primary account, so only need to check
+ // that one.
+ return ProfileOAuth2TokenServiceFactory::GetForProfile(profile)->
+ RefreshTokenIsAvailable();
}
// static

Powered by Google App Engine
This is Rietveld 408576698