| 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 <memory> |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "google_apis/gaia/gaia_urls.h" | 14 #include "google_apis/gaia/gaia_urls.h" |
| 15 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
| 16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 17 #include "net/http/http_status_code.h" | 17 #include "net/http/http_status_code.h" |
| 18 #include "net/url_request/url_fetcher.h" | 18 #include "net/url_request/url_fetcher.h" |
| 19 #include "net/url_request/url_fetcher_delegate.h" | 19 #include "net/url_request/url_fetcher_delegate.h" |
| 20 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 21 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 void MakeGaiaRequest(const GURL& url, | 91 void MakeGaiaRequest(const GURL& url, |
| 92 const std::string& post_body, | 92 const std::string& post_body, |
| 93 int max_retries, | 93 int max_retries, |
| 94 GaiaOAuthClient::Delegate* delegate); | 94 GaiaOAuthClient::Delegate* delegate); |
| 95 void HandleResponse(const net::URLFetcher* source, | 95 void HandleResponse(const net::URLFetcher* source, |
| 96 bool* should_retry_request); | 96 bool* should_retry_request); |
| 97 | 97 |
| 98 int num_retries_; | 98 int num_retries_; |
| 99 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 99 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 100 GaiaOAuthClient::Delegate* delegate_; | 100 GaiaOAuthClient::Delegate* delegate_; |
| 101 scoped_ptr<net::URLFetcher> request_; | 101 std::unique_ptr<net::URLFetcher> request_; |
| 102 RequestType request_type_; | 102 RequestType request_type_; |
| 103 }; | 103 }; |
| 104 | 104 |
| 105 void GaiaOAuthClient::Core::GetTokensFromAuthCode( | 105 void GaiaOAuthClient::Core::GetTokensFromAuthCode( |
| 106 const OAuthClientInfo& oauth_client_info, | 106 const OAuthClientInfo& oauth_client_info, |
| 107 const std::string& auth_code, | 107 const std::string& auth_code, |
| 108 int max_retries, | 108 int max_retries, |
| 109 GaiaOAuthClient::Delegate* delegate) { | 109 GaiaOAuthClient::Delegate* delegate) { |
| 110 DCHECK_EQ(request_type_, NO_PENDING_REQUEST); | 110 DCHECK_EQ(request_type_, NO_PENDING_REQUEST); |
| 111 request_type_ = TOKENS_FROM_AUTH_CODE; | 111 request_type_ = TOKENS_FROM_AUTH_CODE; |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 request_->Start(); | 245 request_->Start(); |
| 246 } | 246 } |
| 247 } | 247 } |
| 248 | 248 |
| 249 void GaiaOAuthClient::Core::HandleResponse( | 249 void GaiaOAuthClient::Core::HandleResponse( |
| 250 const net::URLFetcher* source, | 250 const net::URLFetcher* source, |
| 251 bool* should_retry_request) { | 251 bool* should_retry_request) { |
| 252 // 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 |
| 253 // 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 |
| 254 // to retry, in which case ownership will be returned to request_. | 254 // to retry, in which case ownership will be returned to request_. |
| 255 scoped_ptr<net::URLFetcher> old_request = std::move(request_); | 255 std::unique_ptr<net::URLFetcher> old_request = std::move(request_); |
| 256 DCHECK_EQ(source, old_request.get()); | 256 DCHECK_EQ(source, old_request.get()); |
| 257 | 257 |
| 258 // HTTP_BAD_REQUEST means the arguments are invalid. HTTP_UNAUTHORIZED means | 258 // HTTP_BAD_REQUEST means the arguments are invalid. HTTP_UNAUTHORIZED means |
| 259 // 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 |
| 260 // done here. | 260 // done here. |
| 261 int response_code = source->GetResponseCode(); | 261 int response_code = source->GetResponseCode(); |
| 262 if (response_code == net::HTTP_BAD_REQUEST || | 262 if (response_code == net::HTTP_BAD_REQUEST || |
| 263 response_code == net::HTTP_UNAUTHORIZED) { | 263 response_code == net::HTTP_UNAUTHORIZED) { |
| 264 delegate_->OnOAuthError(); | 264 delegate_->OnOAuthError(); |
| 265 return; | 265 return; |
| 266 } | 266 } |
| 267 | 267 |
| 268 scoped_ptr<base::DictionaryValue> response_dict; | 268 std::unique_ptr<base::DictionaryValue> response_dict; |
| 269 if (source->GetResponseCode() == net::HTTP_OK) { | 269 if (source->GetResponseCode() == net::HTTP_OK) { |
| 270 std::string data; | 270 std::string data; |
| 271 source->GetResponseAsString(&data); | 271 source->GetResponseAsString(&data); |
| 272 scoped_ptr<base::Value> message_value = base::JSONReader::Read(data); | 272 std::unique_ptr<base::Value> message_value = base::JSONReader::Read(data); |
| 273 if (message_value.get() && | 273 if (message_value.get() && |
| 274 message_value->IsType(base::Value::TYPE_DICTIONARY)) { | 274 message_value->IsType(base::Value::TYPE_DICTIONARY)) { |
| 275 response_dict.reset( | 275 response_dict.reset( |
| 276 static_cast<base::DictionaryValue*>(message_value.release())); | 276 static_cast<base::DictionaryValue*>(message_value.release())); |
| 277 } | 277 } |
| 278 } | 278 } |
| 279 | 279 |
| 280 if (!response_dict.get()) { | 280 if (!response_dict.get()) { |
| 281 // 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 |
| 282 // RC_BAD_REQUEST, we may need to retry. | 282 // RC_BAD_REQUEST, we may need to retry. |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 } | 405 } |
| 406 | 406 |
| 407 void GaiaOAuthClient::GetTokenHandleInfo(const std::string& token_handle, | 407 void GaiaOAuthClient::GetTokenHandleInfo(const std::string& token_handle, |
| 408 int max_retries, | 408 int max_retries, |
| 409 Delegate* delegate) { | 409 Delegate* delegate) { |
| 410 return core_->GetTokenInfo("token_handle", token_handle, max_retries, | 410 return core_->GetTokenInfo("token_handle", token_handle, max_retries, |
| 411 delegate); | 411 delegate); |
| 412 } | 412 } |
| 413 | 413 |
| 414 } // namespace gaia | 414 } // namespace gaia |
| OLD | NEW |