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 void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request, | 125 void URLRequest::Delegate::OnSSLCertificateError(URLRequest* request, |
| 126 const SSLInfo& ssl_info, | 126 const SSLInfo& ssl_info, |
| 127 bool is_hsts_ok) { | 127 bool is_hsts_ok) { |
| 128 request->Cancel(); | 128 request->Cancel(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 /////////////////////////////////////////////////////////////////////////////// | 131 /////////////////////////////////////////////////////////////////////////////// |
| 132 // URLRequest | 132 // URLRequest |
| 133 | 133 |
| 134 URLRequest::URLRequest(const GURL& url, Delegate* delegate) | 134 URLRequest::URLRequest(const GURL& url, Delegate* delegate) |
| 135 : url_chain_(1, url), | 135 : context_(NULL), |
| 136 url_chain_(1, url), | |
| 136 method_("GET"), | 137 method_("GET"), |
| 137 load_flags_(LOAD_NORMAL), | 138 load_flags_(LOAD_NORMAL), |
| 138 delegate_(delegate), | 139 delegate_(delegate), |
| 139 is_pending_(false), | 140 is_pending_(false), |
| 140 redirect_limit_(kMaxRedirects), | 141 redirect_limit_(kMaxRedirects), |
| 141 final_upload_progress_(0), | 142 final_upload_progress_(0), |
| 142 priority_(LOWEST), | 143 priority_(LOWEST), |
| 143 identifier_(GenerateURLRequestIdentifier()), | 144 identifier_(GenerateURLRequestIdentifier()), |
| 144 blocked_on_delegate_(false), | 145 blocked_on_delegate_(false), |
| 145 ALLOW_THIS_IN_INITIALIZER_LIST(before_request_callback_( | 146 ALLOW_THIS_IN_INITIALIZER_LIST(before_request_callback_( |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 715 | 716 |
| 716 if (!final_upload_progress_) | 717 if (!final_upload_progress_) |
| 717 final_upload_progress_ = job_->GetUploadProgress(); | 718 final_upload_progress_ = job_->GetUploadProgress(); |
| 718 | 719 |
| 719 PrepareToRestart(); | 720 PrepareToRestart(); |
| 720 Start(); | 721 Start(); |
| 721 return OK; | 722 return OK; |
| 722 } | 723 } |
| 723 | 724 |
| 724 const URLRequestContext* URLRequest::context() const { | 725 const URLRequestContext* URLRequest::context() const { |
| 725 return context_.get(); | 726 return context_; |
| 726 } | 727 } |
| 727 | 728 |
| 728 void URLRequest::set_context(const URLRequestContext* context) { | 729 void URLRequest::set_context(const URLRequestContext* context) { |
|
eroman
2012/05/04 04:27:02
sidecomment: are there any legitimate use cases fo
| |
| 729 // Update the URLRequest lists in the URLRequestContext. | 730 // Update the URLRequest lists in the URLRequestContext. |
| 730 if (context_) { | 731 if (context_) { |
| 731 std::set<const URLRequest*>* url_requests = context_->url_requests(); | 732 std::set<const URLRequest*>* url_requests = context_->url_requests(); |
| 732 CHECK(ContainsKey(*url_requests, this)); | 733 CHECK(ContainsKey(*url_requests, this)); |
| 733 url_requests->erase(this); | 734 url_requests->erase(this); |
| 734 } | 735 } |
| 735 | 736 |
| 736 if (context) { | 737 if (context) { |
| 737 std::set<const URLRequest*>* url_requests = context->url_requests(); | 738 std::set<const URLRequest*>* url_requests = context->url_requests(); |
| 738 CHECK(!ContainsKey(*url_requests, this)); | 739 CHECK(!ContainsKey(*url_requests, this)); |
| 739 url_requests->insert(this); | 740 url_requests->insert(this); |
| 740 } | 741 } |
| 741 | 742 |
| 742 scoped_refptr<const URLRequestContext> prev_context = context_; | 743 const URLRequestContext* prev_context = context_; |
| 743 | 744 |
| 744 context_ = context; | 745 context_ = context; |
| 745 | 746 |
| 746 // If the context this request belongs to has changed, update the tracker. | 747 // If the context this request belongs to has changed, update the tracker. |
| 747 if (prev_context != context) { | 748 if (prev_context != context) { |
| 748 int net_error = OK; | 749 int net_error = OK; |
| 749 // Log error only on failure, not cancellation, as even successful requests | 750 // Log error only on failure, not cancellation, as even successful requests |
| 750 // are "cancelled" on destruction. | 751 // are "cancelled" on destruction. |
| 751 if (status_.status() == URLRequestStatus::FAILED) | 752 if (status_.status() == URLRequestStatus::FAILED) |
| 752 net_error = status_.error(); | 753 net_error = status_.error(); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 889 | 890 |
| 890 void URLRequest::SetUnblockedOnDelegate() { | 891 void URLRequest::SetUnblockedOnDelegate() { |
| 891 if (!blocked_on_delegate_) | 892 if (!blocked_on_delegate_) |
| 892 return; | 893 return; |
| 893 blocked_on_delegate_ = false; | 894 blocked_on_delegate_ = false; |
| 894 load_state_param_.clear(); | 895 load_state_param_.clear(); |
| 895 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 896 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
| 896 } | 897 } |
| 897 | 898 |
| 898 } // namespace net | 899 } // namespace net |
| OLD | NEW |