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

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: TestShellNetworkDelegate 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/url_fetcher_delegate.h" 23 #include "content/public/common/url_fetcher_delegate.h"
24 #include "content/public/common/url_fetcher_factory.h" 24 #include "content/public/common/url_fetcher_factory.h"
25 #include "content/public/common/url_request_user_data.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"
33 #include "net/url_request/url_request_context.h" 34 #include "net/url_request/url_request_context.h"
34 #include "net/url_request/url_request_context_getter.h" 35 #include "net/url_request/url_request_context_getter.h"
(...skipping 205 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 int process_id_; // pid/rid of the associated render view.
jam 2012/03/05 19:11:03 nit: please don't say "pid" as that's confusing, a
jochen (gone - plz use gerrit) 2012/03/08 13:00:02 Done.
252 int routing_id_;
250 net::ResponseCookies cookies_; // Response cookies 253 net::ResponseCookies cookies_; // Response cookies
251 net::HttpRequestHeaders extra_request_headers_; 254 net::HttpRequestHeaders extra_request_headers_;
252 scoped_refptr<net::HttpResponseHeaders> response_headers_; 255 scoped_refptr<net::HttpResponseHeaders> response_headers_;
253 bool was_fetched_via_proxy_; 256 bool was_fetched_via_proxy_;
254 net::HostPortPair socket_address_; 257 net::HostPortPair socket_address_;
255 258
256 std::string upload_content_; // HTTP POST payload 259 std::string upload_content_; // HTTP POST payload
257 std::string upload_content_type_; // MIME type of POST payload 260 std::string upload_content_type_; // MIME type of POST payload
258 std::string referrer_; // HTTP Referer header value 261 std::string referrer_; // HTTP Referer header value
259 bool is_chunked_upload_; // True if using chunked transfer encoding 262 bool is_chunked_upload_; // True if using chunked transfer encoding
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 : fetcher_(fetcher), 544 : fetcher_(fetcher),
542 original_url_(original_url), 545 original_url_(original_url),
543 request_type_(request_type), 546 request_type_(request_type),
544 delegate_(d), 547 delegate_(d),
545 delegate_loop_proxy_( 548 delegate_loop_proxy_(
546 base::MessageLoopProxy::current()), 549 base::MessageLoopProxy::current()),
547 request_(NULL), 550 request_(NULL),
548 load_flags_(net::LOAD_NORMAL), 551 load_flags_(net::LOAD_NORMAL),
549 response_code_(RESPONSE_CODE_INVALID), 552 response_code_(RESPONSE_CODE_INVALID),
550 buffer_(new net::IOBuffer(kBufferSize)), 553 buffer_(new net::IOBuffer(kBufferSize)),
554 process_id_(-1),
555 routing_id_(-1),
551 was_fetched_via_proxy_(false), 556 was_fetched_via_proxy_(false),
552 is_chunked_upload_(false), 557 is_chunked_upload_(false),
553 num_retries_(0), 558 num_retries_(0),
554 was_cancelled_(false), 559 was_cancelled_(false),
555 response_destination_(STRING), 560 response_destination_(STRING),
556 automatically_retry_on_5xx_(true), 561 automatically_retry_on_5xx_(true),
557 max_retries_(0), 562 max_retries_(0),
558 current_response_bytes_(0), 563 current_response_bytes_(0),
559 total_response_bytes_(-1) { 564 total_response_bytes_(-1) {
560 } 565 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 761
757 if (automatically_retry_on_5xx_ && 762 if (automatically_retry_on_5xx_ &&
758 num_retries_ <= max_retries_) { 763 num_retries_ <= max_retries_) {
759 StartOnIOThread(); 764 StartOnIOThread();
760 return; 765 return;
761 } 766 }
762 } else { 767 } else {
763 backoff_delay = base::TimeDelta(); 768 backoff_delay = base::TimeDelta();
764 } 769 }
765 request_context_getter_ = NULL; 770 request_context_getter_ = NULL;
771 process_id_ = -1;
772 routing_id_ = -1;
766 bool posted = delegate_loop_proxy_->PostTask( 773 bool posted = delegate_loop_proxy_->PostTask(
767 FROM_HERE, base::Bind(&Core::OnCompletedURLRequest, this, backoff_delay)); 774 FROM_HERE, base::Bind(&Core::OnCompletedURLRequest, this, backoff_delay));
768 775
769 // If the delegate message loop does not exist any more, then the delegate 776 // If the delegate message loop does not exist any more, then the delegate
770 // should be gone too. 777 // should be gone too.
771 DCHECK(posted || !delegate_); 778 DCHECK(posted || !delegate_);
772 } 779 }
773 780
774 void URLFetcherImpl::Core::ReadResponse() { 781 void URLFetcherImpl::Core::ReadResponse() {
775 // Some servers may treat HEAD requests as GET requests. To free up the 782 // Some servers may treat HEAD requests as GET requests. To free up the
(...skipping 27 matching lines...) Expand all
803 request_.reset(new net::URLRequest(original_url_, this)); 810 request_.reset(new net::URLRequest(original_url_, this));
804 int flags = request_->load_flags() | load_flags_; 811 int flags = request_->load_flags() | load_flags_;
805 if (!g_interception_enabled) { 812 if (!g_interception_enabled) {
806 flags = flags | net::LOAD_DISABLE_INTERCEPT; 813 flags = flags | net::LOAD_DISABLE_INTERCEPT;
807 } 814 }
808 if (is_chunked_upload_) 815 if (is_chunked_upload_)
809 request_->EnableChunkedUpload(); 816 request_->EnableChunkedUpload();
810 request_->set_load_flags(flags); 817 request_->set_load_flags(flags);
811 request_->set_context(request_context_getter_->GetURLRequestContext()); 818 request_->set_context(request_context_getter_->GetURLRequestContext());
812 request_->set_referrer(referrer_); 819 request_->set_referrer(referrer_);
820 if (process_id_ != -1 && routing_id_ != -1) {
821 request_->SetUserData(
822 content::URLRequestUserData::kUserDataKey,
823 new content::URLRequestUserData(process_id_, routing_id_));
824 }
813 825
814 switch (request_type_) { 826 switch (request_type_) {
815 case GET: 827 case GET:
816 break; 828 break;
817 829
818 case POST: 830 case POST:
819 case PUT: 831 case PUT:
820 DCHECK(!upload_content_.empty() || is_chunked_upload_); 832 DCHECK(!upload_content_.empty() || is_chunked_upload_);
821 DCHECK(!upload_content_type_.empty()); 833 DCHECK(!upload_content_type_.empty());
822 834
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 895
884 if (request_.get()) { 896 if (request_.get()) {
885 request_->Cancel(); 897 request_->Cancel();
886 ReleaseRequest(); 898 ReleaseRequest();
887 } 899 }
888 // Release the reference to the request context. There could be multiple 900 // 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 901 // 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 902 // delete the object, but we cannot delay the destruction of the request
891 // context. 903 // context.
892 request_context_getter_ = NULL; 904 request_context_getter_ = NULL;
905 process_id_ = -1;
906 routing_id_ = -1;
893 was_cancelled_ = true; 907 was_cancelled_ = true;
894 temp_file_writer_.reset(); 908 temp_file_writer_.reset();
895 } 909 }
896 910
897 void URLFetcherImpl::Core::OnCompletedURLRequest( 911 void URLFetcherImpl::Core::OnCompletedURLRequest(
898 base::TimeDelta backoff_delay) { 912 base::TimeDelta backoff_delay) {
899 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread()); 913 DCHECK(delegate_loop_proxy_->BelongsToCurrentThread());
900 914
901 // Save the status and backoff_delay so that delegates can read it. 915 // Save the status and backoff_delay so that delegates can read it.
902 if (delegate_) { 916 if (delegate_) {
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 void URLFetcherImpl::GetExtraRequestHeaders(net::HttpRequestHeaders* headers) { 1030 void URLFetcherImpl::GetExtraRequestHeaders(net::HttpRequestHeaders* headers) {
1017 headers->CopyFrom(core_->extra_request_headers_); 1031 headers->CopyFrom(core_->extra_request_headers_);
1018 } 1032 }
1019 1033
1020 void URLFetcherImpl::SetRequestContext( 1034 void URLFetcherImpl::SetRequestContext(
1021 net::URLRequestContextGetter* request_context_getter) { 1035 net::URLRequestContextGetter* request_context_getter) {
1022 DCHECK(!core_->request_context_getter_); 1036 DCHECK(!core_->request_context_getter_);
1023 core_->request_context_getter_ = request_context_getter; 1037 core_->request_context_getter_ = request_context_getter;
1024 } 1038 }
1025 1039
1040 void URLFetcherImpl::AssociateWithRenderView(int process_id, int routing_id) {
1041 DCHECK_EQ(core_->process_id_, -1);
1042 DCHECK_EQ(core_->routing_id_, -1);
1043 DCHECK_GE(process_id, 0);
1044 DCHECK_GE(routing_id, 0);
1045 core_->process_id_ = process_id;
1046 core_->routing_id_ = routing_id;
1047 }
1048
1026 void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry) { 1049 void URLFetcherImpl::SetAutomaticallyRetryOn5xx(bool retry) {
1027 core_->automatically_retry_on_5xx_ = retry; 1050 core_->automatically_retry_on_5xx_ = retry;
1028 } 1051 }
1029 1052
1030 void URLFetcherImpl::SetMaxRetries(int max_retries) { 1053 void URLFetcherImpl::SetMaxRetries(int max_retries) {
1031 core_->max_retries_ = max_retries; 1054 core_->max_retries_ = max_retries;
1032 } 1055 }
1033 1056
1034 int URLFetcherImpl::GetMaxRetries() const { 1057 int URLFetcherImpl::GetMaxRetries() const {
1035 return core_->max_retries_; 1058 return core_->max_retries_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 } 1090 }
1068 1091
1069 void URLFetcherImpl::set_was_fetched_via_proxy(bool flag) { 1092 void URLFetcherImpl::set_was_fetched_via_proxy(bool flag) {
1070 core_->was_fetched_via_proxy_ = flag; 1093 core_->was_fetched_via_proxy_ = flag;
1071 } 1094 }
1072 1095
1073 void URLFetcherImpl::Start() { 1096 void URLFetcherImpl::Start() {
1074 core_->Start(); 1097 core_->Start();
1075 } 1098 }
1076 1099
1077 void URLFetcherImpl::StartWithRequestContextGetter(
1078 net::URLRequestContextGetter* request_context_getter) {
1079 SetRequestContext(request_context_getter);
1080 core_->Start();
1081 }
1082
1083 const GURL& URLFetcherImpl::GetOriginalURL() const { 1100 const GURL& URLFetcherImpl::GetOriginalURL() const {
1084 return core_->original_url_; 1101 return core_->original_url_;
1085 } 1102 }
1086 1103
1087 const GURL& URLFetcherImpl::GetURL() const { 1104 const GURL& URLFetcherImpl::GetURL() const {
1088 return core_->url_; 1105 return core_->url_;
1089 } 1106 }
1090 1107
1091 const net::URLRequestStatus& URLFetcherImpl::GetStatus() const { 1108 const net::URLRequestStatus& URLFetcherImpl::GetStatus() const {
1092 return core_->status_; 1109 return core_->status_;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 1181
1165 // static 1182 // static
1166 content::URLFetcherFactory* URLFetcherImpl::factory() { 1183 content::URLFetcherFactory* URLFetcherImpl::factory() {
1167 return g_factory; 1184 return g_factory;
1168 } 1185 }
1169 1186
1170 // static 1187 // static
1171 void URLFetcherImpl::set_factory(content::URLFetcherFactory* factory) { 1188 void URLFetcherImpl::set_factory(content::URLFetcherFactory* factory) {
1172 g_factory = factory; 1189 g_factory = factory;
1173 } 1190 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698