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

Side by Side Diff: google_apis/gaia/oauth2_access_token_fetcher_impl.cc

Issue 472403002: Prevent invalidating refresh token on transient errors. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix integration tests Created 6 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/sync/test/integration/sync_auth_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "google_apis/gaia/oauth2_access_token_fetcher_impl.h" 5 #include "google_apis/gaia/oauth2_access_token_fetcher_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 histogram_value); 176 histogram_value);
177 if (!status.is_success()) { 177 if (!status.is_success()) {
178 OnGetTokenFailure(CreateAuthError(status)); 178 OnGetTokenFailure(CreateAuthError(status));
179 return; 179 return;
180 } 180 }
181 181
182 switch (source->GetResponseCode()) { 182 switch (source->GetResponseCode()) {
183 case net::HTTP_OK: 183 case net::HTTP_OK:
184 break; 184 break;
185 case net::HTTP_FORBIDDEN: 185 case net::HTTP_FORBIDDEN:
186 case net::HTTP_INTERNAL_SERVER_ERROR:
187 // HTTP_FORBIDDEN (403) is treated as temporary error, because it may be 186 // HTTP_FORBIDDEN (403) is treated as temporary error, because it may be
188 // '403 Rate Limit Exeeded.' 500 is always treated as transient. 187 // '403 Rate Limit Exeeded.'
189 OnGetTokenFailure( 188 OnGetTokenFailure(
190 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); 189 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE));
191 return; 190 return;
192 case net::HTTP_BAD_REQUEST: { 191 case net::HTTP_BAD_REQUEST: {
193 // HTTP_BAD_REQUEST (400) usually contains error as per 192 // HTTP_BAD_REQUEST (400) usually contains error as per
194 // http://tools.ietf.org/html/rfc6749#section-5.2. 193 // http://tools.ietf.org/html/rfc6749#section-5.2.
195 std::string gaia_error; 194 std::string gaia_error;
196 if (!ParseGetAccessTokenFailureResponse(source, &gaia_error)) { 195 if (!ParseGetAccessTokenFailureResponse(source, &gaia_error)) {
197 OnGetTokenFailure( 196 OnGetTokenFailure(
198 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR)); 197 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR));
199 return; 198 return;
200 } 199 }
201 200
202 OAuth2ErrorCodesForHistogram access_error( 201 OAuth2ErrorCodesForHistogram access_error(
203 OAuth2ErrorToHistogramValue(gaia_error)); 202 OAuth2ErrorToHistogramValue(gaia_error));
204 UMA_HISTOGRAM_ENUMERATION("Gaia.BadRequestTypeForOAuth2AccessToken", 203 UMA_HISTOGRAM_ENUMERATION("Gaia.BadRequestTypeForOAuth2AccessToken",
205 access_error, 204 access_error,
206 OAUTH2_ACCESS_ERROR_COUNT); 205 OAUTH2_ACCESS_ERROR_COUNT);
207 206
208 OnGetTokenFailure( 207 OnGetTokenFailure(
209 access_error == OAUTH2_ACCESS_ERROR_INVALID_GRANT 208 access_error == OAUTH2_ACCESS_ERROR_INVALID_GRANT
210 ? GoogleServiceAuthError( 209 ? GoogleServiceAuthError(
211 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS) 210 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)
212 : GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR)); 211 : GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_ERROR));
213 return; 212 return;
214 } 213 }
215 default: 214 default: {
216 // The other errors are treated as permanent error. 215 if (source->GetResponseCode() >= net::HTTP_INTERNAL_SERVER_ERROR) {
217 OnGetTokenFailure(GoogleServiceAuthError( 216 // 5xx is always treated as transient.
218 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS)); 217 OnGetTokenFailure(GoogleServiceAuthError(
218 GoogleServiceAuthError::SERVICE_UNAVAILABLE));
219 } else {
220 // The other errors are treated as permanent error.
221 DLOG(ERROR) << "Unexpected persistent error: http_status="
222 << source->GetResponseCode();
223 OnGetTokenFailure(GoogleServiceAuthError(
224 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS));
225 }
219 return; 226 return;
227 }
220 } 228 }
221 229
222 // The request was successfully fetched and it returned OK. 230 // The request was successfully fetched and it returned OK.
223 // Parse out the access token and the expiration time. 231 // Parse out the access token and the expiration time.
224 std::string access_token; 232 std::string access_token;
225 int expires_in; 233 int expires_in;
226 if (!ParseGetAccessTokenSuccessResponse(source, &access_token, &expires_in)) { 234 if (!ParseGetAccessTokenSuccessResponse(source, &access_token, &expires_in)) {
227 DLOG(WARNING) << "Response doesn't match expected format"; 235 DLOG(WARNING) << "Response doesn't match expected format";
228 OnGetTokenFailure( 236 OnGetTokenFailure(
229 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE)); 237 GoogleServiceAuthError(GoogleServiceAuthError::SERVICE_UNAVAILABLE));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 // static 312 // static
305 bool OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse( 313 bool OAuth2AccessTokenFetcherImpl::ParseGetAccessTokenFailureResponse(
306 const net::URLFetcher* source, 314 const net::URLFetcher* source,
307 std::string* error) { 315 std::string* error) {
308 CHECK(error); 316 CHECK(error);
309 scoped_ptr<base::DictionaryValue> value = ParseGetAccessTokenResponse(source); 317 scoped_ptr<base::DictionaryValue> value = ParseGetAccessTokenResponse(source);
310 if (value.get() == NULL) 318 if (value.get() == NULL)
311 return false; 319 return false;
312 return value->GetString(kErrorKey, error); 320 return value->GetString(kErrorKey, error);
313 } 321 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/sync_auth_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698