| OLD | NEW |
| 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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 net_log_(BoundNetLog::Make(context->net_log(), | 209 net_log_(BoundNetLog::Make(context->net_log(), |
| 210 NetLog::SOURCE_URL_REQUEST)), | 210 NetLog::SOURCE_URL_REQUEST)), |
| 211 url_chain_(1, url), | 211 url_chain_(1, url), |
| 212 method_("GET"), | 212 method_("GET"), |
| 213 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), | 213 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), |
| 214 load_flags_(LOAD_NORMAL), | 214 load_flags_(LOAD_NORMAL), |
| 215 delegate_(delegate), | 215 delegate_(delegate), |
| 216 is_pending_(false), | 216 is_pending_(false), |
| 217 is_redirecting_(false), | 217 is_redirecting_(false), |
| 218 redirect_limit_(kMaxRedirects), | 218 redirect_limit_(kMaxRedirects), |
| 219 priority_(DEFAULT_PRIORITY), | 219 base_priority_(DEFAULT_PRIORITY), |
| 220 identifier_(GenerateURLRequestIdentifier()), | 220 identifier_(GenerateURLRequestIdentifier()), |
| 221 calling_delegate_(false), | 221 calling_delegate_(false), |
| 222 delegate_info_usage_(DELEGATE_INFO_DEBUG_ONLY), | 222 delegate_info_usage_(DELEGATE_INFO_DEBUG_ONLY), |
| 223 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete, | 223 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete, |
| 224 base::Unretained(this))), | 224 base::Unretained(this))), |
| 225 has_notified_completion_(false), | 225 has_notified_completion_(false), |
| 226 received_response_content_length_(0), | 226 received_response_content_length_(0), |
| 227 creation_time_(base::TimeTicks::Now()) { | 227 creation_time_(base::TimeTicks::Now()) { |
| 228 SIMPLE_STATS_COUNTER("URLRequestCount"); | 228 SIMPLE_STATS_COUNTER("URLRequestCount"); |
| 229 | 229 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 246 net_log_(BoundNetLog::Make(context->net_log(), | 246 net_log_(BoundNetLog::Make(context->net_log(), |
| 247 NetLog::SOURCE_URL_REQUEST)), | 247 NetLog::SOURCE_URL_REQUEST)), |
| 248 url_chain_(1, url), | 248 url_chain_(1, url), |
| 249 method_("GET"), | 249 method_("GET"), |
| 250 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), | 250 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), |
| 251 load_flags_(LOAD_NORMAL), | 251 load_flags_(LOAD_NORMAL), |
| 252 delegate_(delegate), | 252 delegate_(delegate), |
| 253 is_pending_(false), | 253 is_pending_(false), |
| 254 is_redirecting_(false), | 254 is_redirecting_(false), |
| 255 redirect_limit_(kMaxRedirects), | 255 redirect_limit_(kMaxRedirects), |
| 256 priority_(DEFAULT_PRIORITY), | 256 base_priority_(DEFAULT_PRIORITY), |
| 257 identifier_(GenerateURLRequestIdentifier()), | 257 identifier_(GenerateURLRequestIdentifier()), |
| 258 calling_delegate_(false), | 258 calling_delegate_(false), |
| 259 delegate_info_usage_(DELEGATE_INFO_DEBUG_ONLY), | 259 delegate_info_usage_(DELEGATE_INFO_DEBUG_ONLY), |
| 260 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete, | 260 before_request_callback_(base::Bind(&URLRequest::BeforeRequestComplete, |
| 261 base::Unretained(this))), | 261 base::Unretained(this))), |
| 262 has_notified_completion_(false), | 262 has_notified_completion_(false), |
| 263 received_response_content_length_(0), | 263 received_response_content_length_(0), |
| 264 creation_time_(base::TimeTicks::Now()) { | 264 creation_time_(base::TimeTicks::Now()) { |
| 265 SIMPLE_STATS_COUNTER("URLRequestCount"); | 265 SIMPLE_STATS_COUNTER("URLRequestCount"); |
| 266 | 266 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 void URLRequest::GetCharset(string* charset) { | 528 void URLRequest::GetCharset(string* charset) { |
| 529 DCHECK(job_.get()); | 529 DCHECK(job_.get()); |
| 530 job_->GetCharset(charset); | 530 job_->GetCharset(charset); |
| 531 } | 531 } |
| 532 | 532 |
| 533 int URLRequest::GetResponseCode() const { | 533 int URLRequest::GetResponseCode() const { |
| 534 DCHECK(job_.get()); | 534 DCHECK(job_.get()); |
| 535 return job_->GetResponseCode(); | 535 return job_->GetResponseCode(); |
| 536 } | 536 } |
| 537 | 537 |
| 538 void URLRequest::SetLoadFlags(int flags) { |
| 539 if ((load_flags_ & LOAD_IGNORE_LIMITS) != (flags & LOAD_IGNORE_LIMITS)) |
| 540 DCHECK(!job_); |
| 541 load_flags_ = flags; |
| 542 } |
| 543 |
| 538 // static | 544 // static |
| 539 void URLRequest::SetDefaultCookiePolicyToBlock() { | 545 void URLRequest::SetDefaultCookiePolicyToBlock() { |
| 540 CHECK(!g_url_requests_started); | 546 CHECK(!g_url_requests_started); |
| 541 g_default_can_use_cookies = false; | 547 g_default_can_use_cookies = false; |
| 542 } | 548 } |
| 543 | 549 |
| 544 // static | 550 // static |
| 545 bool URLRequest::IsHandledProtocol(const std::string& scheme) { | 551 bool URLRequest::IsHandledProtocol(const std::string& scheme) { |
| 546 return URLRequestJobManager::GetInstance()->SupportsScheme(scheme); | 552 return URLRequestJobManager::GetInstance()->SupportsScheme(scheme); |
| 547 } | 553 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 } | 681 } |
| 676 } | 682 } |
| 677 | 683 |
| 678 void URLRequest::StartJob(URLRequestJob* job) { | 684 void URLRequest::StartJob(URLRequestJob* job) { |
| 679 DCHECK(!is_pending_); | 685 DCHECK(!is_pending_); |
| 680 DCHECK(!job_.get()); | 686 DCHECK(!job_.get()); |
| 681 | 687 |
| 682 net_log_.BeginEvent( | 688 net_log_.BeginEvent( |
| 683 NetLog::TYPE_URL_REQUEST_START_JOB, | 689 NetLog::TYPE_URL_REQUEST_START_JOB, |
| 684 base::Bind(&NetLogURLRequestStartCallback, | 690 base::Bind(&NetLogURLRequestStartCallback, |
| 685 &url(), &method_, load_flags_, priority_, | 691 &url(), &method_, load_flags_, GetPriority(), |
| 686 upload_data_stream_ ? upload_data_stream_->identifier() : -1)); | 692 upload_data_stream_ ? upload_data_stream_->identifier() : -1)); |
| 687 | 693 |
| 688 job_ = job; | 694 job_ = job; |
| 689 job_->SetExtraRequestHeaders(extra_request_headers_); | 695 job_->SetExtraRequestHeaders(extra_request_headers_); |
| 690 job_->SetPriority(priority_); | 696 job_->SetPriority(GetPriority()); |
| 691 | 697 |
| 692 if (upload_data_stream_.get()) | 698 if (upload_data_stream_.get()) |
| 693 job_->SetUpload(upload_data_stream_.get()); | 699 job_->SetUpload(upload_data_stream_.get()); |
| 694 | 700 |
| 695 is_pending_ = true; | 701 is_pending_ = true; |
| 696 is_redirecting_ = false; | 702 is_redirecting_ = false; |
| 697 | 703 |
| 698 response_info_.was_cached = false; | 704 response_info_.was_cached = false; |
| 699 | 705 |
| 700 // Don't allow errors to be sent from within Start(). | 706 // Don't allow errors to be sent from within Start(). |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 } | 993 } |
| 988 | 994 |
| 989 int64 URLRequest::GetExpectedContentSize() const { | 995 int64 URLRequest::GetExpectedContentSize() const { |
| 990 int64 expected_content_size = -1; | 996 int64 expected_content_size = -1; |
| 991 if (job_.get()) | 997 if (job_.get()) |
| 992 expected_content_size = job_->expected_content_size(); | 998 expected_content_size = job_->expected_content_size(); |
| 993 | 999 |
| 994 return expected_content_size; | 1000 return expected_content_size; |
| 995 } | 1001 } |
| 996 | 1002 |
| 1003 RequestPriority URLRequest::GetPriority() const { |
| 1004 return (load_flags_ & LOAD_IGNORE_LIMITS) ? MAXIMUM_PRIORITY : base_priority_; |
| 1005 } |
| 1006 |
| 997 void URLRequest::SetPriority(RequestPriority priority) { | 1007 void URLRequest::SetPriority(RequestPriority priority) { |
| 998 DCHECK_GE(priority, MINIMUM_PRIORITY); | 1008 DCHECK_GE(priority, MINIMUM_PRIORITY); |
| 999 DCHECK_LE(priority, MAXIMUM_PRIORITY); | 1009 DCHECK_LE(priority, MAXIMUM_PRIORITY); |
| 1000 if (priority_ == priority) | 1010 |
| 1011 RequestPriority old_priority = GetPriority(); |
| 1012 |
| 1013 base_priority_ = priority; |
| 1014 |
| 1015 if (GetPriority() == old_priority) |
| 1001 return; | 1016 return; |
| 1002 | 1017 |
| 1003 priority_ = priority; | |
| 1004 if (job_.get()) { | 1018 if (job_.get()) { |
| 1005 net_log_.AddEvent(NetLog::TYPE_URL_REQUEST_SET_PRIORITY, | 1019 net_log_.AddEvent(NetLog::TYPE_URL_REQUEST_SET_PRIORITY, |
| 1006 NetLog::IntegerCallback("priority", priority_)); | 1020 NetLog::IntegerCallback("priority", GetPriority())); |
| 1007 job_->SetPriority(priority_); | 1021 job_->SetPriority(GetPriority()); |
| 1008 } | 1022 } |
| 1009 } | 1023 } |
| 1010 | 1024 |
| 1011 bool URLRequest::GetHSTSRedirect(GURL* redirect_url) const { | 1025 bool URLRequest::GetHSTSRedirect(GURL* redirect_url) const { |
| 1012 const GURL& url = this->url(); | 1026 const GURL& url = this->url(); |
| 1013 if (!url.SchemeIs("http")) | 1027 if (!url.SchemeIs("http")) |
| 1014 return false; | 1028 return false; |
| 1015 TransportSecurityState::DomainState domain_state; | 1029 TransportSecurityState::DomainState domain_state; |
| 1016 if (context()->transport_security_state() && | 1030 if (context()->transport_security_state() && |
| 1017 context()->transport_security_state()->GetDomainState( | 1031 context()->transport_security_state()->GetDomainState( |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 new base::debug::StackTrace(NULL, 0); | 1210 new base::debug::StackTrace(NULL, 0); |
| 1197 *stack_trace_copy = stack_trace; | 1211 *stack_trace_copy = stack_trace; |
| 1198 stack_trace_.reset(stack_trace_copy); | 1212 stack_trace_.reset(stack_trace_copy); |
| 1199 } | 1213 } |
| 1200 | 1214 |
| 1201 const base::debug::StackTrace* URLRequest::stack_trace() const { | 1215 const base::debug::StackTrace* URLRequest::stack_trace() const { |
| 1202 return stack_trace_.get(); | 1216 return stack_trace_.get(); |
| 1203 } | 1217 } |
| 1204 | 1218 |
| 1205 } // namespace net | 1219 } // namespace net |
| OLD | NEW |