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 "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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 this, before_request_callback_, &delegate_redirect_url_); | 421 this, before_request_callback_, &delegate_redirect_url_); |
422 if (error == net::ERR_IO_PENDING) { | 422 if (error == net::ERR_IO_PENDING) { |
423 // Paused on the delegate, will invoke |before_request_callback_| later. | 423 // Paused on the delegate, will invoke |before_request_callback_| later. |
424 SetBlockedOnDelegate(); | 424 SetBlockedOnDelegate(); |
425 } else { | 425 } else { |
426 BeforeRequestComplete(error); | 426 BeforeRequestComplete(error); |
427 } | 427 } |
428 return; | 428 return; |
429 } | 429 } |
430 | 430 |
431 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); | 431 StartJob(URLRequestJobManager::GetInstance()->CreateJob( |
| 432 this, context_->network_delegate())); |
432 } | 433 } |
433 | 434 |
434 /////////////////////////////////////////////////////////////////////////////// | 435 /////////////////////////////////////////////////////////////////////////////// |
435 | 436 |
436 void URLRequest::BeforeRequestComplete(int error) { | 437 void URLRequest::BeforeRequestComplete(int error) { |
437 DCHECK(!job_); | 438 DCHECK(!job_); |
438 DCHECK_NE(ERR_IO_PENDING, error); | 439 DCHECK_NE(ERR_IO_PENDING, error); |
439 | 440 |
440 // Check that there are no callbacks to already canceled requests. | 441 // Check that there are no callbacks to already canceled requests. |
441 DCHECK_NE(URLRequestStatus::CANCELED, status_.status()); | 442 DCHECK_NE(URLRequestStatus::CANCELED, status_.status()); |
442 | 443 |
443 if (blocked_on_delegate_) | 444 if (blocked_on_delegate_) |
444 SetUnblockedOnDelegate(); | 445 SetUnblockedOnDelegate(); |
445 | 446 |
446 if (error != OK) { | 447 if (error != OK) { |
447 std::string source("delegate"); | 448 std::string source("delegate"); |
448 net_log_.AddEvent(NetLog::TYPE_CANCELLED, | 449 net_log_.AddEvent(NetLog::TYPE_CANCELLED, |
449 NetLog::StringCallback("source", &source)); | 450 NetLog::StringCallback("source", &source)); |
450 StartJob(new URLRequestErrorJob(this, error)); | 451 StartJob(new URLRequestErrorJob(this, context_->network_delegate(), error)); |
451 } else if (!delegate_redirect_url_.is_empty()) { | 452 } else if (!delegate_redirect_url_.is_empty()) { |
452 GURL new_url; | 453 GURL new_url; |
453 new_url.Swap(&delegate_redirect_url_); | 454 new_url.Swap(&delegate_redirect_url_); |
454 | 455 |
455 URLRequestRedirectJob* job = new URLRequestRedirectJob(this, new_url); | 456 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
| 457 this, context_->network_delegate(), new_url); |
456 // Use status code 307 to preserve the method, so POST requests work. | 458 // Use status code 307 to preserve the method, so POST requests work. |
457 job->set_redirect_code( | 459 job->set_redirect_code( |
458 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); | 460 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); |
459 StartJob(job); | 461 StartJob(job); |
460 } else { | 462 } else { |
461 StartJob(URLRequestJobManager::GetInstance()->CreateJob(this)); | 463 StartJob(URLRequestJobManager::GetInstance()->CreateJob( |
| 464 this, context_->network_delegate())); |
462 } | 465 } |
463 } | 466 } |
464 | 467 |
465 void URLRequest::StartJob(URLRequestJob* job) { | 468 void URLRequest::StartJob(URLRequestJob* job) { |
466 DCHECK(!is_pending_); | 469 DCHECK(!is_pending_); |
467 DCHECK(!job_); | 470 DCHECK(!job_); |
468 | 471 |
469 net_log_.BeginEvent( | 472 net_log_.BeginEvent( |
470 NetLog::TYPE_URL_REQUEST_START_JOB, | 473 NetLog::TYPE_URL_REQUEST_START_JOB, |
471 base::Bind(&NetLogURLRequestStartCallback, | 474 base::Bind(&NetLogURLRequestStartCallback, |
(...skipping 12 matching lines...) Expand all Loading... |
484 // Don't allow errors to be sent from within Start(). | 487 // Don't allow errors to be sent from within Start(). |
485 // TODO(brettw) this may cause NotifyDone to be sent synchronously, | 488 // TODO(brettw) this may cause NotifyDone to be sent synchronously, |
486 // we probably don't want this: they should be sent asynchronously so | 489 // we probably don't want this: they should be sent asynchronously so |
487 // the caller does not get reentered. | 490 // the caller does not get reentered. |
488 job_->Start(); | 491 job_->Start(); |
489 } | 492 } |
490 | 493 |
491 void URLRequest::Restart() { | 494 void URLRequest::Restart() { |
492 // Should only be called if the original job didn't make any progress. | 495 // Should only be called if the original job didn't make any progress. |
493 DCHECK(job_ && !job_->has_response_started()); | 496 DCHECK(job_ && !job_->has_response_started()); |
494 RestartWithJob(URLRequestJobManager::GetInstance()->CreateJob(this)); | 497 RestartWithJob(URLRequestJobManager::GetInstance()->CreateJob( |
| 498 this, context_->network_delegate())); |
495 } | 499 } |
496 | 500 |
497 void URLRequest::RestartWithJob(URLRequestJob *job) { | 501 void URLRequest::RestartWithJob(URLRequestJob *job) { |
498 DCHECK(job->request() == this); | 502 DCHECK(job->request() == this); |
499 PrepareToRestart(); | 503 PrepareToRestart(); |
500 StartJob(job); | 504 StartJob(job); |
501 } | 505 } |
502 | 506 |
503 void URLRequest::Cancel() { | 507 void URLRequest::Cancel() { |
504 DoCancel(ERR_ABORTED, SSLInfo()); | 508 DoCancel(ERR_ABORTED, SSLInfo()); |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 new base::debug::StackTrace(NULL, 0); | 925 new base::debug::StackTrace(NULL, 0); |
922 *stack_trace_copy = stack_trace; | 926 *stack_trace_copy = stack_trace; |
923 stack_trace_.reset(stack_trace_copy); | 927 stack_trace_.reset(stack_trace_copy); |
924 } | 928 } |
925 | 929 |
926 const base::debug::StackTrace* URLRequest::stack_trace() const { | 930 const base::debug::StackTrace* URLRequest::stack_trace() const { |
927 return stack_trace_.get(); | 931 return stack_trace_.get(); |
928 } | 932 } |
929 | 933 |
930 } // namespace net | 934 } // namespace net |
OLD | NEW |