Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: google_apis/gaia/gaia_oauth_client.cc

Issue 11572044: Automatically retry the following URLFetchers when the network changes: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Document the retry behavior Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/policy/device_management_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_->SetMaxRetriesOn5xx(max_retries); 131 request_->SetMaxRetriesOn5xx(max_retries);
132 // Fetchers are sometimes cancelled because a network change was detected,
133 // especially at startup and after sign-in on ChromeOS. Retrying once should
134 // be enough in those cases; let the fetcher retry up to 3 times just in case.
135 // http://crbug.com/163710
136 request_->SetAutomaticallyRetryOnNetworkChanges(3);
132 request_->Start(); 137 request_->Start();
133 } 138 }
134 139
135 void GaiaOAuthClient::Core::MakeGaiaRequest( 140 void GaiaOAuthClient::Core::MakeGaiaRequest(
136 const std::string& post_body, 141 const std::string& post_body,
137 int max_retries, 142 int max_retries,
138 GaiaOAuthClient::Delegate* delegate) { 143 GaiaOAuthClient::Delegate* delegate) {
139 DCHECK(!request_.get()) << "Tried to fetch two things at once!"; 144 DCHECK(!request_.get()) << "Tried to fetch two things at once!";
140 delegate_ = delegate; 145 delegate_ = delegate;
141 num_retries_ = 0; 146 num_retries_ = 0;
142 request_.reset(net::URLFetcher::Create( 147 request_.reset(net::URLFetcher::Create(
143 0, gaia_url_, net::URLFetcher::POST, this)); 148 0, gaia_url_, net::URLFetcher::POST, this));
144 request_->SetRequestContext(request_context_getter_); 149 request_->SetRequestContext(request_context_getter_);
145 request_->SetUploadData("application/x-www-form-urlencoded", post_body); 150 request_->SetUploadData("application/x-www-form-urlencoded", post_body);
146 request_->SetMaxRetriesOn5xx(max_retries); 151 request_->SetMaxRetriesOn5xx(max_retries);
152 // See comment on SetAutomaticallyRetryOnNetworkChanges() above.
153 request_->SetAutomaticallyRetryOnNetworkChanges(3);
147 request_->Start(); 154 request_->Start();
148 } 155 }
149 156
150 // URLFetcher::Delegate implementation. 157 // URLFetcher::Delegate implementation.
151 void GaiaOAuthClient::Core::OnURLFetchComplete( 158 void GaiaOAuthClient::Core::OnURLFetchComplete(
152 const net::URLFetcher* source) { 159 const net::URLFetcher* source) {
153 bool should_retry = false; 160 bool should_retry = false;
154 HandleResponse(source, &should_retry); 161 HandleResponse(source, &should_retry);
155 if (should_retry) { 162 if (should_retry) {
156 // Explicitly call ReceivedContentWasMalformed() to ensure the current 163 // Explicitly call ReceivedContentWasMalformed() to ensure the current
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 delegate); 282 delegate);
276 } 283 }
277 284
278 void GaiaOAuthClient::GetUserInfo(const std::string& access_token, 285 void GaiaOAuthClient::GetUserInfo(const std::string& access_token,
279 int max_retries, 286 int max_retries,
280 Delegate* delegate) { 287 Delegate* delegate) {
281 return core_->GetUserInfo(access_token, max_retries, delegate); 288 return core_->GetUserInfo(access_token, max_retries, delegate);
282 } 289 }
283 290
284 } // namespace gaia 291 } // namespace gaia
OLDNEW
« no previous file with comments | « chrome/browser/policy/device_management_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698