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_IMPL_H_ | |
6 #define NET_SPDY_BIDIRECTIONAL_STREAM_SPDY_IMPL_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <memory> | |
11 #include <vector> | |
12 | |
13 #include "base/macros.h" | |
14 #include "base/memory/ref_counted.h" | |
15 #include "base/memory/weak_ptr.h" | |
16 #include "net/base/load_timing_info.h" | |
17 #include "net/base/net_export.h" | |
18 #include "net/http/bidirectional_stream_impl.h" | |
19 #include "net/http/bidirectional_stream_request_info.h" | |
20 #include "net/http/http_request_info.h" | |
21 #include "net/log/net_log_source.h" | |
22 #include "net/spdy/spdy_read_queue.h" | |
23 #include "net/spdy/spdy_session.h" | |
24 #include "net/spdy/spdy_stream.h" | |
25 | |
26 namespace base { | |
27 class Timer; | |
28 } // namespace base | |
29 | |
30 namespace net { | |
31 | |
32 class IOBuffer; | |
33 class NetLogWithSource; | |
34 class SpdyHeaderBlock; | |
35 | |
36 class NET_EXPORT_PRIVATE BidirectionalStreamSpdyImpl | |
37 : public BidirectionalStreamImpl, | |
38 public SpdyStream::Delegate { | |
39 public: | |
40 BidirectionalStreamSpdyImpl(const base::WeakPtr<SpdySession>& spdy_session, | |
41 NetLogSource source_dependency); | |
42 | |
43 ~BidirectionalStreamSpdyImpl() override; | |
44 | |
45 // BidirectionalStreamImpl implementation: | |
46 void Start(const BidirectionalStreamRequestInfo* request_info, | |
47 const NetLogWithSource& net_log, | |
48 bool send_request_headers_automatically, | |
49 BidirectionalStreamImpl::Delegate* delegate, | |
50 std::unique_ptr<base::Timer> timer) override; | |
51 void SendRequestHeaders() override; | |
52 int ReadData(IOBuffer* buf, int buf_len) override; | |
53 void SendData(const scoped_refptr<IOBuffer>& data, | |
54 int length, | |
55 bool end_stream) override; | |
56 void SendvData(const std::vector<scoped_refptr<IOBuffer>>& buffers, | |
57 const std::vector<int>& lengths, | |
58 bool end_stream) override; | |
59 NextProto GetProtocol() const override; | |
60 int64_t GetTotalReceivedBytes() const override; | |
61 int64_t GetTotalSentBytes() const override; | |
62 bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override; | |
63 | |
64 // SpdyStream::Delegate implementation: | |
65 void OnHeadersSent() override; | |
66 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override; | |
67 void OnDataReceived(std::unique_ptr<SpdyBuffer> buffer) override; | |
68 void OnDataSent() override; | |
69 void OnTrailers(const SpdyHeaderBlock& trailers) override; | |
70 void OnClose(int status) override; | |
71 NetLogSource source_dependency() const override; | |
72 | |
73 private: | |
74 int SendRequestHeadersHelper(); | |
75 void OnStreamInitialized(int rv); | |
76 // Notifies delegate of an error. | |
77 void NotifyError(int rv); | |
78 void ResetStream(); | |
79 void ScheduleBufferedRead(); | |
80 void DoBufferedRead(); | |
81 bool ShouldWaitForMoreBufferedData() const; | |
82 // Handles the case where stream is closed when SendData()/SendvData() is | |
83 // called. Return true if stream is closed. | |
84 bool MaybeHandleStreamClosedInSendData(); | |
85 | |
86 const base::WeakPtr<SpdySession> spdy_session_; | |
87 const BidirectionalStreamRequestInfo* request_info_; | |
88 BidirectionalStreamImpl::Delegate* delegate_; | |
89 std::unique_ptr<base::Timer> timer_; | |
90 SpdyStreamRequest stream_request_; | |
91 base::WeakPtr<SpdyStream> stream_; | |
92 const NetLogSource source_dependency_; | |
93 | |
94 NextProto negotiated_protocol_; | |
95 | |
96 // Buffers the data as it arrives asynchronously from the stream. | |
97 SpdyReadQueue read_data_queue_; | |
98 // Whether received more data has arrived since started waiting. | |
99 bool more_read_data_pending_; | |
100 // User provided read buffer for ReadData() response. | |
101 scoped_refptr<IOBuffer> read_buffer_; | |
102 int read_buffer_len_; | |
103 | |
104 // Whether client has written the end of stream flag in request headers or | |
105 // in SendData()/SendvData(). | |
106 bool written_end_of_stream_; | |
107 // Whether a SendData() or SendvData() is pending. | |
108 bool write_pending_; | |
109 | |
110 // Whether OnClose has been invoked. | |
111 bool stream_closed_; | |
112 // Status reported in OnClose. | |
113 int closed_stream_status_; | |
114 // After |stream_| has been closed, this keeps track of the total number of | |
115 // bytes received over the network for |stream_| while it was open. | |
116 int64_t closed_stream_received_bytes_; | |
117 // After |stream_| has been closed, this keeps track of the total number of | |
118 // bytes sent over the network for |stream_| while it was open. | |
119 int64_t closed_stream_sent_bytes_; | |
120 // True if |stream_| has LoadTimingInfo when it is closed. | |
121 bool closed_has_load_timing_info_; | |
122 // LoadTimingInfo populated when |stream_| is closed. | |
123 LoadTimingInfo closed_load_timing_info_; | |
124 | |
125 // This is the combined buffer of buffers passed in through SendvData. | |
126 // Keep a reference here so it is alive until OnDataSent is invoked. | |
127 scoped_refptr<IOBuffer> pending_combined_buffer_; | |
128 | |
129 base::WeakPtrFactory<BidirectionalStreamSpdyImpl> weak_factory_; | |
130 | |
131 DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamSpdyImpl); | |
132 }; | |
133 | |
134 } // namespace net | |
135 | |
136 #endif // NET_SPDY_BIDIRECTIONAL_STREAM_SPDY_IMPL_H_ | |
OLD | NEW |