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

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 DeterministicSocketData 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_job.h » ('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/base/request_priority.h"
13 #include "net/http/bidirectional_stream_job.h"
14 #include "net/http/bidirectional_stream_request_info.h"
15 #include "net/http/http_stream_factory.h"
16 #include "net/ssl/ssl_config.h"
17 #include "url/gurl.h"
18
19 namespace net {
20
21 class BoundNetLog;
22 class HttpAuthController;
23 class HttpNetworkSession;
24 class HttpStream;
25 class HttpStreamRequest;
26 class IOBuffer;
27 class ProxyInfo;
28 class SpdyHeaderBlock;
29
30 // A class to do HTTP/2 bidirectional streaming. Note that at most one each of
31 // ReadData or SendData should be in flight until the operation completes
mef 2015/12/15 22:59:40 nit: end with .
xunjieli 2015/12/16 00:26:09 Done.
32 // The BidirectionalStream must be torn down before the HttpNetworkSession.
33 class NET_EXPORT BidirectionalStream : public BidirectionalStreamJob::Delegate,
34 public HttpStreamRequest::Delegate {
35 public:
36 // Delegate interface to get notified of success of failure. Callbacks will be
37 // invoked asynchronously.
38 class NET_EXPORT Delegate {
39 public:
40 Delegate() {}
41
42 // Called when headers have been sent. This is called at most once for
43 // the lifetime of a stream.
44 // The delegate may call BidirectionalStreamJob::SendData to start
45 // sending data.
mef 2015/12/15 22:59:39 or call BidirectionalStream::Cancel to cancel the
xunjieli 2015/12/16 00:26:09 It's illegal to call Cancel during OnHeadersSent o
46 virtual void OnHeadersSent() = 0;
47
48 // Called when headers are received. This is called at most once for the
49 // lifetime of a stream.
50 // The delegate may call BidirectionalStream::ReadData to start reading
51 // or call BidirectionalStream::Cancel to cancel the stream.
52 virtual void OnHeadersReceived(const SpdyHeaderBlock& response_headers) = 0;
53
54 // Called when read is completed asynchronously. |bytes_read| specifies how
55 // much data is available.
mef 2015/12/15 22:59:40 read -> pending read is available -> is read.
xunjieli 2015/12/16 00:26:09 Done.
56 // The delegate may call BidirectionalStream::ReadData to continue
57 // reading or call BidirectionalStream::Cancel to cancel the stream.
58 virtual void OnDataRead(int bytes_read) = 0;
59
60 // Called when the entire buffer passed through SendData is sent.
mef 2015/12/15 22:59:40 Update comment similarly to OnDataRead().
xunjieli 2015/12/16 00:26:09 Done.
61 virtual void OnDataSent() = 0;
62
63 // Called when trailers are received. This is called as soon as trailers
64 // are received, which can happen before a read completes.
mef 2015/12/15 22:59:40 Maybe clarify that no action is required from the
xunjieli 2015/12/16 00:26:08 Done.
65 virtual void OnTrailersReceived(const SpdyHeaderBlock& trailers) = 0;
66
67 // Called when the stream is closed or an error occurred.
68 // No other delegate functions will be called after this.
69 virtual void OnFailed(int error) = 0;
70
71 protected:
72 virtual ~Delegate() {}
mef 2015/12/15 22:59:40 Should {} go into .cc file?
xunjieli 2015/12/16 00:26:09 Done. Good catch. Thanks!
73
74 private:
75 DISALLOW_COPY_AND_ASSIGN(Delegate);
76 };
77
78 BidirectionalStream(const BidirectionalStreamRequestInfo& request_info,
mef 2015/12/15 22:59:40 need comment, especially considering that this is
xunjieli 2015/12/16 00:26:09 Done.
79 RequestPriority priority,
80 HttpNetworkSession* session,
81 Delegate* delegate);
82
83 // Constructor that accepts a Timer, which can be used in tests to control
84 // the buffering of received data.
85 BidirectionalStream(const BidirectionalStreamRequestInfo& request_info,
mef 2015/12/15 22:59:39 FWIW HttpStream-related classes pass request_info
xunjieli 2015/12/16 00:26:08 Done.
86 RequestPriority priority,
87 HttpNetworkSession* session,
88 Delegate* delegate,
89 scoped_ptr<base::Timer> timer);
90
91 // Cancels |stream_request_| or |stream_job_| if applicable.
92 // |this| should not be destroyed during Delegate::OnHeadersSent or
mef 2015/12/15 22:59:40 That's an interesting comment. Why not? Do we need
xunjieli 2015/12/16 00:26:08 It's illegal to call Cancel during OnHeadersSent o
mef 2015/12/16 20:24:40 Acknowledged. This should not be a problem for Cro
93 // Delegate::OnDataSent.
94 ~BidirectionalStream() override;
95
96 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read,
97 // or ERR_IO_PENDING if the read is to be completed asynchronously, or an
98 // error code if any error occurred.
99 // This should not be called before Delegate::OnHeadersSent is invoked, and
mef 2015/12/15 22:59:40 OnHeadersSent -> OnHeadersReceived?
xunjieli 2015/12/16 00:26:09 Done.
100 // should not be called again unless it IO completes synchronously or until
mef 2015/12/15 22:59:39 IO completes -> returns
xunjieli 2015/12/16 00:26:09 Done.
101 // Delegate::OnDataRead is invoked.
102 int ReadData(IOBuffer* buf, int buf_len);
103
104 // Sends data. This should not be called before Delegate::OnHeadersSent is
105 // invoked, and should not be called again until Delegate::OnDataSent is
106 // invoked.
107 void SendData(IOBuffer* data, int length, bool end_stream);
108
109 // If there is |stream_request_|, cancel it. If |stream_job_| is established,
110 // cancel it. No delegate method will be called after Cancel().
111 // Any pending operations may or may not succeed.
112 void Cancel();
113
114 // Getters that should only be called after Delegate::OnHeadersSent:
115
116 // Returns the protocol used by this stream. If stream has not been
117 // stablished, return kProtoUnknown.
mef 2015/12/15 22:59:40 established (here and below).
xunjieli 2015/12/16 00:26:08 Done.
118 NextProto GetProtocol() const;
119
120 // Total number of bytes received over the network of SPDY data, headers, and
121 // push_promise frames associated with this stream, including the size of
122 // frame headers, after SSL decryption and not including proxy overhead.
123 // If stream has not been stablished, return 0.
124 int64_t GetTotalReceivedBytes() const;
125
126 // Total number of bytes sent over the network of SPDY frames associated with
127 // this stream, including the size of frame headers, before SSL encryption and
128 // not including proxy overhead. Note that some SPDY frames such as pings are
129 // not associated with any stream, and are not included in this value.
130 int64_t GetTotalSentBytes() const;
131
132 // TODO(xunjieli): Implement a method to do flow control and a method to ping
133 // remote end point.
134
135 private:
136 // BidirectionalStreamJob::Delegate implementation:
137 void OnHeadersSent() override;
138 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override;
139 void OnDataRead(int bytes_read) override;
140 void OnDataSent() override;
141 void OnTrailersReceived(const SpdyHeaderBlock& trailers) override;
142 void OnFailed(int error) override;
143
144 // HttpStreamRequest::Delegate implementation:
145 void OnStreamReady(const SSLConfig& used_ssl_config,
146 const ProxyInfo& used_proxy_info,
147 HttpStream* stream) override;
148 void OnBidirectionalStreamJobReady(const SSLConfig& used_ssl_config,
149 const ProxyInfo& used_proxy_info,
150 BidirectionalStreamJob* stream) override;
151 void OnWebSocketHandshakeStreamReady(
152 const SSLConfig& used_ssl_config,
153 const ProxyInfo& used_proxy_info,
154 WebSocketHandshakeStreamBase* stream) override;
155 void OnStreamFailed(int status,
156 const SSLConfig& used_ssl_config,
157 SSLFailureState ssl_failure_state) override;
158 void OnCertificateError(int status,
159 const SSLConfig& used_ssl_config,
160 const SSLInfo& ssl_info) override;
161 void OnNeedsProxyAuth(const HttpResponseInfo& response_info,
162 const SSLConfig& used_ssl_config,
163 const ProxyInfo& used_proxy_info,
164 HttpAuthController* auth_controller) override;
165 void OnNeedsClientAuth(const SSLConfig& used_ssl_config,
166 SSLCertRequestInfo* cert_info) override;
167 void OnHttpsProxyTunnelResponse(const HttpResponseInfo& response_info,
168 const SSLConfig& used_ssl_config,
169 const ProxyInfo& used_proxy_info,
170 HttpStream* stream) override;
171 void OnQuicBroken() override;
172
173 const BidirectionalStreamRequestInfo request_info_;
mef 2015/12/15 22:59:40 can this be a scoped_ptr<BidirectionalStreamReques
xunjieli 2015/12/16 00:26:09 Done. I think it should take a raw pointer. Whoeve
mef 2015/12/16 20:24:40 Excellent, sgtm!
174 const RequestPriority priority_;
175 const BoundNetLog net_log_;
176
177 Delegate* const delegate_;
178
179 scoped_ptr<base::Timer> timer_;
180 scoped_ptr<HttpStreamRequest> stream_request_;
181 scoped_ptr<BidirectionalStreamJob> stream_job_;
182
183 DISALLOW_COPY_AND_ASSIGN(BidirectionalStream);
184 };
185
186 } // namespace net
187
188 #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_job.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698