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

Side by Side Diff: net/url_request/url_request_job.cc

Issue 67019: URLRequest::Interceptor enhancements... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 8 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
« no previous file with comments | « net/url_request/url_request_job.h ('k') | net/url_request/url_request_job_manager.h » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "net/url_request/url_request_job.h" 5 #include "net/url_request/url_request_job.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "net/base/auth.h" 10 #include "net/base/auth.h"
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // Reference the |ref| directly out of the original URL to avoid a 330 // Reference the |ref| directly out of the original URL to avoid a
331 // malloc. 331 // malloc.
332 replacements.SetRef(url.spec().data(), 332 replacements.SetRef(url.spec().data(),
333 url.parsed_for_possibly_invalid_spec().ref); 333 url.parsed_for_possibly_invalid_spec().ref);
334 new_location = new_location.ReplaceComponents(replacements); 334 new_location = new_location.ReplaceComponents(replacements);
335 } 335 }
336 336
337 // Toggle this flag to true so the consumer can access response headers. 337 // Toggle this flag to true so the consumer can access response headers.
338 // Then toggle it back if we choose to follow the redirect. 338 // Then toggle it back if we choose to follow the redirect.
339 has_handled_response_ = true; 339 has_handled_response_ = true;
340 request_->delegate()->OnReceivedRedirect(request_, new_location); 340 request_->ReceivedRedirect(new_location);
341 341
342 // Ensure that the request wasn't destroyed in OnReceivedRedirect 342 // Ensure that the request wasn't detached or destroyed in ReceivedRedirect
343 if (!request_ || !request_->delegate()) 343 if (!request_ || !request_->delegate())
344 return; 344 return;
345 345
346 // If we were not cancelled, then follow the redirect. 346 // If we were not cancelled, then follow the redirect.
347 if (request_->status().is_success()) { 347 if (request_->status().is_success()) {
348 has_handled_response_ = false; 348 has_handled_response_ = false;
349 FollowRedirect(new_location, http_status_code); 349 FollowRedirect(new_location, http_status_code);
350 return; 350 return;
351 } 351 }
352 } else if (NeedsAuth()) { 352 } else if (NeedsAuth()) {
(...skipping 12 matching lines...) Expand all
365 if (request_->status().is_success()) 365 if (request_->status().is_success())
366 SetupFilter(); 366 SetupFilter();
367 367
368 if (!filter_.get()) { 368 if (!filter_.get()) {
369 std::string content_length; 369 std::string content_length;
370 request_->GetResponseHeaderByName("content-length", &content_length); 370 request_->GetResponseHeaderByName("content-length", &content_length);
371 if (!content_length.empty()) 371 if (!content_length.empty())
372 expected_content_size_ = StringToInt64(content_length); 372 expected_content_size_ = StringToInt64(content_length);
373 } 373 }
374 374
375 request_->delegate()->OnResponseStarted(request_); 375 request_->ResponseStarted();
376 } 376 }
377 377
378 void URLRequestJob::NotifyStartError(const URLRequestStatus &status) { 378 void URLRequestJob::NotifyStartError(const URLRequestStatus &status) {
379 DCHECK(!has_handled_response_); 379 DCHECK(!has_handled_response_);
380 has_handled_response_ = true; 380 has_handled_response_ = true;
381 if (request_) { 381 if (request_) {
382 request_->set_status(status); 382 request_->set_status(status);
383 if (request_->delegate()) 383 request_->ResponseStarted();
384 request_->delegate()->OnResponseStarted(request_);
385 } 384 }
386 } 385 }
387 386
388 void URLRequestJob::NotifyReadComplete(int bytes_read) { 387 void URLRequestJob::NotifyReadComplete(int bytes_read) {
389 if (!request_ || !request_->delegate()) 388 if (!request_ || !request_->delegate())
390 return; // The request was destroyed, so there is no more work to do. 389 return; // The request was destroyed, so there is no more work to do.
391 390
392 // TODO(darin): Bug 1004233. Re-enable this test once all of the chrome 391 // TODO(darin): Bug 1004233. Re-enable this test once all of the chrome
393 // unit_tests have been fixed to not trip this. 392 // unit_tests have been fixed to not trip this.
394 //DCHECK(!request_->status().is_io_pending()); 393 //DCHECK(!request_->status().is_io_pending());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 if (request_ && 474 if (request_ &&
476 !request_->status().is_success() && 475 !request_->status().is_success() &&
477 request_->delegate()) { 476 request_->delegate()) {
478 // We report the error differently depending on whether we've called 477 // We report the error differently depending on whether we've called
479 // OnResponseStarted yet. 478 // OnResponseStarted yet.
480 if (has_handled_response_) { 479 if (has_handled_response_) {
481 // We signal the error by calling OnReadComplete with a bytes_read of -1. 480 // We signal the error by calling OnReadComplete with a bytes_read of -1.
482 request_->delegate()->OnReadCompleted(request_, -1); 481 request_->delegate()->OnReadCompleted(request_, -1);
483 } else { 482 } else {
484 has_handled_response_ = true; 483 has_handled_response_ = true;
485 request_->delegate()->OnResponseStarted(request_); 484 request_->ResponseStarted();
486 } 485 }
487 } 486 }
488 } 487 }
489 488
490 void URLRequestJob::NotifyCanceled() { 489 void URLRequestJob::NotifyCanceled() {
491 if (!done_) { 490 if (!done_) {
492 NotifyDone(URLRequestStatus(URLRequestStatus::CANCELED, 491 NotifyDone(URLRequestStatus(URLRequestStatus::CANCELED,
493 net::ERR_ABORTED)); 492 net::ERR_ABORTED));
494 } 493 }
495 } 494 }
496 495
496 void URLRequestJob::NotifyRestartRequired() {
497 DCHECK(!has_handled_response_);
498 if (GetStatus().status() != URLRequestStatus::CANCELED)
499 request_->Restart();
500 }
501
497 bool URLRequestJob::FilterHasData() { 502 bool URLRequestJob::FilterHasData() {
498 return filter_.get() && filter_->stream_data_len(); 503 return filter_.get() && filter_->stream_data_len();
499 } 504 }
500 505
501 void URLRequestJob::FollowRedirect(const GURL& location, 506 void URLRequestJob::FollowRedirect(const GURL& location,
502 int http_status_code) { 507 int http_status_code) {
503 g_url_request_job_tracker.OnJobRedirect(this, location, http_status_code); 508 g_url_request_job_tracker.OnJobRedirect(this, location, http_status_code);
504 Kill(); 509 Kill();
505 // Kill could have notified the Delegate and destroyed the request. 510 // Kill could have notified the Delegate and destroyed the request.
506 if (!request_) 511 if (!request_)
(...skipping 18 matching lines...) Expand all
525 return request_->status(); 530 return request_->status();
526 // If the request is gone, we must be cancelled. 531 // If the request is gone, we must be cancelled.
527 return URLRequestStatus(URLRequestStatus::CANCELED, 532 return URLRequestStatus(URLRequestStatus::CANCELED,
528 net::ERR_ABORTED); 533 net::ERR_ABORTED);
529 } 534 }
530 535
531 void URLRequestJob::SetStatus(const URLRequestStatus &status) { 536 void URLRequestJob::SetStatus(const URLRequestStatus &status) {
532 if (request_) 537 if (request_)
533 request_->set_status(status); 538 request_->set_status(status);
534 } 539 }
OLDNEW
« no previous file with comments | « net/url_request/url_request_job.h ('k') | net/url_request/url_request_job_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698