summaryrefslogtreecommitdiffstats
path: root/net/http/http_response_body_drainer.h
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-21 18:08:50 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-21 18:08:50 +0000
commit0b0bf036e2c2722b5d31162ad620b450763fa352 (patch)
treebbeeb3eaaa34df96d3f947d63280a93746837536 /net/http/http_response_body_drainer.h
parent78859c7d87db4433d068533b104c7c1addf7e7eb (diff)
downloadchromium_src-0b0bf036e2c2722b5d31162ad620b450763fa352.zip
chromium_src-0b0bf036e2c2722b5d31162ad620b450763fa352.tar.gz
chromium_src-0b0bf036e2c2722b5d31162ad620b450763fa352.tar.bz2
Reland r59910 - Add HttpResponseBodyDrainer. Use it for unfinished HttpStreams."
There's one simple fix. wtc had asked me to increment the buffer so we keep reading into new memory while draining the body. So I added |total_read_| to |read_buf_|. The problem is |read_buf_| is an IOBuffer*, not a char*, so I'm causing us to read into raw heap memory. Crashes ensue. My unit tests didn't catch it because they never actually read data. I've fixed that by doing a memset(). I've fixed the problem by not bothering to increment the read index, since that would require throwing away IOBuffers or some intrusive modifications to IOBuffer. BUG=54277 TEST=HttpResponseBodyDrainerTest.* Also see the manual testing instructions in r59910. Review URL: http://codereview.chromium.org/3449014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60075 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_response_body_drainer.h')
-rw-r--r--net/http/http_response_body_drainer.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/net/http/http_response_body_drainer.h b/net/http/http_response_body_drainer.h
new file mode 100644
index 0000000..dbcdd99
--- /dev/null
+++ b/net/http/http_response_body_drainer.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_HTTP_HTTP_RESPONSE_BODY_DRAINER_H_
+#define NET_HTTP_HTTP_RESPONSE_BODY_DRAINER_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
+#include "base/timer.h"
+#include "net/base/completion_callback.h"
+
+namespace net {
+
+class HttpStream;
+class IOBuffer;
+
+class HttpResponseBodyDrainer {
+ public:
+ // The size in bytes of the buffer we use to drain the response body that
+ // we want to throw away. The response body is typically a small page just a
+ // few hundred bytes long. We set a limit to prevent it from taking too long,
+ // since we may as well just create a new socket then.
+ enum { kDrainBodyBufferSize = 16384 };
+ enum { kTimeoutInSeconds = 5 };
+
+ explicit HttpResponseBodyDrainer(HttpStream* stream);
+
+ // Starts reading the body until completion, or we hit the buffer limit, or we
+ // timeout. After Start(), |this| will eventually delete itself.
+ void Start();
+
+ private:
+ enum State {
+ STATE_DRAIN_RESPONSE_BODY,
+ STATE_DRAIN_RESPONSE_BODY_COMPLETE,
+ STATE_NONE,
+ };
+
+ ~HttpResponseBodyDrainer();
+
+ int DoLoop(int result);
+
+ int DoDrainResponseBody();
+ int DoDrainResponseBodyComplete(int result);
+
+ void OnIOComplete(int result);
+ void OnTimerFired();
+ void Finish(int result);
+
+ const scoped_ptr<HttpStream> stream_;
+ State next_state_;
+ scoped_refptr<IOBuffer> read_buf_;
+ int total_read_;
+ CompletionCallbackImpl<HttpResponseBodyDrainer> io_callback_;
+ CompletionCallback* user_callback_;
+ base::OneShotTimer<HttpResponseBodyDrainer> timer_;
+
+ DISALLOW_COPY_AND_ASSIGN(HttpResponseBodyDrainer);
+};
+
+} // namespace net
+
+#endif // NET_HTTP_HTTP_RESPONSE_BODY_DRAINER_H_