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

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

Issue 11419034: net: Move ownership of UploadDataStream from URLRequestHttpJob to URLRequest (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove a local variable Created 8 years 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
« no previous file with comments | « net/url_request/url_request.h ('k') | net/url_request/url_request_http_job.h » ('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 "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"
11 #include "base/debug/stack_trace.h" 11 #include "base/debug/stack_trace.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/memory/singleton.h" 13 #include "base/memory/singleton.h"
14 #include "base/message_loop.h" 14 #include "base/message_loop.h"
15 #include "base/metrics/stats_counters.h" 15 #include "base/metrics/stats_counters.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/synchronization/lock.h" 17 #include "base/synchronization/lock.h"
18 #include "net/base/auth.h" 18 #include "net/base/auth.h"
19 #include "net/base/host_port_pair.h" 19 #include "net/base/host_port_pair.h"
20 #include "net/base/load_flags.h" 20 #include "net/base/load_flags.h"
21 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
22 #include "net/base/net_log.h" 22 #include "net/base/net_log.h"
23 #include "net/base/network_change_notifier.h" 23 #include "net/base/network_change_notifier.h"
24 #include "net/base/network_delegate.h" 24 #include "net/base/network_delegate.h"
25 #include "net/base/ssl_cert_request_info.h" 25 #include "net/base/ssl_cert_request_info.h"
26 #include "net/base/upload_data.h" 26 #include "net/base/upload_data.h"
27 #include "net/base/upload_data_stream.h"
27 #include "net/http/http_response_headers.h" 28 #include "net/http/http_response_headers.h"
28 #include "net/http/http_util.h" 29 #include "net/http/http_util.h"
29 #include "net/url_request/url_request_context.h" 30 #include "net/url_request/url_request_context.h"
30 #include "net/url_request/url_request_error_job.h" 31 #include "net/url_request/url_request_error_job.h"
31 #include "net/url_request/url_request_job.h" 32 #include "net/url_request/url_request_job.h"
32 #include "net/url_request/url_request_job_manager.h" 33 #include "net/url_request/url_request_job_manager.h"
33 #include "net/url_request/url_request_netlog_params.h" 34 #include "net/url_request/url_request_netlog_params.h"
34 #include "net/url_request/url_request_redirect_job.h" 35 #include "net/url_request/url_request_redirect_job.h"
35 36
36 using base::Time; 37 using base::Time;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) { 247 void URLRequest::RegisterRequestInterceptor(Interceptor* interceptor) {
247 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor); 248 URLRequestJobManager::GetInstance()->RegisterRequestInterceptor(interceptor);
248 } 249 }
249 250
250 // static 251 // static
251 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) { 252 void URLRequest::UnregisterRequestInterceptor(Interceptor* interceptor) {
252 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor( 253 URLRequestJobManager::GetInstance()->UnregisterRequestInterceptor(
253 interceptor); 254 interceptor);
254 } 255 }
255 256
256 void URLRequest::AppendBytesToUpload(const char* bytes, int bytes_len) {
257 DCHECK(bytes_len > 0 && bytes);
258 if (!upload_)
259 upload_ = new UploadData();
260 upload_->AppendBytes(bytes, bytes_len);
261 }
262
263 void URLRequest::EnableChunkedUpload() { 257 void URLRequest::EnableChunkedUpload() {
264 DCHECK(!upload_ || upload_->is_chunked()); 258 DCHECK(!upload_ || upload_->is_chunked());
265 if (!upload_) { 259 if (!upload_) {
266 upload_ = new UploadData(); 260 upload_ = new UploadData();
267 upload_->set_is_chunked(true); 261 upload_->set_is_chunked(true);
262 upload_data_stream_.reset(new UploadDataStream(upload_));
268 } 263 }
269 } 264 }
270 265
271 void URLRequest::AppendChunkToUpload(const char* bytes, 266 void URLRequest::AppendChunkToUpload(const char* bytes,
272 int bytes_len, 267 int bytes_len,
273 bool is_last_chunk) { 268 bool is_last_chunk) {
274 DCHECK(upload_); 269 DCHECK(upload_);
275 DCHECK(upload_->is_chunked()); 270 DCHECK(upload_->is_chunked());
276 DCHECK_GT(bytes_len, 0); 271 DCHECK_GT(bytes_len, 0);
277 upload_->AppendChunk(bytes, bytes_len, is_last_chunk); 272 upload_->AppendChunk(bytes, bytes_len, is_last_chunk);
278 } 273 }
279 274
280 void URLRequest::set_upload(UploadData* upload) { 275 void URLRequest::set_upload(UploadData* upload) {
281 upload_ = upload; 276 upload_ = upload;
277 upload_data_stream_.reset(new UploadDataStream(upload_));
282 } 278 }
283 279
284 // Get the upload data directly. 280 const UploadDataStream* URLRequest::get_upload() const {
285 const UploadData* URLRequest::get_upload() const { 281 return upload_data_stream_.get();
286 return upload_.get();
287 }
288
289 UploadData* URLRequest::get_upload_mutable() {
290 return upload_.get();
291 } 282 }
292 283
293 bool URLRequest::has_upload() const { 284 bool URLRequest::has_upload() const {
294 return upload_ != NULL; 285 return upload_data_stream_.get() != NULL;
295 } 286 }
296 287
297 void URLRequest::SetExtraRequestHeaderById(int id, const string& value, 288 void URLRequest::SetExtraRequestHeaderById(int id, const string& value,
298 bool overwrite) { 289 bool overwrite) {
299 DCHECK(!is_pending_ || is_redirecting_); 290 DCHECK(!is_pending_ || is_redirecting_);
300 NOTREACHED() << "implement me!"; 291 NOTREACHED() << "implement me!";
301 } 292 }
302 293
303 void URLRequest::SetExtraRequestHeaderByName(const string& name, 294 void URLRequest::SetExtraRequestHeaderByName(const string& name,
304 const string& value, 295 const string& value,
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 514
524 net_log_.BeginEvent( 515 net_log_.BeginEvent(
525 NetLog::TYPE_URL_REQUEST_START_JOB, 516 NetLog::TYPE_URL_REQUEST_START_JOB,
526 base::Bind(&NetLogURLRequestStartCallback, 517 base::Bind(&NetLogURLRequestStartCallback,
527 &url(), &method_, load_flags_, priority_, 518 &url(), &method_, load_flags_, priority_,
528 upload_.get() ? upload_->identifier() : -1)); 519 upload_.get() ? upload_->identifier() : -1));
529 520
530 job_ = job; 521 job_ = job;
531 job_->SetExtraRequestHeaders(extra_request_headers_); 522 job_->SetExtraRequestHeaders(extra_request_headers_);
532 523
533 if (upload_.get()) 524 if (upload_data_stream_.get())
534 job_->SetUpload(upload_.get()); 525 job_->SetUpload(upload_data_stream_.get());
535 526
536 is_pending_ = true; 527 is_pending_ = true;
537 is_redirecting_ = false; 528 is_redirecting_ = false;
538 529
539 response_info_.was_cached = false; 530 response_info_.was_cached = false;
540 531
541 // Don't allow errors to be sent from within Start(). 532 // Don't allow errors to be sent from within Start().
542 // TODO(brettw) this may cause NotifyDone to be sent synchronously, 533 // TODO(brettw) this may cause NotifyDone to be sent synchronously,
543 // we probably don't want this: they should be sent asynchronously so 534 // we probably don't want this: they should be sent asynchronously so
544 // the caller does not get reentered. 535 // the caller does not get reentered.
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 } 757 }
767 758
768 if (!location.is_valid()) 759 if (!location.is_valid())
769 return ERR_INVALID_URL; 760 return ERR_INVALID_URL;
770 761
771 if (!job_->IsSafeRedirect(location)) { 762 if (!job_->IsSafeRedirect(location)) {
772 DVLOG(1) << "disallowing redirect: unsafe protocol"; 763 DVLOG(1) << "disallowing redirect: unsafe protocol";
773 return ERR_UNSAFE_REDIRECT; 764 return ERR_UNSAFE_REDIRECT;
774 } 765 }
775 766
767 if (!final_upload_progress_.position())
768 final_upload_progress_ = job_->GetUploadProgress();
769 PrepareToRestart();
770
776 // For 303 redirects, all request methods except HEAD are converted to GET, 771 // For 303 redirects, all request methods except HEAD are converted to GET,
777 // as per the latest httpbis draft. The draft also allows POST requests to 772 // as per the latest httpbis draft. The draft also allows POST requests to
778 // be converted to GETs when following 301/302 redirects, for historical 773 // be converted to GETs when following 301/302 redirects, for historical
779 // reasons. Most major browsers do this and so shall we. Both RFC 2616 and 774 // reasons. Most major browsers do this and so shall we. Both RFC 2616 and
780 // the httpbis draft say to prompt the user to confirm the generation of new 775 // the httpbis draft say to prompt the user to confirm the generation of new
781 // requests, other than GET and HEAD requests, but IE omits these prompts and 776 // requests, other than GET and HEAD requests, but IE omits these prompts and
782 // so shall we. 777 // so shall we.
783 // See: https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#sectio n-7.3 778 // See: https://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-17#sectio n-7.3
784 bool was_post = method_ == "POST"; 779 bool was_post = method_ == "POST";
785 if ((http_status_code == 303 && method_ != "HEAD") || 780 if ((http_status_code == 303 && method_ != "HEAD") ||
786 ((http_status_code == 301 || http_status_code == 302) && was_post)) { 781 ((http_status_code == 301 || http_status_code == 302) && was_post)) {
787 method_ = "GET"; 782 method_ = "GET";
788 upload_ = NULL; 783 upload_data_stream_.reset();
789 if (was_post) { 784 if (was_post) {
790 // If being switched from POST to GET, must remove headers that were 785 // If being switched from POST to GET, must remove headers that were
791 // specific to the POST and don't have meaning in GET. For example 786 // specific to the POST and don't have meaning in GET. For example
792 // the inclusion of a multipart Content-Type header in GET can cause 787 // the inclusion of a multipart Content-Type header in GET can cause
793 // problems with some servers: 788 // problems with some servers:
794 // http://code.google.com/p/chromium/issues/detail?id=843 789 // http://code.google.com/p/chromium/issues/detail?id=843
795 StripPostSpecificHeaders(&extra_request_headers_); 790 StripPostSpecificHeaders(&extra_request_headers_);
796 } 791 }
797 } 792 }
798 793
799 // Suppress the referrer if we're redirecting out of https. 794 // Suppress the referrer if we're redirecting out of https.
800 if (referrer_policy_ == 795 if (referrer_policy_ ==
801 CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE && 796 CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE &&
802 GURL(referrer_).SchemeIsSecure() && !location.SchemeIsSecure()) { 797 GURL(referrer_).SchemeIsSecure() && !location.SchemeIsSecure()) {
803 referrer_.clear(); 798 referrer_.clear();
804 } 799 }
805 800
806 url_chain_.push_back(location); 801 url_chain_.push_back(location);
807 --redirect_limit_; 802 --redirect_limit_;
808 803
809 if (!final_upload_progress_.position())
810 final_upload_progress_ = job_->GetUploadProgress();
811
812 PrepareToRestart();
813 Start(); 804 Start();
814 return OK; 805 return OK;
815 } 806 }
816 807
817 const URLRequestContext* URLRequest::context() const { 808 const URLRequestContext* URLRequest::context() const {
818 return context_; 809 return context_;
819 } 810 }
820 811
821 int64 URLRequest::GetExpectedContentSize() const { 812 int64 URLRequest::GetExpectedContentSize() const {
822 int64 expected_content_size = -1; 813 int64 expected_content_size = -1;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 new base::debug::StackTrace(NULL, 0); 978 new base::debug::StackTrace(NULL, 0);
988 *stack_trace_copy = stack_trace; 979 *stack_trace_copy = stack_trace;
989 stack_trace_.reset(stack_trace_copy); 980 stack_trace_.reset(stack_trace_copy);
990 } 981 }
991 982
992 const base::debug::StackTrace* URLRequest::stack_trace() const { 983 const base::debug::StackTrace* URLRequest::stack_trace() const {
993 return stack_trace_.get(); 984 return stack_trace_.get();
994 } 985 }
995 986
996 } // namespace net 987 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request.h ('k') | net/url_request/url_request_http_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698