| 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/http/http_auth_controller.h" | 5 #include "net/http/http_auth_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 7 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 8 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 9 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 10 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 11 #include "net/base/auth.h" | 13 #include "net/base/auth.h" |
| 12 #include "net/base/host_resolver.h" | 14 #include "net/base/host_resolver.h" |
| 13 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 14 #include "net/http/http_auth_handler.h" | 16 #include "net/http/http_auth_handler.h" |
| 15 #include "net/http/http_auth_handler_factory.h" | 17 #include "net/http/http_auth_handler_factory.h" |
| 16 #include "net/http/http_network_session.h" | 18 #include "net/http/http_network_session.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 const GURL& auth_url, | 156 const GURL& auth_url, |
| 155 HttpAuthCache* http_auth_cache, | 157 HttpAuthCache* http_auth_cache, |
| 156 HttpAuthHandlerFactory* http_auth_handler_factory) | 158 HttpAuthHandlerFactory* http_auth_handler_factory) |
| 157 : target_(target), | 159 : target_(target), |
| 158 auth_url_(auth_url), | 160 auth_url_(auth_url), |
| 159 auth_origin_(auth_url.GetOrigin()), | 161 auth_origin_(auth_url.GetOrigin()), |
| 160 auth_path_(HttpAuth::AUTH_PROXY ? std::string() : auth_url.path()), | 162 auth_path_(HttpAuth::AUTH_PROXY ? std::string() : auth_url.path()), |
| 161 embedded_identity_used_(false), | 163 embedded_identity_used_(false), |
| 162 default_credentials_used_(false), | 164 default_credentials_used_(false), |
| 163 http_auth_cache_(http_auth_cache), | 165 http_auth_cache_(http_auth_cache), |
| 164 http_auth_handler_factory_(http_auth_handler_factory), | 166 http_auth_handler_factory_(http_auth_handler_factory) { |
| 165 ALLOW_THIS_IN_INITIALIZER_LIST( | |
| 166 io_callback_(this, &HttpAuthController::OnIOComplete)), | |
| 167 user_callback_(NULL) { | |
| 168 } | 167 } |
| 169 | 168 |
| 170 HttpAuthController::~HttpAuthController() { | 169 HttpAuthController::~HttpAuthController() { |
| 171 DCHECK(CalledOnValidThread()); | 170 DCHECK(CalledOnValidThread()); |
| 172 user_callback_ = NULL; | |
| 173 } | 171 } |
| 174 | 172 |
| 175 int HttpAuthController::MaybeGenerateAuthToken(const HttpRequestInfo* request, | 173 int HttpAuthController::MaybeGenerateAuthToken( |
| 176 OldCompletionCallback* callback, | 174 const HttpRequestInfo* request, const CompletionCallback& callback, |
| 177 const BoundNetLog& net_log) { | 175 const BoundNetLog& net_log) { |
| 178 DCHECK(CalledOnValidThread()); | 176 DCHECK(CalledOnValidThread()); |
| 179 bool needs_auth = HaveAuth() || SelectPreemptiveAuth(net_log); | 177 bool needs_auth = HaveAuth() || SelectPreemptiveAuth(net_log); |
| 180 if (!needs_auth) | 178 if (!needs_auth) |
| 181 return OK; | 179 return OK; |
| 182 const AuthCredentials* credentials = NULL; | 180 const AuthCredentials* credentials = NULL; |
| 183 if (identity_.source != HttpAuth::IDENT_SRC_DEFAULT_CREDENTIALS) | 181 if (identity_.source != HttpAuth::IDENT_SRC_DEFAULT_CREDENTIALS) |
| 184 credentials = &identity_.credentials; | 182 credentials = &identity_.credentials; |
| 185 DCHECK(auth_token_.empty()); | 183 DCHECK(auth_token_.empty()); |
| 186 DCHECK(NULL == user_callback_); | 184 DCHECK(callback_.is_null()); |
| 187 int rv = handler_->GenerateAuthToken(credentials, | 185 int rv = handler_->GenerateAuthToken( |
| 188 request, | 186 credentials, request, |
| 189 &io_callback_, | 187 base::Bind(&HttpAuthController::OnIOComplete, base::Unretained(this)), |
| 190 &auth_token_); | 188 &auth_token_); |
| 191 if (DisableOnAuthHandlerResult(rv)) | 189 if (DisableOnAuthHandlerResult(rv)) |
| 192 rv = OK; | 190 rv = OK; |
| 193 if (rv == ERR_IO_PENDING) | 191 if (rv == ERR_IO_PENDING) |
| 194 user_callback_ = callback; | 192 callback_ = callback; |
| 195 else | 193 else |
| 196 OnIOComplete(rv); | 194 OnIOComplete(rv); |
| 197 return rv; | 195 return rv; |
| 198 } | 196 } |
| 199 | 197 |
| 200 bool HttpAuthController::SelectPreemptiveAuth(const BoundNetLog& net_log) { | 198 bool HttpAuthController::SelectPreemptiveAuth(const BoundNetLog& net_log) { |
| 201 DCHECK(CalledOnValidThread()); | 199 DCHECK(CalledOnValidThread()); |
| 202 DCHECK(!HaveAuth()); | 200 DCHECK(!HaveAuth()); |
| 203 DCHECK(identity_.invalid); | 201 DCHECK(identity_.invalid); |
| 204 | 202 |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 | 534 |
| 537 default: | 535 default: |
| 538 return false; | 536 return false; |
| 539 } | 537 } |
| 540 } | 538 } |
| 541 | 539 |
| 542 void HttpAuthController::OnIOComplete(int result) { | 540 void HttpAuthController::OnIOComplete(int result) { |
| 543 DCHECK(CalledOnValidThread()); | 541 DCHECK(CalledOnValidThread()); |
| 544 if (DisableOnAuthHandlerResult(result)) | 542 if (DisableOnAuthHandlerResult(result)) |
| 545 result = OK; | 543 result = OK; |
| 546 if (user_callback_) { | 544 if (!callback_.is_null()) { |
| 547 OldCompletionCallback* c = user_callback_; | 545 CompletionCallback c = callback_; |
| 548 user_callback_ = NULL; | 546 callback_.Reset(); |
| 549 c->Run(result); | 547 c.Run(result); |
| 550 } | 548 } |
| 551 } | 549 } |
| 552 | 550 |
| 553 scoped_refptr<AuthChallengeInfo> HttpAuthController::auth_info() { | 551 scoped_refptr<AuthChallengeInfo> HttpAuthController::auth_info() { |
| 554 DCHECK(CalledOnValidThread()); | 552 DCHECK(CalledOnValidThread()); |
| 555 return auth_info_; | 553 return auth_info_; |
| 556 } | 554 } |
| 557 | 555 |
| 558 bool HttpAuthController::IsAuthSchemeDisabled(HttpAuth::Scheme scheme) const { | 556 bool HttpAuthController::IsAuthSchemeDisabled(HttpAuth::Scheme scheme) const { |
| 559 DCHECK(CalledOnValidThread()); | 557 DCHECK(CalledOnValidThread()); |
| 560 return disabled_schemes_.find(scheme) != disabled_schemes_.end(); | 558 return disabled_schemes_.find(scheme) != disabled_schemes_.end(); |
| 561 } | 559 } |
| 562 | 560 |
| 563 void HttpAuthController::DisableAuthScheme(HttpAuth::Scheme scheme) { | 561 void HttpAuthController::DisableAuthScheme(HttpAuth::Scheme scheme) { |
| 564 DCHECK(CalledOnValidThread()); | 562 DCHECK(CalledOnValidThread()); |
| 565 disabled_schemes_.insert(scheme); | 563 disabled_schemes_.insert(scheme); |
| 566 } | 564 } |
| 567 | 565 |
| 568 } // namespace net | 566 } // namespace net |
| OLD | NEW |