summaryrefslogtreecommitdiffstats
path: root/chrome/browser/renderer_host/async_resource_handler.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-24 02:39:54 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-24 02:39:54 +0000
commite993abfe81feaa374d476828a44942d296bdcc78 (patch)
tree201fffef0ba93ce41afaf2bd6e61e05b61c04028 /chrome/browser/renderer_host/async_resource_handler.cc
parent0afe80d755b899c188313629ea3f45f0fe5be981 (diff)
downloadchromium_src-e993abfe81feaa374d476828a44942d296bdcc78.zip
chromium_src-e993abfe81feaa374d476828a44942d296bdcc78.tar.gz
chromium_src-e993abfe81feaa374d476828a44942d296bdcc78.tar.bz2
revert r8603
Review URL: http://codereview.chromium.org/18576 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8605 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host/async_resource_handler.cc')
-rw-r--r--chrome/browser/renderer_host/async_resource_handler.cc49
1 files changed, 15 insertions, 34 deletions
diff --git a/chrome/browser/renderer_host/async_resource_handler.cc b/chrome/browser/renderer_host/async_resource_handler.cc
index 814415e..a59f61e 100644
--- a/chrome/browser/renderer_host/async_resource_handler.cc
+++ b/chrome/browser/renderer_host/async_resource_handler.cc
@@ -5,31 +5,8 @@
#include "chrome/browser/renderer_host/async_resource_handler.h"
#include "base/process.h"
-#include "net/base/io_buffer.h"
-
-SharedIOBuffer* AsyncResourceHandler::spare_read_buffer_;
-
-// Our version of IOBuffer that uses shared memory.
-class SharedIOBuffer : public net::IOBuffer {
- public:
- SharedIOBuffer(int buffer_size) : net::IOBuffer(NULL), ok_(false) {
- if (shared_memory_.Create(std::wstring(), false, false, buffer_size) &&
- shared_memory_.Map(buffer_size)) {
- ok_ = true;
- data_ = reinterpret_cast<char*>(shared_memory_.memory());
- }
- }
- ~SharedIOBuffer() {
- data_ = NULL;
- }
- base::SharedMemory* shared_memory() { return &shared_memory_; }
- bool ok() { return ok_; }
-
- private:
- base::SharedMemory shared_memory_;
- bool ok_;
-};
+base::SharedMemory* AsyncResourceHandler::spare_read_buffer_;
AsyncResourceHandler::AsyncResourceHandler(
ResourceDispatcherHost::Receiver* receiver,
@@ -67,19 +44,22 @@ bool AsyncResourceHandler::OnResponseStarted(int request_id,
return true;
}
-bool AsyncResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf,
- int* buf_size, int min_size) {
+bool AsyncResourceHandler::OnWillRead(int request_id,
+ char** buf, int* buf_size,
+ int min_size) {
DCHECK(min_size == -1);
static const int kReadBufSize = 32768;
if (spare_read_buffer_) {
- read_buffer_ = spare_read_buffer_;
+ read_buffer_.reset(spare_read_buffer_);
spare_read_buffer_ = NULL;
} else {
- read_buffer_ = new SharedIOBuffer(kReadBufSize);
- if (!read_buffer_->ok())
+ read_buffer_.reset(new base::SharedMemory);
+ if (!read_buffer_->Create(std::wstring(), false, false, kReadBufSize))
+ return false;
+ if (!read_buffer_->Map(kReadBufSize))
return false;
}
- *buf = read_buffer_.get();
+ *buf = static_cast<char*>(read_buffer_->memory());
*buf_size = kReadBufSize;
return true;
}
@@ -95,7 +75,7 @@ bool AsyncResourceHandler::OnReadCompleted(int request_id, int* bytes_read) {
}
base::SharedMemoryHandle handle;
- if (!read_buffer_->shared_memory()->GiveToProcess(render_process_, &handle)) {
+ if (!read_buffer_->GiveToProcess(render_process_, &handle)) {
// We wrongfully incremented the pending data count. Fake an ACK message
// to fix this. We can't move this call above the WillSendData because
// it's killing our read_buffer_, and we don't want that when we pause
@@ -117,14 +97,15 @@ bool AsyncResourceHandler::OnResponseCompleted(int request_id,
// If we still have a read buffer, then see about caching it for later...
if (spare_read_buffer_) {
- read_buffer_ = NULL;
- } else if (read_buffer_.get() && read_buffer_->data()) {
- read_buffer_.swap(&spare_read_buffer_);
+ read_buffer_.reset();
+ } else if (read_buffer_.get() && read_buffer_->memory()) {
+ spare_read_buffer_ = read_buffer_.release();
}
return true;
}
// static
void AsyncResourceHandler::GlobalCleanup() {
+ delete spare_read_buffer_;
spare_read_buffer_ = NULL;
}