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 virtual ~BidirectionalStreamJob(); |
| 77 |
| 78 // Starts the BidirectionalStreamJob and sends request headers. |
| 79 virtual void Start(const BidirectionalStreamRequestInfo& request_info, |
| 80 RequestPriority priority, |
| 81 const BoundNetLog& net_log, |
| 82 BidirectionalStreamJob::Delegate* delegate, |
| 83 scoped_ptr<base::Timer> timer) = 0; |
| 84 |
| 85 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read, |
| 86 // ERR_IO_PENDING if the read is to be completed asynchronously, or an error |
| 87 // code if any error occurred. |
| 88 // This should not be called before Delegate::OnHeadersSent is invoked, and |
| 89 // should not be called again unless it IO completes synchronously or until |
| 90 // Delegate::OnDataRead is invoked. |
| 91 virtual int ReadData(IOBuffer* buf, int buf_len) = 0; |
| 92 |
| 93 // Sends data. This should not be called be called before |
| 94 // Delegate::OnHeadersSent is invoked, and should not be called again until |
| 95 // Delegate::OnDataSent is invoked. |
| 96 virtual void SendData(IOBuffer* data, int length, bool end_stream) = 0; |
| 97 |
| 98 // Cancels the stream. No Delegate method will be called. Any pending |
| 99 // operations may or may not succeed. |
| 100 virtual void Cancel() = 0; |
| 101 |
| 102 // Returns the protocol used by this stream. Always between |
| 103 // kProtoSPDYMinimumVersion and kProtoSPDYMaximumVersion. |
| 104 virtual NextProto GetProtocol() const = 0; |
| 105 |
| 106 // Total number of bytes received over the network of SPDY data, headers, and |
| 107 // push_promise frames associated with this stream, including the size of |
| 108 // frame headers, after SSL decryption and not including proxy overhead. |
| 109 virtual int64_t GetTotalReceivedBytes() const = 0; |
| 110 |
| 111 // Total number of bytes sent over the network of SPDY frames associated with |
| 112 // this stream, including the size of frame headers, before SSL encryption and |
| 113 // not including proxy overhead. Note that some SPDY frames such as pings are |
| 114 // not associated with any stream, and are not included in this value. |
| 115 virtual int64_t GetTotalSentBytes() const = 0; |
| 116 |
| 117 private: |
| 118 DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamJob); |
| 119 }; |
| 120 |
| 121 } // namespace net |
| 122 |
| 123 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_JOB_H_ |
OLD | NEW |