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

Side by Side Diff: content/common/net/url_fetcher_impl.cc

Issue 9572001: Do cookie checks in NetworkDelegate instead of the URLRequest::Delegate. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: clang fix Created 8 years, 9 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 "content/common/net/url_fetcher_impl.h" 5 #include "content/common/net/url_fetcher_impl.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/file_util_proxy.h" 12 #include "base/file_util_proxy.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h" 15 #include "base/memory/weak_ptr.h"
16 #include "base/message_loop_proxy.h" 16 #include "base/message_loop_proxy.h"
17 #include "base/metrics/histogram.h" 17 #include "base/metrics/histogram.h"
18 #include "base/platform_file.h" 18 #include "base/platform_file.h"
19 #include "base/stl_util.h" 19 #include "base/stl_util.h"
20 #include "base/string_util.h" 20 #include "base/string_util.h"
21 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
22 #include "base/timer.h" 22 #include "base/timer.h"
23 #include "content/public/common/content_url_request_user_data.h"
23 #include "content/public/common/url_fetcher_delegate.h" 24 #include "content/public/common/url_fetcher_delegate.h"
24 #include "content/public/common/url_fetcher_factory.h" 25 #include "content/public/common/url_fetcher_factory.h"
25 #include "googleurl/src/gurl.h" 26 #include "googleurl/src/gurl.h"
26 #include "net/base/host_port_pair.h" 27 #include "net/base/host_port_pair.h"
27 #include "net/base/io_buffer.h" 28 #include "net/base/io_buffer.h"
28 #include "net/base/load_flags.h" 29 #include "net/base/load_flags.h"
29 #include "net/base/net_errors.h" 30 #include "net/base/net_errors.h"
30 #include "net/http/http_request_headers.h" 31 #include "net/http/http_request_headers.h"
31 #include "net/http/http_response_headers.h" 32 #include "net/http/http_response_headers.h"
32 #include "net/url_request/url_request.h" 33 #include "net/url_request/url_request.h"
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 // on which file access happens. 241 // on which file access happens.
241 scoped_ptr<net::URLRequest> request_; // The actual request this wraps 242 scoped_ptr<net::URLRequest> request_; // The actual request this wraps
242 int load_flags_; // Flags for the load operation 243 int load_flags_; // Flags for the load operation
243 int response_code_; // HTTP status code for the request 244 int response_code_; // HTTP status code for the request
244 std::string data_; // Results of the request, when we are 245 std::string data_; // Results of the request, when we are
245 // storing the response as a string. 246 // storing the response as a string.
246 scoped_refptr<net::IOBuffer> buffer_; 247 scoped_refptr<net::IOBuffer> buffer_;
247 // Read buffer 248 // Read buffer
248 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 249 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
249 // Cookie/cache info for the request 250 // Cookie/cache info for the request
251 scoped_ptr<content::ContentURLRequestUserData> content_url_request_user_data_;
250 net::ResponseCookies cookies_; // Response cookies 252 net::ResponseCookies cookies_; // Response cookies
251 net::HttpRequestHeaders extra_request_headers_; 253 net::HttpRequestHeaders extra_request_headers_;
252 scoped_refptr<net::HttpResponseHeaders> response_headers_; 254 scoped_refptr<net::HttpResponseHeaders> response_headers_;
253 bool was_fetched_via_proxy_; 255 bool was_fetched_via_proxy_;
254 net::HostPortPair socket_address_; 256 net::HostPortPair socket_address_;
255 257
256 std::string upload_content_; // HTTP POST payload 258 std::string upload_content_; // HTTP POST payload
257 std::string upload_content_type_; // MIME type of POST payload 259 std::string upload_content_type_; // MIME type of POST payload
258 std::string referrer_; // HTTP Referer header value 260 std::string referrer_; // HTTP Referer header value
259 bool is_chunked_upload_; // True if using chunked transfer encoding 261 bool is_chunked_upload_; // True if using chunked transfer encoding
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 563
562 URLFetcherImpl::Core::~Core() { 564 URLFetcherImpl::Core::~Core() {
563 // |request_| should be NULL. If not, it's unsafe to delete it here since we 565 // |request_| should be NULL. If not, it's unsafe to delete it here since we
564 // may not be on the IO thread. 566 // may not be on the IO thread.
565 DCHECK(!request_.get()); 567 DCHECK(!request_.get());
566 } 568 }
567 569
568 void URLFetcherImpl::Core::Start() { 570 void URLFetcherImpl::Core::Start() {
569 DCHECK(delegate_loop_proxy_); 571 DCHECK(delegate_loop_proxy_);
570 DCHECK(request_context_getter_) << "We need an URLRequestContext!"; 572 DCHECK(request_context_getter_) << "We need an URLRequestContext!";
573 DCHECK(content_url_request_user_data_.get())
574 << "We need a ContentURLRequestUserData!";
571 if (io_message_loop_proxy_) { 575 if (io_message_loop_proxy_) {
572 DCHECK_EQ(io_message_loop_proxy_, 576 DCHECK_EQ(io_message_loop_proxy_,
573 request_context_getter_->GetIOMessageLoopProxy()); 577 request_context_getter_->GetIOMessageLoopProxy());
574 } else { 578 } else {
575 io_message_loop_proxy_ = request_context_getter_->GetIOMessageLoopProxy(); 579 io_message_loop_proxy_ = request_context_getter_->GetIOMessageLoopProxy();
576 } 580 }
577 DCHECK(io_message_loop_proxy_.get()) << "We need an IO message loop proxy"; 581 DCHECK(io_message_loop_proxy_.get()) << "We need an IO message loop proxy";
578 582
579 io_message_loop_proxy_->PostTask( 583 io_message_loop_proxy_->PostTask(
580 FROM_HERE, base::Bind(&Core::StartOnIOThread, this)); 584 FROM_HERE, base::Bind(&Core::StartOnIOThread, this));
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 760
757 if (automatically_retry_on_5xx_ && 761 if (automatically_retry_on_5xx_ &&
758 num_retries_ <= max_retries_) { 762 num_retries_ <= max_retries_) {
759 StartOnIOThread(); 763 StartOnIOThread();
760 return; 764 return;
761 } 765 }
762 } else { 766 } else {
763 backoff_delay = base::TimeDelta(); 767 backoff_delay = base::TimeDelta();
764 } 768 }
765 request_context_getter_ = NULL; 769 request_context_getter_ = NULL;
770 content_url_request_user_data_.reset(NULL);
766 bool posted = delegate_loop_proxy_->PostTask( 771 bool posted = delegate_loop_proxy_->PostTask(
767 FROM_HERE, base::Bind(&Core::OnCompletedURLRequest, this, backoff_delay)); 772 FROM_HERE, base::Bind(&Core::OnCompletedURLRequest, this, backoff_delay));
768 773
769 // If the delegate message loop does not exist any more, then the delegate 774 // If the delegate message loop does not exist any more, then the delegate
770 // should be gone too. 775 // should be gone too.
771 DCHECK(posted || !delegate_); 776 DCHECK(posted || !delegate_);
772 } 777 }
773 778
774 void URLFetcherImpl::Core::ReadResponse() { 779 void URLFetcherImpl::Core::ReadResponse() {
775 // Some servers may treat HEAD requests as GET requests. To free up the 780 // Some servers may treat HEAD requests as GET requests. To free up the
(...skipping 13 matching lines...) Expand all
789 void URLFetcherImpl::Core::StartURLRequest() { 794 void URLFetcherImpl::Core::StartURLRequest() {
790 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); 795 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread());
791 796
792 if (was_cancelled_) { 797 if (was_cancelled_) {
793 // Since StartURLRequest() is posted as a *delayed* task, it may 798 // Since StartURLRequest() is posted as a *delayed* task, it may
794 // run after the URLFetcher was already stopped. 799 // run after the URLFetcher was already stopped.
795 return; 800 return;
796 } 801 }
797 802
798 DCHECK(request_context_getter_); 803 DCHECK(request_context_getter_);
804 DCHECK(content_url_request_user_data_.get());
799 DCHECK(!request_.get()); 805 DCHECK(!request_.get());
800 806
801 g_registry.Get().AddURLFetcherCore(this); 807 g_registry.Get().AddURLFetcherCore(this);
802 current_response_bytes_ = 0; 808 current_response_bytes_ = 0;
803 request_.reset(new net::URLRequest(original_url_, this)); 809 request_.reset(new net::URLRequest(original_url_, this));
804 int flags = request_->load_flags() | load_flags_; 810 int flags = request_->load_flags() | load_flags_;
805 if (!g_interception_enabled) { 811 if (!g_interception_enabled) {
806 flags = flags | net::LOAD_DISABLE_INTERCEPT; 812 flags = flags | net::LOAD_DISABLE_INTERCEPT;
807 } 813 }
808 if (is_chunked_upload_) 814 if (is_chunked_upload_)
809 request_->EnableChunkedUpload(); 815 request_->EnableChunkedUpload();
810 request_->set_load_flags(flags); 816 request_->set_load_flags(flags);
811 request_->set_context(request_context_getter_->GetURLRequestContext()); 817 request_->set_context(request_context_getter_->GetURLRequestContext());
812 request_->set_referrer(referrer_); 818 request_->set_referrer(referrer_);
819 request_->SetUserData(
820 content::ContentURLRequestUserData::kUserDataKey,
821 new content::ContentURLRequestUserData(
822 content_url_request_user_data_->process_id(),
823 content_url_request_user_data_->routing_id()));
813 824
814 switch (request_type_) { 825 switch (request_type_) {
815 case GET: 826 case GET:
816 break; 827 break;
817 828
818 case POST: 829 case POST:
819 case PUT: 830 case PUT:
820 DCHECK(!upload_content_.empty() || is_chunked_upload_); 831 DCHECK(!upload_content_.empty() || is_chunked_upload_);
821 DCHECK(!upload_content_type_.empty()); 832 DCHECK(!upload_content_type_.empty());
822 833
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 894
884 if (request_.get()) { 895 if (request_.get()) {
885 request_->Cancel(); 896 request_->Cancel();
886 ReleaseRequest(); 897 ReleaseRequest();
887 } 898 }
888 // Release the reference to the request context. There could be multiple 899 // Release the reference to the request context. There could be multiple
889 // references to URLFetcher::Core at this point so it may take a while to 900 // references to URLFetcher::Core at this point so it may take a while to
890 // delete the object, but we cannot delay the destruction of the request 901 // delete the object, but we cannot delay the destruction of the request
891 // context. 902 // context.
892 request_context_getter_ = NULL; 903 request_context_getter_ = NULL;
904 content_url_request_user_data_.reset(NULL);
893 was_cancelled_ = true; 905 was_cancelled_ = true;
894 temp_file_writer_.reset(); 906 temp_file_writer_.reset();
895 } 907 }
896 908
897 void URLFetcherImpl::Core::OnCompletedURLRequest( 909 void URLFetcherImpl::Core::OnCompletedURLRequest(
898 base::TimeDelta backoff_delay) { 910 base::TimeDelta backoff_delay) {
899 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread()); 911 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread());
900 912
901 // Save the status and backoff_delay so that delegates can read it. 913 // Save the status and backoff_delay so that delegates can read it.
902 if (delegate_) { 914 if (delegate_) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 void URLFetcherImpl::GetExtraRequestHeaders(net::HttpRequestHeaders* headers) { 1028 void URLFetcherImpl::GetExtraRequestHeaders(net::HttpRequestHeaders* headers) {
1017 headers->CopyFrom(core_->extra_request_headers_); 1029 headers->CopyFrom(core_->extra_request_headers_);
1018 } 1030 }
1019 1031
1020 void URLFetcherImpl::SetRequestContext( 1032 void URLFetcherImpl::SetRequestContext(
1021 net::URLRequestContextGetter* request_context_getter) { 1033 net::URLRequestContextGetter* request_context_getter) {
1022 DCHECK(!core_->request_context_getter_); 1034 DCHECK(!core_->request_context_getter_);
1023 core_->request_context_getter_ = request_context_getter; 1035 core_->request_context_getter_ = request_context_getter;
1024 } 1036 }
1025 1037
1038 void URLFetcherImpl::SetContentURLRequestUserData(
1039 content::ContentURLRequestUserData* user_data) {
1040 DCHECK(!core_->content_url_request_user_data_.get());
1041 core_->content_url_request_user_data_.reset(user_data);
1042 }
1043
1026 void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry) { 1044 void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry) {
1027 core_->automatically_retry_on_5xx_ = retry; 1045 core_->automatically_retry_on_5xx_ = retry;
1028 } 1046 }
1029 1047
1030 void URLFetcherImpl::SetMaxRetries(int max_retries) { 1048 void URLFetcherImpl::SetMaxRetries(int max_retries) {
1031 core_->max_retries_ = max_retries; 1049 core_->max_retries_ = max_retries;
1032 } 1050 }
1033 1051
1034 int URLFetcherImpl::GetMaxRetries() const { 1052 int URLFetcherImpl::GetMaxRetries() const {
1035 return core_->max_retries_; 1053 return core_->max_retries_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 } 1085 }
1068 1086
1069 void URLFetcherImpl::set_was_fetched_via_proxy(bool flag) { 1087 void URLFetcherImpl::set_was_fetched_via_proxy(bool flag) {
1070 core_->was_fetched_via_proxy_ = flag; 1088 core_->was_fetched_via_proxy_ = flag;
1071 } 1089 }
1072 1090
1073 void URLFetcherImpl::Start() { 1091 void URLFetcherImpl::Start() {
1074 core_->Start(); 1092 core_->Start();
1075 } 1093 }
1076 1094
1077 void URLFetcherImpl::StartWithRequestContextGetter( 1095 void URLFetcherImpl::StartWithRequestContextGetterAndUserData(
1078 net::URLRequestContextGetter* request_context_getter) { 1096 net::URLRequestContextGetter* request_context_getter,
1097 content::ContentURLRequestUserData* user_data) {
1079 SetRequestContext(request_context_getter); 1098 SetRequestContext(request_context_getter);
1099 SetContentURLRequestUserData(user_data);
1080 core_->Start(); 1100 core_->Start();
1081 } 1101 }
1082 1102
1083 const GURL& URLFetcherImpl::GetOriginalURL() const { 1103 const GURL& URLFetcherImpl::GetOriginalURL() const {
1084 return core_->original_url_; 1104 return core_->original_url_;
1085 } 1105 }
1086 1106
1087 const GURL& URLFetcherImpl::GetURL() const { 1107 const GURL& URLFetcherImpl::GetURL() const {
1088 return core_->url_; 1108 return core_->url_;
1089 } 1109 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 1184
1165 // static 1185 // static
1166 content::URLFetcherFactory* URLFetcherImpl::factory() { 1186 content::URLFetcherFactory* URLFetcherImpl::factory() {
1167 return g_factory; 1187 return g_factory;
1168 } 1188 }
1169 1189
1170 // static 1190 // static
1171 void URLFetcherImpl::set_factory(content::URLFetcherFactory* factory) { 1191 void URLFetcherImpl::set_factory(content::URLFetcherFactory* factory) {
1172 g_factory = factory; 1192 g_factory = factory;
1173 } 1193 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698