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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 context->url_requests()->insert(this); | 276 context->url_requests()->insert(this); |
277 | 277 |
278 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); | 278 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); |
279 } | 279 } |
280 | 280 |
281 URLRequest::~URLRequest() { | 281 URLRequest::~URLRequest() { |
282 Cancel(); | 282 Cancel(); |
283 | 283 |
284 if (network_delegate_) { | 284 if (network_delegate_) { |
285 network_delegate_->NotifyURLRequestDestroyed(this); | 285 network_delegate_->NotifyURLRequestDestroyed(this); |
286 if (job_) | 286 if (job_.get()) |
287 job_->NotifyURLRequestDestroyed(); | 287 job_->NotifyURLRequestDestroyed(); |
288 } | 288 } |
289 | 289 |
290 if (job_) | 290 if (job_.get()) |
291 OrphanJob(); | 291 OrphanJob(); |
292 | 292 |
293 int deleted = context_->url_requests()->erase(this); | 293 int deleted = context_->url_requests()->erase(this); |
294 CHECK_EQ(1, deleted); | 294 CHECK_EQ(1, deleted); |
295 | 295 |
296 int net_error = OK; | 296 int net_error = OK; |
297 // Log error only on failure, not cancellation, as even successful requests | 297 // Log error only on failure, not cancellation, as even successful requests |
298 // are "cancelled" on destruction. | 298 // are "cancelled" on destruction. |
299 if (status_.status() == URLRequestStatus::FAILED) | 299 if (status_.status() == URLRequestStatus::FAILED) |
300 net_error = status_.error(); | 300 net_error = status_.error(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 378 |
379 // NOTE: This method will likely become non-trivial once the other setters | 379 // NOTE: This method will likely become non-trivial once the other setters |
380 // for request headers are implemented. | 380 // for request headers are implemented. |
381 } | 381 } |
382 | 382 |
383 LoadStateWithParam URLRequest::GetLoadState() const { | 383 LoadStateWithParam URLRequest::GetLoadState() const { |
384 if (blocked_on_delegate_) { | 384 if (blocked_on_delegate_) { |
385 return LoadStateWithParam(LOAD_STATE_WAITING_FOR_DELEGATE, | 385 return LoadStateWithParam(LOAD_STATE_WAITING_FOR_DELEGATE, |
386 load_state_param_); | 386 load_state_param_); |
387 } | 387 } |
388 return LoadStateWithParam(job_ ? job_->GetLoadState() : LOAD_STATE_IDLE, | 388 return LoadStateWithParam(job_.get() ? job_->GetLoadState() : LOAD_STATE_IDLE, |
389 base::string16()); | 389 base::string16()); |
390 } | 390 } |
391 | 391 |
392 UploadProgress URLRequest::GetUploadProgress() const { | 392 UploadProgress URLRequest::GetUploadProgress() const { |
393 if (!job_) { | 393 if (!job_.get()) { |
394 // We haven't started or the request was cancelled | 394 // We haven't started or the request was cancelled |
395 return UploadProgress(); | 395 return UploadProgress(); |
396 } | 396 } |
397 if (final_upload_progress_.position()) { | 397 if (final_upload_progress_.position()) { |
398 // The first job completed and none of the subsequent series of | 398 // The first job completed and none of the subsequent series of |
399 // GETs when following redirects will upload anything, so we return the | 399 // GETs when following redirects will upload anything, so we return the |
400 // cached results from the initial job, the POST. | 400 // cached results from the initial job, the POST. |
401 return final_upload_progress_; | 401 return final_upload_progress_; |
402 } | 402 } |
403 return job_->GetUploadProgress(); | 403 return job_->GetUploadProgress(); |
404 } | 404 } |
405 | 405 |
406 void URLRequest::GetResponseHeaderById(int id, string* value) { | 406 void URLRequest::GetResponseHeaderById(int id, string* value) { |
407 DCHECK(job_); | 407 DCHECK(job_.get()); |
408 NOTREACHED() << "implement me!"; | 408 NOTREACHED() << "implement me!"; |
409 } | 409 } |
410 | 410 |
411 void URLRequest::GetResponseHeaderByName(const string& name, string* value) { | 411 void URLRequest::GetResponseHeaderByName(const string& name, string* value) { |
412 DCHECK(value); | 412 DCHECK(value); |
413 if (response_info_.headers) { | 413 if (response_info_.headers.get()) { |
414 response_info_.headers->GetNormalizedHeader(name, value); | 414 response_info_.headers->GetNormalizedHeader(name, value); |
415 } else { | 415 } else { |
416 value->clear(); | 416 value->clear(); |
417 } | 417 } |
418 } | 418 } |
419 | 419 |
420 void URLRequest::GetAllResponseHeaders(string* headers) { | 420 void URLRequest::GetAllResponseHeaders(string* headers) { |
421 DCHECK(headers); | 421 DCHECK(headers); |
422 if (response_info_.headers) { | 422 if (response_info_.headers.get()) { |
423 response_info_.headers->GetNormalizedHeaders(headers); | 423 response_info_.headers->GetNormalizedHeaders(headers); |
424 } else { | 424 } else { |
425 headers->clear(); | 425 headers->clear(); |
426 } | 426 } |
427 } | 427 } |
428 | 428 |
429 HostPortPair URLRequest::GetSocketAddress() const { | 429 HostPortPair URLRequest::GetSocketAddress() const { |
430 DCHECK(job_); | 430 DCHECK(job_.get()); |
431 return job_->GetSocketAddress(); | 431 return job_->GetSocketAddress(); |
432 } | 432 } |
433 | 433 |
434 HttpResponseHeaders* URLRequest::response_headers() const { | 434 HttpResponseHeaders* URLRequest::response_headers() const { |
435 return response_info_.headers.get(); | 435 return response_info_.headers.get(); |
436 } | 436 } |
437 | 437 |
438 void URLRequest::GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const { | 438 void URLRequest::GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const { |
439 *load_timing_info = load_timing_info_; | 439 *load_timing_info = load_timing_info_; |
440 } | 440 } |
441 | 441 |
442 bool URLRequest::GetResponseCookies(ResponseCookies* cookies) { | 442 bool URLRequest::GetResponseCookies(ResponseCookies* cookies) { |
443 DCHECK(job_); | 443 DCHECK(job_.get()); |
444 return job_->GetResponseCookies(cookies); | 444 return job_->GetResponseCookies(cookies); |
445 } | 445 } |
446 | 446 |
447 void URLRequest::GetMimeType(string* mime_type) { | 447 void URLRequest::GetMimeType(string* mime_type) { |
448 DCHECK(job_); | 448 DCHECK(job_.get()); |
449 job_->GetMimeType(mime_type); | 449 job_->GetMimeType(mime_type); |
450 } | 450 } |
451 | 451 |
452 void URLRequest::GetCharset(string* charset) { | 452 void URLRequest::GetCharset(string* charset) { |
453 DCHECK(job_); | 453 DCHECK(job_.get()); |
454 job_->GetCharset(charset); | 454 job_->GetCharset(charset); |
455 } | 455 } |
456 | 456 |
457 int URLRequest::GetResponseCode() { | 457 int URLRequest::GetResponseCode() { |
458 DCHECK(job_); | 458 DCHECK(job_.get()); |
459 return job_->GetResponseCode(); | 459 return job_->GetResponseCode(); |
460 } | 460 } |
461 | 461 |
462 // static | 462 // static |
463 void URLRequest::SetDefaultCookiePolicyToBlock() { | 463 void URLRequest::SetDefaultCookiePolicyToBlock() { |
464 CHECK(!g_url_requests_started); | 464 CHECK(!g_url_requests_started); |
465 g_default_can_use_cookies = false; | 465 g_default_can_use_cookies = false; |
466 } | 466 } |
467 | 467 |
468 // static | 468 // static |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 return; | 541 return; |
542 } | 542 } |
543 | 543 |
544 StartJob(URLRequestJobManager::GetInstance()->CreateJob( | 544 StartJob(URLRequestJobManager::GetInstance()->CreateJob( |
545 this, network_delegate_)); | 545 this, network_delegate_)); |
546 } | 546 } |
547 | 547 |
548 /////////////////////////////////////////////////////////////////////////////// | 548 /////////////////////////////////////////////////////////////////////////////// |
549 | 549 |
550 void URLRequest::BeforeRequestComplete(int error) { | 550 void URLRequest::BeforeRequestComplete(int error) { |
551 DCHECK(!job_); | 551 DCHECK(!job_.get()); |
552 DCHECK_NE(ERR_IO_PENDING, error); | 552 DCHECK_NE(ERR_IO_PENDING, error); |
553 DCHECK_EQ(network_delegate_, context_->network_delegate()); | 553 DCHECK_EQ(network_delegate_, context_->network_delegate()); |
554 | 554 |
555 // Check that there are no callbacks to already canceled requests. | 555 // Check that there are no callbacks to already canceled requests. |
556 DCHECK_NE(URLRequestStatus::CANCELED, status_.status()); | 556 DCHECK_NE(URLRequestStatus::CANCELED, status_.status()); |
557 | 557 |
558 if (blocked_on_delegate_) | 558 if (blocked_on_delegate_) |
559 SetUnblockedOnDelegate(); | 559 SetUnblockedOnDelegate(); |
560 | 560 |
561 if (error != OK) { | 561 if (error != OK) { |
(...skipping 11 matching lines...) Expand all Loading... |
573 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); | 573 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); |
574 StartJob(job); | 574 StartJob(job); |
575 } else { | 575 } else { |
576 StartJob(URLRequestJobManager::GetInstance()->CreateJob( | 576 StartJob(URLRequestJobManager::GetInstance()->CreateJob( |
577 this, network_delegate_)); | 577 this, network_delegate_)); |
578 } | 578 } |
579 } | 579 } |
580 | 580 |
581 void URLRequest::StartJob(URLRequestJob* job) { | 581 void URLRequest::StartJob(URLRequestJob* job) { |
582 DCHECK(!is_pending_); | 582 DCHECK(!is_pending_); |
583 DCHECK(!job_); | 583 DCHECK(!job_.get()); |
584 | 584 |
585 net_log_.BeginEvent( | 585 net_log_.BeginEvent( |
586 NetLog::TYPE_URL_REQUEST_START_JOB, | 586 NetLog::TYPE_URL_REQUEST_START_JOB, |
587 base::Bind(&NetLogURLRequestStartCallback, | 587 base::Bind(&NetLogURLRequestStartCallback, |
588 &url(), &method_, load_flags_, priority_, | 588 &url(), &method_, load_flags_, priority_, |
589 upload_data_stream_ ? upload_data_stream_->identifier() : -1)); | 589 upload_data_stream_ ? upload_data_stream_->identifier() : -1)); |
590 | 590 |
591 job_ = job; | 591 job_ = job; |
592 job_->SetExtraRequestHeaders(extra_request_headers_); | 592 job_->SetExtraRequestHeaders(extra_request_headers_); |
593 job_->SetPriority(priority_); | 593 job_->SetPriority(priority_); |
594 | 594 |
595 if (upload_data_stream_.get()) | 595 if (upload_data_stream_.get()) |
596 job_->SetUpload(upload_data_stream_.get()); | 596 job_->SetUpload(upload_data_stream_.get()); |
597 | 597 |
598 is_pending_ = true; | 598 is_pending_ = true; |
599 is_redirecting_ = false; | 599 is_redirecting_ = false; |
600 | 600 |
601 response_info_.was_cached = false; | 601 response_info_.was_cached = false; |
602 | 602 |
603 // Don't allow errors to be sent from within Start(). | 603 // Don't allow errors to be sent from within Start(). |
604 // TODO(brettw) this may cause NotifyDone to be sent synchronously, | 604 // TODO(brettw) this may cause NotifyDone to be sent synchronously, |
605 // we probably don't want this: they should be sent asynchronously so | 605 // we probably don't want this: they should be sent asynchronously so |
606 // the caller does not get reentered. | 606 // the caller does not get reentered. |
607 job_->Start(); | 607 job_->Start(); |
608 } | 608 } |
609 | 609 |
610 void URLRequest::Restart() { | 610 void URLRequest::Restart() { |
611 // Should only be called if the original job didn't make any progress. | 611 // Should only be called if the original job didn't make any progress. |
612 DCHECK(job_ && !job_->has_response_started()); | 612 DCHECK(job_.get() && !job_->has_response_started()); |
613 RestartWithJob(URLRequestJobManager::GetInstance()->CreateJob( | 613 RestartWithJob( |
614 this, network_delegate_)); | 614 URLRequestJobManager::GetInstance()->CreateJob(this, network_delegate_)); |
615 } | 615 } |
616 | 616 |
617 void URLRequest::RestartWithJob(URLRequestJob *job) { | 617 void URLRequest::RestartWithJob(URLRequestJob *job) { |
618 DCHECK(job->request() == this); | 618 DCHECK(job->request() == this); |
619 PrepareToRestart(); | 619 PrepareToRestart(); |
620 StartJob(job); | 620 StartJob(job); |
621 } | 621 } |
622 | 622 |
623 void URLRequest::Cancel() { | 623 void URLRequest::Cancel() { |
624 DoCancel(ERR_ABORTED, SSLInfo()); | 624 DoCancel(ERR_ABORTED, SSLInfo()); |
625 } | 625 } |
626 | 626 |
627 void URLRequest::CancelWithError(int error) { | 627 void URLRequest::CancelWithError(int error) { |
628 DoCancel(error, SSLInfo()); | 628 DoCancel(error, SSLInfo()); |
629 } | 629 } |
630 | 630 |
631 void URLRequest::CancelWithSSLError(int error, const SSLInfo& ssl_info) { | 631 void URLRequest::CancelWithSSLError(int error, const SSLInfo& ssl_info) { |
632 // This should only be called on a started request. | 632 // This should only be called on a started request. |
633 if (!is_pending_ || !job_ || job_->has_response_started()) { | 633 if (!is_pending_ || !job_.get() || job_->has_response_started()) { |
634 NOTREACHED(); | 634 NOTREACHED(); |
635 return; | 635 return; |
636 } | 636 } |
637 DoCancel(error, ssl_info); | 637 DoCancel(error, ssl_info); |
638 } | 638 } |
639 | 639 |
640 void URLRequest::DoCancel(int error, const SSLInfo& ssl_info) { | 640 void URLRequest::DoCancel(int error, const SSLInfo& ssl_info) { |
641 DCHECK(error < 0); | 641 DCHECK(error < 0); |
642 | 642 |
643 // If the URL request already has an error status, then canceling is a no-op. | 643 // If the URL request already has an error status, then canceling is a no-op. |
644 // Plus, we don't want to change the error status once it has been set. | 644 // Plus, we don't want to change the error status once it has been set. |
645 if (status_.is_success()) { | 645 if (status_.is_success()) { |
646 status_.set_status(URLRequestStatus::CANCELED); | 646 status_.set_status(URLRequestStatus::CANCELED); |
647 status_.set_error(error); | 647 status_.set_error(error); |
648 response_info_.ssl_info = ssl_info; | 648 response_info_.ssl_info = ssl_info; |
649 | 649 |
650 // If the request hasn't already been completed, log a cancellation event. | 650 // If the request hasn't already been completed, log a cancellation event. |
651 if (!has_notified_completion_) { | 651 if (!has_notified_completion_) { |
652 // Don't log an error code on ERR_ABORTED, since that's redundant. | 652 // Don't log an error code on ERR_ABORTED, since that's redundant. |
653 net_log_.AddEventWithNetErrorCode(NetLog::TYPE_CANCELLED, | 653 net_log_.AddEventWithNetErrorCode(NetLog::TYPE_CANCELLED, |
654 error == ERR_ABORTED ? OK : error); | 654 error == ERR_ABORTED ? OK : error); |
655 } | 655 } |
656 } | 656 } |
657 | 657 |
658 if (is_pending_ && job_) | 658 if (is_pending_ && job_.get()) |
659 job_->Kill(); | 659 job_->Kill(); |
660 | 660 |
661 // We need to notify about the end of this job here synchronously. The | 661 // We need to notify about the end of this job here synchronously. The |
662 // Job sends an asynchronous notification but by the time this is processed, | 662 // Job sends an asynchronous notification but by the time this is processed, |
663 // our |context_| is NULL. | 663 // our |context_| is NULL. |
664 NotifyRequestCompleted(); | 664 NotifyRequestCompleted(); |
665 | 665 |
666 // The Job will call our NotifyDone method asynchronously. This is done so | 666 // The Job will call our NotifyDone method asynchronously. This is done so |
667 // that the Delegate implementation can call Cancel without having to worry | 667 // that the Delegate implementation can call Cancel without having to worry |
668 // about being called recursively. | 668 // about being called recursively. |
669 } | 669 } |
670 | 670 |
671 bool URLRequest::Read(IOBuffer* dest, int dest_size, int* bytes_read) { | 671 bool URLRequest::Read(IOBuffer* dest, int dest_size, int* bytes_read) { |
672 DCHECK(job_); | 672 DCHECK(job_.get()); |
673 DCHECK(bytes_read); | 673 DCHECK(bytes_read); |
674 *bytes_read = 0; | 674 *bytes_read = 0; |
675 | 675 |
676 // This handles a cancel that happens while paused. | 676 // This handles a cancel that happens while paused. |
677 // TODO(ahendrickson): DCHECK() that it is not done after | 677 // TODO(ahendrickson): DCHECK() that it is not done after |
678 // http://crbug.com/115705 is fixed. | 678 // http://crbug.com/115705 is fixed. |
679 if (job_->is_done()) | 679 if (job_->is_done()) |
680 return false; | 680 return false; |
681 | 681 |
682 if (dest_size == 0) { | 682 if (dest_size == 0) { |
683 // Caller is not too bright. I guess we've done what they asked. | 683 // Caller is not too bright. I guess we've done what they asked. |
684 return true; | 684 return true; |
685 } | 685 } |
686 | 686 |
687 // Once the request fails or is cancelled, read will just return 0 bytes | 687 // Once the request fails or is cancelled, read will just return 0 bytes |
688 // to indicate end of stream. | 688 // to indicate end of stream. |
689 if (!status_.is_success()) { | 689 if (!status_.is_success()) { |
690 return true; | 690 return true; |
691 } | 691 } |
692 | 692 |
693 bool rv = job_->Read(dest, dest_size, bytes_read); | 693 bool rv = job_->Read(dest, dest_size, bytes_read); |
694 // If rv is false, the status cannot be success. | 694 // If rv is false, the status cannot be success. |
695 DCHECK(rv || status_.status() != URLRequestStatus::SUCCESS); | 695 DCHECK(rv || status_.status() != URLRequestStatus::SUCCESS); |
696 if (rv && *bytes_read <= 0 && status_.is_success()) | 696 if (rv && *bytes_read <= 0 && status_.is_success()) |
697 NotifyRequestCompleted(); | 697 NotifyRequestCompleted(); |
698 return rv; | 698 return rv; |
699 } | 699 } |
700 | 700 |
701 void URLRequest::StopCaching() { | 701 void URLRequest::StopCaching() { |
702 DCHECK(job_); | 702 DCHECK(job_.get()); |
703 job_->StopCaching(); | 703 job_->StopCaching(); |
704 } | 704 } |
705 | 705 |
706 void URLRequest::NotifyReceivedRedirect(const GURL& location, | 706 void URLRequest::NotifyReceivedRedirect(const GURL& location, |
707 bool* defer_redirect) { | 707 bool* defer_redirect) { |
708 is_redirecting_ = true; | 708 is_redirecting_ = true; |
709 | 709 |
710 URLRequestJob* job = | 710 URLRequestJob* job = |
711 URLRequestJobManager::GetInstance()->MaybeInterceptRedirect( | 711 URLRequestJobManager::GetInstance()->MaybeInterceptRedirect( |
712 this, network_delegate_, location); | 712 this, network_delegate_, location); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
744 NotifyRequestCompleted(); | 744 NotifyRequestCompleted(); |
745 | 745 |
746 delegate_->OnResponseStarted(this); | 746 delegate_->OnResponseStarted(this); |
747 // Nothing may appear below this line as OnResponseStarted may delete | 747 // Nothing may appear below this line as OnResponseStarted may delete |
748 // |this|. | 748 // |this|. |
749 } | 749 } |
750 } | 750 } |
751 } | 751 } |
752 | 752 |
753 void URLRequest::FollowDeferredRedirect() { | 753 void URLRequest::FollowDeferredRedirect() { |
754 CHECK(job_); | 754 CHECK(job_.get()); |
755 CHECK(status_.is_success()); | 755 CHECK(status_.is_success()); |
756 | 756 |
757 job_->FollowDeferredRedirect(); | 757 job_->FollowDeferredRedirect(); |
758 } | 758 } |
759 | 759 |
760 void URLRequest::SetAuth(const AuthCredentials& credentials) { | 760 void URLRequest::SetAuth(const AuthCredentials& credentials) { |
761 DCHECK(job_); | 761 DCHECK(job_.get()); |
762 DCHECK(job_->NeedsAuth()); | 762 DCHECK(job_->NeedsAuth()); |
763 | 763 |
764 job_->SetAuth(credentials); | 764 job_->SetAuth(credentials); |
765 } | 765 } |
766 | 766 |
767 void URLRequest::CancelAuth() { | 767 void URLRequest::CancelAuth() { |
768 DCHECK(job_); | 768 DCHECK(job_.get()); |
769 DCHECK(job_->NeedsAuth()); | 769 DCHECK(job_->NeedsAuth()); |
770 | 770 |
771 job_->CancelAuth(); | 771 job_->CancelAuth(); |
772 } | 772 } |
773 | 773 |
774 void URLRequest::ContinueWithCertificate(X509Certificate* client_cert) { | 774 void URLRequest::ContinueWithCertificate(X509Certificate* client_cert) { |
775 DCHECK(job_); | 775 DCHECK(job_.get()); |
776 | 776 |
777 job_->ContinueWithCertificate(client_cert); | 777 job_->ContinueWithCertificate(client_cert); |
778 } | 778 } |
779 | 779 |
780 void URLRequest::ContinueDespiteLastError() { | 780 void URLRequest::ContinueDespiteLastError() { |
781 DCHECK(job_); | 781 DCHECK(job_.get()); |
782 | 782 |
783 job_->ContinueDespiteLastError(); | 783 job_->ContinueDespiteLastError(); |
784 } | 784 } |
785 | 785 |
786 void URLRequest::PrepareToRestart() { | 786 void URLRequest::PrepareToRestart() { |
787 DCHECK(job_); | 787 DCHECK(job_.get()); |
788 | 788 |
789 // Close the current URL_REQUEST_START_JOB, since we will be starting a new | 789 // Close the current URL_REQUEST_START_JOB, since we will be starting a new |
790 // one. | 790 // one. |
791 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_START_JOB); | 791 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_START_JOB); |
792 | 792 |
793 OrphanJob(); | 793 OrphanJob(); |
794 | 794 |
795 response_info_ = HttpResponseInfo(); | 795 response_info_ = HttpResponseInfo(); |
796 response_info_.request_time = base::Time::Now(); | 796 response_info_.request_time = base::Time::Now(); |
797 | 797 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
880 Start(); | 880 Start(); |
881 return OK; | 881 return OK; |
882 } | 882 } |
883 | 883 |
884 const URLRequestContext* URLRequest::context() const { | 884 const URLRequestContext* URLRequest::context() const { |
885 return context_; | 885 return context_; |
886 } | 886 } |
887 | 887 |
888 int64 URLRequest::GetExpectedContentSize() const { | 888 int64 URLRequest::GetExpectedContentSize() const { |
889 int64 expected_content_size = -1; | 889 int64 expected_content_size = -1; |
890 if (job_) | 890 if (job_.get()) |
891 expected_content_size = job_->expected_content_size(); | 891 expected_content_size = job_->expected_content_size(); |
892 | 892 |
893 return expected_content_size; | 893 return expected_content_size; |
894 } | 894 } |
895 | 895 |
896 void URLRequest::SetPriority(RequestPriority priority) { | 896 void URLRequest::SetPriority(RequestPriority priority) { |
897 DCHECK_GE(priority, MINIMUM_PRIORITY); | 897 DCHECK_GE(priority, MINIMUM_PRIORITY); |
898 DCHECK_LT(priority, NUM_PRIORITIES); | 898 DCHECK_LT(priority, NUM_PRIORITIES); |
899 if (priority_ == priority) | 899 if (priority_ == priority) |
900 return; | 900 return; |
901 | 901 |
902 priority_ = priority; | 902 priority_ = priority; |
903 if (job_) { | 903 if (job_.get()) { |
904 net_log_.AddEvent(NetLog::TYPE_URL_REQUEST_SET_PRIORITY, | 904 net_log_.AddEvent(NetLog::TYPE_URL_REQUEST_SET_PRIORITY, |
905 NetLog::IntegerCallback("priority", priority_)); | 905 NetLog::IntegerCallback("priority", priority_)); |
906 job_->SetPriority(priority_); | 906 job_->SetPriority(priority_); |
907 } | 907 } |
908 } | 908 } |
909 | 909 |
910 bool URLRequest::GetHSTSRedirect(GURL* redirect_url) const { | 910 bool URLRequest::GetHSTSRedirect(GURL* redirect_url) const { |
911 const GURL& url = this->url(); | 911 const GURL& url = this->url(); |
912 if (!url.SchemeIs("http")) | 912 if (!url.SchemeIs("http")) |
913 return false; | 913 return false; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 if (delegate_) | 1038 if (delegate_) |
1039 delegate_->OnReadCompleted(this, bytes_read); | 1039 delegate_->OnReadCompleted(this, bytes_read); |
1040 | 1040 |
1041 // Nothing below this line as OnReadCompleted may delete |this|. | 1041 // Nothing below this line as OnReadCompleted may delete |this|. |
1042 } | 1042 } |
1043 | 1043 |
1044 void URLRequest::OnHeadersComplete() { | 1044 void URLRequest::OnHeadersComplete() { |
1045 // Cache load timing information now, as information will be lost once the | 1045 // Cache load timing information now, as information will be lost once the |
1046 // socket is closed and the ClientSocketHandle is Reset, which will happen | 1046 // socket is closed and the ClientSocketHandle is Reset, which will happen |
1047 // once the body is complete. The start times should already be populated. | 1047 // once the body is complete. The start times should already be populated. |
1048 if (job_) { | 1048 if (job_.get()) { |
1049 // Keep a copy of the two times the URLRequest sets. | 1049 // Keep a copy of the two times the URLRequest sets. |
1050 base::TimeTicks request_start = load_timing_info_.request_start; | 1050 base::TimeTicks request_start = load_timing_info_.request_start; |
1051 base::Time request_start_time = load_timing_info_.request_start_time; | 1051 base::Time request_start_time = load_timing_info_.request_start_time; |
1052 | 1052 |
1053 // Clear load times. Shouldn't be neded, but gives the GetLoadTimingInfo a | 1053 // Clear load times. Shouldn't be neded, but gives the GetLoadTimingInfo a |
1054 // consistent place to start from. | 1054 // consistent place to start from. |
1055 load_timing_info_ = LoadTimingInfo(); | 1055 load_timing_info_ = LoadTimingInfo(); |
1056 job_->GetLoadTimingInfo(&load_timing_info_); | 1056 job_->GetLoadTimingInfo(&load_timing_info_); |
1057 | 1057 |
1058 load_timing_info_.request_start = request_start; | 1058 load_timing_info_.request_start = request_start; |
1059 load_timing_info_.request_start_time = request_start_time; | 1059 load_timing_info_.request_start_time = request_start_time; |
1060 | 1060 |
1061 ConvertRealLoadTimesToBlockingTimes(&load_timing_info_); | 1061 ConvertRealLoadTimesToBlockingTimes(&load_timing_info_); |
1062 } | 1062 } |
1063 } | 1063 } |
1064 | 1064 |
1065 void URLRequest::NotifyRequestCompleted() { | 1065 void URLRequest::NotifyRequestCompleted() { |
1066 // TODO(battre): Get rid of this check, according to willchan it should | 1066 // TODO(battre): Get rid of this check, according to willchan it should |
1067 // not be needed. | 1067 // not be needed. |
1068 if (has_notified_completion_) | 1068 if (has_notified_completion_) |
1069 return; | 1069 return; |
1070 | 1070 |
1071 is_pending_ = false; | 1071 is_pending_ = false; |
1072 is_redirecting_ = false; | 1072 is_redirecting_ = false; |
1073 has_notified_completion_ = true; | 1073 has_notified_completion_ = true; |
1074 if (network_delegate_) | 1074 if (network_delegate_) |
1075 network_delegate_->NotifyCompleted(this, job_ != NULL); | 1075 network_delegate_->NotifyCompleted(this, job_.get() != NULL); |
1076 } | 1076 } |
1077 | 1077 |
1078 void URLRequest::SetBlockedOnDelegate() { | 1078 void URLRequest::SetBlockedOnDelegate() { |
1079 blocked_on_delegate_ = true; | 1079 blocked_on_delegate_ = true; |
1080 if (!load_state_param_.empty()) { | 1080 if (!load_state_param_.empty()) { |
1081 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, | 1081 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, |
1082 NetLog::StringCallback("delegate", &load_state_param_)); | 1082 NetLog::StringCallback("delegate", &load_state_param_)); |
1083 } else { | 1083 } else { |
1084 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE); | 1084 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE); |
1085 } | 1085 } |
(...skipping 12 matching lines...) Expand all Loading... |
1098 new base::debug::StackTrace(NULL, 0); | 1098 new base::debug::StackTrace(NULL, 0); |
1099 *stack_trace_copy = stack_trace; | 1099 *stack_trace_copy = stack_trace; |
1100 stack_trace_.reset(stack_trace_copy); | 1100 stack_trace_.reset(stack_trace_copy); |
1101 } | 1101 } |
1102 | 1102 |
1103 const base::debug::StackTrace* URLRequest::stack_trace() const { | 1103 const base::debug::StackTrace* URLRequest::stack_trace() const { |
1104 return stack_trace_.get(); | 1104 return stack_trace_.get(); |
1105 } | 1105 } |
1106 | 1106 |
1107 } // namespace net | 1107 } // namespace net |
OLD | NEW |