summaryrefslogtreecommitdiffstats
path: root/net/url_request
diff options
context:
space:
mode:
authormnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-01 13:40:02 +0000
committermnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-01 13:40:02 +0000
commitbe4d55fe8d843628223a7b40162007ab734d1402 (patch)
treed8ecca580b0561fab811d41447339cfd473ae229 /net/url_request
parent221e544540fc33994373a8e88ba68300f840da75 (diff)
downloadchromium_src-be4d55fe8d843628223a7b40162007ab734d1402.zip
chromium_src-be4d55fe8d843628223a7b40162007ab734d1402.tar.gz
chromium_src-be4d55fe8d843628223a7b40162007ab734d1402.tar.bz2
Move net::HTTPSProber from net_base to net
net::HTTPSProber belongs into the net library, where also it's only user net::URLRequest is living. This fixes undefined references in net_base caused by net::HTTPSProber when not linking against net. BUG=45493 TEST=Building hresolv with the plain ld linker in shared library configuration should not generate undefined references. Review URL: http://codereview.chromium.org/2441001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48632 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/url_request')
-rw-r--r--net/url_request/https_prober.cc80
-rw-r--r--net/url_request/https_prober.h73
-rw-r--r--net/url_request/url_request_http_job.cc2
3 files changed, 154 insertions, 1 deletions
diff --git a/net/url_request/https_prober.cc b/net/url_request/https_prober.cc
new file mode 100644
index 0000000..a7163ba
--- /dev/null
+++ b/net/url_request/https_prober.cc
@@ -0,0 +1,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
diff --git a/net/url_request/https_prober.h b/net/url_request/https_prober.h
new file mode 100644
index 0000000..327fc16
--- /dev/null
+++ b/net/url_request/https_prober.h
@@ -0,0 +1,73 @@
+// 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.
+
+#ifndef NET_BASE_HTTPS_PROBER_H_
+#define NET_BASE_HTTPS_PROBER_H_
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "base/singleton.h"
+#include "base/task.h"
+#include "net/url_request/url_request.h"
+
+class URLRequestContext;
+
+namespace net {
+
+// This should be scoped inside HTTPSProber, but VC cannot compile
+// HTTPProber::Delegate when HTTPSProber also inherits from
+// URLRequest::Delegate.
+class HTTPSProberDelegate {
+ public:
+ virtual void ProbeComplete(bool result) = 0;
+};
+
+// HTTPSProber is a singleton object that manages HTTPS probes. A HTTPS probe
+// determines if we can connect to a given host over HTTPS. It's used when
+// transparently upgrading from HTTP to HTTPS (for example, for SPDY).
+class HTTPSProber : public URLRequest::Delegate {
+ public:
+ HTTPSProber() { }
+
+ // HaveProbed returns true if the given host is known to have been probed
+ // since the browser was last started.
+ bool HaveProbed(const std::string& host) const;
+
+ // InFlight returns true iff a probe for the given host is currently active.
+ bool InFlight(const std::string& host) const;
+
+ // ProbeHost starts a new probe for the given host. If the host is known to
+ // have been probed since the browser was started, false is returned and no
+ // other action is taken. If a probe to the given host in currently inflight,
+ // false will be returned, and no other action is taken. Otherwise, a new
+ // probe is started, true is returned and the Delegate will be called with the
+ // results (true means a successful handshake).
+ bool ProbeHost(const std::string& host, URLRequestContext* ctx,
+ HTTPSProberDelegate* delegate);
+
+ // Implementation of URLRequest::Delegate
+ void OnAuthRequired(URLRequest* request,
+ net::AuthChallengeInfo* auth_info);
+ void OnSSLCertificateError(URLRequest* request,
+ int cert_error,
+ net::X509Certificate* cert);
+ void OnResponseStarted(URLRequest* request);
+ void OnReadCompleted(URLRequest* request, int bytes_read);
+
+ private:
+ void Success(URLRequest* request);
+ void Failure(URLRequest* request);
+ void DoCallback(URLRequest* request, bool result);
+
+ std::map<std::string, HTTPSProberDelegate*> inflight_probes_;
+ std::set<std::string> probed_;
+
+ friend struct DefaultSingletonTraits<HTTPSProber>;
+ DISALLOW_EVIL_CONSTRUCTORS(HTTPSProber);
+};
+
+} // namespace net
+#endif
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index c907a6a..420100f 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -15,7 +15,6 @@
#include "net/base/cert_status_flags.h"
#include "net/base/cookie_policy.h"
#include "net/base/filter.h"
-#include "net/base/https_prober.h"
#include "net/base/transport_security_state.h"
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
@@ -28,6 +27,7 @@
#include "net/http/http_transaction.h"
#include "net/http/http_transaction_factory.h"
#include "net/http/http_util.h"
+#include "net/url_request/https_prober.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_error_job.h"