summaryrefslogtreecommitdiffstats
path: root/net/http/http_stream_factory.h
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-23 00:08:48 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-23 00:08:48 +0000
commitc4744cdbbe22df6848e354dbfa9dbb1dc36e76d8 (patch)
treeb6d92d6b17ae0e140485fb53b53ef0017a99a6c0 /net/http/http_stream_factory.h
parent95fb385e5e68a69a39c77d66d801bebdaf39c311 (diff)
downloadchromium_src-c4744cdbbe22df6848e354dbfa9dbb1dc36e76d8.zip
chromium_src-c4744cdbbe22df6848e354dbfa9dbb1dc36e76d8.tar.gz
chromium_src-c4744cdbbe22df6848e354dbfa9dbb1dc36e76d8.tar.bz2
Revert 75668 for breaking ChromeOS build - Refactor HttpStreamFactory.
Rename StreamFactory and StreamRequest to HttpStreamFactory and HttpStreamRequest. Rename HttpStreamFactory to HttpStreamFactoryImpl. Create HttpStreamFactoryImpl::Request (inherits from HttpStreamRequest) and HttpStreamFactoryImpl::Job (most of the old HttpStreamRequest code, other than the interface, moved here). Currently there is still a strong binding within HttpStreamFactoryImpl between requests and jobs. This will be removed in a future changelist. Note that due to the preparation for late binding, information like HttpRequestInfo and SSLConfig and ProxyInfo are just copied. It's possible we can consider refcounting them to reduce copies, but I think it's not worth the effort / ugliness. I also did some minor cleanups like moving SpdySettingsStorage into SpdySessionPool and some CloseIdleConnections() cleanup. BUG=54371,42669 TEST=unit tests Review URL: http://codereview.chromium.org/6543004 TBR=willchan@chromium.org git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75670 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_stream_factory.h')
-rw-r--r--net/http/http_stream_factory.h213
1 files changed, 51 insertions, 162 deletions
diff --git a/net/http/http_stream_factory.h b/net/http/http_stream_factory.h
index 3d3bada..97bd79c 100644
--- a/net/http/http_stream_factory.h
+++ b/net/http/http_stream_factory.h
@@ -6,176 +6,35 @@
#define NET_HTTP_HTTP_STREAM_FACTORY_H_
#include <list>
+#include <map>
+#include <set>
#include <string>
-#include "base/string16.h"
-#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
#include "net/base/completion_callback.h"
-#include "net/base/load_states.h"
-
-class GURL;
+#include "net/base/host_mapping_rules.h"
+#include "net/base/host_port_pair.h"
+#include "net/base/ssl_config_service.h"
+#include "net/http/http_auth.h"
+#include "net/http/http_auth_controller.h"
+#include "net/http/http_stream_request.h"
+#include "net/http/stream_factory.h"
+#include "net/proxy/proxy_service.h"
+#include "net/socket/client_socket_handle.h"
namespace net {
-class BoundNetLog;
-class HostMappingRules;
-class HostPortPair;
-class HttpAlternateProtocols;
-class HttpAuthController;
class HttpNetworkSession;
-class HttpResponseInfo;
-class HttpStream;
-class ProxyInfo;
-class SSLCertRequestInfo;
-class SSLInfo;
-class X509Certificate;
struct HttpRequestInfo;
-struct SSLConfig;
-
-// The HttpStreamRequest is the client's handle to the worker object which
-// handles the creation of an HttpStream. While the HttpStream is being
-// created, this object is the creator's handle for interacting with the
-// HttpStream creation process. The request is cancelled by deleting it, after
-// which no callbacks will be invoked.
-class HttpStreamRequest {
- public:
- // The HttpStreamRequest::Delegate is a set of callback methods for a
- // HttpStreamRequestJob. Generally, only one of these methods will be
- // called as a result of a stream request.
- class Delegate {
- public:
- virtual ~Delegate() {}
-
- // This is the success case.
- // |stream| is now owned by the delegate.
- // |used_ssl_config| indicates the actual SSL configuration used for this
- // stream, since the HttpStreamRequest may have modified the configuration
- // during stream processing.
- // |used_proxy_info| indicates the actual ProxyInfo used for this stream,
- // since the HttpStreamRequest performs the proxy resolution.
- virtual void OnStreamReady(
- const SSLConfig& used_ssl_config,
- const ProxyInfo& used_proxy_info,
- HttpStream* stream) = 0;
-
- // This is the failure to create a stream case.
- // |used_ssl_config| indicates the actual SSL configuration used for this
- // stream, since the HttpStreamRequest may have modified the configuration
- // during stream processing.
- virtual void OnStreamFailed(int status,
- const SSLConfig& used_ssl_config) = 0;
-
- // Called when we have a certificate error for the request.
- // |used_ssl_config| indicates the actual SSL configuration used for this
- // stream, since the HttpStreamRequest may have modified the configuration
- // during stream processing.
- virtual void OnCertificateError(int status,
- const SSLConfig& used_ssl_config,
- const SSLInfo& ssl_info) = 0;
-
- // This is the failure case where we need proxy authentication during
- // proxy tunnel establishment. For the tunnel case, we were unable to
- // create the HttpStream, so the caller provides the auth and then resumes
- // the HttpStreamRequest.
- //
- // For the non-tunnel case, the caller will discover the authentication
- // failure when reading response headers. At that point, he will handle the
- // authentication failure and restart the HttpStreamRequest entirely.
- //
- // Ownership of |auth_controller| and |proxy_response| are owned
- // by the HttpStreamRequest. |proxy_response| is not guaranteed to be usable
- // after the lifetime of this callback. The delegate may take a reference
- // to |auth_controller| if it is needed beyond the lifetime of this
- // callback.
- //
- // |used_ssl_config| indicates the actual SSL configuration used for this
- // stream, since the HttpStreamRequest may have modified the configuration
- // during stream processing.
- virtual void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response,
- const SSLConfig& used_ssl_config,
- const ProxyInfo& used_proxy_info,
- HttpAuthController* auth_controller) = 0;
-
- // This is the failure for SSL Client Auth
- // Ownership of |cert_info| is retained by the HttpStreamRequest. The
- // delegate may take a reference if it needs the cert_info beyond the
- // lifetime of this callback.
- virtual void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
- SSLCertRequestInfo* cert_info) = 0;
-
- // This is the failure of the CONNECT request through an HTTPS proxy.
- // Headers can be read from |response_info|, while the body can be read
- // from |stream|.
- //
- // |used_ssl_config| indicates the actual SSL configuration used for this
- // stream, since the HttpStreamRequest may have modified the configuration
- // during stream processing.
- //
- // |used_proxy_info| indicates the actual ProxyInfo used for this stream,
- // since the HttpStreamRequest performs the proxy resolution.
- //
- // Ownership of |stream| is transferred to the delegate.
- virtual void OnHttpsProxyTunnelResponse(
- const HttpResponseInfo& response_info,
- const SSLConfig& used_ssl_config,
- const ProxyInfo& used_proxy_info,
- HttpStream* stream) = 0;
- };
-
- virtual ~HttpStreamRequest() {}
-
- // When a HttpStream creation process is stalled due to necessity
- // of Proxy authentication credentials, the delegate OnNeedsProxyAuth
- // will have been called. It now becomes the delegate's responsibility
- // to collect the necessary credentials, and then call this method to
- // resume the HttpStream creation process.
- virtual int RestartTunnelWithProxyAuth(const string16& username,
- const string16& password) = 0;
-
- // Returns the LoadState for the request.
- virtual LoadState GetLoadState() const = 0;
-
- // Returns true if an AlternateProtocol for this request was available.
- virtual bool was_alternate_protocol_available() const = 0;
-
- // Returns true if TLS/NPN was negotiated for this stream.
- virtual bool was_npn_negotiated() const = 0;
-
- // Returns true if this stream is being fetched over SPDY.
- virtual bool using_spdy() const = 0;
-};
+class HttpStreamRequest;
-// The HttpStreamFactory defines an interface for creating usable HttpStreams.
-class HttpStreamFactory {
+class HttpStreamFactory : public StreamFactory,
+ public HttpStreamRequest::PreconnectDelegate {
public:
+ HttpStreamFactory();
virtual ~HttpStreamFactory();
- void ProcessAlternateProtocol(
- HttpAlternateProtocols* alternate_protocols,
- const std::string& alternate_protocol_str,
- const HostPortPair& http_host_port_pair);
-
- // Virtual interface methods.
-
- // Request a stream.
- // Will callback to the HttpStreamRequestDelegate upon completion.
- virtual HttpStreamRequest* RequestStream(
- const HttpRequestInfo& info,
- const SSLConfig& ssl_config,
- HttpStreamRequest::Delegate* delegate,
- const BoundNetLog& net_log) = 0;
-
- // Requests that enough connections for |num_streams| be opened.
- virtual void PreconnectStreams(int num_streams,
- const HttpRequestInfo& info,
- const SSLConfig& ssl_config,
- const BoundNetLog& net_log) = 0;
-
- virtual void AddTLSIntolerantServer(const GURL& url) = 0;
- virtual bool IsTLSIntolerantServer(const GURL& url) const = 0;
-
// Static settings
- static GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint);
// Turns spdy on or off.
static void set_spdy_enabled(bool value) {
@@ -206,7 +65,12 @@ class HttpStreamFactory {
static bool force_spdy_always() { return force_spdy_always_; }
// Add a URL to exclude from forced SPDY.
- static void add_forced_spdy_exclusion(const std::string& value);
+ static void add_forced_spdy_exclusion(const std::string& value) {
+ HostPortPair pair = HostPortPair::FromURL(GURL(value));
+ if (!forced_spdy_exclusions_)
+ forced_spdy_exclusions_ = new std::list<HostPortPair>();
+ forced_spdy_exclusions_->push_back(pair);
+ }
static std::list<HostPortPair>* forced_spdy_exclusions() {
return forced_spdy_exclusions_;
}
@@ -218,7 +82,7 @@ class HttpStreamFactory {
}
static const std::string* next_protos() { return next_protos_; }
- // Sets the HttpStreamFactoryImpl into a mode where it can ignore certificate
+ // Sets the HttpStreamFactory into a mode where it can ignore certificate
// errors. This is for testing.
static void set_ignore_certificate_errors(bool value) {
ignore_certificate_errors_ = value;
@@ -229,11 +93,35 @@ class HttpStreamFactory {
static void SetHostMappingRules(const std::string& rules);
- protected:
- HttpStreamFactory();
+ // StreamFactory Interface
+ virtual StreamRequest* RequestStream(const HttpRequestInfo* info,
+ SSLConfig* ssl_config,
+ ProxyInfo* proxy_info,
+ HttpNetworkSession* session,
+ StreamRequest::Delegate* delegate,
+ const BoundNetLog& net_log);
+ virtual int PreconnectStreams(int num_streams,
+ const HttpRequestInfo* info,
+ SSLConfig* ssl_config,
+ ProxyInfo* proxy_info,
+ HttpNetworkSession* session,
+ const BoundNetLog& net_log,
+ CompletionCallback* callback);
+ virtual void AddTLSIntolerantServer(const GURL& url);
+ virtual bool IsTLSIntolerantServer(const GURL& url);
+ virtual void ProcessAlternateProtocol(
+ HttpAlternateProtocols* alternate_protocols,
+ const std::string& alternate_protocol_str,
+ const HostPortPair& http_host_port_pair);
+ virtual GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint);
+
+ // HttpStreamRequest::PreconnectDelegate API
+ virtual void OnPreconnectsComplete(HttpStreamRequest* request, int result);
private:
- static const HostMappingRules& host_mapping_rules();
+ typedef std::map<HttpStreamRequest*, CompletionCallback*> RequestCallbackMap;
+ RequestCallbackMap request_callback_map_;
+ std::set<std::string> tls_intolerant_servers_;
static const HostMappingRules* host_mapping_rules_;
static const std::string* next_protos_;
@@ -250,3 +138,4 @@ class HttpStreamFactory {
} // namespace net
#endif // NET_HTTP_HTTP_STREAM_FACTORY_H_
+