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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "google_apis/gaia/gaia_urls.h" | 12 #include "google_apis/gaia/gaia_urls.h" |
13 #include "net/base/escape.h" | 13 #include "net/base/escape.h" |
| 14 #include "net/base/load_flags.h" |
14 #include "net/http/http_status_code.h" | 15 #include "net/http/http_status_code.h" |
15 #include "net/url_request/url_fetcher.h" | 16 #include "net/url_request/url_fetcher.h" |
16 #include "net/url_request/url_fetcher_delegate.h" | 17 #include "net/url_request/url_fetcher_delegate.h" |
17 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 const char kAccessTokenValue[] = "access_token"; | 22 const char kAccessTokenValue[] = "access_token"; |
22 const char kRefreshTokenValue[] = "refresh_token"; | 23 const char kRefreshTokenValue[] = "refresh_token"; |
23 const char kExpiresInValue[] = "expires_in"; | 24 const char kExpiresInValue[] = "expires_in"; |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 int max_retries, | 161 int max_retries, |
161 Delegate* delegate) { | 162 Delegate* delegate) { |
162 delegate_ = delegate; | 163 delegate_ = delegate; |
163 num_retries_ = 0; | 164 num_retries_ = 0; |
164 request_.reset(net::URLFetcher::Create( | 165 request_.reset(net::URLFetcher::Create( |
165 kUrlFetcherId, GURL(GaiaUrls::GetInstance()->oauth_user_info_url()), | 166 kUrlFetcherId, GURL(GaiaUrls::GetInstance()->oauth_user_info_url()), |
166 net::URLFetcher::GET, this)); | 167 net::URLFetcher::GET, this)); |
167 request_->SetRequestContext(request_context_getter_.get()); | 168 request_->SetRequestContext(request_context_getter_.get()); |
168 request_->AddExtraRequestHeader("Authorization: OAuth " + oauth_access_token); | 169 request_->AddExtraRequestHeader("Authorization: OAuth " + oauth_access_token); |
169 request_->SetMaxRetriesOn5xx(max_retries); | 170 request_->SetMaxRetriesOn5xx(max_retries); |
| 171 request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 172 net::LOAD_DO_NOT_SAVE_COOKIES); |
| 173 |
170 // Fetchers are sometimes cancelled because a network change was detected, | 174 // Fetchers are sometimes cancelled because a network change was detected, |
171 // especially at startup and after sign-in on ChromeOS. Retrying once should | 175 // especially at startup and after sign-in on ChromeOS. Retrying once should |
172 // be enough in those cases; let the fetcher retry up to 3 times just in case. | 176 // be enough in those cases; let the fetcher retry up to 3 times just in case. |
173 // http://crbug.com/163710 | 177 // http://crbug.com/163710 |
174 request_->SetAutomaticallyRetryOnNetworkChanges(3); | 178 request_->SetAutomaticallyRetryOnNetworkChanges(3); |
175 request_->Start(); | 179 request_->Start(); |
176 } | 180 } |
177 | 181 |
178 void GaiaOAuthClient::Core::GetTokenInfo(const std::string& oauth_access_token, | 182 void GaiaOAuthClient::Core::GetTokenInfo(const std::string& oauth_access_token, |
179 int max_retries, | 183 int max_retries, |
(...skipping 15 matching lines...) Expand all Loading... |
195 int max_retries, | 199 int max_retries, |
196 GaiaOAuthClient::Delegate* delegate) { | 200 GaiaOAuthClient::Delegate* delegate) { |
197 DCHECK(!request_.get()) << "Tried to fetch two things at once!"; | 201 DCHECK(!request_.get()) << "Tried to fetch two things at once!"; |
198 delegate_ = delegate; | 202 delegate_ = delegate; |
199 num_retries_ = 0; | 203 num_retries_ = 0; |
200 request_.reset(net::URLFetcher::Create( | 204 request_.reset(net::URLFetcher::Create( |
201 kUrlFetcherId, url, net::URLFetcher::POST, this)); | 205 kUrlFetcherId, url, net::URLFetcher::POST, this)); |
202 request_->SetRequestContext(request_context_getter_.get()); | 206 request_->SetRequestContext(request_context_getter_.get()); |
203 request_->SetUploadData("application/x-www-form-urlencoded", post_body); | 207 request_->SetUploadData("application/x-www-form-urlencoded", post_body); |
204 request_->SetMaxRetriesOn5xx(max_retries); | 208 request_->SetMaxRetriesOn5xx(max_retries); |
| 209 request_->SetLoadFlags(net::LOAD_DO_NOT_SEND_COOKIES | |
| 210 net::LOAD_DO_NOT_SAVE_COOKIES); |
205 // See comment on SetAutomaticallyRetryOnNetworkChanges() above. | 211 // See comment on SetAutomaticallyRetryOnNetworkChanges() above. |
206 request_->SetAutomaticallyRetryOnNetworkChanges(3); | 212 request_->SetAutomaticallyRetryOnNetworkChanges(3); |
207 request_->Start(); | 213 request_->Start(); |
208 } | 214 } |
209 | 215 |
210 // URLFetcher::Delegate implementation. | 216 // URLFetcher::Delegate implementation. |
211 void GaiaOAuthClient::Core::OnURLFetchComplete( | 217 void GaiaOAuthClient::Core::OnURLFetchComplete( |
212 const net::URLFetcher* source) { | 218 const net::URLFetcher* source) { |
213 bool should_retry = false; | 219 bool should_retry = false; |
214 HandleResponse(source, &should_retry); | 220 HandleResponse(source, &should_retry); |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 return core_->GetUserId(access_token, max_retries, delegate); | 369 return core_->GetUserId(access_token, max_retries, delegate); |
364 } | 370 } |
365 | 371 |
366 void GaiaOAuthClient::GetTokenInfo(const std::string& access_token, | 372 void GaiaOAuthClient::GetTokenInfo(const std::string& access_token, |
367 int max_retries, | 373 int max_retries, |
368 Delegate* delegate) { | 374 Delegate* delegate) { |
369 return core_->GetTokenInfo(access_token, max_retries, delegate); | 375 return core_->GetTokenInfo(access_token, max_retries, delegate); |
370 } | 376 } |
371 | 377 |
372 } // namespace gaia | 378 } // namespace gaia |
OLD | NEW |