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

Side by Side Diff: chrome/browser/google_apis/base_requests.cc

Issue 17379020: Get rid of RequestRegistry (part 5): each request cancels itself. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months 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
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 "chrome/browser/google_apis/base_requests.h" 5 #include "chrome/browser/google_apis/base_requests.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 return false; 211 return false;
212 } 212 }
213 213
214 bool UrlFetchRequestBase::GetContentFile(base::FilePath* local_file_path, 214 bool UrlFetchRequestBase::GetContentFile(base::FilePath* local_file_path,
215 int64* range_offset, 215 int64* range_offset,
216 int64* range_length, 216 int64* range_length,
217 std::string* upload_content_type) { 217 std::string* upload_content_type) {
218 return false; 218 return false;
219 } 219 }
220 220
221 void UrlFetchRequestBase::DoCancel() { 221 void UrlFetchRequestBase::Cancel() {
222 url_fetcher_.reset(NULL); 222 url_fetcher_.reset(NULL);
223 RunCallbackOnPrematureFailure(GDATA_CANCELLED); 223 RunCallbackOnPrematureFailure(GDATA_CANCELLED);
224 NotifyFinish();
224 } 225 }
225 226
226 // static 227 // static
227 GDataErrorCode UrlFetchRequestBase::GetErrorCode(const URLFetcher* source) { 228 GDataErrorCode UrlFetchRequestBase::GetErrorCode(const URLFetcher* source) {
228 GDataErrorCode code = static_cast<GDataErrorCode>(source->GetResponseCode()); 229 GDataErrorCode code = static_cast<GDataErrorCode>(source->GetResponseCode());
229 if (!source->GetStatus().is_success()) { 230 if (!source->GetStatus().is_success()) {
230 switch (source->GetStatus().error()) { 231 switch (source->GetStatus().error()) {
231 case net::ERR_NETWORK_CHANGED: 232 case net::ERR_NETWORK_CHANGED:
232 code = GDATA_NO_CONNECTION; 233 code = GDATA_NO_CONNECTION;
233 break; 234 break;
234 default: 235 default:
235 code = GDATA_OTHER_ERROR; 236 code = GDATA_OTHER_ERROR;
236 } 237 }
237 } 238 }
238 return code; 239 return code;
239 } 240 }
240 241
241 void UrlFetchRequestBase::OnProcessURLFetchResultsComplete(bool result) { 242 void UrlFetchRequestBase::OnProcessURLFetchResultsComplete(bool result) {
242 NotifyFinish(result ? REQUEST_COMPLETED : REQUEST_FAILED); 243 NotifyFinish();
243 } 244 }
244 245
245 void UrlFetchRequestBase::OnURLFetchComplete(const URLFetcher* source) { 246 void UrlFetchRequestBase::OnURLFetchComplete(const URLFetcher* source) {
246 GDataErrorCode code = GetErrorCode(source); 247 GDataErrorCode code = GetErrorCode(source);
247 DVLOG(1) << "Response headers:\n" << GetResponseHeadersAsString(source); 248 DVLOG(1) << "Response headers:\n" << GetResponseHeadersAsString(source);
248 249
249 if (code == HTTP_UNAUTHORIZED) { 250 if (code == HTTP_UNAUTHORIZED) {
250 if (++re_authenticate_count_ <= kMaxReAuthenticateAttemptsPerRequest) { 251 if (++re_authenticate_count_ <= kMaxReAuthenticateAttemptsPerRequest) {
251 // Reset re_authenticate_callback_ so Start() can be called again. 252 // Reset re_authenticate_callback_ so Start() can be called again.
252 ReAuthenticateCallback callback = re_authenticate_callback_; 253 ReAuthenticateCallback callback = re_authenticate_callback_;
(...skipping 14 matching lines...) Expand all
267 RunCallbackOnPrematureFailure(code); 268 RunCallbackOnPrematureFailure(code);
268 269
269 // Check if this failed before we even started fetching. If so, register 270 // Check if this failed before we even started fetching. If so, register
270 // for start so we can properly unregister with finish. 271 // for start so we can properly unregister with finish.
271 if (!started_) 272 if (!started_)
272 NotifyStart(); 273 NotifyStart();
273 274
274 // Note: NotifyFinish() must be invoked at the end, after all other callbacks 275 // Note: NotifyFinish() must be invoked at the end, after all other callbacks
275 // and notifications. Once NotifyFinish() is called, the current instance of 276 // and notifications. Once NotifyFinish() is called, the current instance of
276 // request will be deleted from the RequestRegistry and become invalid. 277 // request will be deleted from the RequestRegistry and become invalid.
277 NotifyFinish(REQUEST_FAILED); 278 NotifyFinish();
278 }
279
280 RequestRegistry::Request* UrlFetchRequestBase::AsRequestRegistryRequest() {
281 return this;
282 } 279 }
283 280
284 base::WeakPtr<AuthenticatedRequestInterface> 281 base::WeakPtr<AuthenticatedRequestInterface>
285 UrlFetchRequestBase::GetWeakPtr() { 282 UrlFetchRequestBase::GetWeakPtr() {
286 return weak_ptr_factory_.GetWeakPtr(); 283 return weak_ptr_factory_.GetWeakPtr();
287 } 284 }
288 285
289 //============================ EntryActionRequest ============================ 286 //============================ EntryActionRequest ============================
290 287
291 EntryActionRequest::EntryActionRequest( 288 EntryActionRequest::EntryActionRequest(
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 695
699 download_action_callback_.Run(code, temp_file); 696 download_action_callback_.Run(code, temp_file);
700 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS); 697 OnProcessURLFetchResultsComplete(code == HTTP_SUCCESS);
701 } 698 }
702 699
703 void DownloadFileRequest::RunCallbackOnPrematureFailure(GDataErrorCode code) { 700 void DownloadFileRequest::RunCallbackOnPrematureFailure(GDataErrorCode code) {
704 download_action_callback_.Run(code, base::FilePath()); 701 download_action_callback_.Run(code, base::FilePath());
705 } 702 }
706 703
707 } // namespace google_apis 704 } // namespace google_apis
OLDNEW
« no previous file with comments | « chrome/browser/google_apis/base_requests.h ('k') | chrome/browser/google_apis/request_registry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698