| Index: net/url_request/url_request.cc
|
| diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc
|
| index 02667b5afe128d4eba237b2ecfc56c3dddff1767..9496ed4eb92196839f106cc83263dfff4842fe4b 100644
|
| --- a/net/url_request/url_request.cc
|
| +++ b/net/url_request/url_request.cc
|
| @@ -9,6 +9,7 @@
|
| #include "base/message_loop.h"
|
| #include "base/metrics/stats_counters.h"
|
| #include "base/synchronization/lock.h"
|
| +#include "net/base/auth.h"
|
| #include "net/base/host_port_pair.h"
|
| #include "net/base/load_flags.h"
|
| #include "net/base/net_errors.h"
|
| @@ -144,7 +145,10 @@ URLRequest::URLRequest(const GURL& url, Delegate* delegate)
|
| blocked_on_delegate_(false),
|
| ALLOW_THIS_IN_INITIALIZER_LIST(
|
| before_request_callback_(this, &URLRequest::BeforeRequestComplete)),
|
| - has_notified_completion_(false) {
|
| + has_notified_completion_(false),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(
|
| + auth_required_callback_(
|
| + this, &URLRequest::NotifyAuthRequiredComplete)) {
|
| SIMPLE_STATS_COUNTER("URLRequestCount");
|
|
|
| // Sanity check out environment.
|
| @@ -770,13 +774,45 @@ void URLRequest::NotifyAuthRequired(AuthChallengeInfo* auth_info) {
|
| // URLRequestTestHTTP.BasicAuthWithCookies. In both cases we observe a
|
| // call sequence of OnBeforeSendHeaders -> OnSendHeaders ->
|
| // OnBeforeSendHeaders.
|
| - if (context_ && context_->network_delegate())
|
| - context_->network_delegate()->NotifyAuthRequired(this, *auth_info);
|
| + int rv = OK;
|
| + auth_info_ = auth_info;
|
| + if (context_ && context_->network_delegate()) {
|
| + // Will this delete the callback when it is executed? Or can
|
| + // it be used multiple times?
|
| + rv = context_->network_delegate()->NotifyAuthRequired(
|
| + this, *auth_info, &auth_required_callback_, &auth_credentials_);
|
| + }
|
| +
|
| + if (rv == ERR_IO_PENDING) {
|
| + SetBlockedOnDelegate();
|
| + } else {
|
| + NotifyAuthRequiredComplete(rv);
|
| + }
|
| +}
|
| +
|
| +void URLRequest::NotifyAuthRequiredComplete(int result) {
|
| + // Not sure if we need to handle the cancelation case.
|
| + CHECK(result == OK || result == ERR_EMPTY_RESPONSE);
|
|
|
| + // NotifyAuthRequired may be called multiple times, such as
|
| + // when an authentication attempt fails. Clear out the data
|
| + // so it can be reset on another round.
|
| + AuthCredentials credentials = auth_credentials_;
|
| + auth_credentials_ = AuthCredentials();
|
| +
|
| + // If the NetworkDelegate provided a username and password, try
|
| + // using that.
|
| + if (credentials.is_valid) {
|
| + SetAuth(credentials.username, credentials.password);
|
| + return;
|
| + }
|
| +
|
| + // Otherwise, defer to the URLRequest Delegate.
|
| if (delegate_)
|
| - delegate_->OnAuthRequired(this, auth_info);
|
| + delegate_->OnAuthRequired(this, auth_info_.get());
|
| }
|
|
|
| +
|
| void URLRequest::NotifyCertificateRequested(
|
| SSLCertRequestInfo* cert_request_info) {
|
| if (delegate_)
|
|
|