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

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: Use private inheritance 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 <stdint.h>
9
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "net/http/bidirectional_stream_job.h"
13 #include "net/http/bidirectional_stream_request_info.h"
mmenke 2015/12/16 23:04:36 Can be forward declared.
xunjieli 2015/12/17 18:18:54 Done.
14 #include "net/http/http_stream_factory.h"
15 #include "net/ssl/ssl_config.h"
16 #include "url/gurl.h"
mmenke 2015/12/16 23:04:36 Can forward declare GURL and SSLConfig.
xunjieli 2015/12/17 18:18:54 Done.
17
18 namespace net {
19
20 class BoundNetLog;
21 class HttpAuthController;
22 class HttpNetworkSession;
23 class HttpStream;
24 class HttpStreamRequest;
25 class IOBuffer;
26 class ProxyInfo;
27 class SpdyHeaderBlock;
28
29 // A class to do HTTP/2 bidirectional streaming. Note that at most one each of
30 // ReadData or SendData should be in flight until the operation completes.
31 // The BidirectionalStream must be torn down before the HttpNetworkSession.
32 class NET_EXPORT BidirectionalStream : private BidirectionalStreamJob::Delegate,
33 private HttpStreamRequest::Delegate {
mmenke 2015/12/16 23:04:36 private inheritance is banned by the style guide.
xunjieli 2015/12/17 18:18:54 The overridden methods are private. If I use publi
mmenke 2015/12/17 18:58:20 NON_EXPORTED_BASE(public BidirectionalStreamJob::D
xunjieli 2015/12/17 21:18:21 Done.
34 public:
35 // Delegate interface to get notified of success of failure. Callbacks will be
36 // invoked asynchronously.
37 class NET_EXPORT Delegate {
38 public:
39 Delegate();
40
41 // Called when headers have been sent. This is called at most once for
42 // the lifetime of a stream.
43 // The delegate may call BidirectionalStream::ReadData to start reading,
44 // or call BidirectionalStream::SendData to send data.
45 // The delegate should not call BidirectionalStream::Cancel
46 // during this callback.
47 virtual void OnHeadersSent() = 0;
48
49 // Called when headers are received. This is called at most once for the
50 // lifetime of a stream.
51 // The delegate may call BidirectionalStream::ReadData to start reading,
52 // call BidirectionalStream::SendData to send data,
53 // or call BidirectionalStream::Cancel to cancel the stream.
54 virtual void OnHeadersReceived(const SpdyHeaderBlock& response_headers) = 0;
55
56 // Called when a pending read is completed asynchronously.
57 // |bytes_read| specifies how much data is read.
58 // The delegate may call BidirectionalStream::ReadData to continue
59 // reading, call BidirectionalStream::SendData to send data,
60 // or call BidirectionalStream::Cancel to cancel the stream.
61 virtual void OnDataRead(int bytes_read) = 0;
62
63 // Called when the entire buffer passed through SendData is sent.
64 // The delegate may call BidirectionalStream::ReadData to continue
65 // reading, call BidirectionalStream::SendData to send data,
66 // The delegate should not call BidirectionalStream::Cancel
67 // during this callback.
68 virtual void OnDataSent() = 0;
69
70 // Called when trailers are received. This is called as soon as trailers
71 // are received, which can happen before a read completes.
72 // The delegate is able to continue reading if there is no pending read and
73 // EOF has not been received, or to send data if there is no pending send.
74 virtual void OnTrailersReceived(const SpdyHeaderBlock& trailers) = 0;
75
76 // Called when the stream is closed or an error occurred.
77 // No other delegate functions will be called after this.
78 virtual void OnFailed(int error) = 0;
79
80 protected:
81 virtual ~Delegate();
82
83 private:
84 DISALLOW_COPY_AND_ASSIGN(Delegate);
85 };
86
87 // Constructs a BidirectionalStream. |request_info| contains information about
88 // the request. |session| is the http network session with which this request
mmenke 2015/12/16 23:04:36 Mention |request_info| must be non-NULL?
xunjieli 2015/12/17 18:18:54 Done.
89 // will be made. |delegate| must be non-NULL.
mmenke 2015/12/16 23:04:36 Mention lifetime requirements relative to |session
xunjieli 2015/12/17 18:18:54 Done.
90 BidirectionalStream(const BidirectionalStreamRequestInfo* request_info,
91 HttpNetworkSession* session,
92 Delegate* delegate);
93
94 // Constructor that accepts a Timer, which can be used in tests to control
95 // the buffering of received data.
96 BidirectionalStream(const BidirectionalStreamRequestInfo* request_info,
97 HttpNetworkSession* session,
98 Delegate* delegate,
99 scoped_ptr<base::Timer> timer);
100
101 // Cancels |stream_request_| or |stream_job_| if applicable.
102 // |this| should not be destroyed during Delegate::OnHeadersSent or
103 // Delegate::OnDataSent.
104 ~BidirectionalStream() override;
105
106 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read,
107 // or ERR_IO_PENDING if the read is to be completed asynchronously, or an
108 // error code if any error occurred. If returns 0, there is no more data to
109 // read. This should not be called before Delegate::OnHeadersReceived is
110 // invoked, and should not be called again unless it returns with number
111 // greater than 0 or until Delegate::OnDataRead is invoked.
112 int ReadData(IOBuffer* buf, int buf_len);
113
114 // Sends data. This should not be called before Delegate::OnHeadersSent is
115 // invoked, and should not be called again until Delegate::OnDataSent is
116 // invoked.
mmenke 2015/12/16 23:04:36 Mention |end_stream|
xunjieli 2015/12/17 18:18:54 Done.
117 void SendData(IOBuffer* data, int length, bool end_stream);
118
119 // If there is |stream_request_|, cancel it. If |stream_job_| is established,
mmenke 2015/12/16 23:04:36 is a |stream_request_| (or if |stream_request_| is
xunjieli 2015/12/17 18:18:54 Done.
120 // cancel it. No delegate method will be called after Cancel().
121 // Any pending operations may or may not succeed.
122 void Cancel();
123
124 // Getters that should only be called after Delegate::OnHeadersSent:
mmenke 2015/12/16 23:04:36 No longer true
xunjieli 2015/12/17 18:18:55 Done.
125
126 // Returns the protocol used by this stream. If stream has not been
127 // established, return kProtoUnknown.
128 NextProto GetProtocol() const;
129
130 // Total number of bytes received over the network of SPDY data, headers, and
131 // push_promise frames associated with this stream, including the size of
132 // frame headers, after SSL decryption and not including proxy overhead.
133 // If stream has not been established, return 0.
134 int64_t GetTotalReceivedBytes() const;
135
136 // Total number of bytes sent over the network of SPDY frames associated with
137 // this stream, including the size of frame headers, before SSL encryption and
138 // not including proxy overhead. Note that some SPDY frames such as pings are
139 // not associated with any stream, and are not included in this value.
140 int64_t GetTotalSentBytes() const;
141
142 // TODO(xunjieli): Implement a method to do flow control and a method to ping
143 // remote end point.
144
145 private:
146 // BidirectionalStreamJob::Delegate implementation:
147 void OnHeadersSent() override;
148 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override;
149 void OnDataRead(int bytes_read) override;
150 void OnDataSent() override;
151 void OnTrailersReceived(const SpdyHeaderBlock& trailers) override;
152 void OnFailed(int error) override;
153
154 // HttpStreamRequest::Delegate implementation:
155 void OnStreamReady(const SSLConfig& used_ssl_config,
156 const ProxyInfo& used_proxy_info,
157 HttpStream* stream) override;
158 void OnBidirectionalStreamJobReady(const SSLConfig& used_ssl_config,
159 const ProxyInfo& used_proxy_info,
160 BidirectionalStreamJob* stream) override;
161 void OnWebSocketHandshakeStreamReady(
162 const SSLConfig& used_ssl_config,
163 const ProxyInfo& used_proxy_info,
164 WebSocketHandshakeStreamBase* stream) override;
165 void OnStreamFailed(int status,
166 const SSLConfig& used_ssl_config,
167 SSLFailureState ssl_failure_state) override;
168 void OnCertificateError(int status,
169 const SSLConfig& used_ssl_config,
170 const SSLInfo& ssl_info) override;
171 void OnNeedsProxyAuth(const HttpResponseInfo& response_info,
172 const SSLConfig& used_ssl_config,
173 const ProxyInfo& used_proxy_info,
174 HttpAuthController* auth_controller) override;
175 void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
176 SSLCertRequestInfo* cert_info) override;
177 void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info,
178 const SSLConfig& used_ssl_config,
179 const ProxyInfo& used_proxy_info,
180 HttpStream* stream) override;
181 void OnQuicBroken() override;
182
183 const BidirectionalStreamRequestInfo* request_info_;
184 const BoundNetLog net_log_;
mmenke 2015/12/16 23:04:36 include net_log.h
xunjieli 2015/12/17 18:18:54 I forward declared it.
mmenke 2015/12/17 18:36:29 You can't forward declare types of class member va
xunjieli 2015/12/17 21:18:21 Done. Ah, I see. That makes sense. Will keep this
185
186 Delegate* const delegate_;
187
188 scoped_ptr<base::Timer> timer_;
189 scoped_ptr<HttpStreamRequest> stream_request_;
190 scoped_ptr<BidirectionalStreamJob> stream_job_;
mmenke 2015/12/16 23:04:36 Should document these.
xunjieli 2015/12/17 18:18:54 Done.
191
192 DISALLOW_COPY_AND_ASSIGN(BidirectionalStream);
193 };
194
195 } // namespace net
196
197 #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