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_SPDY_BIDIRECTIONAL_STREAM_SPDY_JOB_H_ | |
6 #define NET_SPDY_BIDIRECTIONAL_STREAM_SPDY_JOB_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include "base/macros.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/memory/weak_ptr.h" | |
13 #include "net/http/bidirectional_stream_job.h" | |
14 #include "net/http/bidirectional_stream_request_info.h" | |
15 #include "net/http/http_request_info.h" | |
16 #include "net/spdy/spdy_read_queue.h" | |
17 #include "net/spdy/spdy_session.h" | |
18 #include "net/spdy/spdy_stream.h" | |
19 | |
20 namespace base { | |
21 class Timer; | |
22 } // namespace base | |
23 | |
24 namespace net { | |
25 | |
26 class BoundNetLog; | |
27 class IOBuffer; | |
28 class SpdyHeaderBlock; | |
29 | |
30 class NET_EXPORT_PRIVATE BidirectionalStreamSpdyJob | |
31 : public BidirectionalStreamJob, | |
32 public SpdyStream::Delegate { | |
33 public: | |
34 explicit BidirectionalStreamSpdyJob( | |
35 const base::WeakPtr<SpdySession>& spdy_session); | |
36 | |
37 ~BidirectionalStreamSpdyJob() override; | |
38 | |
39 // BidirectionalStreamJob implementation: | |
40 void Start(const BidirectionalStreamRequestInfo* request_info, | |
41 const BoundNetLog& net_log, | |
42 BidirectionalStreamJob::Delegate* delegate, | |
43 scoped_ptr<base::Timer> timer) override; | |
44 int ReadData(IOBuffer* buf, int buf_len) override; | |
45 void SendData(IOBuffer* data, int length, bool end_stream) override; | |
46 void Cancel() override; | |
47 NextProto GetProtocol() const override; | |
48 int64_t GetTotalReceivedBytes() const override; | |
49 int64_t GetTotalSentBytes() const override; | |
50 | |
51 // SpdyStream::Delegate implementation: | |
52 void OnRequestHeadersSent() override; | |
53 SpdyResponseHeadersStatus OnResponseHeadersUpdated( | |
54 const SpdyHeaderBlock& response_headers) override; | |
55 void OnDataReceived(scoped_ptr<SpdyBuffer> buffer) override; | |
56 void OnDataSent() override; | |
57 void OnTrailers(const SpdyHeaderBlock& trailers) override; | |
58 void OnClose(int status) override; | |
59 | |
60 private: | |
61 void SendRequestHeaders(); | |
62 void OnStreamInitialized(int rv); | |
63 void ScheduleBufferedRead(); | |
64 void DoBufferedRead(); | |
65 bool ShouldWaitForMoreBufferedData() const; | |
66 | |
67 const base::WeakPtr<SpdySession> spdy_session_; | |
68 const BidirectionalStreamRequestInfo* request_info_; | |
69 BidirectionalStreamJob::Delegate* delegate_; | |
70 scoped_ptr<base::Timer> timer_; | |
71 SpdyStreamRequest stream_request_; | |
72 base::WeakPtr<SpdyStream> stream_; | |
73 | |
74 NextProto negotiated_protocol_; | |
75 | |
76 // Buffers the data as it arrives asynchronously from the stream. | |
77 SpdyReadQueue read_data_queue_; | |
78 // Whether received more data has arrived since started waiting. | |
79 bool more_read_data_pending_; | |
80 // User provided read buffer for ReadData() response. | |
81 scoped_refptr<IOBuffer> read_buffer_; | |
82 int read_buffer_len_; | |
83 | |
84 // Whether OnClose has been invoked. | |
85 bool stream_closed_; | |
86 // Status reported in OnClose. | |
87 int closed_stream_status_; | |
88 // After |stream_| has been closed, this keeps track of the total number of | |
89 // bytes received over the network for |stream_| while it was open. | |
90 int64_t closed_stream_received_bytes_; | |
91 // After |stream_| has been closed, this keeps track of the total number of | |
92 // bytes sent over the network for |stream_| while it was open. | |
93 int64_t closed_stream_sent_bytes_; | |
94 | |
95 base::WeakPtrFactory<BidirectionalStreamSpdyJob> weak_factory_; | |
96 | |
97 DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamSpdyJob); | |
98 }; | |
99 | |
100 } // namespace net | |
101 | |
102 #endif // NET_SPDY_BIDIRECTIONAL_STREAM_SPDY_JOB_H_ | |
OLD | NEW |