Index: content/browser/renderer_host/redirect_to_file_resource_handler.cc |
diff --git a/content/browser/renderer_host/redirect_to_file_resource_handler.cc b/content/browser/renderer_host/redirect_to_file_resource_handler.cc |
index 2f9b7c1b6b96905fa8ba4196eeeb3d2a1286e483..d7f0ea3a7a383178e1bfc1d451f135a0a1a09f6c 100644 |
--- a/content/browser/renderer_host/redirect_to_file_resource_handler.cc |
+++ b/content/browser/renderer_host/redirect_to_file_resource_handler.cc |
@@ -23,8 +23,8 @@ using webkit_blob::ShareableFileReference; |
namespace content { |
-// TODO(darin): Use the buffer sizing algorithm from AsyncResourceHandler. |
-static const int kReadBufSize = 32768; |
+static const int kInitialReadBufSize = 32768; |
+static const int kMaxReadBufSize = 524288; |
RedirectToFileResourceHandler::RedirectToFileResourceHandler( |
scoped_ptr<ResourceHandler> next_handler, |
@@ -39,6 +39,7 @@ RedirectToFileResourceHandler::RedirectToFileResourceHandler( |
buf_write_pending_(false), |
write_cursor_(0), |
write_callback_pending_(false), |
+ next_buffer_size_(kInitialReadBufSize), |
did_defer_(false), |
completed_during_write_(false) { |
} |
@@ -92,8 +93,8 @@ bool RedirectToFileResourceHandler::OnWillRead(int request_id, |
int min_size) { |
DCHECK_EQ(-1, min_size); |
- if (!buf_->capacity()) |
- buf_->SetCapacity(kReadBufSize); |
+ if (buf_->capacity() < next_buffer_size_) |
+ buf_->SetCapacity(next_buffer_size_); |
// We should have paused this network request already if the buffer is full. |
DCHECK(!BufIsFull()); |
@@ -111,8 +112,14 @@ bool RedirectToFileResourceHandler::OnReadCompleted(int request_id, |
DCHECK(buf_write_pending_); |
buf_write_pending_ = false; |
- // We use the buffer's offset field to record the end of the buffer. |
+ if (buf_->capacity() == bytes_read) { |
darin (slow to review)
2012/07/26 18:51:59
I had just imagined a BufferSizeAlgorithm class wi
|
+ // 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); |
+ } |
+ // We use the buffer's offset field to record the end of the buffer. |
int new_offset = buf_->offset() + bytes_read; |
DCHECK(new_offset <= buf_->capacity()); |
buf_->set_offset(new_offset); |