Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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( | 20 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 21 io_callback_(this, &HttpResponseBodyDrainer::OnIOComplete)), | 21 io_callback_(this, &HttpResponseBodyDrainer::OnIOComplete)), |
| 22 user_callback_(NULL), | 22 user_callback_(NULL), |
| 23 session_(NULL) {} | 23 session_(NULL) {} |
| 24 | 24 |
| 25 HttpResponseBodyDrainer::~HttpResponseBodyDrainer() {} | 25 HttpResponseBodyDrainer::~HttpResponseBodyDrainer() {} |
| 26 | 26 |
| 27 void HttpResponseBodyDrainer::Start(HttpNetworkSession* session) { | 27 void HttpResponseBodyDrainer::Start(HttpNetworkSession* session) { |
| 28 read_buf_ = new IOBuffer(kDrainBodyBufferSize); | 28 StartWithSize(session, kDrainBodyBufferSize); |
| 29 } | |
| 30 | |
| 31 void HttpResponseBodyDrainer::StartWithSize(HttpNetworkSession* session, | |
| 32 int num_bytes_to_drain) { | |
| 33 DCHECK_LT(0, num_bytes_to_drain); | |
| 34 read_size_ = num_bytes_to_drain; | |
| 35 read_buf_ = new IOBuffer(read_size_); | |
|
mmenke
2011/11/18 15:45:38
This could be a very large amount of memory, for,
James Simonsen
2011/11/22 01:24:20
Done.
| |
| 29 next_state_ = STATE_DRAIN_RESPONSE_BODY; | 36 next_state_ = STATE_DRAIN_RESPONSE_BODY; |
| 30 int rv = DoLoop(OK); | 37 int rv = DoLoop(OK); |
| 31 | 38 |
| 32 if (rv == ERR_IO_PENDING) { | 39 if (rv == ERR_IO_PENDING) { |
| 33 timer_.Start(FROM_HERE, | 40 timer_.Start(FROM_HERE, |
| 34 base::TimeDelta::FromSeconds(kTimeoutInSeconds), | 41 base::TimeDelta::FromSeconds(kTimeoutInSeconds), |
| 35 this, | 42 this, |
| 36 &HttpResponseBodyDrainer::OnTimerFired); | 43 &HttpResponseBodyDrainer::OnTimerFired); |
| 37 session_ = session; | 44 session_ = session; |
| 38 session->AddResponseDrainer(this); | 45 session->AddResponseDrainer(this); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 64 } | 71 } |
| 65 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 72 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 66 | 73 |
| 67 return rv; | 74 return rv; |
| 68 } | 75 } |
| 69 | 76 |
| 70 int HttpResponseBodyDrainer::DoDrainResponseBody() { | 77 int HttpResponseBodyDrainer::DoDrainResponseBody() { |
| 71 next_state_ = STATE_DRAIN_RESPONSE_BODY_COMPLETE; | 78 next_state_ = STATE_DRAIN_RESPONSE_BODY_COMPLETE; |
| 72 | 79 |
| 73 return stream_->ReadResponseBody( | 80 return stream_->ReadResponseBody( |
| 74 read_buf_, kDrainBodyBufferSize - total_read_, | 81 read_buf_, read_size_ - total_read_, |
| 75 &io_callback_); | 82 &io_callback_); |
| 76 } | 83 } |
| 77 | 84 |
| 78 int HttpResponseBodyDrainer::DoDrainResponseBodyComplete(int result) { | 85 int HttpResponseBodyDrainer::DoDrainResponseBodyComplete(int result) { |
| 79 DCHECK_NE(ERR_IO_PENDING, result); | 86 DCHECK_NE(ERR_IO_PENDING, result); |
| 80 | 87 |
| 81 if (result < 0) | 88 if (result < 0) |
| 82 return result; | 89 return result; |
| 83 | 90 |
| 84 if (result == 0) | 91 if (result == 0) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 stream_->Close(true /* no keep-alive */); | 125 stream_->Close(true /* no keep-alive */); |
| 119 } else { | 126 } else { |
| 120 DCHECK_EQ(OK, result); | 127 DCHECK_EQ(OK, result); |
| 121 stream_->Close(false /* keep-alive */); | 128 stream_->Close(false /* keep-alive */); |
| 122 } | 129 } |
| 123 | 130 |
| 124 delete this; | 131 delete this; |
| 125 } | 132 } |
| 126 | 133 |
| 127 } // namespace net | 134 } // namespace net |
| OLD | NEW |