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

Side by Side Diff: net/quic/bidirectional_stream_quic_impl.cc

Issue 1992953004: [Cronet] Make delaying sending request headers explicit in bidirectional stream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review Created 4 years, 7 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 #include "net/quic/bidirectional_stream_quic_impl.h" 5 #include "net/quic/bidirectional_stream_quic_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/timer/timer.h" 10 #include "base/timer/timer.h"
(...skipping 14 matching lines...) Expand all
25 delegate_(nullptr), 25 delegate_(nullptr),
26 response_status_(OK), 26 response_status_(OK),
27 negotiated_protocol_(kProtoUnknown), 27 negotiated_protocol_(kProtoUnknown),
28 read_buffer_len_(0), 28 read_buffer_len_(0),
29 headers_bytes_received_(0), 29 headers_bytes_received_(0),
30 headers_bytes_sent_(0), 30 headers_bytes_sent_(0),
31 closed_stream_received_bytes_(0), 31 closed_stream_received_bytes_(0),
32 closed_stream_sent_bytes_(0), 32 closed_stream_sent_bytes_(0),
33 has_sent_headers_(false), 33 has_sent_headers_(false),
34 has_received_headers_(false), 34 has_received_headers_(false),
35 disable_auto_flush_(false), 35 delay_headers_until_next_send_data_(false),
36 weak_factory_(this) { 36 weak_factory_(this) {
37 DCHECK(session_); 37 DCHECK(session_);
38 session_->AddObserver(this); 38 session_->AddObserver(this);
39 } 39 }
40 40
41 BidirectionalStreamQuicImpl::~BidirectionalStreamQuicImpl() { 41 BidirectionalStreamQuicImpl::~BidirectionalStreamQuicImpl() {
42 Cancel(); 42 Cancel();
43 if (session_) 43 if (session_)
44 session_->RemoveObserver(this); 44 session_->RemoveObserver(this);
45 } 45 }
46 46
47 void BidirectionalStreamQuicImpl::Start( 47 void BidirectionalStreamQuicImpl::Start(
48 const BidirectionalStreamRequestInfo* request_info, 48 const BidirectionalStreamRequestInfo* request_info,
49 const BoundNetLog& net_log, 49 const BoundNetLog& net_log,
50 bool disable_auto_flush, 50 bool delay_headers_until_next_send_data,
51 BidirectionalStreamImpl::Delegate* delegate, 51 BidirectionalStreamImpl::Delegate* delegate,
52 std::unique_ptr<base::Timer> /* timer */) { 52 std::unique_ptr<base::Timer> /* timer */) {
53 DCHECK(!stream_); 53 DCHECK(!stream_);
54 54
55 disable_auto_flush_ = disable_auto_flush; 55 delay_headers_until_next_send_data_ = delay_headers_until_next_send_data;
56 if (!session_) { 56 if (!session_) {
57 NotifyError(was_handshake_confirmed_ ? ERR_QUIC_PROTOCOL_ERROR 57 NotifyError(was_handshake_confirmed_ ? ERR_QUIC_PROTOCOL_ERROR
58 : ERR_QUIC_HANDSHAKE_FAILED); 58 : ERR_QUIC_HANDSHAKE_FAILED);
59 return; 59 return;
60 } 60 }
61 61
62 delegate_ = delegate; 62 delegate_ = delegate;
63 request_info_ = request_info; 63 request_info_ = request_info;
64 64
65 int rv = stream_request_.StartRequest( 65 int rv = stream_request_.StartRequest(
(...skipping 30 matching lines...) Expand all
96 read_buffer_len_ = buffer_len; 96 read_buffer_len_ = buffer_len;
97 return ERR_IO_PENDING; 97 return ERR_IO_PENDING;
98 } 98 }
99 99
100 void BidirectionalStreamQuicImpl::SendData(const scoped_refptr<IOBuffer>& data, 100 void BidirectionalStreamQuicImpl::SendData(const scoped_refptr<IOBuffer>& data,
101 int length, 101 int length,
102 bool end_stream) { 102 bool end_stream) {
103 DCHECK(stream_); 103 DCHECK(stream_);
104 DCHECK(length > 0 || (length == 0 && end_stream)); 104 DCHECK(length > 0 || (length == 0 && end_stream));
105 105
106 std::unique_ptr<QuicConnection::ScopedPacketBundler> bundler;
107 if (!has_sent_headers_) {
108 DCHECK(delay_headers_until_next_send_data_);
109 // Creates a bundler only if there are headers to be sent along with the
110 // single data buffer.
111 bundler.reset(new QuicConnection::ScopedPacketBundler(
112 session_->connection(), QuicConnection::SEND_ACK_IF_PENDING));
113 SendRequestHeaders();
114 }
115
106 base::StringPiece string_data(data->data(), length); 116 base::StringPiece string_data(data->data(), length);
107 int rv = stream_->WriteStreamData( 117 int rv = stream_->WriteStreamData(
108 string_data, end_stream, 118 string_data, end_stream,
109 base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, 119 base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete,
110 weak_factory_.GetWeakPtr())); 120 weak_factory_.GetWeakPtr()));
111 DCHECK(rv == OK || rv == ERR_IO_PENDING); 121 DCHECK(rv == OK || rv == ERR_IO_PENDING);
112 if (rv == OK) { 122 if (rv == OK) {
113 base::ThreadTaskRunnerHandle::Get()->PostTask( 123 base::ThreadTaskRunnerHandle::Get()->PostTask(
114 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, 124 FROM_HERE, base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete,
115 weak_factory_.GetWeakPtr(), OK)); 125 weak_factory_.GetWeakPtr(), OK));
116 } 126 }
117 } 127 }
118 128
119 void BidirectionalStreamQuicImpl::SendvData( 129 void BidirectionalStreamQuicImpl::SendvData(
120 const std::vector<scoped_refptr<IOBuffer>>& buffers, 130 const std::vector<scoped_refptr<IOBuffer>>& buffers,
121 const std::vector<int>& lengths, 131 const std::vector<int>& lengths,
122 bool end_stream) { 132 bool end_stream) {
123 DCHECK(stream_); 133 DCHECK(stream_);
124 DCHECK_EQ(buffers.size(), lengths.size()); 134 DCHECK_EQ(buffers.size(), lengths.size());
125 135
126 QuicConnection::ScopedPacketBundler bundler( 136 QuicConnection::ScopedPacketBundler bundler(
127 session_->connection(), QuicConnection::SEND_ACK_IF_PENDING); 137 session_->connection(), QuicConnection::SEND_ACK_IF_PENDING);
128 if (!has_sent_headers_) { 138 if (!has_sent_headers_) {
139 DCHECK(delay_headers_until_next_send_data_);
129 SendRequestHeaders(); 140 SendRequestHeaders();
130 } 141 }
131 142
132 int rv = stream_->WritevStreamData( 143 int rv = stream_->WritevStreamData(
133 buffers, lengths, end_stream, 144 buffers, lengths, end_stream,
134 base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete, 145 base::Bind(&BidirectionalStreamQuicImpl::OnSendDataComplete,
135 weak_factory_.GetWeakPtr())); 146 weak_factory_.GetWeakPtr()));
136 147
137 DCHECK(rv == OK || rv == ERR_IO_PENDING); 148 DCHECK(rv == OK || rv == ERR_IO_PENDING);
138 if (rv == OK) { 149 if (rv == OK) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 DCHECK_NE(OK, error); 242 DCHECK_NE(OK, error);
232 session_.reset(); 243 session_.reset();
233 NotifyError(error); 244 NotifyError(error);
234 } 245 }
235 246
236 void BidirectionalStreamQuicImpl::OnStreamReady(int rv) { 247 void BidirectionalStreamQuicImpl::OnStreamReady(int rv) {
237 DCHECK_NE(ERR_IO_PENDING, rv); 248 DCHECK_NE(ERR_IO_PENDING, rv);
238 DCHECK(rv == OK || !stream_); 249 DCHECK(rv == OK || !stream_);
239 if (rv == OK) { 250 if (rv == OK) {
240 stream_->SetDelegate(this); 251 stream_->SetDelegate(this);
241 if (!disable_auto_flush_) { 252 if (!delay_headers_until_next_send_data_) {
242 SendRequestHeaders(); 253 SendRequestHeaders();
243 } 254 }
244 delegate_->OnStreamReady(); 255 delegate_->OnStreamReady();
245 } else { 256 } else {
246 NotifyError(rv); 257 NotifyError(rv);
247 } 258 }
248 } 259 }
249 260
250 void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) { 261 void BidirectionalStreamQuicImpl::OnSendDataComplete(int rv) {
251 DCHECK(rv == OK || !stream_); 262 DCHECK(rv == OK || !stream_);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 void BidirectionalStreamQuicImpl::ResetStream() { 298 void BidirectionalStreamQuicImpl::ResetStream() {
288 if (!stream_) 299 if (!stream_)
289 return; 300 return;
290 closed_stream_received_bytes_ = stream_->stream_bytes_read(); 301 closed_stream_received_bytes_ = stream_->stream_bytes_read();
291 closed_stream_sent_bytes_ = stream_->stream_bytes_written(); 302 closed_stream_sent_bytes_ = stream_->stream_bytes_written();
292 stream_->SetDelegate(nullptr); 303 stream_->SetDelegate(nullptr);
293 stream_ = nullptr; 304 stream_ = nullptr;
294 } 305 }
295 306
296 } // namespace net 307 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698