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/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. | |
mef
2015/11/10 23:00:27
Maybe add a comment about lifetime scenarios that
xunjieli
2015/11/13 23:41:45
I am not very sure what the lifetime scenarios you
xunjieli
2015/11/25 16:58:58
Done.
| |
22 class NET_EXPORT_PRIVATE BidirectionalStreamJob { | |
23 public: | |
24 // Delegate to handle BidirectionalStreamJob events. | |
25 class Delegate { | |
26 public: | |
27 Delegate(); | |
28 | |
29 // Called when an error occurs. E.g. when a connection to the server cannot | |
30 // be established. | |
31 virtual void OnFailed(Error error) = 0; | |
32 | |
33 // Called when the request headers have been sent. | |
34 virtual void OnRequestHeadersSent() = 0; | |
35 | |
36 // Called when response headers are received. | |
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 virtual void OnReadCompleted(int bytes_read) = 0; | |
42 | |
43 // Called when the entire buffer passed through SendData is sent. | |
44 virtual void OnDataSent() = 0; | |
45 | |
46 // Called when trailers are received. | |
47 virtual void OnTrailers(const SpdyHeaderBlock& trailers) = 0; | |
48 | |
49 // Called when the stream is closed. No other delegate functions will be | |
50 // called after this. |status| is an error code or OK. | |
51 virtual void OnClose(int status) = 0; | |
52 | |
53 protected: | |
54 virtual ~Delegate(); | |
55 | |
56 private: | |
57 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
58 }; | |
59 | |
60 BidirectionalStreamJob(); | |
61 virtual ~BidirectionalStreamJob(); | |
62 | |
63 // Starts the BidirectionalStreamJob and sends request headers. | |
64 virtual void Start(const HttpRequestInfo& request_info, | |
65 RequestPriority priority, | |
66 const BoundNetLog& net_log, | |
67 Delegate* delegate) = 0; | |
68 | |
69 // Reads at most |buf_len| bytes into |buf|. Returns the number of bytes read, | |
70 // or ERR_IO_PENDING if the read is to be completed asynchronously. | |
71 virtual int ReadData(IOBuffer* buf, int buf_len) = 0; | |
72 | |
73 // Sends data. This should not be called again until OnDataSent is invoked. | |
74 virtual void SendData(IOBuffer* data, int length, bool end_stream) = 0; | |
75 | |
76 // Cancels the stream. No Delegate method will be called. | |
77 virtual void Cancel() = 0; | |
78 | |
79 private: | |
80 DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamJob); | |
81 }; | |
82 | |
83 } // namespace net | |
84 | |
85 #endif // NET_HTTP_BIDIRECTIONAL_STREAM_JOB_H_ | |
OLD | NEW |