OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 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_QUIC_BIDIRECTIONAL_STREAM_QUIC_IMPL_H_ | |
6 #define NET_QUIC_BIDIRECTIONAL_STREAM_QUIC_IMPL_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" | |
mef
2016/03/09 17:20:37
nit: probably can just forward-declare Bidirection
xunjieli
2016/03/09 21:34:53
Done.
| |
15 #include "net/net_features.h" | |
16 #include "net/quic/quic_chromium_client_session.h" | |
17 #include "net/quic/quic_chromium_client_stream.h" | |
18 | |
19 #if !BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) | |
20 #error Only include this if ENABLE_BIDIRECTIONAL_STREAM is defined | |
21 #endif | |
22 | |
23 namespace base { | |
24 class Timer; | |
25 } // namespace base | |
26 | |
27 namespace net { | |
28 | |
29 class BoundNetLog; | |
30 class IOBuffer; | |
31 class SpdyHeaderBlock; | |
32 | |
33 class NET_EXPORT_PRIVATE BidirectionalStreamQuicImpl | |
34 : public BidirectionalStreamJob, | |
35 public QuicChromiumClientStream::Delegate, | |
36 public QuicChromiumClientSession::Observer { | |
37 public: | |
38 explicit BidirectionalStreamQuicImpl( | |
39 const base::WeakPtr<QuicChromiumClientSession>& session); | |
40 | |
41 ~BidirectionalStreamQuicImpl() override; | |
42 | |
43 // BidirectionalStreamJob implementation: | |
44 void Start(const BidirectionalStreamRequestInfo* request_info, | |
45 const BoundNetLog& net_log, | |
46 BidirectionalStreamJob::Delegate* delegate, | |
47 scoped_ptr<base::Timer> timer) override; | |
48 int ReadData(IOBuffer* buf, int buf_len) override; | |
49 void SendData(IOBuffer* data, int length, bool end_stream) override; | |
50 void Cancel() override; | |
51 NextProto GetProtocol() const override; | |
52 int64_t GetTotalReceivedBytes() const override; | |
53 int64_t GetTotalSentBytes() const override; | |
54 | |
55 private: | |
56 // QuicChromiumClientStream::Delegate implementation: | |
57 void OnHeadersAvailable(const SpdyHeaderBlock& headers, | |
58 size_t frame_len) override; | |
59 void OnDataAvailable() override; | |
60 void OnClose(QuicErrorCode error) override; | |
61 void OnError(int error) override; | |
62 bool HasSendHeadersComplete() override; | |
63 | |
64 // QuicChromiumClientSession::Observer implementation: | |
65 void OnCryptoHandshakeConfirmed() override; | |
66 void OnSessionClosed(int error) override; | |
67 | |
68 void OnStreamReady(int rv); | |
69 void OnSendDataComplete(int rv); | |
70 void OnReadDataComplete(int rv); | |
71 | |
72 // Helper method to send request headers. | |
73 void SendRequestHeaders(); | |
74 // Notifies the delegate of an error. | |
75 void NotifyError(int error); | |
76 // Resets the stream and ensures that |delegate_| won't be called back. | |
77 void ResetStream(); | |
78 | |
79 base::WeakPtr<QuicChromiumClientSession> session_; | |
80 bool was_handshake_confirmed_; // True if the crypto handshake succeeded. | |
81 QuicChromiumClientSession::StreamRequest stream_request_; | |
82 QuicChromiumClientStream* stream_; // Non-owning. | |
83 | |
84 const BidirectionalStreamRequestInfo* request_info_; | |
85 BidirectionalStreamJob::Delegate* delegate_; | |
86 // Saves the response status if the stream is explicitly closed via OnError | |
87 // or OnClose with an error. Once all buffered data has been returned, this | |
88 // will be used as the final response. | |
89 int response_status_; | |
90 | |
91 // The protocol that is negotiated. | |
92 NextProto negotiated_protocol_; | |
93 // User provided read buffer for ReadData() response. | |
94 scoped_refptr<IOBuffer> read_buffer_; | |
95 int read_buffer_len_; | |
96 | |
97 // Number of bytes received by the headers stream on behalf of this stream. | |
98 int64_t headers_bytes_received_; | |
99 // Number of bytes sent by the headers stream on behalf of this stream. | |
100 int64_t headers_bytes_sent_; | |
101 // After |stream_| has been closed, this keeps track of the total number of | |
102 // bytes received over the network for |stream_| while it was open. | |
103 int64_t closed_stream_received_bytes_; | |
104 // After |stream_| has been closed, this keeps track of the total number of | |
105 // bytes sent over the network for |stream_| while it was open. | |
106 int64_t closed_stream_sent_bytes_; | |
107 // Indicates whether initial headers have been sent. | |
108 bool has_sent_headers_; | |
109 // Indicates whether initial headers have been received. | |
110 bool has_received_headers_; | |
111 | |
112 base::WeakPtrFactory<BidirectionalStreamQuicImpl> weak_factory_; | |
113 | |
114 DISALLOW_COPY_AND_ASSIGN(BidirectionalStreamQuicImpl); | |
115 }; | |
116 | |
117 } // namespace net | |
118 | |
119 #endif // NET_QUIC_BIDIRECTIONAL_STREAM_QUIC_IMPL_H_ | |
OLD | NEW |