| 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/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_stream.h" | 12 #include "net/http/http_stream.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 HttpResponseBodyDrainer::HttpResponseBodyDrainer(HttpStream* stream) | 16 HttpResponseBodyDrainer::HttpResponseBodyDrainer(HttpStream* stream) |
| 17 : stream_(stream), | 17 : stream_(stream), |
| 18 next_state_(STATE_NONE), | 18 next_state_(STATE_NONE), |
| 19 total_read_(0), | 19 total_read_(0), |
| 20 ALLOW_THIS_IN_INITIALIZER_LIST( | |
| 21 io_callback_(this, &HttpResponseBodyDrainer::OnIOComplete)), | |
| 22 user_callback_(NULL), | |
| 23 session_(NULL) {} | 20 session_(NULL) {} |
| 24 | 21 |
| 25 HttpResponseBodyDrainer::~HttpResponseBodyDrainer() {} | 22 HttpResponseBodyDrainer::~HttpResponseBodyDrainer() {} |
| 26 | 23 |
| 27 void HttpResponseBodyDrainer::Start(HttpNetworkSession* session) { | 24 void HttpResponseBodyDrainer::Start(HttpNetworkSession* session) { |
| 28 StartWithSize(session, kDrainBodyBufferSize); | 25 StartWithSize(session, kDrainBodyBufferSize); |
| 29 } | 26 } |
| 30 | 27 |
| 31 void HttpResponseBodyDrainer::StartWithSize(HttpNetworkSession* session, | 28 void HttpResponseBodyDrainer::StartWithSize(HttpNetworkSession* session, |
| 32 int num_bytes_to_drain) { | 29 int num_bytes_to_drain) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 80 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 84 | 81 |
| 85 return rv; | 82 return rv; |
| 86 } | 83 } |
| 87 | 84 |
| 88 int HttpResponseBodyDrainer::DoDrainResponseBody() { | 85 int HttpResponseBodyDrainer::DoDrainResponseBody() { |
| 89 next_state_ = STATE_DRAIN_RESPONSE_BODY_COMPLETE; | 86 next_state_ = STATE_DRAIN_RESPONSE_BODY_COMPLETE; |
| 90 | 87 |
| 91 return stream_->ReadResponseBody( | 88 return stream_->ReadResponseBody( |
| 92 read_buf_, read_size_ - total_read_, | 89 read_buf_, read_size_ - total_read_, |
| 93 &io_callback_); | 90 base::Bind(&HttpResponseBodyDrainer::OnIOComplete, |
| 91 base::Unretained(this))); |
| 94 } | 92 } |
| 95 | 93 |
| 96 int HttpResponseBodyDrainer::DoDrainResponseBodyComplete(int result) { | 94 int HttpResponseBodyDrainer::DoDrainResponseBodyComplete(int result) { |
| 97 DCHECK_NE(ERR_IO_PENDING, result); | 95 DCHECK_NE(ERR_IO_PENDING, result); |
| 98 | 96 |
| 99 if (result < 0) | 97 if (result < 0) |
| 100 return result; | 98 return result; |
| 101 | 99 |
| 102 if (result == 0) | 100 if (result == 0) |
| 103 return ERR_CONNECTION_CLOSED; | 101 return ERR_CONNECTION_CLOSED; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 stream_->Close(true /* no keep-alive */); | 134 stream_->Close(true /* no keep-alive */); |
| 137 } else { | 135 } else { |
| 138 DCHECK_EQ(OK, result); | 136 DCHECK_EQ(OK, result); |
| 139 stream_->Close(false /* keep-alive */); | 137 stream_->Close(false /* keep-alive */); |
| 140 } | 138 } |
| 141 | 139 |
| 142 delete this; | 140 delete this; |
| 143 } | 141 } |
| 144 | 142 |
| 145 } // namespace net | 143 } // namespace net |
| OLD | NEW |