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_H_ | |
| 6 #define NET_HTTP_BIDIRECTIONAL_STREAM_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "net/base/net_export.h" | |
| 10 #include "net/base/request_priority.h" | |
| 11 #include "net/http/http_request_info.h" | |
| 12 #include "net/spdy/spdy_session.h" | |
| 13 #include "net/spdy/spdy_stream.h" | |
| 14 | |
| 15 namespace net { | |
| 16 | |
| 17 struct HttpRequestInfo; | |
| 18 class IOBuffer; | |
| 19 class BoundNetLog; | |
| 20 | |
| 21 // An interface that exposes bidirectional streaming. Note that only one | |
| 22 // ReadData or SendData should be in flight until the operation completes | |
| 23 // synchronously or asynchronously. | |
| 24 class NET_EXPORT BidirectionalStream { | |
|
mmenke
2015/11/03 20:32:13
NET_EXPORT_PRIVATE (You'll need to make the helper
xunjieli
2015/11/05 23:17:13
Done.
| |
| 25 public: | |
| 26 // Delegate to handle BidirectionalStream events. | |
| 27 class Delegate { | |
| 28 public: | |
| 29 Delegate(); | |
| 30 | |
| 31 // Called when an error occurs. E.g. when a connection to the server cannot | |
| 32 // be established. | |
| 33 virtual void OnFailed(int error) = 0; | |
|
mef
2015/11/04 20:13:53
UrlRequest has a status() method. Does this callba
mmenke
2015/11/04 20:42:41
This and knowledge of whether you're waiting on it
| |
| 34 | |
| 35 // Called when the request headers have been sent. | |
| 36 virtual void OnRequestHeadersSent() = 0; | |
|
mef
2015/11/04 20:13:53
We need to add something like HttpResponseInfo, wi
xunjieli
2015/11/05 23:17:13
Acknowledged. Added as a TODO.
| |
| 37 | |
| 38 // Called when response headers are received. | |
| 39 virtual void OnHeaders(const SpdyHeaderBlock& response_headers) = 0; | |
|
mef
2015/11/02 18:00:42
Is this called only once or could it happen multip
mef
2015/11/04 20:13:53
Is there some way to get Http status code at this
xunjieli
2015/11/05 23:17:13
Yes, we can get it from the header ":status"
xunjieli
2015/11/05 23:17:13
It's called once. I've added comment.
| |
| 40 | |
| 41 // Called when read is completed asynchronously. |bytes_read| specifies how | |
| 42 // much data is available. | |
| 43 virtual void OnReadCompleted(int bytes_read) = 0; | |
|
mef
2015/11/04 20:13:52
Is there some way to get running received bytes co
xunjieli
2015/11/05 23:17:13
This byte count here is pre-decompression. We can
| |
| 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 the stream is closed. No other delegate functions will be | |
| 52 // called after this. |status| is an error code or OK. | |
| 53 virtual void OnClose(int status) = 0; | |
| 54 | |
| 55 protected: | |
| 56 virtual ~Delegate(); | |
| 57 | |
| 58 private: | |
| 59 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
| 60 }; | |
| 61 | |
| 62 BidirectionalStream(); | |
| 63 virtual ~BidirectionalStream(); | |
| 64 | |
| 65 // Starts the BidirectionalStream 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 // TODO(xunjieli): implement a method to do flow control. | |
|
mef
2015/11/02 18:00:42
We also need a method for ping, but fine to have i
xunjieli
2015/11/05 23:17:13
Acknowledged.
| |
| 82 | |
| 83 private: | |
| 84 DISALLOW_COPY_AND_ASSIGN(BidirectionalStream); | |
| 85 }; | |
| 86 | |
| 87 } // namespace net | |
| 88 | |
| 89 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_H_ | |
| OLD | NEW |