| OLD | NEW |
| 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 "google_apis/gaia/gaia_oauth_client.h" | 5 #include "google_apis/gaia/gaia_oauth_client.h" |
| 6 | 6 |
| 7 #include <utility> |
| 8 |
| 7 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 11 #include "base/values.h" | 13 #include "base/values.h" |
| 12 #include "google_apis/gaia/gaia_urls.h" | 14 #include "google_apis/gaia/gaia_urls.h" |
| 13 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
| 14 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 15 #include "net/http/http_status_code.h" | 17 #include "net/http/http_status_code.h" |
| 16 #include "net/url_request/url_fetcher.h" | 18 #include "net/url_request/url_fetcher.h" |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 request_->Start(); | 245 request_->Start(); |
| 244 } | 246 } |
| 245 } | 247 } |
| 246 | 248 |
| 247 void GaiaOAuthClient::Core::HandleResponse( | 249 void GaiaOAuthClient::Core::HandleResponse( |
| 248 const net::URLFetcher* source, | 250 const net::URLFetcher* source, |
| 249 bool* should_retry_request) { | 251 bool* should_retry_request) { |
| 250 // Move ownership of the request fetcher into a local scoped_ptr which | 252 // Move ownership of the request fetcher into a local scoped_ptr which |
| 251 // will be nuked when we're done handling the request, unless we need | 253 // will be nuked when we're done handling the request, unless we need |
| 252 // to retry, in which case ownership will be returned to request_. | 254 // to retry, in which case ownership will be returned to request_. |
| 253 scoped_ptr<net::URLFetcher> old_request = request_.Pass(); | 255 scoped_ptr<net::URLFetcher> old_request = std::move(request_); |
| 254 DCHECK_EQ(source, old_request.get()); | 256 DCHECK_EQ(source, old_request.get()); |
| 255 | 257 |
| 256 // HTTP_BAD_REQUEST means the arguments are invalid. HTTP_UNAUTHORIZED means | 258 // HTTP_BAD_REQUEST means the arguments are invalid. HTTP_UNAUTHORIZED means |
| 257 // the access or refresh token is invalid. No point retrying. We are | 259 // the access or refresh token is invalid. No point retrying. We are |
| 258 // done here. | 260 // done here. |
| 259 int response_code = source->GetResponseCode(); | 261 int response_code = source->GetResponseCode(); |
| 260 if (response_code == net::HTTP_BAD_REQUEST || | 262 if (response_code == net::HTTP_BAD_REQUEST || |
| 261 response_code == net::HTTP_UNAUTHORIZED) { | 263 response_code == net::HTTP_UNAUTHORIZED) { |
| 262 delegate_->OnOAuthError(); | 264 delegate_->OnOAuthError(); |
| 263 return; | 265 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 276 } | 278 } |
| 277 | 279 |
| 278 if (!response_dict.get()) { | 280 if (!response_dict.get()) { |
| 279 // If we don't have an access token yet and the the error was not | 281 // If we don't have an access token yet and the the error was not |
| 280 // RC_BAD_REQUEST, we may need to retry. | 282 // RC_BAD_REQUEST, we may need to retry. |
| 281 if ((source->GetMaxRetriesOn5xx() != -1) && | 283 if ((source->GetMaxRetriesOn5xx() != -1) && |
| 282 (num_retries_ >= source->GetMaxRetriesOn5xx())) { | 284 (num_retries_ >= source->GetMaxRetriesOn5xx())) { |
| 283 // Retry limit reached. Give up. | 285 // Retry limit reached. Give up. |
| 284 delegate_->OnNetworkError(source->GetResponseCode()); | 286 delegate_->OnNetworkError(source->GetResponseCode()); |
| 285 } else { | 287 } else { |
| 286 request_ = old_request.Pass(); | 288 request_ = std::move(old_request); |
| 287 *should_retry_request = true; | 289 *should_retry_request = true; |
| 288 } | 290 } |
| 289 return; | 291 return; |
| 290 } | 292 } |
| 291 | 293 |
| 292 RequestType type = request_type_; | 294 RequestType type = request_type_; |
| 293 request_type_ = NO_PENDING_REQUEST; | 295 request_type_ = NO_PENDING_REQUEST; |
| 294 | 296 |
| 295 switch (type) { | 297 switch (type) { |
| 296 case USER_EMAIL: { | 298 case USER_EMAIL: { |
| 297 std::string email; | 299 std::string email; |
| 298 response_dict->GetString("email", &email); | 300 response_dict->GetString("email", &email); |
| 299 delegate_->OnGetUserEmailResponse(email); | 301 delegate_->OnGetUserEmailResponse(email); |
| 300 break; | 302 break; |
| 301 } | 303 } |
| 302 | 304 |
| 303 case USER_ID: { | 305 case USER_ID: { |
| 304 std::string id; | 306 std::string id; |
| 305 response_dict->GetString("id", &id); | 307 response_dict->GetString("id", &id); |
| 306 delegate_->OnGetUserIdResponse(id); | 308 delegate_->OnGetUserIdResponse(id); |
| 307 break; | 309 break; |
| 308 } | 310 } |
| 309 | 311 |
| 310 case USER_INFO: { | 312 case USER_INFO: { |
| 311 delegate_->OnGetUserInfoResponse(response_dict.Pass()); | 313 delegate_->OnGetUserInfoResponse(std::move(response_dict)); |
| 312 break; | 314 break; |
| 313 } | 315 } |
| 314 | 316 |
| 315 case TOKEN_INFO: { | 317 case TOKEN_INFO: { |
| 316 delegate_->OnGetTokenInfoResponse(response_dict.Pass()); | 318 delegate_->OnGetTokenInfoResponse(std::move(response_dict)); |
| 317 break; | 319 break; |
| 318 } | 320 } |
| 319 | 321 |
| 320 case TOKENS_FROM_AUTH_CODE: | 322 case TOKENS_FROM_AUTH_CODE: |
| 321 case REFRESH_TOKEN: { | 323 case REFRESH_TOKEN: { |
| 322 std::string access_token; | 324 std::string access_token; |
| 323 std::string refresh_token; | 325 std::string refresh_token; |
| 324 int expires_in_seconds = 0; | 326 int expires_in_seconds = 0; |
| 325 response_dict->GetString(kAccessTokenValue, &access_token); | 327 response_dict->GetString(kAccessTokenValue, &access_token); |
| 326 response_dict->GetString(kRefreshTokenValue, &refresh_token); | 328 response_dict->GetString(kRefreshTokenValue, &refresh_token); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 } | 405 } |
| 404 | 406 |
| 405 void GaiaOAuthClient::GetTokenHandleInfo(const std::string& token_handle, | 407 void GaiaOAuthClient::GetTokenHandleInfo(const std::string& token_handle, |
| 406 int max_retries, | 408 int max_retries, |
| 407 Delegate* delegate) { | 409 Delegate* delegate) { |
| 408 return core_->GetTokenInfo("token_handle", token_handle, max_retries, | 410 return core_->GetTokenInfo("token_handle", token_handle, max_retries, |
| 409 delegate); | 411 delegate); |
| 410 } | 412 } |
| 411 | 413 |
| 412 } // namespace gaia | 414 } // namespace gaia |
| OLD | NEW |