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 <set> | 8 #include <set> |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "net/http/http_stream_factory_impl.h" | 10 #include "net/http/http_stream_factory_impl.h" |
11 #include "net/log/net_log.h" | 11 #include "net/log/net_log.h" |
12 #include "net/socket/connection_attempts.h" | 12 #include "net/socket/connection_attempts.h" |
13 #include "net/socket/ssl_client_socket.h" | 13 #include "net/socket/ssl_client_socket.h" |
14 #include "net/spdy/spdy_session_key.h" | 14 #include "net/spdy/spdy_session_key.h" |
15 #include "net/ssl/ssl_failure_state.h" | 15 #include "net/ssl/ssl_failure_state.h" |
16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
17 | 17 |
18 namespace net { | 18 namespace net { |
19 | 19 |
20 class ClientSocketHandle; | 20 class ClientSocketHandle; |
21 class HttpStream; | 21 class HttpStream; |
22 class SpdySession; | 22 class SpdySession; |
23 | 23 |
24 class HttpStreamFactoryImpl::Request : public HttpStreamRequest { | 24 class HttpStreamFactoryImpl::Request : public HttpStreamRequest { |
25 public: | 25 public: |
| 26 // |for_bidirectional| should only be true if requesting for a |
| 27 // net::BidirectionalStream. |
26 Request(const GURL& url, | 28 Request(const GURL& url, |
27 HttpStreamFactoryImpl* factory, | 29 HttpStreamFactoryImpl* factory, |
28 HttpStreamRequest::Delegate* delegate, | 30 HttpStreamRequest::Delegate* delegate, |
29 WebSocketHandshakeStreamBase::CreateHelper* | 31 WebSocketHandshakeStreamBase::CreateHelper* |
30 websocket_handshake_stream_create_helper, | 32 websocket_handshake_stream_create_helper, |
31 const BoundNetLog& net_log); | 33 const BoundNetLog& net_log, |
| 34 bool for_bidirectional); |
| 35 |
32 ~Request() override; | 36 ~Request() override; |
33 | 37 |
34 // The GURL from the HttpRequestInfo the started the Request. | 38 // The GURL from the HttpRequestInfo the started the Request. |
35 const GURL& url() const { return url_; } | 39 const GURL& url() const { return url_; } |
36 | 40 |
37 const BoundNetLog& net_log() const { return net_log_; } | 41 const BoundNetLog& net_log() const { return net_log_; } |
38 | 42 |
39 // Called when the Job determines the appropriate |spdy_session_key| for the | 43 // Called when the Job determines the appropriate |spdy_session_key| for the |
40 // Request. Note that this does not mean that SPDY is necessarily supported | 44 // Request. Note that this does not mean that SPDY is necessarily supported |
41 // for this SpdySessionKey, since we may need to wait for NPN to complete | 45 // for this SpdySessionKey, since we may need to wait for NPN to complete |
42 // before knowing if SPDY is available. | 46 // before knowing if SPDY is available. |
43 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key); | 47 void SetSpdySessionKey(const SpdySessionKey& spdy_session_key); |
44 bool HasSpdySessionKey() const; | 48 bool HasSpdySessionKey() const; |
45 | 49 |
46 // Attaches |job| to this request. Does not mean that Request will use |job|, | 50 // Attaches |job| to this request. Does not mean that Request will use |job|, |
47 // but Request will own |job|. | 51 // but Request will own |job|. |
48 void AttachJob(HttpStreamFactoryImpl::Job* job); | 52 void AttachJob(HttpStreamFactoryImpl::Job* job); |
49 | 53 |
50 // Marks completion of the request. Must be called before OnStreamReady(). | 54 // Marks completion of the request. Must be called before OnStreamReady(). |
51 void Complete(bool was_npn_negotiated, | 55 void Complete(bool was_npn_negotiated, |
52 NextProto protocol_negotiated, | 56 NextProto protocol_negotiated, |
53 bool using_spdy); | 57 bool using_spdy); |
54 | 58 |
55 // If this Request has a |spdy_session_key_|, remove this session from the | 59 // If this Request has a |spdy_session_key_|, remove this session from the |
56 // SpdySessionRequestMap. | 60 // SpdySessionRequestMap. |
57 void RemoveRequestFromSpdySessionRequestMap(); | 61 void RemoveRequestFromSpdySessionRequestMap(); |
58 | 62 |
59 // Called by an attached Job if it sets up a SpdySession. | 63 // Called by an attached Job if it sets up a SpdySession. |
60 void OnNewSpdySessionReady(Job* job, | 64 // |stream| is null when |for_bidirectional| is true. |
61 scoped_ptr<HttpStream> stream, | 65 // |bidirectional_stream| is null when |for_bidirectional| is false. |
62 const base::WeakPtr<SpdySession>& spdy_session, | 66 void OnNewSpdySessionReady( |
63 bool direct); | 67 Job* job, |
| 68 scoped_ptr<HttpStream> stream, |
| 69 scoped_ptr<BidirectionalStream> bidirectional_stream, |
| 70 const base::WeakPtr<SpdySession>& spdy_session, |
| 71 bool direct); |
64 | 72 |
65 // Called by an attached Job to record connection attempts made by the socket | 73 // Called by an attached Job to record connection attempts made by the socket |
66 // layer for this stream request. | 74 // layer for this stream request. |
67 void AddConnectionAttempts(const ConnectionAttempts& attempts); | 75 void AddConnectionAttempts(const ConnectionAttempts& attempts); |
68 | 76 |
69 WebSocketHandshakeStreamBase::CreateHelper* | 77 WebSocketHandshakeStreamBase::CreateHelper* |
70 websocket_handshake_stream_create_helper() { | 78 websocket_handshake_stream_create_helper() { |
71 return websocket_handshake_stream_create_helper_; | 79 return websocket_handshake_stream_create_helper_; |
72 } | 80 } |
73 | 81 |
74 // HttpStreamRequest::Delegate methods which we implement. Note we don't | 82 // HttpStreamRequest::Delegate methods which we implement. Note we don't |
75 // actually subclass HttpStreamRequest::Delegate. | 83 // actually subclass HttpStreamRequest::Delegate. |
76 | 84 |
77 void OnStreamReady(Job* job, | 85 void OnStreamReady(Job* job, |
78 const SSLConfig& used_ssl_config, | 86 const SSLConfig& used_ssl_config, |
79 const ProxyInfo& used_proxy_info, | 87 const ProxyInfo& used_proxy_info, |
80 HttpStream* stream); | 88 HttpStream* stream); |
| 89 void OnBidirectionalStreamReady(Job* job, |
| 90 const SSLConfig& used_ssl_config, |
| 91 const ProxyInfo& used_proxy_info, |
| 92 BidirectionalStream* stream); |
| 93 |
81 void OnWebSocketHandshakeStreamReady(Job* job, | 94 void OnWebSocketHandshakeStreamReady(Job* job, |
82 const SSLConfig& used_ssl_config, | 95 const SSLConfig& used_ssl_config, |
83 const ProxyInfo& used_proxy_info, | 96 const ProxyInfo& used_proxy_info, |
84 WebSocketHandshakeStreamBase* stream); | 97 WebSocketHandshakeStreamBase* stream); |
85 void OnStreamFailed(Job* job, | 98 void OnStreamFailed(Job* job, |
86 int status, | 99 int status, |
87 const SSLConfig& used_ssl_config, | 100 const SSLConfig& used_ssl_config, |
88 SSLFailureState ssl_failure_state); | 101 SSLFailureState ssl_failure_state); |
89 void OnCertificateError(Job* job, | 102 void OnCertificateError(Job* job, |
90 int status, | 103 int status, |
(...skipping 16 matching lines...) Expand all Loading... |
107 | 120 |
108 // HttpStreamRequest methods. | 121 // HttpStreamRequest methods. |
109 | 122 |
110 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override; | 123 int RestartTunnelWithProxyAuth(const AuthCredentials& credentials) override; |
111 void SetPriority(RequestPriority priority) override; | 124 void SetPriority(RequestPriority priority) override; |
112 LoadState GetLoadState() const override; | 125 LoadState GetLoadState() const override; |
113 bool was_npn_negotiated() const override; | 126 bool was_npn_negotiated() const override; |
114 NextProto protocol_negotiated() const override; | 127 NextProto protocol_negotiated() const override; |
115 bool using_spdy() const override; | 128 bool using_spdy() const override; |
116 const ConnectionAttempts& connection_attempts() const override; | 129 const ConnectionAttempts& connection_attempts() const override; |
| 130 bool for_bidirectional() const { return for_bidirectional_; } |
117 | 131 |
118 private: | 132 private: |
119 // Used to bind |job| to the request and orphan all other jobs in |jobs_|. | 133 // Used to bind |job| to the request and orphan all other jobs in |jobs_|. |
120 void BindJob(Job* job); | 134 void BindJob(Job* job); |
121 | 135 |
122 // Used to orphan all jobs in |jobs_|. | 136 // Used to orphan all jobs in |jobs_|. |
123 void OrphanJobs(); | 137 void OrphanJobs(); |
124 | 138 |
125 // Used to cancel all jobs in |jobs_|. | 139 // Used to cancel all jobs in |jobs_|. |
126 void CancelJobs(); | 140 void CancelJobs(); |
(...skipping 13 matching lines...) Expand all Loading... |
140 std::set<HttpStreamFactoryImpl::Job*> jobs_; | 154 std::set<HttpStreamFactoryImpl::Job*> jobs_; |
141 scoped_ptr<const SpdySessionKey> spdy_session_key_; | 155 scoped_ptr<const SpdySessionKey> spdy_session_key_; |
142 | 156 |
143 bool completed_; | 157 bool completed_; |
144 bool was_npn_negotiated_; | 158 bool was_npn_negotiated_; |
145 // Protocol negotiated with the server. | 159 // Protocol negotiated with the server. |
146 NextProto protocol_negotiated_; | 160 NextProto protocol_negotiated_; |
147 bool using_spdy_; | 161 bool using_spdy_; |
148 ConnectionAttempts connection_attempts_; | 162 ConnectionAttempts connection_attempts_; |
149 | 163 |
| 164 const bool for_bidirectional_; |
150 DISALLOW_COPY_AND_ASSIGN(Request); | 165 DISALLOW_COPY_AND_ASSIGN(Request); |
151 }; | 166 }; |
152 | 167 |
153 } // namespace net | 168 } // namespace net |
154 | 169 |
155 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ | 170 #endif // NET_HTTP_HTTP_STREAM_FACTORY_IMPL_REQUEST_H_ |
OLD | NEW |