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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 62423002: Fix one case that can make sync backend stuck in auth error state. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 // be there. 636 // be there.
637 InitializeBackend(!HasSyncSetupCompleted()); 637 InitializeBackend(!HasSyncSetupCompleted());
638 } 638 }
639 639
640 void ProfileSyncService::OnGetTokenSuccess( 640 void ProfileSyncService::OnGetTokenSuccess(
641 const OAuth2TokenService::Request* request, 641 const OAuth2TokenService::Request* request,
642 const std::string& access_token, 642 const std::string& access_token,
643 const base::Time& expiration_time) { 643 const base::Time& expiration_time) {
644 DCHECK_EQ(access_token_request_, request); 644 DCHECK_EQ(access_token_request_, request);
645 access_token_request_.reset(); 645 access_token_request_.reset();
646 // Reset backoff time after successful response.
647 request_access_token_backoff_.Reset();
648 access_token_ = access_token; 646 access_token_ = access_token;
649 if (backend_) 647 if (backend_)
650 backend_->UpdateCredentials(GetCredentials()); 648 backend_->UpdateCredentials(GetCredentials());
651 else 649 else
652 TryStart(); 650 TryStart();
653 } 651 }
654 652
655 void ProfileSyncService::OnGetTokenFailure( 653 void ProfileSyncService::OnGetTokenFailure(
656 const OAuth2TokenService::Request* request, 654 const OAuth2TokenService::Request* request,
657 const GoogleServiceAuthError& error) { 655 const GoogleServiceAuthError& error) {
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1104 } 1102 }
1105 1103
1106 } // namespace 1104 } // namespace
1107 1105
1108 void ProfileSyncService::OnConnectionStatusChange( 1106 void ProfileSyncService::OnConnectionStatusChange(
1109 syncer::ConnectionStatus status) { 1107 syncer::ConnectionStatus status) {
1110 if (status == syncer::CONNECTION_AUTH_ERROR) { 1108 if (status == syncer::CONNECTION_AUTH_ERROR) {
1111 // Sync server returned error indicating that access token is invalid. It 1109 // Sync server returned error indicating that access token is invalid. It
1112 // could be either expired or access is revoked. Let's request another 1110 // could be either expired or access is revoked. Let's request another
1113 // access token and if access is revoked then request for token will fail 1111 // access token and if access is revoked then request for token will fail
1114 // with corresponding error. 1112 // with corresponding error. If access token is repeatedly reported
1115 RequestAccessToken(); 1113 // invalid, there may be some issues with token server, e.g. authentication
1114 // server is inconsistent with token issue server. In that case, we
1115 // backoff token requests exponentially to avoid hammering token server
1116 // too much and to avoid getting same token due to token server's caching
1117 // policy. |request_access_token_retry_timer_| is used to backoff request
1118 // triggered by both auth error and failure talking to GAIA server.
1119 // Therefore, we're likely to reach the backoff ceiling more quickly than
1120 // you would expect from looking at the BackoffPolicy if both types of
1121 // errors happen. We shouldn't receive two errors back-to-back without
1122 // attempting a token/sync request in between, thus crank up request delay
1123 // unnecessary. This is because we won't make a sync request if we hit an
1124 // error until GAIA succeeds at sending a new token, and we won't request
1125 // a new token unless sync reports a token failure. But to be safe, don't
1126 // schedule request if this happens.
1127 if (request_access_token_retry_timer_.IsRunning()) {
1128 NOTREACHED();
1129 } else if (request_access_token_backoff_.failure_count() == 0) {
1130 // First time request without delay. Currently invalid token is used
1131 // to initialize sync backend and we'll always end up here. We don't
1132 // want to delay initialization.
1133 request_access_token_backoff_.InformOfRequest(false);
1134 RequestAccessToken();
1135 } else {
1136 request_access_token_backoff_.InformOfRequest(false);
1137 request_access_token_retry_timer_.Start(
1138 FROM_HERE,
1139 request_access_token_backoff_.GetTimeUntilRelease(),
1140 base::Bind(&ProfileSyncService::RequestAccessToken,
1141 weak_factory_.GetWeakPtr()));
1142 }
1116 } else { 1143 } else {
1144 // Reset backoff time after successful connection.
1145 if (status == syncer::CONNECTION_OK) {
1146 // Request shouldn't be scheduled at this time. But if it is, it's
1147 // possible that sync flips between OK and auth error states rapidly,
1148 // thus hammers token server. To be safe, only reset backoff delay when
1149 // no scheduled request.
1150 if (request_access_token_retry_timer_.IsRunning()) {
1151 NOTREACHED();
1152 } else {
1153 request_access_token_backoff_.Reset();
1154 }
1155 }
1156
1117 const GoogleServiceAuthError auth_error = 1157 const GoogleServiceAuthError auth_error =
1118 ConnectionStatusToAuthError(status); 1158 ConnectionStatusToAuthError(status);
1119 DVLOG(1) << "Connection status change: " << auth_error.ToString(); 1159 DVLOG(1) << "Connection status change: " << auth_error.ToString();
1120 UpdateAuthErrorState(auth_error); 1160 UpdateAuthErrorState(auth_error);
1121 } 1161 }
1122 } 1162 }
1123 1163
1124 void ProfileSyncService::OnStopSyncingPermanently() { 1164 void ProfileSyncService::OnStopSyncingPermanently() {
1125 sync_prefs_.SetStartSuppressed(true); 1165 sync_prefs_.SetStartSuppressed(true);
1126 DisableForUser(); 1166 DisableForUser();
(...skipping 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after
2134 NOTREACHED(); 2174 NOTREACHED();
2135 #endif 2175 #endif
2136 } 2176 }
2137 2177
2138 return signin_->GetAuthenticatedUsername(); 2178 return signin_->GetAuthenticatedUsername();
2139 } 2179 }
2140 2180
2141 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() { 2181 WeakHandle<syncer::JsEventHandler> ProfileSyncService::GetJsEventHandler() {
2142 return MakeWeakHandle(sync_js_controller_.AsWeakPtr()); 2182 return MakeWeakHandle(sync_js_controller_.AsWeakPtr());
2143 } 2183 }
OLDNEW
« no previous file with comments | « no previous file | sync/engine/net/server_connection_manager.cc » ('j') | sync/engine/net/server_connection_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698