diff options
author | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-19 05:56:38 +0000 |
---|---|---|
committer | mbelshe@chromium.org <mbelshe@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-19 05:56:38 +0000 |
commit | 8e6441caa3adedf373b8ff80bb1fb48caff81556 (patch) | |
tree | 4a37d2fe5aaa3aad04b01171feb04e329c7e0383 /net/http/http_stream_request.h | |
parent | 33f275a2e2e703c58f514af8efe963e2e29792f9 (diff) | |
download | chromium_src-8e6441caa3adedf373b8ff80bb1fb48caff81556.zip chromium_src-8e6441caa3adedf373b8ff80bb1fb48caff81556.tar.gz chromium_src-8e6441caa3adedf373b8ff80bb1fb48caff81556.tar.bz2 |
Extract connection logic from HttpNetworkTransaction into a new
HttpStreamFactory. The HttpNetworkTransaction now deals exclusively with
streams rather than connections directly. This cut the size of HTN roughly in
in half.
The HttpNetworkTransaction is still responsible for all proxy and server
authentication functions. This is because the streams may come and go - we
could create a stream, have the server declare auth is needed, and then the
next attempt would be on a different stream. So Auth belongs on the HNT.
The HNT no longer has direct access to the connection itself; instead, it
only knows of an HttpStream.
The StreamRequest, however, is responsible for determining whether the
connection needs to use a proxy, whether AlternateProtocols are available, and
whether the connection should be SPDY or HTTP.
Other changes:
- moved some static configuration methods from HNT to HttpStreamFactory.
- added some methods to the HttpStream.
BUG=none
TEST=all
Review URL: http://codereview.chromium.org/3171002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56646 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_stream_request.h')
-rw-r--r-- | net/http/http_stream_request.h | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/net/http/http_stream_request.h b/net/http/http_stream_request.h new file mode 100644 index 0000000..3039839 --- /dev/null +++ b/net/http/http_stream_request.h @@ -0,0 +1,205 @@ +// Copyright (c) 2010 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_HTTP_HTTP_STREAM_REQUEST_H_ +#define NET_HTTP_HTTP_STREAM_REQUEST_H_ + +#include "base/scoped_ptr.h" +#include "net/base/completion_callback.h" +#include "net/base/host_mapping_rules.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_alternate_protocols.h" +#include "net/http/http_stream_factory.h" +#include "net/http/stream_factory.h" +#include "net/proxy/proxy_service.h" +#include "net/socket/client_socket_handle.h" + +namespace net { + +class ClientSocketHandle; +class HttpAuthController; +class HttpNetworkSession; +class HttpStreamFactory; +class StreamRequestDelegate; + +// An HttpStreamRequest exists for each stream which is in progress of being +// created for the StreamFactory. +class HttpStreamRequest : public StreamFactory::StreamRequestJob { + public: + HttpStreamRequest(HttpStreamFactory* factory, + const scoped_refptr<HttpNetworkSession>& session); + virtual ~HttpStreamRequest(); + + // StreamRequest interface + virtual void Start(const HttpRequestInfo* request_info, + SSLConfig* ssl_config, + ProxyInfo* proxy_info, + StreamFactory::StreamRequestDelegate* delegate, + const BoundNetLog& net_log); + virtual void Cancel(); + virtual int RestartWithCertificate( + const scoped_refptr<X509Certificate>& client_cert); + virtual int RestartTunnelWithProxyAuth(const string16& username, + const string16& password); + virtual LoadState GetLoadState() const; + + virtual bool was_alternate_protocol_available() const { + return was_alternate_protocol_available_; + } + virtual bool was_npn_negotiated() const { return was_npn_negotiated_; } + virtual bool using_spdy() const { return using_spdy_; } + + private: + enum AlternateProtocolMode { + kUnspecified, // Unspecified, check HttpAlternateProtocols + kUsingAlternateProtocol, // Using an alternate protocol + kDoNotUseAlternateProtocol, // Failed to connect once, do not try again. + }; + + enum State { + STATE_RESOLVE_PROXY, + STATE_RESOLVE_PROXY_COMPLETE, + STATE_INIT_CONNECTION, + STATE_INIT_CONNECTION_COMPLETE, + STATE_WAITING_USER_ACTION, + STATE_RESTART_TUNNEL_AUTH, + STATE_RESTART_TUNNEL_AUTH_COMPLETE, + STATE_INIT_STREAM, + STATE_INIT_STREAM_COMPLETE, + STATE_DRAIN_BODY_FOR_AUTH_RESTART, + STATE_DRAIN_BODY_FOR_AUTH_RESTART_COMPLETE, + STATE_NONE + }; + + const HttpRequestInfo& request_info() const; + ProxyInfo* proxy_info() const; + SSLConfig* ssl_config() const; + + // Callbacks to the delegate. + void OnStreamReadyCallback(HttpStreamHandle* stream); + void OnStreamFailedCallback(int result); + void OnCertificateErrorCallback(int result, const SSLInfo& ssl_info); + void OnNeedsProxyAuthCallback( + const scoped_refptr<HttpAuthController>& auth_controller, + const HttpResponseInfo& response_info); + void OnNeedsClientAuthCallback( + const scoped_refptr<SSLCertRequestInfo>& cert_info); + + void OnIOComplete(int result); + int RunLoop(int result); + int DoLoop(int result); + + // Each of these methods corresponds to a State value. Those with an input + // argument receive the result from the previous state. If a method returns + // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the + // next state method as the result arg. + int DoResolveProxy(); + int DoResolveProxyComplete(int result); + int DoInitConnection(); + int DoInitConnectionComplete(int result); + int DoWaitingUserAction(int result); + int DoInitStream(); + int DoInitStreamComplete(int result); + int DoRestartTunnelAuth(); + int DoRestartTunnelAuthComplete(int result); + + // AlternateProtocol API + void MarkBrokenAlternateProtocolAndFallback(); + + // Retrieve SSLInfo from our SSL Socket. + // This must only be called when we are using an SSLSocket. + // After calling, the caller can use ssl_info_. + void GetSSLInfo(); + + // Called when we encounter a network error that could be resolved by trying + // a new proxy configuration. If there is another proxy configuration to try + // then this method sets next_state_ appropriately and returns either OK or + // ERR_IO_PENDING depending on whether or not the new proxy configuration is + // available synchronously or asynchronously. Otherwise, the given error + // code is simply returned. + int ReconsiderProxyAfterError(int error); + + // Called to handle a certificate error. Stores the certificate in the + // allowed_bad_certs list, and checks if the error can be ignored. Returns + // OK if it can be ignored, or the error code otherwise. + int HandleCertificateError(int error); + + // Called to handle a client certificate request. + int HandleCertificateRequest(int error); + + // Called to possibly recover from an SSL handshake error. Sets next_state_ + // and returns OK if recovering from the error. Otherwise, the same error + // code is returned. + int HandleSSLHandshakeError(int error); + + // Record histograms of latency until Connect() completes. + static void LogHttpConnectedMetrics(const ClientSocketHandle& handle); + + const HttpRequestInfo* request_info_; // Use request_info(). + ProxyInfo* proxy_info_; // Use proxy_info(). + SSLConfig* ssl_config_; // Use ssl_config(). + + scoped_refptr<HttpNetworkSession> session_; + CompletionCallbackImpl<HttpStreamRequest> io_callback_; + scoped_ptr<ClientSocketHandle> connection_; + scoped_refptr<HttpStreamFactory> factory_; + StreamFactory::StreamRequestDelegate* delegate_; + BoundNetLog net_log_; + State next_state_; + ProxyService::PacRequest* pac_request_; + SSLInfo ssl_info_; + // The hostname and port of the endpoint. This is not necessarily the one + // specified by the URL, due to Alternate-Protocol or fixed testing ports. + HostPortPair endpoint_; + + // True if handling a HTTPS request, or using SPDY with SSL + bool using_ssl_; + + // True if this network transaction is using SPDY instead of HTTP. + bool using_spdy_; + + // Force spdy for all connections. + bool force_spdy_always_; + + // Force spdy only for SSL connections. + bool force_spdy_over_ssl_; + + // The certificate error while using SPDY over SSL for insecure URLs. + int spdy_certificate_error_; + + scoped_refptr<HttpAuthController> + auth_controllers_[HttpAuth::AUTH_NUM_TARGETS]; + + AlternateProtocolMode alternate_protocol_mode_; + + // Only valid if |alternate_protocol_mode_| == kUsingAlternateProtocol. + HttpAlternateProtocols::Protocol alternate_protocol_; + + // True when the tunnel is in the process of being established - we can't + // read from the socket until the tunnel is done. + bool establishing_tunnel_; + + scoped_ptr<HttpStreamHandle> stream_; + + // True if finding the connection for this request found an alternate + // protocol was available. + bool was_alternate_protocol_available_; + + // True if we negotiated NPN. + bool was_npn_negotiated_; + + // Indicates that this StreamRequest has been cancelled. Note that once + // this has been cancelled, input parameters passed into the StreamRequest + // can no longer be touched (as they belong to the requestor). + bool cancelled_; + + DISALLOW_COPY_AND_ASSIGN(HttpStreamRequest); +}; + +} // namespace net + +#endif // NET_HTTP_HTTP_STREAM_REQUEST_H_ + |