| 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/http/http_auth_handler.h" | 5 #include "net/http/http_auth_handler.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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 11 | 12 |
| 12 namespace net { | 13 namespace net { |
| 13 | 14 |
| 14 HttpAuthHandler::HttpAuthHandler() | 15 HttpAuthHandler::HttpAuthHandler() |
| 15 : auth_scheme_(HttpAuth::AUTH_SCHEME_MAX), | 16 : score_(-1), |
| 16 score_(-1), | |
| 17 target_(HttpAuth::AUTH_NONE), | 17 target_(HttpAuth::AUTH_NONE), |
| 18 properties_(-1) { | 18 properties_(-1) { |
| 19 } | 19 } |
| 20 | 20 |
| 21 HttpAuthHandler::~HttpAuthHandler() { | 21 HttpAuthHandler::~HttpAuthHandler() { |
| 22 } | 22 } |
| 23 | 23 |
| 24 bool HttpAuthHandler::InitFromChallenge( | 24 bool HttpAuthHandler::InitFromChallenge( |
| 25 HttpAuth::ChallengeTokenizer* challenge, | 25 HttpAuth::ChallengeTokenizer* challenge, |
| 26 HttpAuth::Target target, | 26 HttpAuth::Target target, |
| 27 const GURL& origin, | 27 const GURL& origin, |
| 28 const BoundNetLog& net_log) { | 28 const BoundNetLog& net_log) { |
| 29 origin_ = origin; | 29 origin_ = origin; |
| 30 target_ = target; | 30 target_ = target; |
| 31 score_ = -1; | 31 score_ = -1; |
| 32 properties_ = -1; | 32 properties_ = -1; |
| 33 net_log_ = net_log; | 33 net_log_ = net_log; |
| 34 | 34 |
| 35 auth_challenge_ = challenge->challenge_text(); | 35 auth_challenge_ = challenge->challenge_text(); |
| 36 bool ok = Init(challenge); | 36 bool ok = Init(challenge); |
| 37 | 37 |
| 38 // Init() is expected to set the scheme, realm, score, and properties. The | 38 // Init() is expected to set the scheme, realm, score, and properties. The |
| 39 // realm may be empty. | 39 // realm may be empty. |
| 40 DCHECK(!ok || score_ != -1); | 40 DCHECK(!ok || score_ != -1); |
| 41 DCHECK(!ok || properties_ != -1); | 41 DCHECK(!ok || properties_ != -1); |
| 42 DCHECK(!ok || auth_scheme_ != HttpAuth::AUTH_SCHEME_MAX); | 42 DCHECK(!ok || (!auth_scheme_.empty() && |
| 43 StringToLowerASCII(auth_scheme_) == auth_scheme_)); |
| 43 | 44 |
| 44 return ok; | 45 return ok; |
| 45 } | 46 } |
| 46 | 47 |
| 47 namespace { | 48 namespace { |
| 48 | 49 |
| 49 NetLog::EventType EventTypeFromAuthTarget(HttpAuth::Target target) { | 50 NetLog::EventType EventTypeFromAuthTarget(HttpAuth::Target target) { |
| 50 switch (target) { | 51 switch (target) { |
| 51 case HttpAuth::AUTH_PROXY: | 52 case HttpAuth::AUTH_PROXY: |
| 52 return NetLog::TYPE_AUTH_PROXY; | 53 return NetLog::TYPE_AUTH_PROXY; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 callback.Run(rv); | 100 callback.Run(rv); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void HttpAuthHandler::FinishGenerateAuthToken() { | 103 void HttpAuthHandler::FinishGenerateAuthToken() { |
| 103 // TOOD(cbentzel): Should this be done in OK case only? | 104 // TOOD(cbentzel): Should this be done in OK case only? |
| 104 net_log_.EndEvent(EventTypeFromAuthTarget(target_)); | 105 net_log_.EndEvent(EventTypeFromAuthTarget(target_)); |
| 105 callback_.Reset(); | 106 callback_.Reset(); |
| 106 } | 107 } |
| 107 | 108 |
| 108 } // namespace net | 109 } // namespace net |
| OLD | NEW |