Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: components/cronet/ios/cronet_bidirectional_stream.h

Issue 2050483002: [Cronet] Coalesce small buffers into single QUIC packet in GRPC on iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: A little test cleanup. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 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 COMPONENTS_CRONET_IOS_CRONET_BIDIRECTIONAL_STREAM_H_ 5 #ifndef COMPONENTS_CRONET_IOS_CRONET_BIDIRECTIONAL_STREAM_H_
6 #define COMPONENTS_CRONET_IOS_CRONET_BIDIRECTIONAL_STREAM_H_ 6 #define COMPONENTS_CRONET_IOS_CRONET_BIDIRECTIONAL_STREAM_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <vector>
9 10
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
12 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
13 #include "net/http/bidirectional_stream.h" 14 #include "net/http/bidirectional_stream.h"
14 15
15 namespace net { 16 namespace net {
16 class HttpRequestHeaders; 17 class HttpRequestHeaders;
17 class WrappedIOBuffer; 18 class WrappedIOBuffer;
18 } // namespace net 19 } // namespace net
(...skipping 28 matching lines...) Expand all
47 virtual void OnSucceeded() = 0; 48 virtual void OnSucceeded() = 0;
48 49
49 virtual void OnFailed(int error) = 0; 50 virtual void OnFailed(int error) = 0;
50 51
51 virtual void OnCanceled() = 0; 52 virtual void OnCanceled() = 0;
52 }; 53 };
53 54
54 CronetBidirectionalStream(CronetEnvironment* environment, Delegate* delegate); 55 CronetBidirectionalStream(CronetEnvironment* environment, Delegate* delegate);
55 ~CronetBidirectionalStream() override; 56 ~CronetBidirectionalStream() override;
56 57
58 // Disable automatic flushing of each buffer passed to WriteData().
xunjieli 2016/06/10 16:30:50 nit: s/Disable/Disables ?
mef 2016/06/10 18:36:36 Done.
59 void disable_auto_flush(bool disable_auto_flush) {
60 disable_auto_flush_ = disable_auto_flush;
61 }
62
63 // Delay sending request headers until first call to Flush().
xunjieli 2016/06/10 16:30:50 nit: s/Delay/Delays
mef 2016/06/10 18:36:37 Done.
64 void delay_headers_until_flush(bool delay_headers_until_flush) {
65 delay_headers_until_flush_ = delay_headers_until_flush;
66 }
67
57 // Validates method and headers, initializes and starts the request. If 68 // Validates method and headers, initializes and starts the request. If
58 // |end_of_stream| is true, then stream is half-closed after sending header 69 // |end_of_stream| is true, then stream is half-closed after sending header
59 // frame and no data is expected to be written. 70 // frame and no data is expected to be written.
60 // Returns 0 if request is valid and started successfully, 71 // Returns 0 if request is valid and started successfully,
61 // Returns -1 if |method| is not valid HTTP method name. 72 // Returns -1 if |method| is not valid HTTP method name.
62 // Returns position of invalid header value in |headers| if header name is 73 // Returns position of invalid header value in |headers| if header name is
63 // not valid. 74 // not valid.
64 int Start(const char* url, 75 int Start(const char* url,
65 int priority, 76 int priority,
66 const char* method, 77 const char* method,
67 const net::HttpRequestHeaders& headers, 78 const net::HttpRequestHeaders& headers,
68 bool end_of_stream); 79 bool end_of_stream);
69 80
70 // Reads more data into |buffer| up to |capacity| bytes. 81 // Reads more data into |buffer| up to |capacity| bytes.
71 bool ReadData(char* buffer, int capacity); 82 bool ReadData(char* buffer, int capacity);
72 83
73 // Writes |count| bytes of data from |buffer|. The |end_of_stream| is 84 // Writes |count| bytes of data from |buffer|. The |end_of_stream| is
74 // passed to remote to indicate end of stream. 85 // passed to remote to indicate end of stream.
75 bool WriteData(const char* buffer, int count, bool end_of_stream); 86 bool WriteData(const char* buffer, int count, bool end_of_stream);
76 87
88 // Send buffers passed to WriteData().
xunjieli 2016/06/10 16:30:50 nit: s/Send/Sends or maybe Flushes buffer passed
mef 2016/06/10 18:36:37 Done.
89 bool Flush();
90
77 // Cancels the request. The OnCanceled callback is invoked when request is 91 // Cancels the request. The OnCanceled callback is invoked when request is
78 // caneceled, and not other callbacks are invoked afterwards.. 92 // caneceled, and not other callbacks are invoked afterwards..
79 void Cancel(); 93 void Cancel();
80 94
81 // Releases all resources for the request and deletes the object itself. 95 // Releases all resources for the request and deletes the object itself.
82 void Destroy(); 96 void Destroy();
83 97
84 private: 98 private:
85 // States of BidirectionalStream are tracked in |read_state_| and 99 // States of BidirectionalStream are tracked in |read_state_| and
86 // |write_state_|. 100 // |write_state_|.
(...skipping 13 matching lines...) Expand all
100 READING, 114 READING,
101 // There is no more data to read and stream is half-closed by the remote 115 // There is no more data to read and stream is half-closed by the remote
102 // side. 116 // side.
103 READING_DONE, 117 READING_DONE,
104 // Stream is canceled. 118 // Stream is canceled.
105 CANCELED, 119 CANCELED,
106 // Error has occured, stream is closed. 120 // Error has occured, stream is closed.
107 ERROR, 121 ERROR,
108 // Reading and writing are done, and the stream is closed successfully. 122 // Reading and writing are done, and the stream is closed successfully.
109 SUCCESS, 123 SUCCESS,
110 // Waiting for WriteData() to be called. 124 // Waiting for Flush() to be called.
111 WAITING_FOR_WRITE, 125 WAITING_FOR_FLUSH,
112 // Writing to the remote, callback will be invoked when done. 126 // Writing to the remote, callback will be invoked when done.
113 WRITING, 127 WRITING,
114 // There is no more data to write and stream is half-closed by the local 128 // There is no more data to write and stream is half-closed by the local
115 // side. 129 // side.
116 WRITING_DONE, 130 WRITING_DONE,
117 }; 131 };
118 132
133 // Container to hold buffers and sizes of the pending data to be written.
134 struct PendingWriteData {
135 PendingWriteData();
136 ~PendingWriteData();
137
138 // Every IOBuffer in |write_buffer_list| points to the memory owned by the
139 // application.
140 std::vector<scoped_refptr<net::IOBuffer>> write_buffer_list;
141 // A list of the length of each IOBuffer in |write_buffer_list|.
142 std::vector<int> write_buffer_len_list;
143
144 DISALLOW_COPY_AND_ASSIGN(PendingWriteData);
145 };
146
119 // net::BidirectionalStream::Delegate implementations: 147 // net::BidirectionalStream::Delegate implementations:
120 void OnStreamReady(bool request_headers_sent) override; 148 void OnStreamReady(bool request_headers_sent) override;
121 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override; 149 void OnHeadersReceived(const net::SpdyHeaderBlock& response_headers) override;
122 void OnDataRead(int bytes_read) override; 150 void OnDataRead(int bytes_read) override;
123 void OnDataSent() override; 151 void OnDataSent() override;
124 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override; 152 void OnTrailersReceived(const net::SpdyHeaderBlock& trailers) override;
125 void OnFailed(int error) override; 153 void OnFailed(int error) override;
126 // Helper method to derive OnSucceeded. 154 // Helper method to derive OnSucceeded.
127 void MaybeOnSucceded(); 155 void MaybeOnSucceded();
128 156
129 void StartOnNetworkThread( 157 void StartOnNetworkThread(
130 std::unique_ptr<net::BidirectionalStreamRequestInfo> request_info); 158 std::unique_ptr<net::BidirectionalStreamRequestInfo> request_info);
131 void ReadDataOnNetworkThread(scoped_refptr<net::WrappedIOBuffer> read_buffer, 159 void ReadDataOnNetworkThread(scoped_refptr<net::WrappedIOBuffer> read_buffer,
132 int buffer_size); 160 int buffer_size);
133 void WriteDataOnNetworkThread(scoped_refptr<net::WrappedIOBuffer> read_buffer, 161 void WriteDataOnNetworkThread(scoped_refptr<net::WrappedIOBuffer> read_buffer,
134 int buffer_size, 162 int buffer_size,
135 bool end_of_stream); 163 bool end_of_stream);
164 void FlushOnNetworkThread();
165 void SendFlushingWriteData();
136 void CancelOnNetworkThread(); 166 void CancelOnNetworkThread();
137 void DestroyOnNetworkThread(); 167 void DestroyOnNetworkThread();
138 168
139 // Read state is tracking reading flow. Only accessed on network thread. 169 // Read state is tracking reading flow. Only accessed on network thread.
140 // / <--- READING <--- \ 170 // / <--- READING <--- \
141 // | | 171 // | |
142 // \ / 172 // \ /
143 // NOT_STARTED -> STARTED --> WAITING_FOR_READ -> READING_DONE -> SUCCESS 173 // NOT_STARTED -> STARTED --> WAITING_FOR_READ -> READING_DONE -> SUCCESS
144 State read_state_; 174 State read_state_;
145 175
146 // Write state is tracking writing flow. Only accessed on network thread. 176 // Write state is tracking writing flow. Only accessed on network thread.
147 // / <--- WRITING <--- \ 177 // / <--- WRITING <--- \
148 // | | 178 // | |
149 // \ / 179 // \ /
150 // NOT_STARTED -> STARTED --> WAITING_FOR_WRITE -> WRITING_DONE -> SUCCESS 180 // NOT_STARTED -> STARTED --> WAITING_FOR_FLUSH -> WRITING_DONE -> SUCCESS
151 State write_state_; 181 State write_state_;
152 182
153 bool write_end_of_stream_; 183 bool write_end_of_stream_;
184 bool request_headers_sent_;
185
186 bool disable_auto_flush_;
187 bool delay_headers_until_flush_;
154 188
155 CronetEnvironment* const environment_; 189 CronetEnvironment* const environment_;
156 190
157 scoped_refptr<net::WrappedIOBuffer> read_buffer_; 191 scoped_refptr<net::WrappedIOBuffer> read_buffer_;
158 scoped_refptr<net::WrappedIOBuffer> write_buffer_; 192
193 // Write data that is sending.
194 std::unique_ptr<PendingWriteData> sending_write_data_;
195 // Write data that is flushed, but not sending yet.
196 std::unique_ptr<PendingWriteData> flushing_write_data_;
197 // Write data that is pending the flush.
198 std::unique_ptr<PendingWriteData> pending_write_data_;
199
159 std::unique_ptr<net::BidirectionalStream> bidi_stream_; 200 std::unique_ptr<net::BidirectionalStream> bidi_stream_;
160 Delegate* delegate_; 201 Delegate* delegate_;
161 202
162 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStream); 203 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStream);
163 }; 204 };
164 205
165 } // namespace cronet 206 } // namespace cronet
166 207
167 #endif // COMPONENTS_CRONET_IOS_CRONET_BIDIRECTIONAL_STREAM_H_ 208 #endif // COMPONENTS_CRONET_IOS_CRONET_BIDIRECTIONAL_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698