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

Side by Side Diff: net/http/bidirectional_stream.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: Address Andrei's comment and self review 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 2015 The Chromium Authors. All rights reserved. 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 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/http/bidirectional_stream.h" 5 #include "net/http/bidirectional_stream.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 std::unique_ptr<base::Value> headers_param( 52 std::unique_ptr<base::Value> headers_param(
53 headers->NetLogCallback(&empty, capture_mode)); 53 headers->NetLogCallback(&empty, capture_mode));
54 dict->Set("headers", std::move(headers_param)); 54 dict->Set("headers", std::move(headers_param));
55 return std::move(dict); 55 return std::move(dict);
56 } 56 }
57 57
58 } // namespace 58 } // namespace
59 59
60 BidirectionalStream::Delegate::Delegate() {} 60 BidirectionalStream::Delegate::Delegate() {}
61 61
62 void BidirectionalStream::Delegate::OnStreamReady() {}
63
64 BidirectionalStream::Delegate::~Delegate() {} 62 BidirectionalStream::Delegate::~Delegate() {}
65 63
66 BidirectionalStream::BidirectionalStream( 64 BidirectionalStream::BidirectionalStream(
67 std::unique_ptr<BidirectionalStreamRequestInfo> request_info, 65 std::unique_ptr<BidirectionalStreamRequestInfo> request_info,
68 HttpNetworkSession* session, 66 HttpNetworkSession* session,
69 bool disable_auto_flush, 67 bool send_request_headers_automatically,
70 Delegate* delegate) 68 Delegate* delegate)
71 : BidirectionalStream(std::move(request_info), 69 : BidirectionalStream(std::move(request_info),
72 session, 70 session,
73 disable_auto_flush, 71 send_request_headers_automatically,
74 delegate, 72 delegate,
75 base::WrapUnique(new base::Timer(false, false))) {} 73 base::WrapUnique(new base::Timer(false, false))) {}
76 74
77 BidirectionalStream::BidirectionalStream( 75 BidirectionalStream::BidirectionalStream(
78 std::unique_ptr<BidirectionalStreamRequestInfo> request_info, 76 std::unique_ptr<BidirectionalStreamRequestInfo> request_info,
79 HttpNetworkSession* session, 77 HttpNetworkSession* session,
80 bool disable_auto_flush, 78 bool send_request_headers_automatically,
81 Delegate* delegate, 79 Delegate* delegate,
82 std::unique_ptr<base::Timer> timer) 80 std::unique_ptr<base::Timer> timer)
83 : request_info_(std::move(request_info)), 81 : request_info_(std::move(request_info)),
84 net_log_(BoundNetLog::Make(session->net_log(), 82 net_log_(BoundNetLog::Make(session->net_log(),
85 NetLog::SOURCE_BIDIRECTIONAL_STREAM)), 83 NetLog::SOURCE_BIDIRECTIONAL_STREAM)),
86 session_(session), 84 session_(session),
87 disable_auto_flush_(disable_auto_flush), 85 send_request_headers_automatically_(send_request_headers_automatically),
86 request_headers_sent_(false),
88 delegate_(delegate), 87 delegate_(delegate),
89 timer_(std::move(timer)) { 88 timer_(std::move(timer)) {
90 DCHECK(delegate_); 89 DCHECK(delegate_);
91 DCHECK(request_info_); 90 DCHECK(request_info_);
92 91
93 SSLConfig server_ssl_config; 92 SSLConfig server_ssl_config;
94 session->ssl_config_service()->GetSSLConfig(&server_ssl_config); 93 session->ssl_config_service()->GetSSLConfig(&server_ssl_config);
95 session->GetAlpnProtos(&server_ssl_config.alpn_protos); 94 session->GetAlpnProtos(&server_ssl_config.alpn_protos);
96 session->GetNpnProtos(&server_ssl_config.npn_protos); 95 session->GetNpnProtos(&server_ssl_config.npn_protos);
97 96
(...skipping 26 matching lines...) Expand all
124 } 123 }
125 } 124 }
126 125
127 BidirectionalStream::~BidirectionalStream() { 126 BidirectionalStream::~BidirectionalStream() {
128 Cancel(); 127 Cancel();
129 if (net_log_.IsCapturing()) { 128 if (net_log_.IsCapturing()) {
130 net_log_.EndEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE); 129 net_log_.EndEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE);
131 } 130 }
132 } 131 }
133 132
133 void BidirectionalStream::SendRequestHeaders() {
134 DCHECK(stream_impl_);
135 DCHECK(!request_headers_sent_);
mef 2016/06/01 21:33:21 add DCHECK(!send_request_headers_automatically_);
xunjieli 2016/06/01 22:27:16 Done.
136
137 stream_impl_->SendRequestHeaders();
138 }
139
134 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) { 140 int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) {
135 DCHECK(stream_impl_); 141 DCHECK(stream_impl_);
136 142
137 int rv = stream_impl_->ReadData(buf, buf_len); 143 int rv = stream_impl_->ReadData(buf, buf_len);
138 if (rv > 0) { 144 if (rv > 0) {
139 net_log_.AddByteTransferEvent( 145 net_log_.AddByteTransferEvent(
140 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, rv, buf->data()); 146 NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, rv, buf->data());
141 } else if (rv == ERR_IO_PENDING) { 147 } else if (rv == ERR_IO_PENDING) {
142 read_buffer_ = buf; 148 read_buffer_ = buf;
143 // Bytes will be logged in OnDataRead(). 149 // Bytes will be logged in OnDataRead().
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return stream_impl_->GetTotalReceivedBytes(); 201 return stream_impl_->GetTotalReceivedBytes();
196 } 202 }
197 203
198 int64_t BidirectionalStream::GetTotalSentBytes() const { 204 int64_t BidirectionalStream::GetTotalSentBytes() const {
199 if (!stream_impl_) 205 if (!stream_impl_)
200 return 0; 206 return 0;
201 207
202 return stream_impl_->GetTotalSentBytes(); 208 return stream_impl_->GetTotalSentBytes();
203 } 209 }
204 210
205 void BidirectionalStream::OnStreamReady() { 211 void BidirectionalStream::OnStreamReady(bool request_headers_sent) {
206 delegate_->OnStreamReady(); 212 request_headers_sent_ = request_headers_sent;
213 delegate_->OnStreamReady(request_headers_sent);
207 } 214 }
208 215
209 void BidirectionalStream::OnHeadersReceived( 216 void BidirectionalStream::OnHeadersReceived(
210 const SpdyHeaderBlock& response_headers) { 217 const SpdyHeaderBlock& response_headers) {
211 HttpResponseInfo response_info; 218 HttpResponseInfo response_info;
212 if (!SpdyHeadersToHttpResponse(response_headers, HTTP2, &response_info)) { 219 if (!SpdyHeadersToHttpResponse(response_headers, HTTP2, &response_info)) {
213 DLOG(WARNING) << "Invalid headers"; 220 DLOG(WARNING) << "Invalid headers";
214 delegate_->OnFailed(ERR_FAILED); 221 delegate_->OnFailed(ERR_FAILED);
215 return; 222 return;
216 } 223 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 278 }
272 279
273 void BidirectionalStream::OnBidirectionalStreamImplReady( 280 void BidirectionalStream::OnBidirectionalStreamImplReady(
274 const SSLConfig& used_ssl_config, 281 const SSLConfig& used_ssl_config,
275 const ProxyInfo& used_proxy_info, 282 const ProxyInfo& used_proxy_info,
276 BidirectionalStreamImpl* stream) { 283 BidirectionalStreamImpl* stream) {
277 DCHECK(!stream_impl_); 284 DCHECK(!stream_impl_);
278 285
279 stream_request_.reset(); 286 stream_request_.reset();
280 stream_impl_.reset(stream); 287 stream_impl_.reset(stream);
281 stream_impl_->Start(request_info_.get(), net_log_, disable_auto_flush_, this, 288 stream_impl_->Start(request_info_.get(), net_log_,
289 send_request_headers_automatically_, this,
282 std::move(timer_)); 290 std::move(timer_));
283 } 291 }
284 292
285 void BidirectionalStream::OnWebSocketHandshakeStreamReady( 293 void BidirectionalStream::OnWebSocketHandshakeStreamReady(
286 const SSLConfig& used_ssl_config, 294 const SSLConfig& used_ssl_config,
287 const ProxyInfo& used_proxy_info, 295 const ProxyInfo& used_proxy_info,
288 WebSocketHandshakeStreamBase* stream) { 296 WebSocketHandshakeStreamBase* stream) {
289 NOTREACHED(); 297 NOTREACHED();
290 } 298 }
291 299
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 const ProxyInfo& used_proxy_info, 340 const ProxyInfo& used_proxy_info,
333 HttpStream* stream) { 341 HttpStream* stream) {
334 DCHECK(stream_request_); 342 DCHECK(stream_request_);
335 343
336 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE); 344 delegate_->OnFailed(ERR_HTTPS_PROXY_TUNNEL_RESPONSE);
337 } 345 }
338 346
339 void BidirectionalStream::OnQuicBroken() {} 347 void BidirectionalStream::OnQuicBroken() {}
340 348
341 } // namespace net 349 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698