OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef NET_HTTP_BIDIRECTIONAL_STREAM_H_ | |
6 #define NET_HTTP_BIDIRECTIONAL_STREAM_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "net/base/request_priority.h" | |
11 #include "net/http/bidirectional_stream_job.h" | |
12 #include "net/http/http_stream_factory.h" | |
13 #include "net/ssl/ssl_config.h" | |
14 | |
15 namespace net { | |
16 | |
17 class BoundNetLog; | |
18 class HttpAuthController; | |
19 class HttpNetworkSession; | |
20 class HttpStream; | |
21 class HttpStreamRequest; | |
22 class IOBuffer; | |
23 class ProxyInfo; | |
24 struct HttpRequestInfo; | |
25 | |
26 // A class to do HTTP/2 bidirectional streaming. Note that only one | |
27 // ReadData or SendData should be in flight until the operation completes | |
28 // synchronously or asynchronously. The BidirectionalStream must be torn down | |
29 // before the HttpNetworkSession. | |
30 class NET_EXPORT BidirectionalStream : public BidirectionalStreamJob::Delegate, | |
31 public HttpStreamRequest::Delegate { | |
32 public: | |
33 // Delegate interface to get notified of success of failure. Callbacks will be | |
34 // invoked asynchronously. | |
35 // TODO(xunjieli): Surface the protocol negotiated. | |
36 class NET_EXPORT Delegate { | |
37 public: | |
38 Delegate() {} | |
39 | |
40 // Called when the request headers have been sent. | |
41 virtual void OnRequestHeadersSent() = 0; | |
42 | |
43 // Called when response headers are received. | |
44 virtual void OnHeaders(const SpdyHeaderBlock& response_headers) = 0; | |
mmenke
2015/11/25 18:39:18
SpdyHeaderBlock? We're going to be wrapping QUIC,
xunjieli
2015/11/25 22:04:13
Yea. But it looks like QUIC is also using SpdyHead
| |
45 | |
46 // Called when read is completed asynchronously. |bytes_read| specifies how | |
47 // much data is available. | |
48 virtual void OnReadCompleted(int bytes_read) = 0; | |
49 | |
50 // Called when the entire buffer passed through SendData is sent. | |
51 virtual void OnDataSent() = 0; | |
52 | |
53 // Called when trailers are received. | |
54 virtual void OnTrailers(const SpdyHeaderBlock& trailers) = 0; | |
mmenke
2015/11/25 18:39:18
SpdyHeaderBlock? We're going to be wrapping QUIC,
xunjieli
2015/11/25 22:04:13
Same as above.
| |
55 | |
56 // Called when the stream is closed or an error occurred. No other delegate | |
57 // functions will be called after this. |status| is a net error code or OK. | |
58 virtual void OnClose(int status) = 0; | |
59 | |
60 protected: | |
61 virtual ~Delegate() {} | |
62 | |
63 private: | |
64 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
65 }; | |
66 | |
67 // Parts of |request_info| are ignored (e.g. |upload_data_stream| and most | |
68 // load flags). | |
69 BidirectionalStream(const HttpRequestInfo& request_info, | |
mmenke
2015/11/25 18:39:18
May be cleaner to take a struct with just what we
xunjieli
2015/11/25 22:04:13
Done.
| |
70 RequestPriority priority, | |
71 HttpNetworkSession* session, | |
72 Delegate* delegate); | |
73 | |
74 // Destroys the helper and cancels any pending request. | |
75 ~BidirectionalStream() override; | |
76 | |
77 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read, | |
78 // or ERR_IO_PENDING if the read is to be completed asynchronously. | |
79 // There should not be called again unless it IO completes synchronously or | |
80 // until OnReadCompleted is invoked. | |
81 int ReadData(IOBuffer* buf, int buf_len); | |
82 | |
83 // Sends data. This should not be called again until OnDataSent is invoked. | |
84 void SendData(IOBuffer* data, int length, bool end_stream); | |
85 | |
86 // If there is |stream_request_|, cancel it. If |stream_job_| is established, | |
87 // cancel it. | |
88 void Cancel(); | |
89 | |
90 // TODO(xunjieli): implement a method to do flow control, and a method to ping | |
mmenke
2015/11/25 18:39:18
Tiny grammar nit: Remove comma.
xunjieli
2015/11/25 22:04:13
Done.
| |
91 // remote end point. | |
92 | |
93 private: | |
94 // BidirectionalStreamJob::Delegate implementation: | |
95 | |
96 void OnRequestHeadersSent() override; | |
97 | |
98 void OnHeaders(const SpdyHeaderBlock& response_headers) override; | |
99 | |
100 void OnReadCompleted(int bytes_read) override; | |
101 | |
102 void OnDataSent() override; | |
103 | |
104 void OnTrailers(const SpdyHeaderBlock& trailers) override; | |
105 | |
106 void OnClose(int status) override; | |
mmenke
2015/11/25 18:39:18
Remove blank lines between these methods (And the
xunjieli
2015/11/25 22:04:13
Done.
| |
107 | |
108 // HttpStreamRequest::Delegate implementation: | |
109 | |
mmenke
2015/11/25 18:39:18
nit: Remove blank line.
xunjieli
2015/11/25 22:04:13
Done.
| |
110 void OnStreamReady(const SSLConfig& used_ssl_config, | |
111 const ProxyInfo& used_proxy_info, | |
112 HttpStream* stream) override; | |
113 void OnBidirectionalStreamJobReady(const SSLConfig& used_ssl_config, | |
114 const ProxyInfo& used_proxy_info, | |
115 BidirectionalStreamJob* stream) override; | |
116 void OnWebSocketHandshakeStreamReady( | |
117 const SSLConfig& used_ssl_config, | |
118 const ProxyInfo& used_proxy_info, | |
119 WebSocketHandshakeStreamBase* stream) override; | |
120 void OnStreamFailed(int status, | |
121 const SSLConfig& used_ssl_config, | |
122 SSLFailureState ssl_failure_state) override; | |
123 void OnCertificateError(int status, | |
124 const SSLConfig& used_ssl_config, | |
125 const SSLInfo& ssl_info) override; | |
126 void OnNeedsProxyAuth(const HttpResponseInfo& response_info, | |
127 const SSLConfig& used_ssl_config, | |
128 const ProxyInfo& used_proxy_info, | |
129 HttpAuthController* auth_controller) override; | |
130 void OnNeedsClientAuth(const SSLConfig& used_ssl_config, | |
131 SSLCertRequestInfo* cert_info) override; | |
132 void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info, | |
133 const SSLConfig& used_ssl_config, | |
134 const ProxyInfo& used_proxy_info, | |
135 HttpStream* stream) override; | |
136 | |
137 const HttpRequestInfo request_info_; | |
138 RequestPriority priority_; | |
139 BoundNetLog net_log_; | |
140 | |
141 Delegate* delegate_; | |
142 | |
143 scoped_ptr<HttpStreamRequest> stream_request_; | |
144 scoped_ptr<BidirectionalStreamJob> stream_job_; | |
145 | |
146 DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); | |
147 }; | |
148 | |
149 } // namespace net | |
150 | |
151 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ | |
OLD | NEW |