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

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

Issue 10830124: Removed checks that verify URLRequest has a Context (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
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 592 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 603
604 URLRequestJob* job = 604 URLRequestJob* job =
605 URLRequestJobManager::GetInstance()->MaybeInterceptResponse(this); 605 URLRequestJobManager::GetInstance()->MaybeInterceptResponse(this);
606 if (job) { 606 if (job) {
607 RestartWithJob(job); 607 RestartWithJob(job);
608 } else { 608 } else {
609 if (delegate_) { 609 if (delegate_) {
610 // In some cases (e.g. an event was canceled), we might have sent the 610 // In some cases (e.g. an event was canceled), we might have sent the
611 // completion event and receive a NotifyResponseStarted() later. 611 // completion event and receive a NotifyResponseStarted() later.
612 if (!has_notified_completion_ && status_.is_success()) { 612 if (!has_notified_completion_ && status_.is_success()) {
613 if (context_ && context_->network_delegate()) 613 if (context_->network_delegate())
614 context_->network_delegate()->NotifyResponseStarted(this); 614 context_->network_delegate()->NotifyResponseStarted(this);
615 } 615 }
616 616
617 // Notify in case the entire URL Request has been finished. 617 // Notify in case the entire URL Request has been finished.
618 if (!has_notified_completion_ && !status_.is_success()) 618 if (!has_notified_completion_ && !status_.is_success())
619 NotifyRequestCompleted(); 619 NotifyRequestCompleted();
620 620
621 delegate_->OnResponseStarted(this); 621 delegate_->OnResponseStarted(this);
622 // Nothing may appear below this line as OnResponseStarted may delete 622 // Nothing may appear below this line as OnResponseStarted may delete
623 // |this|. 623 // |this|.
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 job_ = NULL; 687 job_ = NULL;
688 } 688 }
689 689
690 int URLRequest::Redirect(const GURL& location, int http_status_code) { 690 int URLRequest::Redirect(const GURL& location, int http_status_code) {
691 if (net_log_.IsLoggingAllEvents()) { 691 if (net_log_.IsLoggingAllEvents()) {
692 net_log_.AddEvent( 692 net_log_.AddEvent(
693 NetLog::TYPE_URL_REQUEST_REDIRECTED, 693 NetLog::TYPE_URL_REQUEST_REDIRECTED,
694 NetLog::StringCallback("location", &location.possibly_invalid_spec())); 694 NetLog::StringCallback("location", &location.possibly_invalid_spec()));
695 } 695 }
696 696
697 if (context_ && context_->network_delegate()) 697 if (context_->network_delegate())
698 context_->network_delegate()->NotifyBeforeRedirect(this, location); 698 context_->network_delegate()->NotifyBeforeRedirect(this, location);
699 699
700 if (redirect_limit_ <= 0) { 700 if (redirect_limit_ <= 0) {
701 DVLOG(1) << "disallowing redirect: exceeds limit"; 701 DVLOG(1) << "disallowing redirect: exceeds limit";
702 return ERR_TOO_MANY_REDIRECTS; 702 return ERR_TOO_MANY_REDIRECTS;
703 } 703 }
704 704
705 if (!location.is_valid()) 705 if (!location.is_valid())
706 return ERR_INVALID_URL; 706 return ERR_INVALID_URL;
707 707
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
781 *redirect_url = url.ReplaceComponents(replacements); 781 *redirect_url = url.ReplaceComponents(replacements);
782 return true; 782 return true;
783 } 783 }
784 return false; 784 return false;
785 } 785 }
786 786
787 void URLRequest::NotifyAuthRequired(AuthChallengeInfo* auth_info) { 787 void URLRequest::NotifyAuthRequired(AuthChallengeInfo* auth_info) {
788 NetworkDelegate::AuthRequiredResponse rv = 788 NetworkDelegate::AuthRequiredResponse rv =
789 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION; 789 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION;
790 auth_info_ = auth_info; 790 auth_info_ = auth_info;
791 if (context_ && context_->network_delegate()) { 791 if (context_->network_delegate()) {
792 rv = context_->network_delegate()->NotifyAuthRequired( 792 rv = context_->network_delegate()->NotifyAuthRequired(
793 this, 793 this,
794 *auth_info, 794 *auth_info,
795 base::Bind(&URLRequest::NotifyAuthRequiredComplete, 795 base::Bind(&URLRequest::NotifyAuthRequiredComplete,
796 base::Unretained(this)), 796 base::Unretained(this)),
797 &auth_credentials_); 797 &auth_credentials_);
798 } 798 }
799 799
800 if (rv == NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING) { 800 if (rv == NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING) {
801 SetBlockedOnDelegate(); 801 SetBlockedOnDelegate();
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 } 848 }
849 849
850 void URLRequest::NotifySSLCertificateError(const SSLInfo& ssl_info, 850 void URLRequest::NotifySSLCertificateError(const SSLInfo& ssl_info,
851 bool fatal) { 851 bool fatal) {
852 if (delegate_) 852 if (delegate_)
853 delegate_->OnSSLCertificateError(this, ssl_info, fatal); 853 delegate_->OnSSLCertificateError(this, ssl_info, fatal);
854 } 854 }
855 855
856 bool URLRequest::CanGetCookies(const CookieList& cookie_list) const { 856 bool URLRequest::CanGetCookies(const CookieList& cookie_list) const {
857 DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES)); 857 DCHECK(!(load_flags_ & LOAD_DO_NOT_SEND_COOKIES));
858 if (context_ && context_->network_delegate()) { 858 if (context_->network_delegate()) {
859 return context_->network_delegate()->CanGetCookies(*this, 859 return context_->network_delegate()->CanGetCookies(*this,
860 cookie_list); 860 cookie_list);
861 } 861 }
862 return g_default_can_use_cookies; 862 return g_default_can_use_cookies;
863 } 863 }
864 864
865 bool URLRequest::CanSetCookie(const std::string& cookie_line, 865 bool URLRequest::CanSetCookie(const std::string& cookie_line,
866 CookieOptions* options) const { 866 CookieOptions* options) const {
867 DCHECK(!(load_flags_ & LOAD_DO_NOT_SAVE_COOKIES)); 867 DCHECK(!(load_flags_ & LOAD_DO_NOT_SAVE_COOKIES));
868 if (context_ && context_->network_delegate()) { 868 if (context_->network_delegate()) {
869 return context_->network_delegate()->CanSetCookie(*this, 869 return context_->network_delegate()->CanSetCookie(*this,
870 cookie_line, 870 cookie_line,
871 options); 871 options);
872 } 872 }
873 return g_default_can_use_cookies; 873 return g_default_can_use_cookies;
874 } 874 }
875 875
876 876
877 void URLRequest::NotifyReadCompleted(int bytes_read) { 877 void URLRequest::NotifyReadCompleted(int bytes_read) {
878 // Notify in case the entire URL Request has been finished. 878 // Notify in case the entire URL Request has been finished.
879 if (bytes_read <= 0) 879 if (bytes_read <= 0)
880 NotifyRequestCompleted(); 880 NotifyRequestCompleted();
881 881
882 if (delegate_) 882 if (delegate_)
883 delegate_->OnReadCompleted(this, bytes_read); 883 delegate_->OnReadCompleted(this, bytes_read);
884 884
885 // Nothing below this line as OnReadCompleted may delete |this|. 885 // Nothing below this line as OnReadCompleted may delete |this|.
886 } 886 }
887 887
888 void URLRequest::NotifyRequestCompleted() { 888 void URLRequest::NotifyRequestCompleted() {
889 // TODO(battre): Get rid of this check, according to willchan it should 889 // TODO(battre): Get rid of this check, according to willchan it should
890 // not be needed. 890 // not be needed.
891 if (has_notified_completion_) 891 if (has_notified_completion_)
892 return; 892 return;
893 893
894 is_pending_ = false; 894 is_pending_ = false;
895 has_notified_completion_ = true; 895 has_notified_completion_ = true;
896 if (context_ && context_->network_delegate()) 896 if (context_->network_delegate())
897 context_->network_delegate()->NotifyCompleted(this, job_ != NULL); 897 context_->network_delegate()->NotifyCompleted(this, job_ != NULL);
898 } 898 }
899 899
900 void URLRequest::SetBlockedOnDelegate() { 900 void URLRequest::SetBlockedOnDelegate() {
901 blocked_on_delegate_ = true; 901 blocked_on_delegate_ = true;
902 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE); 902 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE);
903 } 903 }
904 904
905 void URLRequest::SetUnblockedOnDelegate() { 905 void URLRequest::SetUnblockedOnDelegate() {
906 if (!blocked_on_delegate_) 906 if (!blocked_on_delegate_)
907 return; 907 return;
908 blocked_on_delegate_ = false; 908 blocked_on_delegate_ = false;
909 load_state_param_.clear(); 909 load_state_param_.clear();
910 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE); 910 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE);
911 } 911 }
912 912
913 void URLRequest::set_stack_trace(const base::debug::StackTrace& stack_trace) { 913 void URLRequest::set_stack_trace(const base::debug::StackTrace& stack_trace) {
914 base::debug::StackTrace* stack_trace_copy = 914 base::debug::StackTrace* stack_trace_copy =
915 new base::debug::StackTrace(NULL, 0); 915 new base::debug::StackTrace(NULL, 0);
916 *stack_trace_copy = stack_trace; 916 *stack_trace_copy = stack_trace;
917 stack_trace_.reset(stack_trace_copy); 917 stack_trace_.reset(stack_trace_copy);
918 } 918 }
919 919
920 const base::debug::StackTrace* URLRequest::stack_trace() const { 920 const base::debug::StackTrace* URLRequest::stack_trace() const {
921 return stack_trace_.get(); 921 return stack_trace_.get();
922 } 922 }
923 923
924 } // namespace net 924 } // namespace net
OLDNEW
« no previous file with comments | « chrome/browser/automation/url_request_automation_job.cc ('k') | net/url_request/url_request_file_job.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698