Chromium Code Reviews| 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 | 125 |
| 126 void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request, | 126 void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request, |
| 127 const SSLInfo& ssl_info, | 127 const SSLInfo& ssl_info, |
| 128 bool is_hsts_ok) { | 128 bool is_hsts_ok) { |
| 129 request->Cancel(); | 129 request->Cancel(); |
| 130 } | 130 } |
| 131 | 131 |
| 132 /////////////////////////////////////////////////////////////////////////////// | 132 /////////////////////////////////////////////////////////////////////////////// |
| 133 // URLRequest | 133 // URLRequest |
| 134 | 134 |
| 135 URLRequest::URLRequest(const GURL& url, Delegate* delegate) | 135 URLRequest::URLRequest(const GURL& url, |
| 136 : context_(NULL), | 136 Delegate* delegate, |
| 137 const URLRequestContext* context) | |
| 138 : context_(context), | |
|
willchan no longer on Chromium
2012/06/20 02:43:00
Since we're just going to crash later in ~URLReque
shalev
2012/06/20 20:13:12
Done.
| |
| 137 url_chain_(1, url), | 139 url_chain_(1, url), |
| 138 method_("GET"), | 140 method_("GET"), |
| 139 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), | 141 referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), |
| 140 load_flags_(LOAD_NORMAL), | 142 load_flags_(LOAD_NORMAL), |
| 141 delegate_(delegate), | 143 delegate_(delegate), |
| 142 is_pending_(false), | 144 is_pending_(false), |
| 143 redirect_limit_(kMaxRedirects), | 145 redirect_limit_(kMaxRedirects), |
| 144 final_upload_progress_(0), | 146 final_upload_progress_(0), |
| 145 priority_(LOWEST), | 147 priority_(LOWEST), |
| 146 identifier_(GenerateURLRequestIdentifier()), | 148 identifier_(GenerateURLRequestIdentifier()), |
| 147 blocked_on_delegate_(false), | 149 blocked_on_delegate_(false), |
| 148 ALLOW_THIS_IN_INITIALIZER_LIST(before_request_callback_( | 150 ALLOW_THIS_IN_INITIALIZER_LIST(before_request_callback_( |
| 149 base::Bind(&URLRequest::BeforeRequestComplete, | 151 base::Bind(&URLRequest::BeforeRequestComplete, |
| 150 base::Unretained(this)))), | 152 base::Unretained(this)))), |
| 151 has_notified_completion_(false), | 153 has_notified_completion_(false), |
| 152 creation_time_(base::TimeTicks::Now()) { | 154 creation_time_(base::TimeTicks::Now()) { |
| 153 SIMPLE_STATS_COUNTER("URLRequestCount"); | 155 SIMPLE_STATS_COUNTER("URLRequestCount"); |
| 154 | 156 |
| 155 // Sanity check out environment. | 157 // Sanity check out environment. |
| 156 DCHECK(MessageLoop::current()) << | 158 DCHECK(MessageLoop::current()) << |
| 157 "The current MessageLoop must exist"; | 159 "The current MessageLoop must exist"; |
| 158 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << | 160 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << |
| 159 "The current MessageLoop must be TYPE_IO"; | 161 "The current MessageLoop must be TYPE_IO"; |
| 162 | |
| 163 std::set<const URLRequest*>* url_requests = context->url_requests(); | |
| 164 CHECK(!ContainsKey(*url_requests, this)); | |
|
mmenke
2012/06/20 18:33:50
nit: Since this is the constructor, I don't think
shalev
2012/06/20 20:13:12
Done.
| |
| 165 url_requests->insert(this); | |
| 166 | |
| 167 net_log_ = BoundNetLog::Make(context->net_log(), | |
| 168 NetLog::SOURCE_URL_REQUEST); | |
|
mmenke
2012/06/20 18:33:50
You can put this in the initializer list.
shalev
2012/06/20 20:13:12
Done.
| |
| 169 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); | |
| 160 } | 170 } |
| 161 | 171 |
| 162 URLRequest::~URLRequest() { | 172 URLRequest::~URLRequest() { |
| 163 Cancel(); | 173 Cancel(); |
| 164 | 174 |
| 165 if (context_ && context_->network_delegate()) { | 175 if (context_ && context_->network_delegate()) { |
| 166 context_->network_delegate()->NotifyURLRequestDestroyed(this); | 176 context_->network_delegate()->NotifyURLRequestDestroyed(this); |
| 167 if (job_) | 177 if (job_) |
| 168 job_->NotifyURLRequestDestroyed(); | 178 job_->NotifyURLRequestDestroyed(); |
| 169 } | 179 } |
| 170 | 180 |
| 171 if (job_) | 181 if (job_) |
| 172 OrphanJob(); | 182 OrphanJob(); |
| 173 | 183 |
| 174 set_context(NULL); | 184 std::set<const URLRequest*>* url_requests = context_->url_requests(); |
| 185 CHECK(ContainsKey(*url_requests, this)); | |
| 186 url_requests->erase(this); | |
| 187 | |
| 188 int net_error = OK; | |
| 189 // Log error only on failure, not cancellation, as even successful requests | |
| 190 // are "cancelled" on destruction. | |
| 191 if (status_.status() == URLRequestStatus::FAILED) | |
| 192 net_error = status_.error(); | |
| 193 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_REQUEST_ALIVE, net_error); | |
| 175 } | 194 } |
| 176 | 195 |
| 177 // static | 196 // static |
| 178 URLRequest::ProtocolFactory* URLRequest::RegisterProtocolFactory( | 197 URLRequest::ProtocolFactory* URLRequest::RegisterProtocolFactory( |
| 179 const string& scheme, ProtocolFactory* factory) { | 198 const string& scheme, ProtocolFactory* factory) { |
| 180 return URLRequestJobManager::GetInstance()->RegisterProtocolFactory(scheme, | 199 return URLRequestJobManager::GetInstance()->RegisterProtocolFactory(scheme, |
| 181 factory); | 200 factory); |
| 182 } | 201 } |
| 183 | 202 |
| 184 // static | 203 // static |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 720 | 739 |
| 721 PrepareToRestart(); | 740 PrepareToRestart(); |
| 722 Start(); | 741 Start(); |
| 723 return OK; | 742 return OK; |
| 724 } | 743 } |
| 725 | 744 |
| 726 const URLRequestContext* URLRequest::context() const { | 745 const URLRequestContext* URLRequest::context() const { |
| 727 return context_; | 746 return context_; |
| 728 } | 747 } |
| 729 | 748 |
| 730 void URLRequest::set_context(const URLRequestContext* context) { | |
| 731 // Update the URLRequest lists in the URLRequestContext. | |
| 732 if (context_) { | |
| 733 std::set<const URLRequest*>* url_requests = context_->url_requests(); | |
| 734 CHECK(ContainsKey(*url_requests, this)); | |
| 735 url_requests->erase(this); | |
| 736 } | |
| 737 | |
| 738 if (context) { | |
| 739 std::set<const URLRequest*>* url_requests = context->url_requests(); | |
| 740 CHECK(!ContainsKey(*url_requests, this)); | |
| 741 url_requests->insert(this); | |
| 742 } | |
| 743 | |
| 744 const URLRequestContext* prev_context = context_; | |
| 745 | |
| 746 context_ = context; | |
| 747 | |
| 748 // If the context this request belongs to has changed, update the tracker. | |
| 749 if (prev_context != context) { | |
| 750 int net_error = OK; | |
| 751 // Log error only on failure, not cancellation, as even successful requests | |
| 752 // are "cancelled" on destruction. | |
| 753 if (status_.status() == URLRequestStatus::FAILED) | |
| 754 net_error = status_.error(); | |
| 755 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_REQUEST_ALIVE, net_error); | |
| 756 net_log_ = BoundNetLog(); | |
| 757 | |
| 758 if (context) { | |
| 759 net_log_ = BoundNetLog::Make(context->net_log(), | |
| 760 NetLog::SOURCE_URL_REQUEST); | |
| 761 net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); | |
| 762 } | |
| 763 } | |
| 764 } | |
| 765 | |
| 766 int64 URLRequest::GetExpectedContentSize() const { | 749 int64 URLRequest::GetExpectedContentSize() const { |
| 767 int64 expected_content_size = -1; | 750 int64 expected_content_size = -1; |
| 768 if (job_) | 751 if (job_) |
| 769 expected_content_size = job_->expected_content_size(); | 752 expected_content_size = job_->expected_content_size(); |
| 770 | 753 |
| 771 return expected_content_size; | 754 return expected_content_size; |
| 772 } | 755 } |
| 773 | 756 |
| 774 bool URLRequest::GetHSTSRedirect(GURL* redirect_url) const { | 757 bool URLRequest::GetHSTSRedirect(GURL* redirect_url) const { |
| 775 const GURL& url = this->url(); | 758 const GURL& url = this->url(); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 923 new base::debug::StackTrace(NULL, 0); | 906 new base::debug::StackTrace(NULL, 0); |
| 924 *stack_trace_copy = stack_trace; | 907 *stack_trace_copy = stack_trace; |
| 925 stack_trace_.reset(stack_trace_copy); | 908 stack_trace_.reset(stack_trace_copy); |
| 926 } | 909 } |
| 927 | 910 |
| 928 const base::debug::StackTrace* URLRequest::stack_trace() const { | 911 const base::debug::StackTrace* URLRequest::stack_trace() const { |
| 929 return stack_trace_.get(); | 912 return stack_trace_.get(); |
| 930 } | 913 } |
| 931 | 914 |
| 932 } // namespace net | 915 } // namespace net |
| OLD | NEW |