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

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

Issue 10855209: Refactoring: ProtocolHandler::MaybeCreateJob takes NetworkDelegate as argument (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Latest merge Created 8 years, 4 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.h ('k') | net/url_request/url_request_about_job.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) 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 "net/url_request/url_request.h" 5 #include "net/url_request/url_request.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 void URLRequest::Deprecated::UnregisterRequestInterceptor( 89 void URLRequest::Deprecated::UnregisterRequestInterceptor(
90 Interceptor* interceptor) { 90 Interceptor* interceptor) {
91 URLRequest::UnregisterRequestInterceptor(interceptor); 91 URLRequest::UnregisterRequestInterceptor(interceptor);
92 } 92 }
93 93
94 /////////////////////////////////////////////////////////////////////////////// 94 ///////////////////////////////////////////////////////////////////////////////
95 // URLRequest::Interceptor 95 // URLRequest::Interceptor
96 96
97 URLRequestJob* URLRequest::Interceptor::MaybeInterceptRedirect( 97 URLRequestJob* URLRequest::Interceptor::MaybeInterceptRedirect(
98 URLRequest* request, 98 URLRequest* request,
99 NetworkDelegate* network_delegate,
99 const GURL& location) { 100 const GURL& location) {
100 return NULL; 101 return NULL;
101 } 102 }
102 103
103 URLRequestJob* URLRequest::Interceptor::MaybeInterceptResponse( 104 URLRequestJob* URLRequest::Interceptor::MaybeInterceptResponse(
104 URLRequest* request) { 105 URLRequest* request, NetworkDelegate* network_delegate) {
105 return NULL; 106 return NULL;
106 } 107 }
107 108
108 /////////////////////////////////////////////////////////////////////////////// 109 ///////////////////////////////////////////////////////////////////////////////
109 // URLRequest::Delegate 110 // URLRequest::Delegate
110 111
111 void URLRequest::Delegate::OnReceivedRedirect(URLRequest* request, 112 void URLRequest::Delegate::OnReceivedRedirect(URLRequest* request,
112 const GURL& new_url, 113 const GURL& new_url,
113 bool* defer_redirect) { 114 bool* defer_redirect) {
114 } 115 }
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 this, before_request_callback_, &delegate_redirect_url_); 422 this, before_request_callback_, &delegate_redirect_url_);
422 if (error == net::ERR_IO_PENDING) { 423 if (error == net::ERR_IO_PENDING) {
423 // Paused on the delegate, will invoke |before_request_callback_| later. 424 // Paused on the delegate, will invoke |before_request_callback_| later.
424 SetBlockedOnDelegate(); 425 SetBlockedOnDelegate();
425 } else { 426 } else {
426 BeforeRequestComplete(error); 427 BeforeRequestComplete(error);
427 } 428 }
428 return; 429 return;
429 } 430 }
430 431
431 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); 432 StartJob(URLRequestJobManager::GetInstance()->CreateJob(
433 this, context_->network_delegate()));
432 } 434 }
433 435
434 /////////////////////////////////////////////////////////////////////////////// 436 ///////////////////////////////////////////////////////////////////////////////
435 437
436 void URLRequest::BeforeRequestComplete(int error) { 438 void URLRequest::BeforeRequestComplete(int error) {
437 DCHECK(!job_); 439 DCHECK(!job_);
438 DCHECK_NE(ERR_IO_PENDING, error); 440 DCHECK_NE(ERR_IO_PENDING, error);
439 441
440 // Check that there are no callbacks to already canceled requests. 442 // Check that there are no callbacks to already canceled requests.
441 DCHECK_NE(URLRequestStatus::CANCELED, status_.status()); 443 DCHECK_NE(URLRequestStatus::CANCELED, status_.status());
442 444
443 if (blocked_on_delegate_) 445 if (blocked_on_delegate_)
444 SetUnblockedOnDelegate(); 446 SetUnblockedOnDelegate();
445 447
446 if (error != OK) { 448 if (error != OK) {
447 std::string source("delegate"); 449 std::string source("delegate");
448 net_log_.AddEvent(NetLog::TYPE_CANCELLED, 450 net_log_.AddEvent(NetLog::TYPE_CANCELLED,
449 NetLog::StringCallback("source", &source)); 451 NetLog::StringCallback("source", &source));
450 StartJob(new URLRequestErrorJob(this, error)); 452 StartJob(new URLRequestErrorJob(this, context_->network_delegate(), error));
451 } else if (!delegate_redirect_url_.is_empty()) { 453 } else if (!delegate_redirect_url_.is_empty()) {
452 GURL new_url; 454 GURL new_url;
453 new_url.Swap(&delegate_redirect_url_); 455 new_url.Swap(&delegate_redirect_url_);
454 456
455 URLRequestRedirectJob* job = new URLRequestRedirectJob(this, new_url); 457 URLRequestRedirectJob* job = new URLRequestRedirectJob(
458 this, context_->network_delegate(), new_url);
456 // Use status code 307 to preserve the method, so POST requests work. 459 // Use status code 307 to preserve the method, so POST requests work.
457 job->set_redirect_code( 460 job->set_redirect_code(
458 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); 461 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT);
459 StartJob(job); 462 StartJob(job);
460 } else { 463 } else {
461 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); 464 StartJob(URLRequestJobManager::GetInstance()->CreateJob(
465 this, context_->network_delegate()));
462 } 466 }
463 } 467 }
464 468
465 void URLRequest::StartJob(URLRequestJob* job) { 469 void URLRequest::StartJob(URLRequestJob* job) {
466 DCHECK(!is_pending_); 470 DCHECK(!is_pending_);
467 DCHECK(!job_); 471 DCHECK(!job_);
468 472
469 net_log_.BeginEvent( 473 net_log_.BeginEvent(
470 NetLog::TYPE_URL_REQUEST_START_JOB, 474 NetLog::TYPE_URL_REQUEST_START_JOB,
471 base::Bind(&NetLogURLRequestStartCallback, 475 base::Bind(&NetLogURLRequestStartCallback,
(...skipping 12 matching lines...) Expand all
484 // Don't allow errors to be sent from within Start(). 488 // Don't allow errors to be sent from within Start().
485 // TODO(brettw) this may cause NotifyDone to be sent synchronously, 489 // TODO(brettw) this may cause NotifyDone to be sent synchronously,
486 // we probably don't want this: they should be sent asynchronously so 490 // we probably don't want this: they should be sent asynchronously so
487 // the caller does not get reentered. 491 // the caller does not get reentered.
488 job_->Start(); 492 job_->Start();
489 } 493 }
490 494
491 void URLRequest::Restart() { 495 void URLRequest::Restart() {
492 // Should only be called if the original job didn't make any progress. 496 // Should only be called if the original job didn't make any progress.
493 DCHECK(job_ && !job_->has_response_started()); 497 DCHECK(job_ && !job_->has_response_started());
494 RestartWithJob(URLRequestJobManager::GetInstance()->CreateJob(this)); 498 RestartWithJob(URLRequestJobManager::GetInstance()->CreateJob(
499 this, context_->network_delegate()));
495 } 500 }
496 501
497 void URLRequest::RestartWithJob(URLRequestJob *job) { 502 void URLRequest::RestartWithJob(URLRequestJob *job) {
498 DCHECK(job->request() == this); 503 DCHECK(job->request() == this);
499 PrepareToRestart(); 504 PrepareToRestart();
500 StartJob(job); 505 StartJob(job);
501 } 506 }
502 507
503 void URLRequest::Cancel() { 508 void URLRequest::Cancel() {
504 DoCancel(ERR_ABORTED, SSLInfo()); 509 DoCancel(ERR_ABORTED, SSLInfo());
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 } 584 }
580 585
581 void URLRequest::StopCaching() { 586 void URLRequest::StopCaching() {
582 DCHECK(job_); 587 DCHECK(job_);
583 job_->StopCaching(); 588 job_->StopCaching();
584 } 589 }
585 590
586 void URLRequest::NotifyReceivedRedirect(const GURL& location, 591 void URLRequest::NotifyReceivedRedirect(const GURL& location,
587 bool* defer_redirect) { 592 bool* defer_redirect) {
588 URLRequestJob* job = 593 URLRequestJob* job =
589 URLRequestJobManager::GetInstance()->MaybeInterceptRedirect(this, 594 URLRequestJobManager::GetInstance()->MaybeInterceptRedirect(
590 location); 595 this, context_->network_delegate(), location);
591 if (job) { 596 if (job) {
592 RestartWithJob(job); 597 RestartWithJob(job);
593 } else if (delegate_) { 598 } else if (delegate_) {
594 delegate_->OnReceivedRedirect(this, location, defer_redirect); 599 delegate_->OnReceivedRedirect(this, location, defer_redirect);
595 } 600 }
596 } 601 }
597 602
598 void URLRequest::NotifyResponseStarted() { 603 void URLRequest::NotifyResponseStarted() {
599 int net_error = OK; 604 int net_error = OK;
600 if (!status_.is_success()) 605 if (!status_.is_success())
601 net_error = status_.error(); 606 net_error = status_.error();
602 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_URL_REQUEST_START_JOB, 607 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_URL_REQUEST_START_JOB,
603 net_error); 608 net_error);
604 609
605 URLRequestJob* job = 610 URLRequestJob* job =
606 URLRequestJobManager::GetInstance()->MaybeInterceptResponse(this); 611 URLRequestJobManager::GetInstance()->MaybeInterceptResponse(
612 this, context_->network_delegate());
607 if (job) { 613 if (job) {
608 RestartWithJob(job); 614 RestartWithJob(job);
609 } else { 615 } else {
610 if (delegate_) { 616 if (delegate_) {
611 // In some cases (e.g. an event was canceled), we might have sent the 617 // In some cases (e.g. an event was canceled), we might have sent the
612 // completion event and receive a NotifyResponseStarted() later. 618 // completion event and receive a NotifyResponseStarted() later.
613 if (!has_notified_completion_ && status_.is_success()) { 619 if (!has_notified_completion_ && status_.is_success()) {
614 if (context_->network_delegate()) 620 if (context_->network_delegate())
615 context_->network_delegate()->NotifyResponseStarted(this); 621 context_->network_delegate()->NotifyResponseStarted(this);
616 } 622 }
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 new base::debug::StackTrace(NULL, 0); 928 new base::debug::StackTrace(NULL, 0);
923 *stack_trace_copy = stack_trace; 929 *stack_trace_copy = stack_trace;
924 stack_trace_.reset(stack_trace_copy); 930 stack_trace_.reset(stack_trace_copy);
925 } 931 }
926 932
927 const base::debug::StackTrace* URLRequest::stack_trace() const { 933 const base::debug::StackTrace* URLRequest::stack_trace() const {
928 return stack_trace_.get(); 934 return stack_trace_.get();
929 } 935 }
930 936
931 } // namespace net 937 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request.h ('k') | net/url_request/url_request_about_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698