| 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 "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 DCHECK(!request_.get()); | 121 DCHECK(!request_.get()); |
| 122 request_type_ = USER_INFO; | 122 request_type_ = USER_INFO; |
| 123 delegate_ = delegate; | 123 delegate_ = delegate; |
| 124 num_retries_ = 0; | 124 num_retries_ = 0; |
| 125 request_.reset(net::URLFetcher::Create( | 125 request_.reset(net::URLFetcher::Create( |
| 126 0, GURL(GaiaUrls::GetInstance()->oauth_user_info_url()), | 126 0, GURL(GaiaUrls::GetInstance()->oauth_user_info_url()), |
| 127 net::URLFetcher::GET, this)); | 127 net::URLFetcher::GET, this)); |
| 128 request_->SetRequestContext(request_context_getter_); | 128 request_->SetRequestContext(request_context_getter_); |
| 129 request_->AddExtraRequestHeader( | 129 request_->AddExtraRequestHeader( |
| 130 "Authorization: OAuth " + oauth_access_token); | 130 "Authorization: OAuth " + oauth_access_token); |
| 131 request_->SetMaxRetries(max_retries); | 131 request_->SetMaxRetriesOn5xx(max_retries); |
| 132 request_->Start(); | 132 request_->Start(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void GaiaOAuthClient::Core::MakeGaiaRequest( | 135 void GaiaOAuthClient::Core::MakeGaiaRequest( |
| 136 const std::string& post_body, | 136 const std::string& post_body, |
| 137 int max_retries, | 137 int max_retries, |
| 138 GaiaOAuthClient::Delegate* delegate) { | 138 GaiaOAuthClient::Delegate* delegate) { |
| 139 DCHECK(!request_.get()) << "Tried to fetch two things at once!"; | 139 DCHECK(!request_.get()) << "Tried to fetch two things at once!"; |
| 140 delegate_ = delegate; | 140 delegate_ = delegate; |
| 141 num_retries_ = 0; | 141 num_retries_ = 0; |
| 142 request_.reset(net::URLFetcher::Create( | 142 request_.reset(net::URLFetcher::Create( |
| 143 0, gaia_url_, net::URLFetcher::POST, this)); | 143 0, gaia_url_, net::URLFetcher::POST, this)); |
| 144 request_->SetRequestContext(request_context_getter_); | 144 request_->SetRequestContext(request_context_getter_); |
| 145 request_->SetUploadData("application/x-www-form-urlencoded", post_body); | 145 request_->SetUploadData("application/x-www-form-urlencoded", post_body); |
| 146 request_->SetMaxRetries(max_retries); | 146 request_->SetMaxRetriesOn5xx(max_retries); |
| 147 request_->Start(); | 147 request_->Start(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 // URLFetcher::Delegate implementation. | 150 // URLFetcher::Delegate implementation. |
| 151 void GaiaOAuthClient::Core::OnURLFetchComplete( | 151 void GaiaOAuthClient::Core::OnURLFetchComplete( |
| 152 const net::URLFetcher* source) { | 152 const net::URLFetcher* source) { |
| 153 bool should_retry = false; | 153 bool should_retry = false; |
| 154 HandleResponse(source, &should_retry); | 154 HandleResponse(source, &should_retry); |
| 155 if (should_retry) { | 155 if (should_retry) { |
| 156 // Explicitly call ReceivedContentWasMalformed() to ensure the current | 156 // Explicitly call ReceivedContentWasMalformed() to ensure the current |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 if (message_value.get() && | 188 if (message_value.get() && |
| 189 message_value->IsType(Value::TYPE_DICTIONARY)) { | 189 message_value->IsType(Value::TYPE_DICTIONARY)) { |
| 190 response_dict.reset( | 190 response_dict.reset( |
| 191 static_cast<DictionaryValue*>(message_value.release())); | 191 static_cast<DictionaryValue*>(message_value.release())); |
| 192 } | 192 } |
| 193 } | 193 } |
| 194 | 194 |
| 195 if (!response_dict.get()) { | 195 if (!response_dict.get()) { |
| 196 // If we don't have an access token yet and the the error was not | 196 // If we don't have an access token yet and the the error was not |
| 197 // RC_BAD_REQUEST, we may need to retry. | 197 // RC_BAD_REQUEST, we may need to retry. |
| 198 if ((source->GetMaxRetries() != -1) && | 198 if ((source->GetMaxRetriesOn5xx() != -1) && |
| 199 (num_retries_ > source->GetMaxRetries())) { | 199 (num_retries_ > source->GetMaxRetriesOn5xx())) { |
| 200 // Retry limit reached. Give up. | 200 // Retry limit reached. Give up. |
| 201 delegate_->OnNetworkError(source->GetResponseCode()); | 201 delegate_->OnNetworkError(source->GetResponseCode()); |
| 202 } else { | 202 } else { |
| 203 request_ = old_request.Pass(); | 203 request_ = old_request.Pass(); |
| 204 *should_retry_request = true; | 204 *should_retry_request = true; |
| 205 } | 205 } |
| 206 return; | 206 return; |
| 207 } | 207 } |
| 208 | 208 |
| 209 RequestType type = request_type_; | 209 RequestType type = request_type_; |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 delegate); | 275 delegate); |
| 276 } | 276 } |
| 277 | 277 |
| 278 void GaiaOAuthClient::GetUserInfo(const std::string& access_token, | 278 void GaiaOAuthClient::GetUserInfo(const std::string& access_token, |
| 279 int max_retries, | 279 int max_retries, |
| 280 Delegate* delegate) { | 280 Delegate* delegate) { |
| 281 return core_->GetUserInfo(access_token, max_retries, delegate); | 281 return core_->GetUserInfo(access_token, max_retries, delegate); |
| 282 } | 282 } |
| 283 | 283 |
| 284 } // namespace gaia | 284 } // namespace gaia |
| OLD | NEW |