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