| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/singleton.h" | 5 #include "base/singleton.h" |
| 6 #include "net/url_request/https_prober.h" | 6 #include "net/url_request/https_prober.h" |
| 7 | 7 |
| 8 #include "net/url_request/url_request.h" | 8 #include "net/url_request/url_request.h" |
| 9 #include "net/url_request/url_request_context.h" | 9 #include "net/url_request/url_request_context.h" |
| 10 | 10 |
| 11 namespace net { | 11 namespace net { |
| 12 | 12 |
| 13 HTTPSProber::HTTPSProber() { | |
| 14 } | |
| 15 | |
| 16 HTTPSProber::~HTTPSProber() { | |
| 17 } | |
| 18 | |
| 19 // static | 13 // static |
| 20 HTTPSProber* HTTPSProber::GetInstance() { | 14 HTTPSProber* HTTPSProber::GetInstance() { |
| 21 return Singleton<HTTPSProber>::get(); | 15 return Singleton<HTTPSProber>::get(); |
| 22 } | 16 } |
| 23 | 17 |
| 24 bool HTTPSProber::HaveProbed(const std::string& host) const { | 18 bool HTTPSProber::HaveProbed(const std::string& host) const { |
| 25 return probed_.find(host) != probed_.end(); | 19 return probed_.find(host) != probed_.end(); |
| 26 } | 20 } |
| 27 | 21 |
| 28 bool HTTPSProber::InFlight(const std::string& host) const { | 22 bool HTTPSProber::InFlight(const std::string& host) const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 39 | 33 |
| 40 GURL url("https://" + host); | 34 GURL url("https://" + host); |
| 41 DCHECK_EQ(url.host(), host); | 35 DCHECK_EQ(url.host(), host); |
| 42 | 36 |
| 43 net::URLRequest* req = new net::URLRequest(url, this); | 37 net::URLRequest* req = new net::URLRequest(url, this); |
| 44 req->set_context(ctx); | 38 req->set_context(ctx); |
| 45 req->Start(); | 39 req->Start(); |
| 46 return true; | 40 return true; |
| 47 } | 41 } |
| 48 | 42 |
| 49 void HTTPSProber::Success(net::URLRequest* request) { | |
| 50 DoCallback(request, true); | |
| 51 } | |
| 52 | |
| 53 void HTTPSProber::Failure(net::URLRequest* request) { | |
| 54 DoCallback(request, false); | |
| 55 } | |
| 56 | |
| 57 void HTTPSProber::DoCallback(net::URLRequest* request, bool result) { | |
| 58 std::map<std::string, HTTPSProberDelegate*>::iterator i = | |
| 59 inflight_probes_.find(request->original_url().host()); | |
| 60 DCHECK(i != inflight_probes_.end()); | |
| 61 | |
| 62 HTTPSProberDelegate* delegate = i->second; | |
| 63 inflight_probes_.erase(i); | |
| 64 probed_.insert(request->original_url().host()); | |
| 65 delete request; | |
| 66 delegate->ProbeComplete(result); | |
| 67 } | |
| 68 | |
| 69 void HTTPSProber::OnAuthRequired(net::URLRequest* request, | 43 void HTTPSProber::OnAuthRequired(net::URLRequest* request, |
| 70 net::AuthChallengeInfo* auth_info) { | 44 net::AuthChallengeInfo* auth_info) { |
| 71 Success(request); | 45 Success(request); |
| 72 } | 46 } |
| 73 | 47 |
| 74 void HTTPSProber::OnSSLCertificateError(net::URLRequest* request, | 48 void HTTPSProber::OnSSLCertificateError(net::URLRequest* request, |
| 75 int cert_error, | 49 int cert_error, |
| 76 net::X509Certificate* cert) { | 50 net::X509Certificate* cert) { |
| 77 request->ContinueDespiteLastError(); | 51 request->ContinueDespiteLastError(); |
| 78 } | 52 } |
| 79 | 53 |
| 80 void HTTPSProber::OnResponseStarted(net::URLRequest* request) { | 54 void HTTPSProber::OnResponseStarted(net::URLRequest* request) { |
| 81 if (request->status().status() == URLRequestStatus::SUCCESS) { | 55 if (request->status().status() == URLRequestStatus::SUCCESS) { |
| 82 Success(request); | 56 Success(request); |
| 83 } else { | 57 } else { |
| 84 Failure(request); | 58 Failure(request); |
| 85 } | 59 } |
| 86 } | 60 } |
| 87 | 61 |
| 88 void HTTPSProber::OnReadCompleted(net::URLRequest* request, int bytes_read) { | 62 void HTTPSProber::OnReadCompleted(net::URLRequest* request, int bytes_read) { |
| 89 NOTREACHED(); | 63 NOTREACHED(); |
| 90 } | 64 } |
| 91 | 65 |
| 66 HTTPSProber::HTTPSProber() { |
| 67 } |
| 68 |
| 69 HTTPSProber::~HTTPSProber() { |
| 70 } |
| 71 |
| 72 void HTTPSProber::Success(net::URLRequest* request) { |
| 73 DoCallback(request, true); |
| 74 } |
| 75 |
| 76 void HTTPSProber::Failure(net::URLRequest* request) { |
| 77 DoCallback(request, false); |
| 78 } |
| 79 |
| 80 void HTTPSProber::DoCallback(net::URLRequest* request, bool result) { |
| 81 std::map<std::string, HTTPSProberDelegate*>::iterator i = |
| 82 inflight_probes_.find(request->original_url().host()); |
| 83 DCHECK(i != inflight_probes_.end()); |
| 84 |
| 85 HTTPSProberDelegate* delegate = i->second; |
| 86 inflight_probes_.erase(i); |
| 87 probed_.insert(request->original_url().host()); |
| 88 delete request; |
| 89 delegate->ProbeComplete(result); |
| 90 } |
| 91 |
| 92 } // namespace net | 92 } // namespace net |
| OLD | NEW |