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 "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
11 #include "net/http/http_auth_challenge_tokenizer.h" | 11 #include "net/http/http_auth_challenge_tokenizer.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 HttpAuthHandler::HttpAuthHandler() | 15 HttpAuthHandler::HttpAuthHandler() |
16 : auth_scheme_(HttpAuth::AUTH_SCHEME_MAX), | 16 : auth_scheme_(HttpAuth::AUTH_SCHEME_MAX), |
17 score_(-1), | 17 score_(-1), |
18 target_(HttpAuth::AUTH_NONE), | 18 target_(HttpAuth::AUTH_NONE), |
19 properties_(-1) { | 19 properties_(-1) { |
20 } | 20 } |
21 | 21 |
22 HttpAuthHandler::~HttpAuthHandler() { | 22 HttpAuthHandler::~HttpAuthHandler() { |
23 } | 23 } |
24 | 24 |
25 bool HttpAuthHandler::InitFromChallenge( | 25 bool HttpAuthHandler::InitFromChallenge(HttpAuthChallengeTokenizer* challenge, |
26 HttpAuthChallengeTokenizer* challenge, | 26 HttpAuth::Target target, |
27 HttpAuth::Target target, | 27 const GURL& origin, |
28 const GURL& origin, | 28 const BoundNetLog& net_log) { |
29 const BoundNetLog& net_log) { | |
30 origin_ = origin; | 29 origin_ = origin; |
31 target_ = target; | 30 target_ = target; |
32 score_ = -1; | 31 score_ = -1; |
33 properties_ = -1; | 32 properties_ = -1; |
34 net_log_ = net_log; | 33 net_log_ = net_log; |
35 | 34 |
36 auth_challenge_ = challenge->challenge_text(); | 35 auth_challenge_ = challenge->challenge_text(); |
37 bool ok = Init(challenge); | 36 bool ok = Init(challenge); |
38 | 37 |
39 // 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 |
(...skipping 14 matching lines...) Expand all Loading... |
54 case HttpAuth::AUTH_SERVER: | 53 case HttpAuth::AUTH_SERVER: |
55 return NetLog::TYPE_AUTH_SERVER; | 54 return NetLog::TYPE_AUTH_SERVER; |
56 default: | 55 default: |
57 NOTREACHED(); | 56 NOTREACHED(); |
58 return NetLog::TYPE_CANCELLED; | 57 return NetLog::TYPE_CANCELLED; |
59 } | 58 } |
60 } | 59 } |
61 | 60 |
62 } // namespace | 61 } // namespace |
63 | 62 |
64 int HttpAuthHandler::GenerateAuthToken( | 63 int HttpAuthHandler::GenerateAuthToken(const AuthCredentials* credentials, |
65 const AuthCredentials* credentials, const HttpRequestInfo* request, | 64 const HttpRequestInfo* request, |
66 const CompletionCallback& callback, std::string* auth_token) { | 65 const CompletionCallback& callback, |
| 66 std::string* auth_token) { |
67 // TODO(cbentzel): Enforce non-NULL callback after cleaning up SocketStream. | 67 // TODO(cbentzel): Enforce non-NULL callback after cleaning up SocketStream. |
68 DCHECK(request); | 68 DCHECK(request); |
69 DCHECK(credentials != NULL || AllowsDefaultCredentials()); | 69 DCHECK(credentials != NULL || AllowsDefaultCredentials()); |
70 DCHECK(auth_token != NULL); | 70 DCHECK(auth_token != NULL); |
71 DCHECK(callback_.is_null()); | 71 DCHECK(callback_.is_null()); |
72 callback_ = callback; | 72 callback_ = callback; |
73 net_log_.BeginEvent(EventTypeFromAuthTarget(target_)); | 73 net_log_.BeginEvent(EventTypeFromAuthTarget(target_)); |
74 int rv = GenerateAuthTokenImpl( | 74 int rv = GenerateAuthTokenImpl( |
75 credentials, request, | 75 credentials, |
| 76 request, |
76 base::Bind(&HttpAuthHandler::OnGenerateAuthTokenComplete, | 77 base::Bind(&HttpAuthHandler::OnGenerateAuthTokenComplete, |
77 base::Unretained(this)), | 78 base::Unretained(this)), |
78 auth_token); | 79 auth_token); |
79 if (rv != ERR_IO_PENDING) | 80 if (rv != ERR_IO_PENDING) |
80 FinishGenerateAuthToken(); | 81 FinishGenerateAuthToken(); |
81 return rv; | 82 return rv; |
82 } | 83 } |
83 | 84 |
84 bool HttpAuthHandler::NeedsIdentity() { | 85 bool HttpAuthHandler::NeedsIdentity() { |
85 return true; | 86 return true; |
(...skipping 14 matching lines...) Expand all Loading... |
100 callback.Run(rv); | 101 callback.Run(rv); |
101 } | 102 } |
102 | 103 |
103 void HttpAuthHandler::FinishGenerateAuthToken() { | 104 void HttpAuthHandler::FinishGenerateAuthToken() { |
104 // TOOD(cbentzel): Should this be done in OK case only? | 105 // TOOD(cbentzel): Should this be done in OK case only? |
105 net_log_.EndEvent(EventTypeFromAuthTarget(target_)); | 106 net_log_.EndEvent(EventTypeFromAuthTarget(target_)); |
106 callback_.Reset(); | 107 callback_.Reset(); |
107 } | 108 } |
108 | 109 |
109 } // namespace net | 110 } // namespace net |
OLD | NEW |