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