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 an error occurs. E.g. when a connection to the server cannot | |
41 // be established. | |
42 virtual void OnFailed(Error error) = 0; | |
43 | |
44 // Called when the request headers have been sent. | |
45 virtual void OnRequestHeadersSent() = 0; | |
46 | |
47 // Called when response headers are received. | |
48 virtual void OnHeaders(const SpdyHeaderBlock& response_headers) = 0; | |
49 | |
50 // Called when read is completed asynchronously. |bytes_read| specifies how | |
51 // much data is available. | |
52 virtual void OnReadCompleted(int bytes_read) = 0; | |
53 | |
54 // Called when the entire buffer passed through SendData is sent. | |
55 virtual void OnDataSent() = 0; | |
56 | |
57 // Called when trailers are received. | |
58 virtual void OnTrailers(const SpdyHeaderBlock& trailers) = 0; | |
59 | |
60 // Called when the stream is closed. No other delegate functions will be | |
61 // called after this. |status| is an error code or OK. | |
mef
2015/11/10 23:00:27
Is |status| indeed a net Error Code?
xunjieli
2015/11/13 23:41:44
Done. Yes. I modified the comment to make this cle
| |
62 virtual void OnClose(int status) = 0; | |
63 | |
64 protected: | |
65 virtual ~Delegate() {} | |
66 | |
67 private: | |
68 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
69 }; | |
70 | |
71 // Parts of |request_info| are ignored (e.g. |upload_data_stream| and most | |
72 // load flags). | |
mef
2015/11/10 23:00:27
That's a good point, should we specify which load_
xunjieli
2015/11/13 23:41:44
I'd like to say all for now. But I don't really kn
| |
73 BidirectionalStream(const HttpRequestInfo& request_info, | |
74 RequestPriority priority, | |
75 HttpNetworkSession* session, | |
76 Delegate* delegate); | |
77 | |
78 // Destroys the helper and cancels any pending request. | |
79 ~BidirectionalStream() override; | |
80 | |
81 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read, | |
82 // or ERR_IO_PENDING if the read is to be completed asynchronously. | |
mef
2015/11/10 23:00:27
Can this have more than one call in flight? If not
xunjieli
2015/11/13 23:41:45
Done.
| |
83 int ReadData(IOBuffer* buf, int buf_len); | |
84 | |
85 // Sends data. This should not be called again until OnDataSent is invoked. | |
86 void SendData(IOBuffer* data, int length, bool end_stream); | |
87 | |
88 // If there is |stream_request_|, cancel it. If |stream_| is established, | |
89 // cancel it. | |
90 void Cancel(); | |
mef
2015/11/10 23:00:27
What if BidirectionalStream is deleted without bei
xunjieli
2015/11/13 23:41:44
Hmm.. Then we probably should call cancel in that
| |
91 | |
92 // TODO(xunjieli): implement a method to do flow control, and a method to ping | |
93 // remote end point. | |
94 | |
95 private: | |
96 // BidirectionalStreamJob::Delegate implementation: | |
97 | |
98 void OnFailed(Error error) override; | |
99 | |
100 void OnRequestHeadersSent() override; | |
101 | |
102 void OnHeaders(const SpdyHeaderBlock& response_headers) override; | |
103 | |
104 void OnReadCompleted(int bytes_read) override; | |
105 | |
106 void OnDataSent() override; | |
107 | |
108 void OnTrailers(const SpdyHeaderBlock& trailers) override; | |
109 | |
110 void OnClose(int status) override; | |
111 | |
112 // HttpStreamRequest::Delegate implementation: | |
113 | |
114 void OnStreamReady(const SSLConfig& used_ssl_config, | |
115 const ProxyInfo& used_proxy_info, | |
116 HttpStream* stream) override; | |
117 void OnBidirectionalStreamJobReady(const SSLConfig& used_ssl_config, | |
118 const ProxyInfo& used_proxy_info, | |
119 BidirectionalStreamJob* stream) override; | |
120 void OnWebSocketHandshakeStreamReady( | |
121 const SSLConfig& used_ssl_config, | |
122 const ProxyInfo& used_proxy_info, | |
123 WebSocketHandshakeStreamBase* stream) override; | |
124 void OnStreamFailed(int status, | |
125 const SSLConfig& used_ssl_config, | |
126 SSLFailureState ssl_failure_state) override; | |
127 void OnCertificateError(int status, | |
128 const SSLConfig& used_ssl_config, | |
129 const SSLInfo& ssl_info) override; | |
130 void OnNeedsProxyAuth(const HttpResponseInfo& response_info, | |
131 const SSLConfig& used_ssl_config, | |
132 const ProxyInfo& used_proxy_info, | |
133 HttpAuthController* auth_controller) override; | |
134 void OnNeedsClientAuth(const SSLConfig& used_ssl_config, | |
135 SSLCertRequestInfo* cert_info) override; | |
136 void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info, | |
137 const SSLConfig& used_ssl_config, | |
138 const ProxyInfo& used_proxy_info, | |
139 HttpStream* stream) override; | |
140 | |
141 const HttpRequestInfo request_info_; | |
142 RequestPriority priority_; | |
143 BoundNetLog net_log_; | |
144 | |
145 Delegate* delegate_; | |
146 | |
147 scoped_ptr<HttpStreamRequest> stream_request_; | |
148 scoped_ptr<BidirectionalStreamJob> stream_; | |
mef
2015/11/10 23:00:27
should this be called |stream_job_| to avoid confu
xunjieli
2015/11/13 23:41:44
Done.
| |
149 | |
150 DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); | |
151 }; | |
152 | |
153 } // namespace net | |
154 | |
155 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ | |
OLD | NEW |