| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/http_response_body_drainer.h" | 5 #include "net/http/http_response_body_drainer.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 11 #include "net/http/http_network_session.h" | 11 #include "net/http/http_network_session.h" |
| 12 #include "net/http/http_response_info.h" |
| 12 #include "net/http/http_stream.h" | 13 #include "net/http/http_stream.h" |
| 13 | 14 |
| 14 namespace net { | 15 namespace net { |
| 15 | 16 |
| 16 HttpResponseBodyDrainer::HttpResponseBodyDrainer(HttpStream* stream) | 17 HttpResponseBodyDrainer::HttpResponseBodyDrainer( |
| 17 : stream_(stream), | 18 HttpStream* stream, |
| 19 scoped_ptr<HttpResponseInfo> response_info) |
| 20 : response_info_(std::move(response_info)), |
| 21 stream_(stream), |
| 18 next_state_(STATE_NONE), | 22 next_state_(STATE_NONE), |
| 19 total_read_(0), | 23 total_read_(0), |
| 20 session_(NULL) {} | 24 session_(nullptr) {} |
| 21 | 25 |
| 22 HttpResponseBodyDrainer::~HttpResponseBodyDrainer() {} | 26 HttpResponseBodyDrainer::~HttpResponseBodyDrainer() {} |
| 23 | 27 |
| 24 void HttpResponseBodyDrainer::Start(HttpNetworkSession* session) { | 28 void HttpResponseBodyDrainer::Start(HttpNetworkSession* session) { |
| 25 read_buf_ = new IOBuffer(kDrainBodyBufferSize); | 29 read_buf_ = new IOBuffer(kDrainBodyBufferSize); |
| 26 next_state_ = STATE_DRAIN_RESPONSE_BODY; | 30 next_state_ = STATE_DRAIN_RESPONSE_BODY; |
| 27 int rv = DoLoop(OK); | 31 int rv = DoLoop(OK); |
| 28 | 32 |
| 29 if (rv == ERR_IO_PENDING) { | 33 if (rv == ERR_IO_PENDING) { |
| 30 timer_.Start(FROM_HERE, | 34 timer_.Start(FROM_HERE, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 void HttpResponseBodyDrainer::OnTimerFired() { | 110 void HttpResponseBodyDrainer::OnTimerFired() { |
| 107 Finish(ERR_TIMED_OUT); | 111 Finish(ERR_TIMED_OUT); |
| 108 } | 112 } |
| 109 | 113 |
| 110 void HttpResponseBodyDrainer::Finish(int result) { | 114 void HttpResponseBodyDrainer::Finish(int result) { |
| 111 DCHECK_NE(ERR_IO_PENDING, result); | 115 DCHECK_NE(ERR_IO_PENDING, result); |
| 112 | 116 |
| 113 if (session_) | 117 if (session_) |
| 114 session_->RemoveResponseDrainer(this); | 118 session_->RemoveResponseDrainer(this); |
| 115 | 119 |
| 116 if (result < 0) { | 120 if (result < 0 || !stream_->CanReuseConnection()) { |
| 117 stream_->Close(true /* no keep-alive */); | 121 stream_->Close(true /* no keep-alive */); |
| 118 } else { | 122 } else { |
| 119 DCHECK_EQ(OK, result); | 123 DCHECK_EQ(OK, result); |
| 120 stream_->Close(false /* keep-alive */); | 124 stream_->Close(false /* keep-alive */); |
| 121 } | 125 } |
| 122 | 126 |
| 123 delete this; | 127 delete this; |
| 124 } | 128 } |
| 125 | 129 |
| 126 } // namespace net | 130 } // namespace net |
| OLD | NEW |