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

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: Merge SendFlushingWriteData and FlushDataOnNetworkThread. 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 // Disables automatic flushing of each buffer passed to WriteData().
59 void disable_auto_flush(bool disable_auto_flush) {
kapishnikov 2016/06/13 21:21:57 I remember we discussed to get rid of disable_auto
mef 2016/06/14 00:20:38 Yes. I think we should keep it optional for compat
60 disable_auto_flush_ = disable_auto_flush;
61 }
62
63 // Delays sending request headers until first call to Flush().
64 void delay_headers_until_flush(bool delay_headers_until_flush) {
kapishnikov 2016/06/13 21:21:57 Should we use camelcase for the sake of API consis
mef 2016/06/14 00:20:38 I don't have strong preference, but I think Chromi
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 // Sends buffers passed to WriteData().
89 bool Flush();
kapishnikov 2016/06/13 21:21:57 What does the return boolean mean? Is it possible
mef 2016/06/14 00:20:38 Good point, changed to void.
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 {
kapishnikov 2016/06/13 21:21:57 |sending_write_data_|, |flushing_write_data_| and
mef 2016/06/14 00:20:38 Done.
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();
136 void CancelOnNetworkThread(); 165 void CancelOnNetworkThread();
137 void DestroyOnNetworkThread(); 166 void DestroyOnNetworkThread();
138 167
139 // Read state is tracking reading flow. Only accessed on network thread. 168 // Read state is tracking reading flow. Only accessed on network thread.
140 // / <--- READING <--- \ 169 // / <--- READING <--- \
141 // | | 170 // | |
142 // \ / 171 // \ /
143 // NOT_STARTED -> STARTED --> WAITING_FOR_READ -> READING_DONE -> SUCCESS 172 // NOT_STARTED -> STARTED --> WAITING_FOR_READ -> READING_DONE -> SUCCESS
144 State read_state_; 173 State read_state_;
145 174
146 // Write state is tracking writing flow. Only accessed on network thread. 175 // Write state is tracking writing flow. Only accessed on network thread.
147 // / <--- WRITING <--- \ 176 // / <--- WRITING <--- \
148 // | | 177 // | |
149 // \ / 178 // \ /
150 // NOT_STARTED -> STARTED --> WAITING_FOR_WRITE -> WRITING_DONE -> SUCCESS 179 // NOT_STARTED -> STARTED --> WAITING_FOR_FLUSH -> WRITING_DONE -> SUCCESS
151 State write_state_; 180 State write_state_;
152 181
153 bool write_end_of_stream_; 182 bool write_end_of_stream_;
183 bool request_headers_sent_;
184
185 bool disable_auto_flush_;
186 bool delay_headers_until_flush_;
154 187
155 CronetEnvironment* const environment_; 188 CronetEnvironment* const environment_;
156 189
157 scoped_refptr<net::WrappedIOBuffer> read_buffer_; 190 scoped_refptr<net::WrappedIOBuffer> read_buffer_;
158 scoped_refptr<net::WrappedIOBuffer> write_buffer_; 191
192 // Write data that is sending.
193 std::unique_ptr<PendingWriteData> sending_write_data_;
194 // Write data that is flushed, but not sending yet.
195 std::unique_ptr<PendingWriteData> flushing_write_data_;
196 // Write data that is pending the flush.
197 std::unique_ptr<PendingWriteData> pending_write_data_;
198
159 std::unique_ptr<net::BidirectionalStream> bidi_stream_; 199 std::unique_ptr<net::BidirectionalStream> bidi_stream_;
160 Delegate* delegate_; 200 Delegate* delegate_;
161 201
162 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStream); 202 DISALLOW_COPY_AND_ASSIGN(CronetBidirectionalStream);
163 }; 203 };
164 204
165 } // namespace cronet 205 } // namespace cronet
166 206
167 #endif // COMPONENTS_CRONET_IOS_CRONET_BIDIRECTIONAL_STREAM_H_ 207 #endif // COMPONENTS_CRONET_IOS_CRONET_BIDIRECTIONAL_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698