| 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> |
| (...skipping 15 matching lines...) Expand all Loading... |
| 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 net::URLRequest::Delegate { | 34 class HTTPSProber : public net::URLRequest::Delegate { |
| 35 public: | 35 public: |
| 36 HTTPSProber(); | 36 // Returns the singleton instance. |
| 37 ~HTTPSProber(); | 37 static HTTPSProber* GetInstance(); |
| 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 net::URLRequest::Delegate | 55 // Implementation of net::URLRequest::Delegate |
| 56 void OnAuthRequired(net::URLRequest* request, | 56 void OnAuthRequired(net::URLRequest* request, |
| 57 net::AuthChallengeInfo* auth_info); | 57 net::AuthChallengeInfo* auth_info); |
| 58 void OnSSLCertificateError(net::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(net::URLRequest* request); | 61 void OnResponseStarted(net::URLRequest* request); |
| 62 void OnReadCompleted(net::URLRequest* request, int bytes_read); | 62 void OnReadCompleted(net::URLRequest* request, int bytes_read); |
| 63 | 63 |
| 64 private: | 64 private: |
| 65 HTTPSProber(); |
| 66 ~HTTPSProber(); |
| 67 |
| 65 void Success(net::URLRequest* request); | 68 void Success(net::URLRequest* request); |
| 66 void Failure(net::URLRequest* request); | 69 void Failure(net::URLRequest* request); |
| 67 void DoCallback(net::URLRequest* request, bool result); | 70 void DoCallback(net::URLRequest* request, bool result); |
| 68 | 71 |
| 69 std::map<std::string, HTTPSProberDelegate*> inflight_probes_; | 72 std::map<std::string, HTTPSProberDelegate*> inflight_probes_; |
| 70 std::set<std::string> probed_; | 73 std::set<std::string> probed_; |
| 71 | 74 |
| 72 friend struct DefaultSingletonTraits<HTTPSProber>; | 75 friend struct DefaultSingletonTraits<HTTPSProber>; |
| 73 DISALLOW_COPY_AND_ASSIGN(HTTPSProber); | 76 DISALLOW_COPY_AND_ASSIGN(HTTPSProber); |
| 74 }; | 77 }; |
| 75 | 78 |
| 76 } // namespace net | 79 } // namespace net |
| 77 #endif | 80 #endif |
| OLD | NEW |