blob: a7163ba5b758b71b28705809a5f3e503cbab9005 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/url_request/https_prober.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
namespace net {
bool HTTPSProber::HaveProbed(const std::string& host) const {
return probed_.find(host) != probed_.end();
}
bool HTTPSProber::InFlight(const std::string& host) const {
return inflight_probes_.find(host) != inflight_probes_.end();
}
bool HTTPSProber::ProbeHost(const std::string& host, URLRequestContext* ctx,
HTTPSProberDelegate* delegate) {
if (HaveProbed(host) || InFlight(host)) {
return false;
}
inflight_probes_[host] = delegate;
GURL url("https://" + host);
DCHECK_EQ(url.host(), host);
URLRequest* req = new URLRequest(url, this);
req->set_context(ctx);
req->Start();
return true;
}
void HTTPSProber::Success(URLRequest* request) {
DoCallback(request, true);
}
void HTTPSProber::Failure(URLRequest* request) {
DoCallback(request, false);
}
void HTTPSProber::DoCallback(URLRequest* request, bool result) {
std::map<std::string, HTTPSProberDelegate*>::iterator i =
inflight_probes_.find(request->original_url().host());
DCHECK(i != inflight_probes_.end());
HTTPSProberDelegate* delegate = i->second;
inflight_probes_.erase(i);
probed_.insert(request->original_url().host());
delete request;
delegate->ProbeComplete(result);
}
void HTTPSProber::OnAuthRequired(URLRequest* request,
net::AuthChallengeInfo* auth_info) {
Success(request);
}
void HTTPSProber::OnSSLCertificateError(URLRequest* request,
int cert_error,
net::X509Certificate* cert) {
request->ContinueDespiteLastError();
}
void HTTPSProber::OnResponseStarted(URLRequest* request) {
if (request->status().status() == URLRequestStatus::SUCCESS) {
Success(request);
} else {
Failure(request);
}
}
void HTTPSProber::OnReadCompleted(URLRequest* request, int bytes_read) {
NOTREACHED();
}
} // namespace net
|