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

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: patch for landing 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
« no previous file with comments | « content/common/net/url_fetcher_impl.h ('k') | content/common/net/url_fetcher_impl_unittest.cc » ('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 "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/common/net/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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // on which file access happens. 237 // on which file access happens.
237 scoped_ptr<net::URLRequest> request_; // The actual request this wraps 238 scoped_ptr<net::URLRequest> request_; // The actual request this wraps
238 int load_flags_; // Flags for the load operation 239 int load_flags_; // Flags for the load operation
239 int response_code_; // HTTP status code for the request 240 int response_code_; // HTTP status code for the request
240 std::string data_; // Results of the request, when we are 241 std::string data_; // Results of the request, when we are
241 // storing the response as a string. 242 // storing the response as a string.
242 scoped_refptr<net::IOBuffer> buffer_; 243 scoped_refptr<net::IOBuffer> buffer_;
243 // Read buffer 244 // Read buffer
244 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; 245 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
245 // Cookie/cache info for the request 246 // Cookie/cache info for the request
247 int render_process_id_; // The RenderView associated with the
248 int render_view_id_; // request
249 GURL first_party_for_cookies_; // The first party URL for the request
246 net::ResponseCookies cookies_; // Response cookies 250 net::ResponseCookies cookies_; // Response cookies
247 net::HttpRequestHeaders extra_request_headers_; 251 net::HttpRequestHeaders extra_request_headers_;
248 scoped_refptr<net::HttpResponseHeaders> response_headers_; 252 scoped_refptr<net::HttpResponseHeaders> response_headers_;
249 bool was_fetched_via_proxy_; 253 bool was_fetched_via_proxy_;
250 net::HostPortPair socket_address_; 254 net::HostPortPair socket_address_;
251 255
252 std::string upload_content_; // HTTP POST payload 256 std::string upload_content_; // HTTP POST payload
253 std::string upload_content_type_; // MIME type of POST payload 257 std::string upload_content_type_; // MIME type of POST payload
254 std::string referrer_; // HTTP Referer header value 258 std::string referrer_; // HTTP Referer header value
255 bool is_chunked_upload_; // True if using chunked transfer encoding 259 bool is_chunked_upload_; // True if using chunked transfer encoding
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 : fetcher_(fetcher), 540 : fetcher_(fetcher),
537 original_url_(original_url), 541 original_url_(original_url),
538 request_type_(request_type), 542 request_type_(request_type),
539 delegate_(d), 543 delegate_(d),
540 delegate_loop_proxy_( 544 delegate_loop_proxy_(
541 base::MessageLoopProxy::current()), 545 base::MessageLoopProxy::current()),
542 request_(NULL), 546 request_(NULL),
543 load_flags_(net::LOAD_NORMAL), 547 load_flags_(net::LOAD_NORMAL),
544 response_code_(RESPONSE_CODE_INVALID), 548 response_code_(RESPONSE_CODE_INVALID),
545 buffer_(new net::IOBuffer(kBufferSize)), 549 buffer_(new net::IOBuffer(kBufferSize)),
550 render_process_id_(-1),
551 render_view_id_(-1),
546 was_fetched_via_proxy_(false), 552 was_fetched_via_proxy_(false),
547 is_chunked_upload_(false), 553 is_chunked_upload_(false),
548 num_retries_(0), 554 num_retries_(0),
549 was_cancelled_(false), 555 was_cancelled_(false),
550 response_destination_(STRING), 556 response_destination_(STRING),
551 automatically_retry_on_5xx_(true), 557 automatically_retry_on_5xx_(true),
552 max_retries_(0), 558 max_retries_(0),
553 current_response_bytes_(0), 559 current_response_bytes_(0),
554 total_response_bytes_(-1) { 560 total_response_bytes_(-1) {
555 } 561 }
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
750 backoff_delay = base::TimeDelta(); 756 backoff_delay = base::TimeDelta();
751 757
752 if (automatically_retry_on_5xx_ && num_retries_ <= max_retries_) { 758 if (automatically_retry_on_5xx_ && num_retries_ <= max_retries_) {
753 StartOnIOThread(); 759 StartOnIOThread();
754 return; 760 return;
755 } 761 }
756 } else { 762 } else {
757 backoff_delay = base::TimeDelta(); 763 backoff_delay = base::TimeDelta();
758 } 764 }
759 request_context_getter_ = NULL; 765 request_context_getter_ = NULL;
766 render_process_id_ = -1;
767 render_view_id_ = -1;
768 first_party_for_cookies_ = GURL();
760 bool posted = delegate_loop_proxy_->PostTask( 769 bool posted = delegate_loop_proxy_->PostTask(
761 FROM_HERE, base::Bind(&Core::OnCompletedURLRequest, this, backoff_delay)); 770 FROM_HERE, base::Bind(&Core::OnCompletedURLRequest, this, backoff_delay));
762 771
763 // If the delegate message loop does not exist any more, then the delegate 772 // If the delegate message loop does not exist any more, then the delegate
764 // should be gone too. 773 // should be gone too.
765 DCHECK(posted || !delegate_); 774 DCHECK(posted || !delegate_);
766 } 775 }
767 776
768 void URLFetcherImpl::Core::ReadResponse() { 777 void URLFetcherImpl::Core::ReadResponse() {
769 // Some servers may treat HEAD requests as GET requests. To free up the 778 // Some servers may treat HEAD requests as GET requests. To free up the
(...skipping 27 matching lines...) Expand all
797 request_.reset(new net::URLRequest(original_url_, this)); 806 request_.reset(new net::URLRequest(original_url_, this));
798 int flags = request_->load_flags() | load_flags_; 807 int flags = request_->load_flags() | load_flags_;
799 if (!g_interception_enabled) 808 if (!g_interception_enabled)
800 flags = flags | net::LOAD_DISABLE_INTERCEPT; 809 flags = flags | net::LOAD_DISABLE_INTERCEPT;
801 810
802 if (is_chunked_upload_) 811 if (is_chunked_upload_)
803 request_->EnableChunkedUpload(); 812 request_->EnableChunkedUpload();
804 request_->set_load_flags(flags); 813 request_->set_load_flags(flags);
805 request_->set_context(request_context_getter_->GetURLRequestContext()); 814 request_->set_context(request_context_getter_->GetURLRequestContext());
806 request_->set_referrer(referrer_); 815 request_->set_referrer(referrer_);
816 request_->set_first_party_for_cookies(first_party_for_cookies_.is_empty() ?
817 original_url_ : first_party_for_cookies_);
818 if (render_process_id_ != -1 && render_view_id_ != -1) {
819 request_->SetUserData(
820 URLRequestUserData::kUserDataKey,
821 new URLRequestUserData(render_process_id_, render_view_id_));
822 }
807 823
808 switch (request_type_) { 824 switch (request_type_) {
809 case GET: 825 case GET:
810 break; 826 break;
811 827
812 case POST: 828 case POST:
813 case PUT: 829 case PUT:
814 DCHECK(!upload_content_.empty() || is_chunked_upload_); 830 DCHECK(!upload_content_.empty() || is_chunked_upload_);
815 DCHECK(!upload_content_type_.empty()); 831 DCHECK(!upload_content_type_.empty());
816 832
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 892
877 if (request_.get()) { 893 if (request_.get()) {
878 request_->Cancel(); 894 request_->Cancel();
879 ReleaseRequest(); 895 ReleaseRequest();
880 } 896 }
881 // Release the reference to the request context. There could be multiple 897 // Release the reference to the request context. There could be multiple
882 // references to URLFetcher::Core at this point so it may take a while to 898 // references to URLFetcher::Core at this point so it may take a while to
883 // delete the object, but we cannot delay the destruction of the request 899 // delete the object, but we cannot delay the destruction of the request
884 // context. 900 // context.
885 request_context_getter_ = NULL; 901 request_context_getter_ = NULL;
902 render_process_id_ = -1;
903 render_view_id_ = -1;
904 first_party_for_cookies_ = GURL();
886 was_cancelled_ = true; 905 was_cancelled_ = true;
887 file_writer_.reset(); 906 file_writer_.reset();
888 } 907 }
889 908
890 void URLFetcherImpl::Core::OnCompletedURLRequest( 909 void URLFetcherImpl::Core::OnCompletedURLRequest(
891 base::TimeDelta backoff_delay) { 910 base::TimeDelta backoff_delay) {
892 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread()); 911 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread());
893 912
894 // 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.
895 if (delegate_) { 914 if (delegate_) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 void URLFetcherImpl::GetExtraRequestHeaders(net::HttpRequestHeaders* headers) { 1027 void URLFetcherImpl::GetExtraRequestHeaders(net::HttpRequestHeaders* headers) {
1009 headers->CopyFrom(core_->extra_request_headers_); 1028 headers->CopyFrom(core_->extra_request_headers_);
1010 } 1029 }
1011 1030
1012 void URLFetcherImpl::SetRequestContext( 1031 void URLFetcherImpl::SetRequestContext(
1013 net::URLRequestContextGetter* request_context_getter) { 1032 net::URLRequestContextGetter* request_context_getter) {
1014 DCHECK(!core_->request_context_getter_); 1033 DCHECK(!core_->request_context_getter_);
1015 core_->request_context_getter_ = request_context_getter; 1034 core_->request_context_getter_ = request_context_getter;
1016 } 1035 }
1017 1036
1037 void URLFetcherImpl::AssociateWithRenderView(
1038 const GURL& first_party_for_cookies,
1039 int render_process_id,
1040 int render_view_id) {
1041 DCHECK(core_->first_party_for_cookies_.is_empty());
1042 DCHECK_EQ(core_->render_process_id_, -1);
1043 DCHECK_EQ(core_->render_view_id_, -1);
1044 DCHECK_GE(render_process_id, 0);
1045 DCHECK_GE(render_view_id, 0);
1046 core_->first_party_for_cookies_ = first_party_for_cookies;
1047 core_->render_process_id_ = render_process_id;
1048 core_->render_view_id_ = render_view_id;
1049 }
1050
1018 void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry) { 1051 void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry) {
1019 core_->automatically_retry_on_5xx_ = retry; 1052 core_->automatically_retry_on_5xx_ = retry;
1020 } 1053 }
1021 1054
1022 void URLFetcherImpl::SetMaxRetries(int max_retries) { 1055 void URLFetcherImpl::SetMaxRetries(int max_retries) {
1023 core_->max_retries_ = max_retries; 1056 core_->max_retries_ = max_retries;
1024 } 1057 }
1025 1058
1026 int URLFetcherImpl::GetMaxRetries() const { 1059 int URLFetcherImpl::GetMaxRetries() const {
1027 return core_->max_retries_; 1060 return core_->max_retries_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 } 1092 }
1060 1093
1061 void URLFetcherImpl::set_was_fetched_via_proxy(bool flag) { 1094 void URLFetcherImpl::set_was_fetched_via_proxy(bool flag) {
1062 core_->was_fetched_via_proxy_ = flag; 1095 core_->was_fetched_via_proxy_ = flag;
1063 } 1096 }
1064 1097
1065 void URLFetcherImpl::Start() { 1098 void URLFetcherImpl::Start() {
1066 core_->Start(); 1099 core_->Start();
1067 } 1100 }
1068 1101
1069 void URLFetcherImpl::StartWithRequestContextGetter(
1070 net::URLRequestContextGetter* request_context_getter) {
1071 SetRequestContext(request_context_getter);
1072 core_->Start();
1073 }
1074
1075 const GURL& URLFetcherImpl::GetOriginalURL() const { 1102 const GURL& URLFetcherImpl::GetOriginalURL() const {
1076 return core_->original_url_; 1103 return core_->original_url_;
1077 } 1104 }
1078 1105
1079 const GURL& URLFetcherImpl::GetURL() const { 1106 const GURL& URLFetcherImpl::GetURL() const {
1080 return core_->url_; 1107 return core_->url_;
1081 } 1108 }
1082 1109
1083 const net::URLRequestStatus& URLFetcherImpl::GetStatus() const { 1110 const net::URLRequestStatus& URLFetcherImpl::GetStatus() const {
1084 return core_->status_; 1111 return core_->status_;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 1181
1155 // static 1182 // static
1156 content::URLFetcherFactory* URLFetcherImpl::factory() { 1183 content::URLFetcherFactory* URLFetcherImpl::factory() {
1157 return g_factory; 1184 return g_factory;
1158 } 1185 }
1159 1186
1160 // static 1187 // static
1161 void URLFetcherImpl::set_factory(content::URLFetcherFactory* factory) { 1188 void URLFetcherImpl::set_factory(content::URLFetcherFactory* factory) {
1162 g_factory = factory; 1189 g_factory = factory;
1163 } 1190 }
OLDNEW
« no previous file with comments | « content/common/net/url_fetcher_impl.h ('k') | content/common/net/url_fetcher_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698