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

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: Fix bug and added a test 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/macros.h"
9 #include "net/base/net_export.h"
10 #include "net/base/request_priority.h"
11
12 namespace net {
13
14 class BoundNetLog;
15 class IOBuffer;
16 class SpdyHeaderBlock;
17 struct HttpRequestInfo;
18
19 // Exposes an interface to do HTTP/2 bidirectional streaming.
20 // Note that only one ReadData or SendData should be in flight until the
21 // operation completes synchronously or asynchronously.
22 // BidirectionalStreamJob once created by HttpStreamFactoryImpl should be owned
23 // by BidirectionalStream.
24 class NET_EXPORT_PRIVATE BidirectionalStreamJob {
25 public:
26 // Delegate to handle BidirectionalStreamJob events.
27 class Delegate {
28 public:
29 Delegate();
30
31 // Called when the request headers have been sent.
32 virtual void OnRequestHeadersSent() = 0;
33
34 // Called when response headers are received.
35 // The delegate should call BidirectionalStreamJob::ReadData to start
36 // reading or call BidirectionalStream::Cancel to cancel the stream.
37 virtual void OnHeaders(const SpdyHeaderBlock& response_headers) = 0;
38
39 // Called when read is completed asynchronously. |bytes_read| specifies how
40 // much data is available.
41 // The delegate should call BidirectionalStreamJob::ReadData to continue
42 // reading or call BidirectionalStream::Cancel to cancel the stream.
43 virtual void OnReadCompleted(int bytes_read) = 0;
44
45 // Called when the entire buffer passed through SendData is sent.
46 virtual void OnDataSent() = 0;
47
48 // Called when trailers are received.
49 virtual void OnTrailers(const SpdyHeaderBlock& trailers) = 0;
50
51 // Called when an error occurred.
52 // No other delegate functions will be called after this.
53 virtual void OnFailed(int status) = 0;
54
55 protected:
56 virtual ~Delegate();
57
58 private:
59 DISALLOW_COPY_AND_ASSIGN(Delegate);
60 };
61
62 BidirectionalStreamJob();
63 virtual ~BidirectionalStreamJob();
64
65 // Starts the BidirectionalStreamJob and sends request headers.
66 virtual void Start(const HttpRequestInfo& request_info,
67 RequestPriority priority,
68 const BoundNetLog& net_log,
69 Delegate* delegate) = 0;
70
71 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read,
72 // or ERR_IO_PENDING if the read is to be completed asynchronously.
73 virtual int ReadData(IOBuffer* buf, int buf_len) = 0;
74
75 // Sends data. This should not be called again until OnDataSent is invoked.
76 virtual void SendData(IOBuffer* data, int length, bool end_stream) = 0;
77
78 // Cancels the stream. No Delegate method will be called.
79 virtual void Cancel() = 0;
80
81 private:
82 DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamJob);
83 };
84
85 } // namespace net
86
87 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_JOB_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698