Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(343)

Side by Side Diff: net/http/bidirectional_stream.h

Issue 1326503003: Added a net::BidirectionalStream to expose a bidirectional streaming interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Get rid of Delegate::OnClose Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | net/http/bidirectional_stream.cc » ('j') | net/net.gypi » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 class SpdyHeaderBlock;
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 // The delegate should call BidirectionalStream::ReadData to start reading
45 // or call BidirectionalStream::Cancel to cancel the stream.
46 virtual void OnHeaders(const SpdyHeaderBlock& response_headers) = 0;
47
48 // Called when read is completed asynchronously. |bytes_read| specifies how
49 // much data is available.
50 // The delegate should call BidirectionalStream::ReadData to continue
51 // reading or call BidirectionalStream::Cancel to cancel the stream.
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 // No other delegate functions will be called after this.
mef 2015/12/02 16:36:01 I don't think this is correct statement. I think w
xunjieli 2015/12/02 19:18:51 Good catch. Will do.
59 virtual void OnTrailers(const SpdyHeaderBlock& trailers) = 0;
60
61 // Called when the stream is closed or an error occurred.
62 // No other delegate functions will be called after this.
63 virtual void OnFailed(int error) = 0;
mef 2015/12/02 16:36:01 I think we need either OnClose, or OnSucceeded to
xunjieli 2015/12/02 19:18:51 I'd like to understand why OnClose/OnSucceeded is
64
65 protected:
66 virtual ~Delegate() {}
67
68 private:
69 DISALLOW_COPY_AND_ASSIGN(Delegate);
70 };
71
72 struct NET_EXPORT RequestInfo {
73 RequestInfo();
74 ~RequestInfo();
75
76 // The requested URL.
77 GURL url;
78
79 // The method to use (GET, POST, etc.).
80 std::string method;
81
82 // Any extra request headers (including User-Agent).
83 HttpRequestHeaders extra_headers;
84 };
85
86 BidirectionalStream(const RequestInfo& request_info,
87 RequestPriority priority,
88 HttpNetworkSession* session,
89 Delegate* delegate);
90
91 // Destroys the helper and cancels any pending request.
92 ~BidirectionalStream() override;
93
94 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read,
95 // or ERR_IO_PENDING if the read is to be completed asynchronously.
96 // There should not be called again unless it IO completes synchronously or
97 // until OnReadCompleted is invoked.
98 int ReadData(IOBuffer* buf, int buf_len);
99
100 // Sends data. This should not be called again until OnDataSent is invoked.
101 void SendData(IOBuffer* data, int length, bool end_stream);
102
103 // If there is |stream_request_|, cancel it. If |stream_job_| is established,
104 // cancel it.
105 void Cancel();
106
107 // TODO(xunjieli): implement a method to do flow control and a method to ping
108 // remote end point.
109
110 private:
111 // BidirectionalStreamJob::Delegate implementation:
112 void OnRequestHeadersSent() override;
113 void OnHeaders(const SpdyHeaderBlock& response_headers) override;
114 void OnReadCompleted(int bytes_read) override;
115 void OnDataSent() override;
116 void OnTrailers(const SpdyHeaderBlock& trailers) override;
117 void OnFailed(int error) override;
118
119 // HttpStreamRequest::Delegate implementation:
120 void OnStreamReady(const SSLConfig& used_ssl_config,
121 const ProxyInfo& used_proxy_info,
122 HttpStream* stream) override;
123 void OnBidirectionalStreamJobReady(const SSLConfig& used_ssl_config,
124 const ProxyInfo& used_proxy_info,
125 BidirectionalStreamJob* stream) override;
126 void OnWebSocketHandshakeStreamReady(
127 const SSLConfig& used_ssl_config,
128 const ProxyInfo& used_proxy_info,
129 WebSocketHandshakeStreamBase* stream) override;
130 void OnStreamFailed(int status,
131 const SSLConfig& used_ssl_config,
132 SSLFailureState ssl_failure_state) override;
133 void OnCertificateError(int status,
134 const SSLConfig& used_ssl_config,
135 const SSLInfo& ssl_info) override;
136 void OnNeedsProxyAuth(const HttpResponseInfo& response_info,
137 const SSLConfig& used_ssl_config,
138 const ProxyInfo& used_proxy_info,
139 HttpAuthController* auth_controller) override;
140 void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
141 SSLCertRequestInfo* cert_info) override;
142 void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info,
143 const SSLConfig& used_ssl_config,
144 const ProxyInfo& used_proxy_info,
145 HttpStream* stream) override;
146
147 const RequestInfo request_info_;
148 RequestPriority priority_;
149 BoundNetLog net_log_;
150
151 Delegate* delegate_;
152
153 scoped_ptr<HttpStreamRequest> stream_request_;
154 scoped_ptr<BidirectionalStreamJob> stream_job_;
155
156 DISALLOW_COPY_AND_ASSIGN(BidirectionalStream);
157 };
158
159 } // namespace net
160
161 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_
OLDNEW
« no previous file with comments | « no previous file | net/http/bidirectional_stream.cc » ('j') | net/net.gypi » ('J')

Powered by Google App Engine
This is Rietveld 408576698