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

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: Address Misha's comments 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/http/bidirectional_stream.cc » ('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/basictypes.h"
mmenke 2015/12/08 22:58:34 Not needed.
xunjieli 2015/12/10 23:25:50 Done.
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "net/base/request_priority.h"
12 #include "net/http/bidirectional_stream_job.h"
13 #include "net/http/http_stream_factory.h"
14 #include "net/ssl/ssl_config.h"
15
16 namespace net {
17
18 class BoundNetLog;
19 class HttpAuthController;
20 class HttpNetworkSession;
21 class HttpStream;
22 class HttpStreamRequest;
23 class IOBuffer;
24 class ProxyInfo;
25 class SpdyHeaderBlock;
26
27 // A class to do HTTP/2 bidirectional streaming. Note that only one
28 // ReadData or SendData should be in flight until the operation completes
mmenke 2015/12/08 22:58:34 "one ReadData or SendData" is a bit ambiguous. Co
xunjieli 2015/12/10 23:25:50 Done. I edited it here. The ReadData/SendData meth
29 // synchronously or asynchronously. The BidirectionalStream must be torn down
mmenke 2015/12/08 22:58:34 Suggest removing the "synchronously or asynchronou
xunjieli 2015/12/10 23:25:50 Done.
30 // before the HttpNetworkSession.
31 class NET_EXPORT BidirectionalStream : public BidirectionalStreamJob::Delegate,
32 public HttpStreamRequest::Delegate {
33 public:
34 // Delegate interface to get notified of success of failure. Callbacks will be
35 // invoked asynchronously.
36 // TODO(xunjieli): Surface the protocol negotiated.
37 class NET_EXPORT Delegate {
38 public:
39 Delegate() {}
40
41 // Called when the request headers have been sent.
42 virtual void OnRequestHeadersSent() = 0;
mmenke 2015/12/08 22:58:34 Should either remove request from this, or add "Re
xunjieli 2015/12/10 23:25:50 Done. Good idea!
43
44 // Called when response headers are received.
45 // The delegate should call BidirectionalStream::ReadData to start reading
46 // or call BidirectionalStream::Cancel to cancel the stream.
47 virtual void OnHeaders(const SpdyHeaderBlock& response_headers) = 0;
mmenke 2015/12/08 22:58:34 Should add a Received to the end, to match the Sen
xunjieli 2015/12/10 23:25:50 Done. Good idea!
48
49 // Called when read is completed asynchronously. |bytes_read| specifies how
50 // much data is available.
51 // The delegate should call BidirectionalStream::ReadData to continue
mmenke 2015/12/08 22:58:34 should -> may?
xunjieli 2015/12/10 23:25:50 Done.
52 // reading or call BidirectionalStream::Cancel to cancel the stream.
53 virtual void OnReadCompleted(int bytes_read) = 0;
54
55 // Called when the entire buffer passed through SendData is sent.
56 virtual void OnDataSent() = 0;
mmenke 2015/12/08 22:58:34 OnSendCompleted, to match with OnReadCompleted? O
xunjieli 2015/12/10 23:25:50 Done. Great suggestion.
57
58 // Called when trailers are received.
59 virtual void OnTrailers(const SpdyHeaderBlock& trailers) = 0;
mmenke 2015/12/08 22:58:34 Most other methods here end with a verb (OnHeaders
xunjieli 2015/12/10 23:25:50 Done.
60
61 // Called when the stream is closed or an error occurred.
mmenke 2015/12/08 22:58:34 Is it called when Cancel() is called?
xunjieli 2015/12/10 23:25:50 No, it's not called when Cancel() is called. I edi
62 // No other delegate functions will be called after this.
63 virtual void OnFailed(int error) = 0;
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.
mmenke 2015/12/08 22:58:34 --helper
xunjieli 2015/12/10 23:25:50 Done.
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, or an
96 // error code if any error occurred.
97
98 // There should not be called again unless it IO completes synchronously or
99 // until OnReadCompleted is invoked.
100 int ReadData(IOBuffer* buf, int buf_len);
101
102 // Sends data. This should not be called again until OnDataSent is invoked.
103 void SendData(IOBuffer* data, int length, bool end_stream);
mmenke 2015/12/08 22:58:34 Can either of these be called before OnHeaders? W
xunjieli 2015/12/10 23:25:50 No. SpdyStream::SendData will check that the strea
104
105 // If there is |stream_request_|, cancel it. If |stream_job_| is established,
106 // cancel it.
107 void Cancel();
mmenke 2015/12/08 22:58:34 I guess there's no such thing as successful comple
xunjieli 2015/12/10 23:25:50 There's actually a notion of successful completion
mmenke 2015/12/11 16:42:53 There's no way to tell this class to send the serv
xunjieli 2015/12/11 23:48:39 No. The client initiate the half close by invoking
108
mmenke 2015/12/08 22:58:34 Should we have a SetPriority method? Suppose if t
xunjieli 2015/12/10 23:25:50 Done. I think we only need to pass it during reque
109 // Returns the protocol used by this stream. Always between
110 // kProtoSPDYMinimumVersion and kProtoSPDYMaximumVersion.
111 NextProto GetProtocol() const;
mmenke 2015/12/08 22:58:34 Should mention that none of these getters may be c
xunjieli 2015/12/10 23:25:50 Done. Added comment.
112
113 // Total number of bytes received over the network of SPDY data, headers, and
114 // push_promise frames associated with this stream, including the size of
115 // frame headers, after SSL decryption and not including proxy overhead.
116 int64_t GetTotalReceivedBytes() const;
mmenke 2015/12/08 22:58:34 include stdint.
xunjieli 2015/12/10 23:25:50 Done.
117
118 // Total number of bytes sent over the network of SPDY frames associated with
119 // this stream, including the size of frame headers, before SSL encryption and
120 // not including proxy overhead. Note that some SPDY frames such as pings are
121 // not associated with any stream, and are not included in this value.
122 int64_t GetTotalSentBytes() const;
123
124 // TODO(xunjieli): implement a method to do flow control and a method to ping
mmenke 2015/12/08 22:58:34 nit: implement -> Implement
xunjieli 2015/12/10 23:25:50 Done.
125 // remote end point.
126
127 private:
128 // BidirectionalStreamJob::Delegate implementation:
129 void OnRequestHeadersSent() override;
130 void OnHeaders(const SpdyHeaderBlock& response_headers) override;
131 void OnReadCompleted(int bytes_read) override;
132 void OnDataSent() override;
133 void OnTrailers(const SpdyHeaderBlock& trailers) override;
134 void OnFailed(int error) override;
135
136 // HttpStreamRequest::Delegate implementation:
137 void OnStreamReady(const SSLConfig& used_ssl_config,
138 const ProxyInfo& used_proxy_info,
139 HttpStream* stream) override;
140 void OnBidirectionalStreamJobReady(const SSLConfig& used_ssl_config,
141 const ProxyInfo& used_proxy_info,
142 BidirectionalStreamJob* stream) override;
143 void OnWebSocketHandshakeStreamReady(
144 const SSLConfig& used_ssl_config,
145 const ProxyInfo& used_proxy_info,
146 WebSocketHandshakeStreamBase* stream) override;
147 void OnStreamFailed(int status,
148 const SSLConfig& used_ssl_config,
149 SSLFailureState ssl_failure_state) override;
150 void OnCertificateError(int status,
151 const SSLConfig& used_ssl_config,
152 const SSLInfo& ssl_info) override;
153 void OnNeedsProxyAuth(const HttpResponseInfo& response_info,
154 const SSLConfig& used_ssl_config,
155 const ProxyInfo& used_proxy_info,
156 HttpAuthController* auth_controller) override;
157 void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
158 SSLCertRequestInfo* cert_info) override;
159 void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info,
160 const SSLConfig& used_ssl_config,
161 const ProxyInfo& used_proxy_info,
162 HttpStream* stream) override;
163
164 const RequestInfo request_info_;
165 RequestPriority priority_;
166 BoundNetLog net_log_;
mmenke 2015/12/08 22:58:34 const
xunjieli 2015/12/10 23:25:50 Done.
167
168 Delegate* delegate_;
mmenke 2015/12/08 22:58:34 Delegate* const delegate_;
xunjieli 2015/12/10 23:25:50 Done.
169
170 scoped_ptr<HttpStreamRequest> stream_request_;
171 scoped_ptr<BidirectionalStreamJob> stream_job_;
172
173 DISALLOW_COPY_AND_ASSIGN(BidirectionalStream);
174 };
175
176 } // namespace net
177
178 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_
OLDNEW
« no previous file with comments | « no previous file | net/http/bidirectional_stream.cc » ('j') | net/http/bidirectional_stream.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698