Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1892)

Unified Diff: content/browser/renderer_host/redirect_to_file_resource_handler.cc

Issue 10828024: Let RedirectToFileResourceHandler resize its internal buffer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/renderer_host/redirect_to_file_resource_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « content/browser/renderer_host/redirect_to_file_resource_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698