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