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 33cb827a6d348522f9c00f70309c2076d38059d4..a45bc966e2d747429a6feb83556c7ed39dc4eab8 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), |
|
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.
|
| 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(); |
| + 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.
|
| + url_requests->insert(this); |
| + |
| + net_log_ = BoundNetLog::Make(context->net_log(), |
| + 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.
|
| + net_log_.BeginEvent(NetLog::TYPE_REQUEST_ALIVE); |
| } |
| 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); |
| + |
| + 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 |
| @@ -727,42 +746,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); |
| - } |
| - } |
| -} |
| - |
| int64 URLRequest::GetExpectedContentSize() const { |
| int64 expected_content_size = -1; |
| if (job_) |