OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/spdy/spdy_http_stream.h" | 5 #include "net/spdy/spdy_http_stream.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <list> | 8 #include <list> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "net/base/address_list.h" | 13 #include "net/base/address_list.h" |
14 #include "net/base/host_port_pair.h" | 14 #include "net/base/host_port_pair.h" |
15 #include "net/base/load_flags.h" | 15 #include "net/base/load_flags.h" |
16 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
17 #include "net/http/http_request_headers.h" | 17 #include "net/http/http_request_headers.h" |
18 #include "net/http/http_request_info.h" | 18 #include "net/http/http_request_info.h" |
19 #include "net/http/http_response_info.h" | 19 #include "net/http/http_response_info.h" |
20 #include "net/http/http_util.h" | 20 #include "net/http/http_util.h" |
21 #include "net/spdy/spdy_http_utils.h" | 21 #include "net/spdy/spdy_http_utils.h" |
22 #include "net/spdy/spdy_session.h" | 22 #include "net/spdy/spdy_session.h" |
23 | 23 |
24 namespace net { | 24 namespace net { |
25 | 25 |
26 SpdyHttpStream::SpdyHttpStream(SpdySession* spdy_session, | 26 SpdyHttpStream::SpdyHttpStream(SpdySession* spdy_session, |
27 bool direct) | 27 bool direct) |
28 : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_factory_(this)), | 28 : ALLOW_THIS_IN_INITIALIZER_LIST(read_callback_factory_(this)), |
29 ALLOW_THIS_IN_INITIALIZER_LIST(ping_method_factory_(this)), | |
29 stream_(NULL), | 30 stream_(NULL), |
30 spdy_session_(spdy_session), | 31 spdy_session_(spdy_session), |
31 response_info_(NULL), | 32 response_info_(NULL), |
32 download_finished_(false), | 33 download_finished_(false), |
33 response_headers_received_(false), | 34 response_headers_received_(false), |
34 user_callback_(NULL), | 35 user_callback_(NULL), |
35 user_buffer_len_(0), | 36 user_buffer_len_(0), |
36 buffered_read_callback_pending_(false), | 37 buffered_read_callback_pending_(false), |
37 more_read_data_pending_(false), | 38 more_read_data_pending_(false), |
38 direct_(direct) { } | 39 direct_(direct) { } |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 | 261 |
261 void SpdyHttpStream::Cancel() { | 262 void SpdyHttpStream::Cancel() { |
262 if (spdy_session_) | 263 if (spdy_session_) |
263 spdy_session_->CancelPendingCreateStreams(&stream_); | 264 spdy_session_->CancelPendingCreateStreams(&stream_); |
264 user_callback_ = NULL; | 265 user_callback_ = NULL; |
265 if (stream_) | 266 if (stream_) |
266 stream_->Cancel(); | 267 stream_->Cancel(); |
267 } | 268 } |
268 | 269 |
269 bool SpdyHttpStream::OnSendHeadersComplete(int status) { | 270 bool SpdyHttpStream::OnSendHeadersComplete(int status) { |
271 // Send the spdy ping message here. | |
272 stream_->SendPing(); | |
273 const int kPingTimeMs = 1000; | |
274 MessageLoop::current()->PostDelayedTask(FROM_HERE, ping_method_factory_. | |
275 NewRunnableMethod(&SpdyHttpStream::CheckPingResponse), | |
276 kPingTimeMs); | |
277 | |
270 if (user_callback_) | 278 if (user_callback_) |
271 DoCallback(status); | 279 DoCallback(status); |
272 return request_body_stream_.get() == NULL; | 280 return request_body_stream_.get() == NULL; |
273 } | 281 } |
274 | 282 |
283 void SpdyHttpStream::CheckPingResponse() { | |
284 // TODO(rtenneti): we should send a different error code. | |
285 if (!spdy_session_->DidLastPingWork()) | |
286 DoCallback(ERR_CONNECTION_ABORTED); | |
willchan no longer on Chromium
2011/10/12 05:41:06
Need a different error code.
ramant (doing other things)
2011/10/13 21:41:14
Done.
| |
287 } | |
288 | |
275 int SpdyHttpStream::OnSendBody() { | 289 int SpdyHttpStream::OnSendBody() { |
276 CHECK(request_body_stream_.get()); | 290 CHECK(request_body_stream_.get()); |
277 | 291 |
278 int buf_len = static_cast<int>(request_body_stream_->buf_len()); | 292 int buf_len = static_cast<int>(request_body_stream_->buf_len()); |
279 if (!buf_len) | 293 if (!buf_len) |
280 return OK; | 294 return OK; |
281 bool is_chunked = request_body_stream_->is_chunked(); | 295 bool is_chunked = request_body_stream_->is_chunked(); |
282 // TODO(satish): For non-chunked POST data, we set DATA_FLAG_FIN for all | 296 // TODO(satish): For non-chunked POST data, we set DATA_FLAG_FIN for all |
283 // blocks of data written out. This is wrong if the POST data was larger than | 297 // blocks of data written out. This is wrong if the POST data was larger than |
284 // UploadDataStream::kBufSize as that is the largest buffer that | 298 // UploadDataStream::kBufSize as that is the largest buffer that |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 SSLCertRequestInfo* cert_request_info) { | 480 SSLCertRequestInfo* cert_request_info) { |
467 DCHECK(stream_); | 481 DCHECK(stream_); |
468 stream_->GetSSLCertRequestInfo(cert_request_info); | 482 stream_->GetSSLCertRequestInfo(cert_request_info); |
469 } | 483 } |
470 | 484 |
471 bool SpdyHttpStream::IsSpdyHttpStream() const { | 485 bool SpdyHttpStream::IsSpdyHttpStream() const { |
472 return true; | 486 return true; |
473 } | 487 } |
474 | 488 |
475 } // namespace net | 489 } // namespace net |
OLD | NEW |