Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/metrics/stats_counters.h" | 10 #include "base/metrics/stats_counters.h" |
| 11 #include "base/synchronization/lock.h" | 11 #include "base/synchronization/lock.h" |
| 12 #include "net/base/auth.h" | |
| 12 #include "net/base/host_port_pair.h" | 13 #include "net/base/host_port_pair.h" |
| 13 #include "net/base/load_flags.h" | 14 #include "net/base/load_flags.h" |
| 14 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
| 15 #include "net/base/net_log.h" | 16 #include "net/base/net_log.h" |
| 16 #include "net/base/network_delegate.h" | 17 #include "net/base/network_delegate.h" |
| 17 #include "net/base/ssl_cert_request_info.h" | 18 #include "net/base/ssl_cert_request_info.h" |
| 18 #include "net/base/upload_data.h" | 19 #include "net/base/upload_data.h" |
| 19 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| 20 #include "net/http/http_util.h" | 21 #include "net/http/http_util.h" |
| 21 #include "net/url_request/url_request_context.h" | 22 #include "net/url_request/url_request_context.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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( | 146 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 146 before_request_callback_(this, &URLRequest::BeforeRequestComplete)), | 147 before_request_callback_(this, &URLRequest::BeforeRequestComplete)), |
| 147 has_notified_completion_(false) { | 148 has_notified_completion_(false), |
| 149 ALLOW_THIS_IN_INITIALIZER_LIST( | |
| 150 auth_required_callback_( | |
| 151 this, &URLRequest::NotifyAuthRequiredComplete)) { | |
| 148 SIMPLE_STATS_COUNTER("URLRequestCount"); | 152 SIMPLE_STATS_COUNTER("URLRequestCount"); |
| 149 | 153 |
| 150 // Sanity check out environment. | 154 // Sanity check out environment. |
| 151 DCHECK(MessageLoop::current()) << | 155 DCHECK(MessageLoop::current()) << |
| 152 "The current MessageLoop must exist"; | 156 "The current MessageLoop must exist"; |
| 153 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << | 157 DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << |
| 154 "The current MessageLoop must be TYPE_IO"; | 158 "The current MessageLoop must be TYPE_IO"; |
| 155 } | 159 } |
| 156 | 160 |
| 157 URLRequest::~URLRequest() { | 161 URLRequest::~URLRequest() { |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 | 766 |
| 763 void URLRequest::NotifyAuthRequired(AuthChallengeInfo* auth_info) { | 767 void URLRequest::NotifyAuthRequired(AuthChallengeInfo* auth_info) { |
| 764 // TODO(battre): We could simulate a redirection there as follows: | 768 // TODO(battre): We could simulate a redirection there as follows: |
| 765 // if (context_ && context_->network_delegate()) { | 769 // if (context_ && context_->network_delegate()) { |
| 766 // // We simulate a redirection. | 770 // // We simulate a redirection. |
| 767 // context_->network_delegate()->NotifyBeforeRedirect(this, url()); | 771 // context_->network_delegate()->NotifyBeforeRedirect(this, url()); |
| 768 //} | 772 //} |
| 769 // This fixes URLRequestTestHTTP.BasicAuth but not | 773 // This fixes URLRequestTestHTTP.BasicAuth but not |
| 770 // URLRequestTestHTTP.BasicAuthWithCookies. In both cases we observe a | 774 // URLRequestTestHTTP.BasicAuthWithCookies. In both cases we observe a |
| 771 // call sequence of OnBeforeSendHeaders -> OnSendHeaders -> | 775 // call sequence of OnBeforeSendHeaders -> OnSendHeaders -> |
| 772 // OnBeforeSendHeaders. | 776 // OnBeforeSendHeaders. |
|
battre
2011/09/24 13:17:55
i think this comment becomes obsolete now. Could y
| |
| 773 if (context_ && context_->network_delegate()) | 777 int rv = OK; |
| 774 context_->network_delegate()->NotifyAuthRequired(this, *auth_info); | 778 auth_info_ = auth_info; |
| 779 if (context_ && context_->network_delegate()) { | |
| 780 rv = context_->network_delegate()->NotifyAuthRequired( | |
| 781 this, *auth_info, &auth_required_callback_, &auth_credentials_); | |
| 782 } | |
| 775 | 783 |
| 784 if (rv == ERR_IO_PENDING) { | |
| 785 SetBlockedOnDelegate(); | |
|
battre
2011/09/24 13:17:55
the corresponding SetUnblockedOnDelegate(); is mis
cbentzel
2011/09/26 21:13:36
Done.
| |
| 786 } else { | |
| 787 NotifyAuthRequiredComplete(rv); | |
| 788 } | |
| 789 } | |
| 790 | |
| 791 void URLRequest::NotifyAuthRequiredComplete(int result) { | |
| 792 // NotifyAuthRequired may be called multiple times, such as | |
| 793 // when an authentication attempt fails. Clear out the data | |
| 794 // so it can be reset on another round. | |
| 795 AuthCredentials credentials = auth_credentials_; | |
| 796 auth_credentials_ = AuthCredentials(); | |
| 797 scoped_refptr<AuthChallengeInfo> auth_info; | |
| 798 auth_info.swap(auth_info_); | |
| 799 | |
| 800 if (result != OK) | |
| 801 return; | |
| 802 | |
| 803 // TODO(cbentzel): Should the ERR_EMPTY_RESPONSE be handled? This might | |
| 804 // be equivalent to canceling authentication, | |
|
battre
2011/09/24 13:17:55
probably yes
cbentzel
2011/09/26 21:13:36
Done.
| |
| 805 | |
| 806 // If the NetworkDelegate provided a username and password, try | |
| 807 // using that. | |
| 808 if (credentials.is_valid) { | |
| 809 SetAuth(credentials.username, credentials.password); | |
| 810 return; | |
| 811 } | |
| 812 | |
| 813 // Otherwise, defer to the URLRequest Delegate. | |
| 776 if (delegate_) | 814 if (delegate_) |
| 777 delegate_->OnAuthRequired(this, auth_info); | 815 delegate_->OnAuthRequired(this, auth_info.get()); |
| 778 } | 816 } |
| 779 | 817 |
| 780 void URLRequest::NotifyCertificateRequested( | 818 void URLRequest::NotifyCertificateRequested( |
| 781 SSLCertRequestInfo* cert_request_info) { | 819 SSLCertRequestInfo* cert_request_info) { |
| 782 if (delegate_) | 820 if (delegate_) |
| 783 delegate_->OnCertificateRequested(this, cert_request_info); | 821 delegate_->OnCertificateRequested(this, cert_request_info); |
| 784 } | 822 } |
| 785 | 823 |
| 786 void URLRequest::NotifySSLCertificateError(int cert_error, | 824 void URLRequest::NotifySSLCertificateError(int cert_error, |
| 787 X509Certificate* cert) { | 825 X509Certificate* cert) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 831 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 869 net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
| 832 } | 870 } |
| 833 | 871 |
| 834 void URLRequest::SetUnblockedOnDelegate() { | 872 void URLRequest::SetUnblockedOnDelegate() { |
| 835 blocked_on_delegate_ = false; | 873 blocked_on_delegate_ = false; |
| 836 load_state_param_.clear(); | 874 load_state_param_.clear(); |
| 837 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); | 875 net_log_.EndEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_DELEGATE, NULL); |
| 838 } | 876 } |
| 839 | 877 |
| 840 } // namespace net | 878 } // namespace net |
| OLD | NEW |