Chromium Code Reviews| Index: net/url_request/url_request.cc |
| diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc |
| index efc83c9ac05b01cff9f1ddd92c8003f921bacbc9..e0f3f5732aedc1c3ae9f330c376a5fd0bc23ad45 100644 |
| --- a/net/url_request/url_request.cc |
| +++ b/net/url_request/url_request.cc |
| @@ -132,8 +132,10 @@ void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request, |
| /////////////////////////////////////////////////////////////////////////////// |
| // URLRequest |
| -URLRequest::URLRequest(const GURL& url, Delegate* delegate) |
| - : context_(NULL), |
| +URLRequest::URLRequest(const GURL& url, |
| + Delegate* delegate, |
| + const URLRequestContext* context) |
| + : context_(context), |
| url_chain_(1, url), |
| method_("GET"), |
| referrer_policy_(CLEAR_REFERRER_ON_TRANSITION_FROM_SECURE_TO_INSECURE), |
| @@ -157,6 +159,14 @@ URLRequest::URLRequest(const GURL& url, Delegate* delegate) |
| "The current MessageLoop must exist"; |
| DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << |
| "The current MessageLoop must be TYPE_IO"; |
| + |
| + std::set<const URLRequest*>* url_requests = context->url_requests(); |
|
erikwright (departed)
2012/06/19 21:06:22
since we are removing the DCHECK, you can remove t
shalev
2012/06/20 20:13:12
Done.
|
| + CHECK(!ContainsKey(*url_requests, this)); |
|
erikwright (departed)
2012/06/19 21:06:22
This CHECK can be removed now, since it's pretty m
shalev
2012/06/20 20:13:12
Done.
shalev
2012/06/20 20:13:12
Done.
|
| + url_requests->insert(this); |
| + |
| + net_log_ = BoundNetLog::Make(context->net_log(), |
| + NetLog::SOURCE_URL_REQUEST); |
| + net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE, NULL); |
| } |
| URLRequest::~URLRequest() { |
| @@ -171,7 +181,16 @@ URLRequest::~URLRequest() { |
| if (job_) |
| OrphanJob(); |
| - set_context(NULL); |
| + std::set<const URLRequest*>* url_requests = context_->url_requests(); |
| + CHECK(ContainsKey(*url_requests, this)); |
| + url_requests->erase(this); |
|
erikwright (departed)
2012/06/19 21:06:22
inline url_requests()
shalev
2012/06/20 20:13:12
Done.
|
| + |
| + int net_error = OK; |
| + // Log error only on failure, not cancellation, as even successful requests |
| + // are "cancelled" on destruction. |
| + if (status_.status() == URLRequestStatus::FAILED) |
| + net_error = status_.error(); |
| + net_log_.EndEventWithNetErrorCode(NetLog::TYPE_REQUEST_ALIVE, net_error); |
| } |
| // static |
| @@ -726,42 +745,6 @@ const URLRequestContext* URLRequest::context() const { |
| return context_; |
| } |
| -void URLRequest::set_context(const URLRequestContext* context) { |
| - // Update the URLRequest lists in the URLRequestContext. |
| - if (context_) { |
| - std::set<const URLRequest*>* url_requests = context_->url_requests(); |
| - CHECK(ContainsKey(*url_requests, this)); |
| - url_requests->erase(this); |
| - } |
| - |
| - if (context) { |
| - std::set<const URLRequest*>* url_requests = context->url_requests(); |
| - CHECK(!ContainsKey(*url_requests, this)); |
| - url_requests->insert(this); |
| - } |
| - |
| - const URLRequestContext* prev_context = context_; |
| - |
| - context_ = context; |
| - |
| - // If the context this request belongs to has changed, update the tracker. |
| - if (prev_context != context) { |
| - int net_error = OK; |
| - // Log error only on failure, not cancellation, as even successful requests |
| - // are "cancelled" on destruction. |
| - if (status_.status() == URLRequestStatus::FAILED) |
| - net_error = status_.error(); |
| - net_log_.EndEventWithNetErrorCode(NetLog::TYPE_REQUEST_ALIVE, net_error); |
| - net_log_ = BoundNetLog(); |
| - |
| - if (context) { |
| - net_log_ = BoundNetLog::Make(context->net_log(), |
| - NetLog::SOURCE_URL_REQUEST); |
| - net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE, NULL); |
| - } |
| - } |
| -} |
| - |
| int64 URLRequest::GetExpectedContentSize() const { |
| int64 expected_content_size = -1; |
| if (job_) |