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

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

Issue 9956097: suppress user/password dialog when re-enabling sync (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve Drew's comments. Created 8 years, 9 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 ec2e02334dc1a553618565f005b94a77f6d7beaa..be8436618236fa42aa15de812c6f32bf40b0ea4f 100644
--- a/chrome/browser/signin/signin_tracker.cc
+++ b/chrome/browser/signin/signin_tracker.cc
@@ -27,6 +27,26 @@ SigninTracker::SigninTracker(Profile* profile, Observer* observer)
profile_(profile),
observer_(observer),
credentials_valid_(false) {
+ Initialize();
+}
+
+SigninTracker::SigninTracker(Profile* profile,
+ Observer* observer,
+ LoginState state)
+ : state_(state),
+ profile_(profile),
+ observer_(observer),
+ credentials_valid_(false) {
+ Initialize();
+}
+
+SigninTracker::~SigninTracker() {
+ ProfileSyncService* service =
+ ProfileSyncServiceFactory::GetForProfile(profile_);
+ service->RemoveObserver(this);
+}
+
+void SigninTracker::Initialize() {
DCHECK(observer_);
// Register for notifications from the SigninManager.
registrar_.Add(this,
@@ -48,12 +68,9 @@ SigninTracker::SigninTracker(Profile* profile, Observer* observer)
ProfileSyncService* service =
ProfileSyncServiceFactory::GetForProfile(profile_);
service->AddObserver(this);
-}
-SigninTracker::~SigninTracker() {
- ProfileSyncService* service =
- ProfileSyncServiceFactory::GetForProfile(profile_);
- service->RemoveObserver(this);
+ if (state_ == SERVICES_INITIALIZING)
+ HandleServiceStateChange();
}
void SigninTracker::Observe(int type,
@@ -62,6 +79,7 @@ void SigninTracker::Observe(int type,
// We should not get more than one of these notifications.
switch (type) {
case chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL:
+ LOG(WARNING) << "Got NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL";
DCHECK_EQ(state_, WAITING_FOR_GAIA_VALIDATION);
state_ = SERVICES_INITIALIZING;
observer_->GaiaCredentialsValid();
@@ -71,6 +89,7 @@ void SigninTracker::Observe(int type,
HandleServiceStateChange();
break;
case chrome::NOTIFICATION_GOOGLE_SIGNIN_FAILED: {
+ LOG(WARNING) << "Got NOTIFICATION_GOOGLE_SIGNIN_FAILED";
DCHECK_EQ(state_, WAITING_FOR_GAIA_VALIDATION);
const GoogleServiceAuthError& error =
*(content::Details<const GoogleServiceAuthError>(details).ptr());
@@ -78,10 +97,12 @@ void SigninTracker::Observe(int type,
break;
}
case chrome::NOTIFICATION_TOKEN_AVAILABLE:
+ LOG(WARNING) << "Got 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:
+ LOG(WARNING) << "Got NOTIFICATION_TOKEN_REQUEST_FAILED";
if (state_ == SERVICES_INITIALIZING) {
const TokenService::TokenRequestFailedDetails& token_details =
*(content::Details<const TokenService::TokenRequestFailedDetails>(
@@ -90,6 +111,7 @@ void SigninTracker::Observe(int type,
if (token_details.service() == kSignedInServices[i]) {
// We got an error loading one of our tokens, so notify our
// observer.
+ LOG(WARNING) << "resetting state_ to WAITING_FOR_GAIA_VALIDATION";
state_ = WAITING_FOR_GAIA_VALIDATION;
observer_->SigninFailed(token_details.error());
}
@@ -108,6 +130,8 @@ void SigninTracker::OnStateChanged() {
void SigninTracker::HandleServiceStateChange() {
if (state_ != SERVICES_INITIALIZING) {
+ LOG(WARNING) << "HandleServiceStateChange: state!=SERVICES_INITIALIZING"
+ << (int)state_;
// Ignore service updates until after our GAIA credentials are validated.
return;
}
@@ -120,6 +144,7 @@ void SigninTracker::HandleServiceStateChange() {
ProfileSyncService* service =
ProfileSyncServiceFactory::GetForProfile(profile_);
if (service->waiting_for_auth()) {
+ LOG(WARNING) << "HandleServiceStateChange: service is waiting for auth";
// Still waiting for an auth token to come in so stay in the INITIALIZING
// state (we do this to avoid triggering an early signin error in the case
// where there's a previous auth error in the sync service that hasn't
@@ -129,12 +154,16 @@ void SigninTracker::HandleServiceStateChange() {
// If we haven't loaded all our service tokens yet, just exit (we'll be called
// again when another token is loaded, or will transition to SigninFailed if
// the loading fails).
- if (!AreServiceTokensLoaded(profile_))
+ if (!AreServiceTokensLoaded(profile_)) {
+ LOG(WARNING) << "HandleServiceStateChange: ServiceToken not loaded";
return;
+ }
if (!AreServicesSignedIn(profile_)) {
+ LOG(WARNING) << "HandleServiceStateChange: not signed in to services";
state_ = WAITING_FOR_GAIA_VALIDATION;
observer_->SigninFailed(service->GetAuthError());
} else if (service->sync_initialized()) {
+ LOG(WARNING) << "HandleServiceStateChange: sign in complete!";
state_ = SIGNIN_COMPLETE;
observer_->SigninSuccess();
}
@@ -146,6 +175,8 @@ bool SigninTracker::AreServiceTokensLoaded(Profile* profile) {
TokenService* token_service = TokenServiceFactory::GetForProfile(profile);
for (int i = 0; i < kNumSignedInServices; ++i) {
if (!token_service->HasTokenForService(kSignedInServices[i])) {
+ LOG(WARNING) << "Token not available for service "
+ << kSignedInServices[i];
// Don't have a token for one of our signed-in services.
return false;
}
@@ -159,8 +190,13 @@ bool SigninTracker::AreServicesSignedIn(Profile* profile) {
return false;
ProfileSyncService* service =
ProfileSyncServiceFactory::GetForProfile(profile);
+ LOG(WARNING) << "AreServicesSignedIn: AreCredentialsAvailable() : "
+ << (service->AreCredentialsAvailable() ? "YES" : "NO");
+ LOG(WARNING) << "AreServicesSignedIn: GetAuthError() : "
+ << (int)service->GetAuthError().state();
+ LOG(WARNING) << "AreServicesSignedIn: unrecoverable error? : "
+ << (service->unrecoverable_error_detected() ? "YES" : "NO");
return (service->AreCredentialsAvailable() &&
service->GetAuthError().state() == GoogleServiceAuthError::NONE &&
!service->unrecoverable_error_detected());
}
-

Powered by Google App Engine
This is Rietveld 408576698