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

Side by Side Diff: net/http/bidirectional_stream_job.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
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_JOB_H_
6 #define NET_HTTP_BIDIRECTIONAL_STREAM_JOB_H_
7
8 #include "base/basictypes.h"
9 #include "base/macros.h"
10 #include "net/base/net_export.h"
11 #include "net/base/request_priority.h"
12 #include "net/socket/next_proto.h"
13
14 namespace net {
15
16 class BoundNetLog;
17 class IOBuffer;
18 class SpdyHeaderBlock;
19 struct HttpRequestInfo;
20
21 // Exposes an interface to do HTTP/2 bidirectional streaming.
22 // Note that only one ReadData or SendData should be in flight until the
23 // operation completes synchronously or asynchronously.
24 // BidirectionalStreamJob once created by HttpStreamFactoryImpl should be owned
25 // by BidirectionalStream.
26 class NET_EXPORT_PRIVATE BidirectionalStreamJob {
27 public:
28 // Delegate to handle BidirectionalStreamJob events.
29 class Delegate {
30 public:
31 Delegate();
32
33 // Called when the request headers have been sent.
34 virtual void OnRequestHeadersSent() = 0;
35
36 // Called when response headers are received.
37 // The delegate should call BidirectionalStreamJob::ReadData to start
38 // reading or call BidirectionalStream::Cancel to cancel the stream.
39 virtual void OnHeaders(const SpdyHeaderBlock& response_headers) = 0;
40
41 // Called when read is completed asynchronously. |bytes_read| specifies how
42 // much data is available.
43 // The delegate should call BidirectionalStreamJob::ReadData to continue
44 // reading or call BidirectionalStream::Cancel to cancel the stream.
45 virtual void OnReadCompleted(int bytes_read) = 0;
46
47 // Called when the entire buffer passed through SendData is sent.
48 virtual void OnDataSent() = 0;
49
50 // Called when trailers are received.
51 virtual void OnTrailers(const SpdyHeaderBlock& trailers) = 0;
52
53 // Called when an error occurred.
54 // No other delegate functions will be called after this.
55 virtual void OnFailed(int status) = 0;
56
57 protected:
58 virtual ~Delegate();
59
60 private:
61 DISALLOW_COPY_AND_ASSIGN(Delegate);
62 };
63
64 BidirectionalStreamJob();
65 virtual ~BidirectionalStreamJob();
66
67 // Starts the BidirectionalStreamJob and sends request headers.
68 virtual void Start(const HttpRequestInfo& request_info,
69 RequestPriority priority,
70 const BoundNetLog& net_log,
71 Delegate* delegate) = 0;
72
73 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read,
74 // ERR_IO_PENDING if the read is to be completed asynchronously, or an error
75 // code if any error occurred.
76 virtual int ReadData(IOBuffer* buf, int buf_len) = 0;
77
78 // Sends data. This should not be called again until OnDataSent is invoked.
79 virtual void SendData(IOBuffer* data, int length, bool end_stream) = 0;
80
81 // Cancels the stream. No Delegate method will be called.
82 virtual void Cancel() = 0;
83
84 // Returns the protocol used by this stream. Always between
85 // kProtoSPDYMinimumVersion and kProtoSPDYMaximumVersion.
86 virtual NextProto GetProtocol() const = 0;
87
88 // Total number of bytes received over the network of SPDY data, headers, and
89 // push_promise frames associated with this stream, including the size of
90 // frame headers, after SSL decryption and not including proxy overhead.
91 virtual int64_t GetTotalReceivedBytes() const = 0;
92
93 // Total number of bytes sent over the network of SPDY frames associated with
94 // this stream, including the size of frame headers, before SSL encryption and
95 // not including proxy overhead. Note that some SPDY frames such as pings are
96 // not associated with any stream, and are not included in this value.
97 virtual int64_t GetTotalSentBytes() const = 0;
98
99 private:
100 DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamJob);
101 };
102
103 } // namespace net
104
105 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698