OLD | NEW |
---|---|
(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" | |
mmenke
2015/12/11 22:19:58
nit: Not needed.
xunjieli
2015/12/11 23:48:40
Done.
| |
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 // The delegate may call BidirectionalStreamJob::SendData to start | |
35 // sending data. | |
36 virtual void OnHeadersSent() = 0; | |
37 | |
38 // Called when response headers are received. | |
39 // This is called at most once for the lifetime of a stream. | |
40 // The delegate may call BidirectionalStreamJob::ReadData to start | |
41 // reading or call BidirectionalStream::Cancel to cancel the stream. | |
42 virtual void OnHeadersReceived(const SpdyHeaderBlock& response_headers) = 0; | |
43 | |
44 // Called when read is completed asynchronously. |bytes_read| specifies how | |
45 // much data is available. | |
46 // The delegate may call BidirectionalStreamJob::ReadData to continue | |
47 // reading or call BidirectionalStream::Cancel to cancel the stream. | |
48 virtual void OnDataRead(int bytes_read) = 0; | |
49 | |
50 // Called when the entire buffer passed through SendData is sent. | |
51 virtual void OnDataSent() = 0; | |
52 | |
53 // Called when trailers are received. | |
54 virtual void OnTrailersReceived(const SpdyHeaderBlock& trailers) = 0; | |
55 | |
56 // Called when an error occurred. | |
57 // No other delegate functions will be called after this. | |
58 virtual void OnFailed(int status) = 0; | |
59 | |
60 protected: | |
61 virtual ~Delegate(); | |
62 | |
63 private: | |
64 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
65 }; | |
66 | |
67 BidirectionalStreamJob(); | |
68 virtual ~BidirectionalStreamJob(); | |
69 | |
70 // Starts the BidirectionalStreamJob and sends request headers. | |
71 virtual void Start(const HttpRequestInfo& request_info, | |
72 RequestPriority priority, | |
73 const BoundNetLog& net_log, | |
74 Delegate* delegate) = 0; | |
75 | |
76 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read, | |
77 // ERR_IO_PENDING if the read is to be completed asynchronously, or an error | |
78 // code if any error occurred. | |
79 // This should not be called before Delegate::OnHeadersSent is invoked, and | |
80 // should not be called again unless it IO completes synchronously or until | |
81 // Delegate::OnDataRead is invoked. | |
82 virtual int ReadData(IOBuffer* buf, int buf_len) = 0; | |
83 | |
84 // Sends data. This should not be called be called before | |
85 // Delegate::OnHeadersSent is invoked, and should not be called again until | |
86 // Delegate::OnDataSent is invoked. | |
87 virtual void SendData(IOBuffer* data, int length, bool end_stream) = 0; | |
88 | |
89 // Cancels the stream. No Delegate method will be called. Any pending | |
90 // operations may or may not succeed. | |
91 virtual void Cancel() = 0; | |
92 | |
93 // Returns the protocol used by this stream. Always between | |
94 // kProtoSPDYMinimumVersion and kProtoSPDYMaximumVersion. | |
95 virtual NextProto GetProtocol() const = 0; | |
96 | |
97 // Total number of bytes received over the network of SPDY data, headers, and | |
98 // push_promise frames associated with this stream, including the size of | |
99 // frame headers, after SSL decryption and not including proxy overhead. | |
100 virtual int64_t GetTotalReceivedBytes() const = 0; | |
101 | |
102 // Total number of bytes sent over the network of SPDY frames associated with | |
103 // this stream, including the size of frame headers, before SSL encryption and | |
104 // not including proxy overhead. Note that some SPDY frames such as pings are | |
105 // not associated with any stream, and are not included in this value. | |
106 virtual int64_t GetTotalSentBytes() const = 0; | |
mmenke
2015/12/11 22:19:58
include <stdint.h>
xunjieli
2015/12/11 23:48:40
Done.
| |
107 | |
108 private: | |
109 DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamJob); | |
110 }; | |
111 | |
112 } // namespace net | |
113 | |
114 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_JOB_H_ | |
OLD | NEW |