| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ | 5 #ifndef NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ |
| 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ | 6 #define NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "net/base/net_export.h" | |
| 13 #include "net/http/http_stream_factory_impl.h" | 12 #include "net/http/http_stream_factory_impl.h" |
| 14 #include "net/log/net_log.h" | 13 #include "net/log/net_log.h" |
| 15 #include "net/socket/connection_attempts.h" | 14 #include "net/socket/connection_attempts.h" |
| 16 #include "net/socket/ssl_client_socket.h" | 15 #include "net/socket/ssl_client_socket.h" |
| 17 #include "net/spdy/spdy_session_key.h" | 16 #include "net/spdy/spdy_session_key.h" |
| 18 #include "net/ssl/ssl_failure_state.h" | 17 #include "net/ssl/ssl_failure_state.h" |
| 19 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 20 | 19 |
| 21 namespace net { | 20 namespace net { |
| 22 | 21 |
| 23 class BidirectionalStreamImpl; | 22 class BidirectionalStreamImpl; |
| 24 class ClientSocketHandle; | 23 class ClientSocketHandle; |
| 25 class HttpStream; | 24 class HttpStream; |
| 26 class SpdySession; | 25 class SpdySession; |
| 27 | 26 |
| 28 class HttpStreamFactoryImpl::Request : public HttpStreamRequest { | 27 class HttpStreamFactoryImpl::Request : public HttpStreamRequest { |
| 29 public: | 28 public: |
| 30 class NET_EXPORT_PRIVATE Helper { | |
| 31 public: | |
| 32 virtual ~Helper() {} | |
| 33 | |
| 34 // Returns the LoadState for Request. | |
| 35 virtual LoadState GetLoadState() const = 0; | |
| 36 | |
| 37 // Called when Request is destructed. | |
| 38 virtual void OnRequestComplete() = 0; | |
| 39 | |
| 40 // Called to resume the HttpStream creation process when necessary | |
| 41 // Proxy authentication credentials are collected. | |
| 42 virtual int RestartTunnelWithProxyAuth( | |
| 43 const AuthCredentials& credentials) = 0; | |
| 44 | |
| 45 // Called when the priority of transaction changes. | |
| 46 virtual void SetPriority(RequestPriority priority) = 0; | |
| 47 }; | |
| 48 | |
| 49 // Request will notify |job_controller| when it's destructed. | |
| 50 // Thus |job_controller| is valid for the lifetime of the |this| Request. | |
| 51 Request(const GURL& url, | 29 Request(const GURL& url, |
| 52 Helper* helper, | 30 HttpStreamFactoryImpl* factory, |
| 53 HttpStreamRequest::Delegate* delegate, | 31 HttpStreamRequest::Delegate* delegate, |
| 54 WebSocketHandshakeStreamBase::CreateHelper* | 32 WebSocketHandshakeStreamBase::CreateHelper* |
| 55 websocket_handshake_stream_create_helper, | 33 websocket_handshake_stream_create_helper, |
| 56 const BoundNetLog& net_log, | 34 const BoundNetLog& net_log, |
| 57 StreamType stream_type); | 35 StreamType stream_type); |
| 58 | 36 |
| 59 ~Request() override; | 37 ~Request() override; |
| 60 | 38 |
| 61 // The GURL from the HttpRequestInfo the started the Request. | 39 // The GURL from the HttpRequestInfo the started the Request. |
| 62 const GURL& url() const { return url_; } | 40 const GURL& url() const { return url_; } |
| 63 | 41 |
| 64 const BoundNetLog& net_log() const { return net_log_; } | 42 const BoundNetLog& net_log() const { return net_log_; } |
| 65 | 43 |
| 66 // Called when the |helper_| determines the appropriate |spdy_session_key| | 44 // Called when the Job determines the appropriate |spdy_session_key| for the |
| 67 // for the Request. Note that this does not mean that SPDY is necessarily | 45 // Request. Note that this does not mean that SPDY is necessarily supported |
| 68 // supported for this SpdySessionKey, since we may need to wait for NPN to | 46 // for this SpdySessionKey, since we may need to wait for NPN to complete |
| 69 // complete before knowing if SPDY is available. | 47 // before knowing if SPDY is available. |
| 70 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key); | 48 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key); |
| 71 bool HasSpdySessionKey() const; | 49 bool HasSpdySessionKey() const; |
| 72 | 50 |
| 51 // Attaches |job| to this request. Does not mean that Request will use |job|, |
| 52 // but Request will own |job|. |
| 53 void AttachJob(HttpStreamFactoryImpl::Job* job); |
| 54 |
| 73 // Marks completion of the request. Must be called before OnStreamReady(). | 55 // Marks completion of the request. Must be called before OnStreamReady(). |
| 74 void Complete(bool was_npn_negotiated, | 56 void Complete(bool was_npn_negotiated, |
| 75 NextProto protocol_negotiated, | 57 NextProto protocol_negotiated, |
| 76 bool using_spdy); | 58 bool using_spdy); |
| 77 | 59 |
| 78 void ResetSpdySessionKey(); | 60 // If this Request has a |spdy_session_key_|, remove this session from the |
| 61 // SpdySessionRequestMap. |
| 62 void RemoveRequestFromSpdySessionRequestMap(); |
| 79 | 63 |
| 80 // Called by |helper_| to record connection attempts made by the socket | 64 // Called by an attached Job if it sets up a SpdySession. |
| 81 // layer in an attached Job for this stream request. | 65 // |stream| is null when |stream_type| is HttpStreamRequest::HTTP_STREAM. |
| 66 // |bidirectional_stream_spdy_impl| is null when |stream_type| is |
| 67 // HttpStreamRequest::BIDIRECTIONAL_STREAM. |
| 68 void OnNewSpdySessionReady( |
| 69 Job* job, |
| 70 std::unique_ptr<HttpStream> stream, |
| 71 std::unique_ptr<BidirectionalStreamImpl> bidirectional_stream_spdy_impl, |
| 72 const base::WeakPtr<SpdySession>& spdy_session, |
| 73 bool direct); |
| 74 |
| 75 // Called by an attached Job to record connection attempts made by the socket |
| 76 // layer for this stream request. |
| 82 void AddConnectionAttempts(const ConnectionAttempts& attempts); | 77 void AddConnectionAttempts(const ConnectionAttempts& attempts); |
| 83 | 78 |
| 84 WebSocketHandshakeStreamBase::CreateHelper* | 79 WebSocketHandshakeStreamBase::CreateHelper* |
| 85 websocket_handshake_stream_create_helper() { | 80 websocket_handshake_stream_create_helper() { |
| 86 return websocket_handshake_stream_create_helper_; | 81 return websocket_handshake_stream_create_helper_; |
| 87 } | 82 } |
| 88 | 83 |
| 89 // HttpStreamRequest::Delegate methods which we implement. Note we don't | 84 // HttpStreamRequest::Delegate methods which we implement. Note we don't |
| 90 // actually subclass HttpStreamRequest::Delegate. | 85 // actually subclass HttpStreamRequest::Delegate. |
| 91 | 86 |
| 92 void OnStreamReady(const SSLConfig& used_ssl_config, | 87 void OnStreamReady(Job* job, |
| 88 const SSLConfig& used_ssl_config, |
| 93 const ProxyInfo& used_proxy_info, | 89 const ProxyInfo& used_proxy_info, |
| 94 HttpStream* stream); | 90 HttpStream* stream); |
| 95 void OnBidirectionalStreamImplReady(const SSLConfig& used_ssl_config, | 91 void OnBidirectionalStreamImplReady(Job* job, |
| 92 const SSLConfig& used_ssl_config, |
| 96 const ProxyInfo& used_proxy_info, | 93 const ProxyInfo& used_proxy_info, |
| 97 BidirectionalStreamImpl* stream); | 94 BidirectionalStreamImpl* stream); |
| 98 | 95 |
| 99 void OnWebSocketHandshakeStreamReady(const SSLConfig& used_ssl_config, | 96 void OnWebSocketHandshakeStreamReady(Job* job, |
| 97 const SSLConfig& used_ssl_config, |
| 100 const ProxyInfo& used_proxy_info, | 98 const ProxyInfo& used_proxy_info, |
| 101 WebSocketHandshakeStreamBase* stream); | 99 WebSocketHandshakeStreamBase* stream); |
| 102 void OnStreamFailed(int status, | 100 void OnStreamFailed(Job* job, |
| 101 int status, |
| 103 const SSLConfig& used_ssl_config, | 102 const SSLConfig& used_ssl_config, |
| 104 SSLFailureState ssl_failure_state); | 103 SSLFailureState ssl_failure_state); |
| 105 void OnCertificateError(int status, | 104 void OnCertificateError(Job* job, |
| 105 int status, |
| 106 const SSLConfig& used_ssl_config, | 106 const SSLConfig& used_ssl_config, |
| 107 const SSLInfo& ssl_info); | 107 const SSLInfo& ssl_info); |
| 108 void OnNeedsProxyAuth(const HttpResponseInfo& proxy_response, | 108 void OnNeedsProxyAuth(Job* job, |
| 109 const HttpResponseInfo& proxy_response, |
| 109 const SSLConfig& used_ssl_config, | 110 const SSLConfig& used_ssl_config, |
| 110 const ProxyInfo& used_proxy_info, | 111 const ProxyInfo& used_proxy_info, |
| 111 HttpAuthController* auth_controller); | 112 HttpAuthController* auth_controller); |
| 112 void OnNeedsClientAuth(const SSLConfig& used_ssl_config, | 113 void OnNeedsClientAuth(Job* job, |
| 114 const SSLConfig& used_ssl_config, |
| 113 SSLCertRequestInfo* cert_info); | 115 SSLCertRequestInfo* cert_info); |
| 114 void OnHttpsProxyTunnelResponse( | 116 void OnHttpsProxyTunnelResponse( |
| 117 Job *job, |
| 115 const HttpResponseInfo& response_info, | 118 const HttpResponseInfo& response_info, |
| 116 const SSLConfig& used_ssl_config, | 119 const SSLConfig& used_ssl_config, |
| 117 const ProxyInfo& used_proxy_info, | 120 const ProxyInfo& used_proxy_info, |
| 118 HttpStream* stream); | 121 HttpStream* stream); |
| 119 | 122 |
| 120 // HttpStreamRequest methods. | 123 // HttpStreamRequest methods. |
| 121 | 124 |
| 122 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override; | 125 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override; |
| 123 void SetPriority(RequestPriority priority) override; | 126 void SetPriority(RequestPriority priority) override; |
| 124 LoadState GetLoadState() const override; | 127 LoadState GetLoadState() const override; |
| 125 bool was_npn_negotiated() const override; | 128 bool was_npn_negotiated() const override; |
| 126 NextProto protocol_negotiated() const override; | 129 NextProto protocol_negotiated() const override; |
| 127 bool using_spdy() const override; | 130 bool using_spdy() const override; |
| 128 const ConnectionAttempts& connection_attempts() const override; | 131 const ConnectionAttempts& connection_attempts() const override; |
| 129 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } | 132 HttpStreamRequest::StreamType stream_type() const { return stream_type_; } |
| 130 const SpdySessionKey* spdy_session_key() const { | |
| 131 return spdy_session_key_.get(); | |
| 132 } | |
| 133 | 133 |
| 134 private: | 134 private: |
| 135 // Used to bind |job| to the request and orphan all other jobs in |jobs_|. |
| 136 void BindJob(Job* job); |
| 137 |
| 138 // Used to orphan all jobs in |jobs_|. |
| 139 void OrphanJobs(); |
| 140 |
| 141 // Used to cancel all jobs in |jobs_|. |
| 142 void CancelJobs(); |
| 143 |
| 144 // Called when a Job succeeds. |
| 145 void OnJobSucceeded(Job* job); |
| 146 |
| 135 const GURL url_; | 147 const GURL url_; |
| 136 | 148 HttpStreamFactoryImpl* const factory_; |
| 137 // Unowned. The helper must outlive this request. | |
| 138 Helper* helper_; | |
| 139 | |
| 140 WebSocketHandshakeStreamBase::CreateHelper* const | 149 WebSocketHandshakeStreamBase::CreateHelper* const |
| 141 websocket_handshake_stream_create_helper_; | 150 websocket_handshake_stream_create_helper_; |
| 142 HttpStreamRequest::Delegate* const delegate_; | 151 HttpStreamRequest::Delegate* const delegate_; |
| 143 const BoundNetLog net_log_; | 152 const BoundNetLog net_log_; |
| 144 | 153 |
| 154 // At the point where Job is irrevocably tied to the Request, we set this. |
| 155 std::unique_ptr<Job> bound_job_; |
| 156 std::set<HttpStreamFactoryImpl::Job*> jobs_; |
| 145 std::unique_ptr<const SpdySessionKey> spdy_session_key_; | 157 std::unique_ptr<const SpdySessionKey> spdy_session_key_; |
| 146 | 158 |
| 147 bool completed_; | 159 bool completed_; |
| 148 bool was_npn_negotiated_; | 160 bool was_npn_negotiated_; |
| 149 // Protocol negotiated with the server. | 161 // Protocol negotiated with the server. |
| 150 NextProto protocol_negotiated_; | 162 NextProto protocol_negotiated_; |
| 151 bool using_spdy_; | 163 bool using_spdy_; |
| 152 ConnectionAttempts connection_attempts_; | 164 ConnectionAttempts connection_attempts_; |
| 153 | 165 |
| 154 const HttpStreamRequest::StreamType stream_type_; | 166 const HttpStreamRequest::StreamType stream_type_; |
| 155 DISALLOW_COPY_AND_ASSIGN(Request); | 167 DISALLOW_COPY_AND_ASSIGN(Request); |
| 156 }; | 168 }; |
| 157 | 169 |
| 158 } // namespace net | 170 } // namespace net |
| 159 | 171 |
| 160 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ | 172 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ |
| OLD | NEW |