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/socket/ssl_host_info.h" | 5 #include "net/socket/ssl_host_info.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/pickle.h" | 9 #include "base/pickle.h" |
10 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 } | 25 } |
26 | 26 |
27 SSLHostInfo::SSLHostInfo( | 27 SSLHostInfo::SSLHostInfo( |
28 const std::string& hostname, | 28 const std::string& hostname, |
29 const SSLConfig& ssl_config, | 29 const SSLConfig& ssl_config, |
30 CertVerifier* cert_verifier) | 30 CertVerifier* cert_verifier) |
31 : cert_verification_complete_(false), | 31 : cert_verification_complete_(false), |
32 cert_verification_error_(ERR_CERT_INVALID), | 32 cert_verification_error_(ERR_CERT_INVALID), |
33 hostname_(hostname), | 33 hostname_(hostname), |
34 cert_parsing_failed_(false), | 34 cert_parsing_failed_(false), |
35 cert_verification_callback_(NULL), | |
36 rev_checking_enabled_(ssl_config.rev_checking_enabled), | 35 rev_checking_enabled_(ssl_config.rev_checking_enabled), |
37 verify_ev_cert_(ssl_config.verify_ev_cert), | 36 verify_ev_cert_(ssl_config.verify_ev_cert), |
38 verifier_(cert_verifier), | 37 verifier_(cert_verifier), |
39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 38 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
40 dnsrr_resolver_(NULL), | 39 dnsrr_resolver_(NULL), |
41 dns_callback_(NULL), | 40 dns_callback_(NULL), |
42 dns_handle_(DnsRRResolver::kInvalidHandle) { | 41 dns_handle_(DnsRRResolver::kInvalidHandle) { |
43 } | 42 } |
44 | 43 |
45 SSLHostInfo::~SSLHostInfo() { | 44 SSLHostInfo::~SSLHostInfo() { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 verification_end_time_ = base::TimeTicks(); | 128 verification_end_time_ = base::TimeTicks(); |
130 int rv = verifier_.Verify( | 129 int rv = verifier_.Verify( |
131 cert_.get(), hostname_, flags, crl_set_, &cert_verify_result_, | 130 cert_.get(), hostname_, flags, crl_set_, &cert_verify_result_, |
132 base::Bind(&SSLHostInfo::VerifyCallback, weak_factory_.GetWeakPtr()), | 131 base::Bind(&SSLHostInfo::VerifyCallback, weak_factory_.GetWeakPtr()), |
133 // TODO(willchan): Figure out how to use NetLog here. | 132 // TODO(willchan): Figure out how to use NetLog here. |
134 BoundNetLog()); | 133 BoundNetLog()); |
135 if (rv != ERR_IO_PENDING) | 134 if (rv != ERR_IO_PENDING) |
136 VerifyCallback(rv); | 135 VerifyCallback(rv); |
137 } else { | 136 } else { |
138 cert_parsing_failed_ = true; | 137 cert_parsing_failed_ = true; |
139 DCHECK(!cert_verification_callback_); | 138 DCHECK(cert_verification_callback_.is_null()); |
140 } | 139 } |
141 } | 140 } |
142 | 141 |
143 return true; | 142 return true; |
144 } | 143 } |
145 | 144 |
146 std::string SSLHostInfo::Serialize() const { | 145 std::string SSLHostInfo::Serialize() const { |
147 Pickle p(sizeof(Pickle::Header)); | 146 Pickle p(sizeof(Pickle::Header)); |
148 | 147 |
149 static const unsigned kMaxCertificatesSize = 32 * 1024; | 148 static const unsigned kMaxCertificatesSize = 32 * 1024; |
(...skipping 24 matching lines...) Expand all Loading... |
174 return ""; | 173 return ""; |
175 } | 174 } |
176 | 175 |
177 return std::string(reinterpret_cast<const char *>(p.data()), p.size()); | 176 return std::string(reinterpret_cast<const char *>(p.data()), p.size()); |
178 } | 177 } |
179 | 178 |
180 const CertVerifyResult& SSLHostInfo::cert_verify_result() const { | 179 const CertVerifyResult& SSLHostInfo::cert_verify_result() const { |
181 return cert_verify_result_; | 180 return cert_verify_result_; |
182 } | 181 } |
183 | 182 |
184 int SSLHostInfo::WaitForCertVerification(OldCompletionCallback* callback) { | 183 int SSLHostInfo::WaitForCertVerification(const CompletionCallback& callback) { |
185 if (cert_verification_complete_) | 184 if (cert_verification_complete_) |
186 return cert_verification_error_; | 185 return cert_verification_error_; |
| 186 |
187 DCHECK(!cert_parsing_failed_); | 187 DCHECK(!cert_parsing_failed_); |
188 DCHECK(!cert_verification_callback_); | 188 DCHECK(cert_verification_callback_.is_null()); |
189 DCHECK(!state_.certs.empty()); | 189 DCHECK(!state_.certs.empty()); |
190 cert_verification_callback_ = callback; | 190 cert_verification_callback_ = callback; |
191 return ERR_IO_PENDING; | 191 return ERR_IO_PENDING; |
192 } | 192 } |
193 | 193 |
194 void SSLHostInfo::VerifyCallback(int rv) { | 194 void SSLHostInfo::VerifyCallback(int rv) { |
195 DCHECK(!verification_start_time_.is_null()); | 195 DCHECK(!verification_start_time_.is_null()); |
196 base::TimeTicks now = base::TimeTicks::Now(); | 196 base::TimeTicks now = base::TimeTicks::Now(); |
197 const base::TimeDelta duration = now - verification_start_time(); | 197 const base::TimeDelta duration = now - verification_start_time(); |
198 bool is_google = hostname_ == "google.com" || | 198 bool is_google = hostname_ == "google.com" || |
199 (hostname_.size() > 11 && | 199 (hostname_.size() > 11 && |
200 hostname_.rfind(".google.com") == hostname_.size() - 11); | 200 hostname_.rfind(".google.com") == hostname_.size() - 11); |
201 if (is_google) { | 201 if (is_google) { |
202 UMA_HISTOGRAM_TIMES("Net.SSLHostInfoVerificationTimeMs_Google", duration); | 202 UMA_HISTOGRAM_TIMES("Net.SSLHostInfoVerificationTimeMs_Google", duration); |
203 } | 203 } |
204 UMA_HISTOGRAM_TIMES("Net.SSLHostInfoVerificationTimeMs", duration); | 204 UMA_HISTOGRAM_TIMES("Net.SSLHostInfoVerificationTimeMs", duration); |
205 VLOG(1) << "Verification took " << duration.InMilliseconds() << "ms"; | 205 VLOG(1) << "Verification took " << duration.InMilliseconds() << "ms"; |
206 verification_end_time_ = now; | 206 verification_end_time_ = now; |
207 cert_verification_complete_ = true; | 207 cert_verification_complete_ = true; |
208 cert_verification_error_ = rv; | 208 cert_verification_error_ = rv; |
209 if (cert_verification_callback_) { | 209 if (!cert_verification_callback_.is_null()) { |
210 OldCompletionCallback* callback = cert_verification_callback_; | 210 CompletionCallback callback = cert_verification_callback_; |
211 cert_verification_callback_ = NULL; | 211 cert_verification_callback_.Reset(); |
212 callback->Run(rv); | 212 callback.Run(rv); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 SSLHostInfoFactory::~SSLHostInfoFactory() {} | 216 SSLHostInfoFactory::~SSLHostInfoFactory() {} |
217 | 217 |
218 } // namespace net | 218 } // namespace net |
OLD | NEW |