summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-18 20:28:05 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-18 20:28:05 +0000
commit246a1d1dfc635cf653a773e3fa3ced40e447dd80 (patch)
treef00aa8bdb7bef5c3e1cf87271e8ba64a1e84be52
parent173bcb7077dfad483494a16b0b1583dff59d019c (diff)
downloadchromium_src-246a1d1dfc635cf653a773e3fa3ced40e447dd80.zip
chromium_src-246a1d1dfc635cf653a773e3fa3ced40e447dd80.tar.gz
chromium_src-246a1d1dfc635cf653a773e3fa3ced40e447dd80.tar.bz2
Fix DownloadResourceHandler::OnReadCompleted to defer loading after consuming
the given data (and releasing read_buffer_). The existing code was ignoring a chunk of data and then crashing after the next call to OnWillRead. The crash was caused by OnWillRead failing to set *buf_size when read_buffer_ is non-null. That case was only possible when OnReadCompleted returned early. This is fallout from http://crrev.com/144873, which changed the pause/resume semantics such that deferring from OnReadCompleted pauses future network events instead of pausing the current network event and future network events. In other words, the DownloadResourceHandler still expected OnReadCompleted to be called again upon resuming resource loading. R=jam@chromium.org BUG=137337 Review URL: https://chromiumcodereview.appspot.com/10804011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147305 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--content/browser/download/download_resource_handler.cc18
1 files changed, 8 insertions, 10 deletions
diff --git a/content/browser/download/download_resource_handler.cc b/content/browser/download/download_resource_handler.cc
index cc2bc40..e42d0b4 100644
--- a/content/browser/download/download_resource_handler.cc
+++ b/content/browser/download/download_resource_handler.cc
@@ -237,11 +237,11 @@ bool DownloadResourceHandler::OnWillRead(int request_id, net::IOBuffer** buf,
int* buf_size, int min_size) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(buf && buf_size);
- if (!read_buffer_) {
- *buf_size = min_size < 0 ? kReadBufSize : min_size;
- last_buffer_size_ = *buf_size;
- read_buffer_ = new net::IOBuffer(*buf_size);
- }
+ DCHECK(!read_buffer_);
+
+ *buf_size = min_size < 0 ? kReadBufSize : min_size;
+ last_buffer_size_ = *buf_size;
+ read_buffer_ = new net::IOBuffer(*buf_size);
*buf = read_buffer_.get();
return true;
}
@@ -252,11 +252,6 @@ bool DownloadResourceHandler::OnReadCompleted(int request_id, int bytes_read,
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
DCHECK(read_buffer_);
- if (pause_count_ > 0) {
- *defer = was_deferred_ = true;
- return true;
- }
-
base::TimeTicks now(base::TimeTicks::Now());
if (!last_read_time_.is_null()) {
double seconds_since_last_read = (now - last_read_time_).InSecondsF();
@@ -286,6 +281,9 @@ bool DownloadResourceHandler::OnReadCompleted(int request_id, int bytes_read,
read_buffer_ = NULL; // Drop our reference.
+ if (pause_count_ > 0)
+ *defer = was_deferred_ = true;
+
return true;
}