| 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 "chrome/common/net/gaia/gaia_oauth_client.h" | 5 #include "chrome/common/net/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" |
| 11 #include "content/public/common/content_url_request_user_data.h" |
| 11 #include "content/public/common/url_fetcher.h" | 12 #include "content/public/common/url_fetcher.h" |
| 12 #include "content/public/common/url_fetcher_delegate.h" | 13 #include "content/public/common/url_fetcher_delegate.h" |
| 13 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
| 14 #include "net/base/escape.h" | 15 #include "net/base/escape.h" |
| 15 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
| 16 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 const char kAccessTokenValue[] = "access_token"; | 20 const char kAccessTokenValue[] = "access_token"; |
| 20 const char kRefreshTokenValue[] = "refresh_token"; | 21 const char kRefreshTokenValue[] = "refresh_token"; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 void GaiaOAuthClient::Core::MakeGaiaRequest( | 96 void GaiaOAuthClient::Core::MakeGaiaRequest( |
| 96 std::string post_body, | 97 std::string post_body, |
| 97 int max_retries, | 98 int max_retries, |
| 98 GaiaOAuthClient::Delegate* delegate) { | 99 GaiaOAuthClient::Delegate* delegate) { |
| 99 DCHECK(!request_.get()) << "Tried to fetch two things at once!"; | 100 DCHECK(!request_.get()) << "Tried to fetch two things at once!"; |
| 100 delegate_ = delegate; | 101 delegate_ = delegate; |
| 101 num_retries_ = 0; | 102 num_retries_ = 0; |
| 102 request_.reset(content::URLFetcher::Create( | 103 request_.reset(content::URLFetcher::Create( |
| 103 0, gaia_url_, content::URLFetcher::POST, this)); | 104 0, gaia_url_, content::URLFetcher::POST, this)); |
| 104 request_->SetRequestContext(request_context_getter_); | 105 request_->SetRequestContext(request_context_getter_); |
| 106 // TODO(jochen): Do cookie audit. |
| 107 request_->SetContentURLRequestUserData( |
| 108 new content::ContentURLRequestUserData()); |
| 105 request_->SetUploadData("application/x-www-form-urlencoded", post_body); | 109 request_->SetUploadData("application/x-www-form-urlencoded", post_body); |
| 106 request_->SetMaxRetries(max_retries); | 110 request_->SetMaxRetries(max_retries); |
| 107 request_->Start(); | 111 request_->Start(); |
| 108 } | 112 } |
| 109 | 113 |
| 110 // URLFetcher::Delegate implementation. | 114 // URLFetcher::Delegate implementation. |
| 111 void GaiaOAuthClient::Core::OnURLFetchComplete( | 115 void GaiaOAuthClient::Core::OnURLFetchComplete( |
| 112 const content::URLFetcher* source) { | 116 const content::URLFetcher* source) { |
| 113 bool should_retry = false; | 117 bool should_retry = false; |
| 114 HandleResponse(source, &should_retry); | 118 HandleResponse(source, &should_retry); |
| 115 if (should_retry) { | 119 if (should_retry) { |
| 116 // Explicitly call ReceivedContentWasMalformed() to ensure the current | 120 // Explicitly call ReceivedContentWasMalformed() to ensure the current |
| 117 // request gets counted as a failure for calculation of the back-off | 121 // request gets counted as a failure for calculation of the back-off |
| 118 // period. If it was already a failure by status code, this call will | 122 // period. If it was already a failure by status code, this call will |
| 119 // be ignored. | 123 // be ignored. |
| 120 request_->ReceivedContentWasMalformed(); | 124 request_->ReceivedContentWasMalformed(); |
| 121 num_retries_++; | 125 num_retries_++; |
| 122 // We must set our request_context_getter_ again because | 126 // We must set our request_context_getter_ again because |
| 123 // URLFetcher::Core::RetryOrCompleteUrlFetch resets it to NULL... | 127 // URLFetcher::Core::RetryOrCompleteUrlFetch resets it to NULL... |
| 124 request_->SetRequestContext(request_context_getter_); | 128 request_->SetRequestContext(request_context_getter_); |
| 129 // TODO(jochen): Do cookie audit. |
| 130 request_->SetContentURLRequestUserData( |
| 131 new content::ContentURLRequestUserData()); |
| 125 request_->Start(); | 132 request_->Start(); |
| 126 } else { | 133 } else { |
| 127 request_.reset(); | 134 request_.reset(); |
| 128 } | 135 } |
| 129 } | 136 } |
| 130 | 137 |
| 131 void GaiaOAuthClient::Core::HandleResponse( | 138 void GaiaOAuthClient::Core::HandleResponse( |
| 132 const content::URLFetcher* source, | 139 const content::URLFetcher* source, |
| 133 bool* should_retry_request) { | 140 bool* should_retry_request) { |
| 134 *should_retry_request = false; | 141 *should_retry_request = false; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 const std::string& refresh_token, | 205 const std::string& refresh_token, |
| 199 int max_retries, | 206 int max_retries, |
| 200 Delegate* delegate) { | 207 Delegate* delegate) { |
| 201 return core_->RefreshToken(oauth_client_info, | 208 return core_->RefreshToken(oauth_client_info, |
| 202 refresh_token, | 209 refresh_token, |
| 203 max_retries, | 210 max_retries, |
| 204 delegate); | 211 delegate); |
| 205 } | 212 } |
| 206 | 213 |
| 207 } // namespace gaia | 214 } // namespace gaia |
| OLD | NEW |