diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-26 17:14:27 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-26 17:14:27 +0000 |
commit | 98c45033eb243d49211df0697fd7b2a699621c24 (patch) | |
tree | 618255ecfa151a1bcea23e645b759eff54cb29eb /chrome | |
parent | b36eabf380e2818b8b181f8af4bb4a89aeabe59b (diff) | |
download | chromium_src-98c45033eb243d49211df0697fd7b2a699621c24.zip chromium_src-98c45033eb243d49211df0697fd7b2a699621c24.tar.gz chromium_src-98c45033eb243d49211df0697fd7b2a699621c24.tar.bz2 |
Only double the buffer when AsyncResourceHandler's caller fill the buffer.
This is an update to r29904 and came out of a discussion with Darin.
BUG=http://crbug.com/24493
TEST=NONE
Review URL: http://codereview.chromium.org/335010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30058 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/renderer_host/async_resource_handler.cc | 17 | ||||
-rw-r--r-- | chrome/browser/renderer_host/async_resource_handler.h | 9 |
2 files changed, 16 insertions, 10 deletions
diff --git a/chrome/browser/renderer_host/async_resource_handler.cc b/chrome/browser/renderer_host/async_resource_handler.cc index da188b6..7e83320 100644 --- a/chrome/browser/renderer_host/async_resource_handler.cc +++ b/chrome/browser/renderer_host/async_resource_handler.cc @@ -18,10 +18,10 @@ namespace { SharedIOBuffer* g_spare_read_buffer = NULL; // The initial size of the shared memory buffer. (32 kilobytes). -const int kReadBufSize = 32768; +const int kInitialReadBufSize = 32768; // The maximum size of the shared memory buffer. (512 kilobytes). -const int kMaxBufSize = 524288; +const int kMaxReadBufSize = 524288; } // namespace @@ -66,7 +66,7 @@ AsyncResourceHandler::AsyncResourceHandler( routing_id_(routing_id), process_handle_(process_handle), rdh_(resource_dispatcher_host), - next_buffer_size_(kReadBufSize) { + next_buffer_size_(kInitialReadBufSize) { } bool AsyncResourceHandler::OnUploadProgress(int request_id, @@ -104,7 +104,7 @@ bool AsyncResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf, CHECK(read_buffer_->data()); *buf = read_buffer_.get(); - *buf_size = read_buffer_.get()->buffer_size(); + *buf_size = read_buffer_->buffer_size(); } else { read_buffer_ = new SharedIOBuffer(next_buffer_size_); if (!read_buffer_->ok()) { @@ -117,8 +117,6 @@ bool AsyncResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf, *buf_size = next_buffer_size_; } - next_buffer_size_ = std::min(next_buffer_size_ * 2, kMaxBufSize); - return true; } @@ -127,6 +125,13 @@ bool AsyncResourceHandler::OnReadCompleted(int request_id, int* bytes_read) { return true; DCHECK(read_buffer_.get()); + if (read_buffer_->buffer_size() == *bytes_read) { + // The network layer has saturated our buffer. Next time, we should give it + // a bigger buffer for it to fill, to minimize the number of round trips we + // do with the renderer process. + next_buffer_size_ = std::min(next_buffer_size_ * 2, kMaxReadBufSize); + } + if (!rdh_->WillSendData(process_id_, request_id)) { // We should not send this data now, we have too many pending requests. return true; diff --git a/chrome/browser/renderer_host/async_resource_handler.h b/chrome/browser/renderer_host/async_resource_handler.h index b946d4d..b99ba10 100644 --- a/chrome/browser/renderer_host/async_resource_handler.h +++ b/chrome/browser/renderer_host/async_resource_handler.h @@ -46,10 +46,11 @@ class AsyncResourceHandler : public ResourceHandler { base::ProcessHandle process_handle_; ResourceDispatcherHost* rdh_; - // We exponentially grow the size of the buffer allocated. On the first - // OnWillRead() call, we allocate a buffer of 32k and double it on each - // subsequent call, up to a maximum size of 512k. |next_buffer_size_| is the - // size of the buffer to be allocated on the next OnWillRead() call. + // |next_buffer_size_| is the size of the buffer to be allocated on the next + // OnWillRead() call. We exponentially grow the size of the buffer allocated + // when our owner fills our buffers. On the first OnWillRead() call, we + // allocate a buffer of 32k and double it in OnReadCompleted() if the buffer + // was filled, up to a maximum size of 512k. int next_buffer_size_; DISALLOW_COPY_AND_ASSIGN(AsyncResourceHandler); |