Index: chrome/browser/sync/profile_sync_service.cc |
=================================================================== |
--- chrome/browser/sync/profile_sync_service.cc (revision 112357) |
+++ chrome/browser/sync/profile_sync_service.cc (working copy) |
@@ -84,7 +84,21 @@ |
static const int kSyncClearDataTimeoutInSeconds = 60; // 1 minute. |
+static const char* kRelevantTokenServices[] = { |
+ GaiaConstants::kSyncService, |
+ GaiaConstants::kGaiaOAuth2LoginRefreshToken}; |
+static const int kRelevantTokenServicesCount = |
+ arraysize(kRelevantTokenServices); |
+// Helper to check if the given token service is relevant for sync. |
+static bool IsTokenServiceRelevant(const std::string& service) { |
+ for (int i = 0; i < kRelevantTokenServicesCount; ++i) { |
+ if (service == kRelevantTokenServices[i]) |
+ return true; |
+ } |
+ return false; |
+} |
+ |
bool ShouldShowActionOnUI( |
const browser_sync::SyncProtocolError& error) { |
return (error.action != browser_sync::UNKNOWN_ACTION && |
@@ -141,18 +155,27 @@ |
} |
bool ProfileSyncService::AreCredentialsAvailable() { |
+ return AreCredentialsAvailable(false); |
+} |
+ |
+bool ProfileSyncService::AreCredentialsAvailable( |
+ bool check_oauth_login_token) { |
if (IsManaged()) { |
return false; |
} |
// CrOS user is always logged in. Chrome uses signin_ to check logged in. |
- if (!cros_user_.empty() || !signin_->GetUsername().empty()) { |
- // TODO(chron): Verify CrOS unit test behavior. |
- return profile()->GetTokenService() && |
- profile()->GetTokenService()->HasTokenForService( |
- browser_sync::SyncServiceName()); |
- } |
- return false; |
+ if (cros_user_.empty() && signin_->GetUsername().empty()) |
+ return false; |
+ |
+ TokenService* token_service = profile()->GetTokenService(); |
+ if (!token_service) |
+ return false; |
+ |
+ // TODO(chron): Verify CrOS unit test behavior. |
+ if (!token_service->HasTokenForService(browser_sync::SyncServiceName())) |
+ return false; |
+ return !check_oauth_login_token || token_service->HasOAuthLoginToken(); |
} |
void ProfileSyncService::Initialize() { |
@@ -1442,13 +1465,22 @@ |
break; |
} |
case chrome::NOTIFICATION_TOKEN_REQUEST_FAILED: { |
- GoogleServiceAuthError error( |
- GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
- UpdateAuthErrorState(error); |
+ TokenService::TokenRequestFailedDetails token_details = |
Andrew T Wilson (Slow)
2011/12/02 00:52:35
I'd change this to const TokenService::TokenReques
Munjal (Google)
2011/12/02 02:14:01
Done.
|
+ *(content::Details<const TokenService::TokenRequestFailedDetails>( |
+ details).ptr()); |
+ if (IsTokenServiceRelevant(token_details.service())) { |
+ GoogleServiceAuthError error( |
+ GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); |
+ UpdateAuthErrorState(error); |
+ } |
break; |
} |
case chrome::NOTIFICATION_TOKEN_AVAILABLE: { |
- if (AreCredentialsAvailable()) { |
+ TokenService::TokenAvailableDetails token_details = |
Andrew T Wilson (Slow)
2011/12/02 00:52:35
See previous comment.
Munjal (Google)
2011/12/02 02:14:01
Done.
|
+ *(content::Details<const TokenService::TokenAvailableDetails>( |
+ details).ptr()); |
+ if (IsTokenServiceRelevant(token_details.service()) && |
+ AreCredentialsAvailable(true)) { |
if (backend_initialized_) { |
backend_->UpdateCredentials(GetCredentials()); |
} |
@@ -1458,11 +1490,22 @@ |
break; |
} |
case chrome::NOTIFICATION_TOKEN_LOADING_FINISHED: { |
- // If not in Chrome OS, and we have a username without tokens, |
- // the user will need to signin again, so sign out. |
- if (cros_user_.empty() && |
- !signin_->GetUsername().empty() && |
- !AreCredentialsAvailable()) { |
+ // This notification gets fired when TokenService loads the tokens |
Andrew T Wilson (Slow)
2011/12/02 00:52:35
nit: double-space between "loads the".
Munjal (Google)
2011/12/02 02:14:01
Done.
|
+ // from storage. Here we only check if the chromiumsync token is |
+ // available (versus both chromiumsync and oauth login tokens) to |
+ // start up sync successfully for already logged in users who may |
+ // only have chromiumsync token if they logged in before the code |
+ // to generate oauth login token released. |
+ if (AreCredentialsAvailable()) { |
+ // Initialize the backend if sync token was loaded. |
+ if (backend_initialized_) { |
+ backend_->UpdateCredentials(GetCredentials()); |
+ } |
+ if (!sync_prefs_.IsStartSuppressed()) |
+ StartUp(); |
+ } else if (cros_user_.empty() && !signin_->GetUsername().empty()) { |
+ // If not in Chrome OS, and we have a username without tokens, |
+ // the user will need to signin again, so sign out. |
DisableForUser(); |
} |
break; |