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

Unified Diff: chrome/browser/renderer_host/async_resource_handler.cc

Issue 335010: Only double the buffer when AsyncResourceHandler's caller fill the buffer. (Closed)
Patch Set: Created 11 years, 2 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 | « chrome/browser/renderer_host/async_resource_handler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/renderer_host/async_resource_handler.cc
diff --git a/chrome/browser/renderer_host/async_resource_handler.cc b/chrome/browser/renderer_host/async_resource_handler.cc
index da188b6b6cfb096554ad16300153e0d8ad07fbe9..7e83320114a64335faab7821e25bab16f72cec40 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;
« no previous file with comments | « chrome/browser/renderer_host/async_resource_handler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698