Chromium Code Reviews| 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 <stdint.h> | |
| 9 | |
| 10 #include "base/macros.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "net/base/net_export.h" | |
| 13 #include "net/base/request_priority.h" | |
| 14 #include "net/socket/next_proto.h" | |
| 15 | |
| 16 namespace base { | |
| 17 class Timer; | |
| 18 } // namespace base | |
| 19 | |
| 20 namespace net { | |
| 21 | |
| 22 class BoundNetLog; | |
| 23 class IOBuffer; | |
| 24 class SpdyHeaderBlock; | |
| 25 struct BidirectionalStreamRequestInfo; | |
| 26 | |
| 27 // Exposes an interface to do HTTP/2 bidirectional streaming. | |
| 28 // Note that only one ReadData or SendData should be in flight until the | |
| 29 // operation completes synchronously or asynchronously. | |
| 30 // BidirectionalStreamJob once created by HttpStreamFactoryImpl should be owned | |
| 31 // by BidirectionalStream. | |
| 32 class NET_EXPORT_PRIVATE BidirectionalStreamJob { | |
| 33 public: | |
| 34 // Delegate to handle BidirectionalStreamJob events. | |
| 35 class Delegate { | |
| 36 public: | |
| 37 Delegate(); | |
| 38 | |
| 39 // Called when the request headers have been sent. | |
| 40 // The delegate may call BidirectionalStreamJob::SendData to start | |
| 41 // sending data. | |
| 42 virtual void OnHeadersSent() = 0; | |
| 43 | |
| 44 // Called when response headers are received. | |
| 45 // This is called at most once for the lifetime of a stream. | |
| 46 // The delegate may call BidirectionalStreamJob::ReadData to start | |
| 47 // reading or call BidirectionalStream::Cancel to cancel the stream. | |
| 48 virtual void OnHeadersReceived(const SpdyHeaderBlock& response_headers) = 0; | |
| 49 | |
| 50 // Called when read is completed asynchronously. |bytes_read| specifies how | |
| 51 // much data is available. | |
| 52 // The delegate may call BidirectionalStreamJob::ReadData to continue | |
| 53 // reading or call BidirectionalStream::Cancel to cancel the stream. | |
| 54 virtual void OnDataRead(int bytes_read) = 0; | |
| 55 | |
| 56 // Called when the entire buffer passed through SendData is sent. | |
| 57 virtual void OnDataSent() = 0; | |
| 58 | |
| 59 // Called when trailers are received. This is called as soon as trailers | |
| 60 // are received, which can happen before a read completes. | |
| 61 virtual void OnTrailersReceived(const SpdyHeaderBlock& trailers) = 0; | |
| 62 | |
| 63 // Called when an error occurred. | |
| 64 // No other delegate functions will be called after this. | |
| 65 virtual void OnFailed(int status) = 0; | |
| 66 | |
| 67 protected: | |
| 68 virtual ~Delegate(); | |
| 69 | |
| 70 private: | |
| 71 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
| 72 }; | |
| 73 | |
| 74 BidirectionalStreamJob(); | |
| 75 | |
| 76 // |this| should not be destroyed during Delegate::OnHeadersSent or | |
| 77 // Delegate::OnDataSent. | |
| 78 virtual ~BidirectionalStreamJob(); | |
| 79 | |
| 80 // Starts the BidirectionalStreamJob and sends request headers. | |
| 81 virtual void Start(const BidirectionalStreamRequestInfo& request_info, | |
| 82 RequestPriority priority, | |
|
mef
2015/12/15 22:59:40
should priority be folded into request_info?
xunjieli
2015/12/16 00:26:09
Done. I don't see why not. Though in the future we
| |
| 83 const BoundNetLog& net_log, | |
| 84 BidirectionalStreamJob::Delegate* delegate, | |
| 85 scoped_ptr<base::Timer> timer) = 0; | |
| 86 | |
| 87 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read, | |
| 88 // ERR_IO_PENDING if the read is to be completed asynchronously, or an error | |
| 89 // code if any error occurred. | |
| 90 // This should not be called before Delegate::OnHeadersSent is invoked, and | |
| 91 // should not be called again unless it IO completes synchronously or until | |
| 92 // Delegate::OnDataRead is invoked. | |
| 93 virtual int ReadData(IOBuffer* buf, int buf_len) = 0; | |
| 94 | |
| 95 // Sends data. This should not be called be called before | |
| 96 // Delegate::OnHeadersSent is invoked, and should not be called again until | |
| 97 // Delegate::OnDataSent is invoked. | |
| 98 virtual void SendData(IOBuffer* data, int length, bool end_stream) = 0; | |
| 99 | |
| 100 // Cancels the stream. No Delegate method will be called. Any pending | |
| 101 // operations may or may not succeed. | |
| 102 virtual void Cancel() = 0; | |
| 103 | |
| 104 // Returns the protocol used by this stream. Always between | |
| 105 // kProtoSPDYMinimumVersion and kProtoSPDYMaximumVersion. | |
|
mef
2015/12/15 22:59:40
I suppose that QUIC implementation will return hig
xunjieli
2015/12/16 00:26:09
Done. Good catch! Was copying from SpdyStream, and
| |
| 106 virtual NextProto GetProtocol() const = 0; | |
| 107 | |
| 108 // Total number of bytes received over the network of SPDY data, headers, and | |
| 109 // push_promise frames associated with this stream, including the size of | |
| 110 // frame headers, after SSL decryption and not including proxy overhead. | |
| 111 virtual int64_t GetTotalReceivedBytes() const = 0; | |
| 112 | |
| 113 // Total number of bytes sent over the network of SPDY frames associated with | |
| 114 // this stream, including the size of frame headers, before SSL encryption and | |
| 115 // not including proxy overhead. Note that some SPDY frames such as pings are | |
| 116 // not associated with any stream, and are not included in this value. | |
| 117 virtual int64_t GetTotalSentBytes() const = 0; | |
| 118 | |
| 119 private: | |
| 120 DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamJob); | |
| 121 }; | |
| 122 | |
| 123 } // namespace net | |
| 124 | |
| 125 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_JOB_H_ | |
| OLD | NEW |