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/metrics/histogram.h" | |
9 #include "base/string_util.h" | 8 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
wtc
2011/01/11 20:33:10
Nit: I suspect we can remove "base/stringprintf.h"
| |
11 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
12 | 11 |
13 namespace net { | 12 namespace net { |
14 | 13 |
15 HttpAuthHandler::HttpAuthHandler() | 14 HttpAuthHandler::HttpAuthHandler() |
16 : auth_scheme_(AUTH_SCHEME_MAX), | 15 : auth_scheme_(AUTH_SCHEME_MAX), |
17 score_(-1), | 16 score_(-1), |
18 target_(HttpAuth::AUTH_NONE), | 17 target_(HttpAuth::AUTH_NONE), |
19 properties_(-1), | 18 properties_(-1), |
20 original_callback_(NULL), | 19 original_callback_(NULL), |
21 ALLOW_THIS_IN_INITIALIZER_LIST( | 20 ALLOW_THIS_IN_INITIALIZER_LIST( |
22 wrapper_callback_( | 21 wrapper_callback_( |
23 this, &HttpAuthHandler::OnGenerateAuthTokenComplete)) { | 22 this, &HttpAuthHandler::OnGenerateAuthTokenComplete)) { |
24 } | 23 } |
25 | 24 |
26 HttpAuthHandler::~HttpAuthHandler() { | 25 HttpAuthHandler::~HttpAuthHandler() { |
27 } | 26 } |
28 | 27 |
29 //static | |
30 std::string HttpAuthHandler::GenerateHistogramNameFromScheme( | |
31 const std::string& scheme) { | |
32 return base::StringPrintf("Net.AuthGenerateToken_%s", scheme.c_str()); | |
33 } | |
34 | |
35 bool HttpAuthHandler::InitFromChallenge( | 28 bool HttpAuthHandler::InitFromChallenge( |
36 HttpAuth::ChallengeTokenizer* challenge, | 29 HttpAuth::ChallengeTokenizer* challenge, |
37 HttpAuth::Target target, | 30 HttpAuth::Target target, |
38 const GURL& origin, | 31 const GURL& origin, |
39 const BoundNetLog& net_log) { | 32 const BoundNetLog& net_log) { |
40 origin_ = origin; | 33 origin_ = origin; |
41 target_ = target; | 34 target_ = target; |
42 score_ = -1; | 35 score_ = -1; |
43 properties_ = -1; | 36 properties_ = -1; |
44 net_log_ = net_log; | 37 net_log_ = net_log; |
45 | 38 |
46 auth_challenge_ = challenge->challenge_text(); | 39 auth_challenge_ = challenge->challenge_text(); |
47 bool ok = Init(challenge); | 40 bool ok = Init(challenge); |
48 | 41 |
49 // 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 |
50 // realm may be empty. | 43 // realm may be empty. |
51 DCHECK(!ok || !scheme().empty()); | 44 DCHECK(!ok || !scheme().empty()); |
52 DCHECK(!ok || score_ != -1); | 45 DCHECK(!ok || score_ != -1); |
53 DCHECK(!ok || properties_ != -1); | 46 DCHECK(!ok || properties_ != -1); |
54 DCHECK(!ok || auth_scheme_ != AUTH_SCHEME_MAX); | 47 DCHECK(!ok || auth_scheme_ != AUTH_SCHEME_MAX); |
55 | 48 |
56 if (ok) | |
57 histogram_ = base::Histogram::FactoryTimeGet( | |
58 GenerateHistogramNameFromScheme(scheme()), | |
59 base::TimeDelta::FromMilliseconds(1), | |
60 base::TimeDelta::FromSeconds(10), 50, | |
61 base::Histogram::kUmaTargetedHistogramFlag); | |
62 | |
63 return ok; | 49 return ok; |
64 } | 50 } |
65 | 51 |
66 namespace { | 52 namespace { |
67 | 53 |
68 NetLog::EventType EventTypeFromAuthTarget(HttpAuth::Target target) { | 54 NetLog::EventType EventTypeFromAuthTarget(HttpAuth::Target target) { |
69 switch (target) { | 55 switch (target) { |
70 case HttpAuth::AUTH_PROXY: | 56 case HttpAuth::AUTH_PROXY: |
71 return NetLog::TYPE_AUTH_PROXY; | 57 return NetLog::TYPE_AUTH_PROXY; |
72 case HttpAuth::AUTH_SERVER: | 58 case HttpAuth::AUTH_SERVER: |
(...skipping 10 matching lines...) Expand all Loading... | |
83 const string16* password, | 69 const string16* password, |
84 const HttpRequestInfo* request, | 70 const HttpRequestInfo* request, |
85 CompletionCallback* callback, | 71 CompletionCallback* callback, |
86 std::string* auth_token) { | 72 std::string* auth_token) { |
87 // TODO(cbentzel): Enforce non-NULL callback after cleaning up SocketStream. | 73 // TODO(cbentzel): Enforce non-NULL callback after cleaning up SocketStream. |
88 DCHECK(request); | 74 DCHECK(request); |
89 DCHECK((username == NULL) == (password == NULL)); | 75 DCHECK((username == NULL) == (password == NULL)); |
90 DCHECK(username != NULL || AllowsDefaultCredentials()); | 76 DCHECK(username != NULL || AllowsDefaultCredentials()); |
91 DCHECK(auth_token != NULL); | 77 DCHECK(auth_token != NULL); |
92 DCHECK(original_callback_ == NULL); | 78 DCHECK(original_callback_ == NULL); |
93 DCHECK(histogram_.get()); | |
94 original_callback_ = callback; | 79 original_callback_ = callback; |
95 net_log_.BeginEvent(EventTypeFromAuthTarget(target_), NULL); | 80 net_log_.BeginEvent(EventTypeFromAuthTarget(target_), NULL); |
96 generate_auth_token_start_ = base::TimeTicks::Now(); | |
97 int rv = GenerateAuthTokenImpl(username, password, request, | 81 int rv = GenerateAuthTokenImpl(username, password, request, |
98 &wrapper_callback_, auth_token); | 82 &wrapper_callback_, auth_token); |
99 if (rv != ERR_IO_PENDING) | 83 if (rv != ERR_IO_PENDING) |
100 FinishGenerateAuthToken(); | 84 FinishGenerateAuthToken(); |
101 return rv; | 85 return rv; |
102 } | 86 } |
103 | 87 |
104 bool HttpAuthHandler::NeedsIdentity() { | 88 bool HttpAuthHandler::NeedsIdentity() { |
105 return true; | 89 return true; |
106 } | 90 } |
107 | 91 |
108 bool HttpAuthHandler::AllowsDefaultCredentials() { | 92 bool HttpAuthHandler::AllowsDefaultCredentials() { |
109 return false; | 93 return false; |
110 } | 94 } |
111 | 95 |
112 void HttpAuthHandler::OnGenerateAuthTokenComplete(int rv) { | 96 void HttpAuthHandler::OnGenerateAuthTokenComplete(int rv) { |
113 CompletionCallback* callback = original_callback_; | 97 CompletionCallback* callback = original_callback_; |
114 FinishGenerateAuthToken(); | 98 FinishGenerateAuthToken(); |
115 if (callback) | 99 if (callback) |
116 callback->Run(rv); | 100 callback->Run(rv); |
117 } | 101 } |
118 | 102 |
119 void HttpAuthHandler::FinishGenerateAuthToken() { | 103 void HttpAuthHandler::FinishGenerateAuthToken() { |
120 // TOOD(cbentzel): Should this be done in OK case only? | 104 // TOOD(cbentzel): Should this be done in OK case only? |
121 DCHECK(histogram_.get()); | |
122 base::TimeDelta generate_auth_token_duration = | |
123 base::TimeTicks::Now() - generate_auth_token_start_; | |
124 histogram_->AddTime(generate_auth_token_duration); | |
125 net_log_.EndEvent(EventTypeFromAuthTarget(target_), NULL); | 105 net_log_.EndEvent(EventTypeFromAuthTarget(target_), NULL); |
126 original_callback_ = NULL; | 106 original_callback_ = NULL; |
127 } | 107 } |
128 | 108 |
129 } // namespace net | 109 } // namespace net |
OLD | NEW |