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 #ifndef NET_BASE_HTTPS_PROBER_H_ | 5 #ifndef NET_BASE_HTTPS_PROBER_H_ |
6 #define NET_BASE_HTTPS_PROBER_H_ | 6 #define NET_BASE_HTTPS_PROBER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/singleton.h" | 13 #include "base/singleton.h" |
14 #include "base/task.h" | 14 #include "base/task.h" |
15 #include "net/url_request/url_request.h" | 15 #include "net/url_request/url_request.h" |
16 | 16 |
17 class URLRequestContext; | 17 class URLRequestContext; |
18 | 18 |
19 namespace net { | 19 namespace net { |
20 | 20 |
21 // This should be scoped inside HTTPSProber, but VC cannot compile | 21 // This should be scoped inside HTTPSProber, but VC cannot compile |
22 // HTTPProber::Delegate when HTTPSProber also inherits from | 22 // HTTPProber::Delegate when HTTPSProber also inherits from |
23 // URLRequest::Delegate. | 23 // net::URLRequest::Delegate. |
24 class HTTPSProberDelegate { | 24 class HTTPSProberDelegate { |
25 public: | 25 public: |
26 virtual void ProbeComplete(bool result) = 0; | 26 virtual void ProbeComplete(bool result) = 0; |
27 protected: | 27 protected: |
28 virtual ~HTTPSProberDelegate() {} | 28 virtual ~HTTPSProberDelegate() {} |
29 }; | 29 }; |
30 | 30 |
31 // HTTPSProber is a singleton object that manages HTTPS probes. A HTTPS probe | 31 // HTTPSProber is a singleton object that manages HTTPS probes. A HTTPS probe |
32 // determines if we can connect to a given host over HTTPS. It's used when | 32 // determines if we can connect to a given host over HTTPS. It's used when |
33 // transparently upgrading from HTTP to HTTPS (for example, for SPDY). | 33 // transparently upgrading from HTTP to HTTPS (for example, for SPDY). |
34 class HTTPSProber : public URLRequest::Delegate { | 34 class HTTPSProber : public net::URLRequest::Delegate { |
35 public: | 35 public: |
36 HTTPSProber(); | 36 HTTPSProber(); |
37 ~HTTPSProber(); | 37 ~HTTPSProber(); |
38 | 38 |
39 // HaveProbed returns true if the given host is known to have been probed | 39 // HaveProbed returns true if the given host is known to have been probed |
40 // since the browser was last started. | 40 // since the browser was last started. |
41 bool HaveProbed(const std::string& host) const; | 41 bool HaveProbed(const std::string& host) const; |
42 | 42 |
43 // InFlight returns true iff a probe for the given host is currently active. | 43 // InFlight returns true iff a probe for the given host is currently active. |
44 bool InFlight(const std::string& host) const; | 44 bool InFlight(const std::string& host) const; |
45 | 45 |
46 // ProbeHost starts a new probe for the given host. If the host is known to | 46 // ProbeHost starts a new probe for the given host. If the host is known to |
47 // have been probed since the browser was started, false is returned and no | 47 // have been probed since the browser was started, false is returned and no |
48 // other action is taken. If a probe to the given host in currently inflight, | 48 // other action is taken. If a probe to the given host in currently inflight, |
49 // false will be returned, and no other action is taken. Otherwise, a new | 49 // false will be returned, and no other action is taken. Otherwise, a new |
50 // probe is started, true is returned and the Delegate will be called with the | 50 // probe is started, true is returned and the Delegate will be called with the |
51 // results (true means a successful handshake). | 51 // results (true means a successful handshake). |
52 bool ProbeHost(const std::string& host, URLRequestContext* ctx, | 52 bool ProbeHost(const std::string& host, URLRequestContext* ctx, |
53 HTTPSProberDelegate* delegate); | 53 HTTPSProberDelegate* delegate); |
54 | 54 |
55 // Implementation of URLRequest::Delegate | 55 // Implementation of net::URLRequest::Delegate |
56 void OnAuthRequired(URLRequest* request, | 56 void OnAuthRequired(net::URLRequest* request, |
57 net::AuthChallengeInfo* auth_info); | 57 net::AuthChallengeInfo* auth_info); |
58 void OnSSLCertificateError(URLRequest* request, | 58 void OnSSLCertificateError(net::URLRequest* request, |
59 int cert_error, | 59 int cert_error, |
60 net::X509Certificate* cert); | 60 net::X509Certificate* cert); |
61 void OnResponseStarted(URLRequest* request); | 61 void OnResponseStarted(net::URLRequest* request); |
62 void OnReadCompleted(URLRequest* request, int bytes_read); | 62 void OnReadCompleted(net::URLRequest* request, int bytes_read); |
63 | 63 |
64 private: | 64 private: |
65 void Success(URLRequest* request); | 65 void Success(net::URLRequest* request); |
66 void Failure(URLRequest* request); | 66 void Failure(net::URLRequest* request); |
67 void DoCallback(URLRequest* request, bool result); | 67 void DoCallback(net::URLRequest* request, bool result); |
68 | 68 |
69 std::map<std::string, HTTPSProberDelegate*> inflight_probes_; | 69 std::map<std::string, HTTPSProberDelegate*> inflight_probes_; |
70 std::set<std::string> probed_; | 70 std::set<std::string> probed_; |
71 | 71 |
72 friend struct DefaultSingletonTraits<HTTPSProber>; | 72 friend struct DefaultSingletonTraits<HTTPSProber>; |
73 DISALLOW_COPY_AND_ASSIGN(HTTPSProber); | 73 DISALLOW_COPY_AND_ASSIGN(HTTPSProber); |
74 }; | 74 }; |
75 | 75 |
76 } // namespace net | 76 } // namespace net |
77 #endif | 77 #endif |
OLD | NEW |