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

Side by Side Diff: content/browser/download/download_resource_handler.cc

Issue 10578055: Rewrite guts of ResourceLoader and BufferedResourceHandler to suck less. (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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/download/download_resource_handler.h" 5 #include "content/browser/download/download_resource_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 if (!read_buffer_) { 240 if (!read_buffer_) {
241 *buf_size = min_size < 0 ? kReadBufSize : min_size; 241 *buf_size = min_size < 0 ? kReadBufSize : min_size;
242 last_buffer_size_ = *buf_size; 242 last_buffer_size_ = *buf_size;
243 read_buffer_ = new net::IOBuffer(*buf_size); 243 read_buffer_ = new net::IOBuffer(*buf_size);
244 } 244 }
245 *buf = read_buffer_.get(); 245 *buf = read_buffer_.get();
246 return true; 246 return true;
247 } 247 }
248 248
249 // Pass the buffer to the download file writer. 249 // Pass the buffer to the download file writer.
250 bool DownloadResourceHandler::OnReadCompleted(int request_id, int* bytes_read, 250 bool DownloadResourceHandler::OnReadCompleted(int request_id, int bytes_read,
251 bool* defer) { 251 bool* defer) {
252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
253 if (!read_buffer_) { 253 DCHECK(read_buffer_);
254 // Ignore spurious OnReadCompleted! Deferring from OnReadCompleted tells
255 // the ResourceDispatcherHost that we did not consume the data.
256 // ResumeDeferredRequest then repeats the last OnReadCompleted call.
257 // TODO(darin): Fix the ResourceDispatcherHost to avoid this hack!
258 return true;
259 }
260 254
261 if (pause_count_ > 0) { 255 if (pause_count_ > 0) {
262 *defer = was_deferred_ = true; 256 *defer = was_deferred_ = true;
263 return true; 257 return true;
264 } 258 }
265 259
266 base::TimeTicks now(base::TimeTicks::Now()); 260 base::TimeTicks now(base::TimeTicks::Now());
267 if (!last_read_time_.is_null()) { 261 if (!last_read_time_.is_null()) {
268 double seconds_since_last_read = (now - last_read_time_).InSecondsF(); 262 double seconds_since_last_read = (now - last_read_time_).InSecondsF();
269 if (now == last_read_time_) 263 if (now == last_read_time_)
270 // Use 1/10 ms as a "very small number" so that we avoid 264 // Use 1/10 ms as a "very small number" so that we avoid
271 // divide-by-zero error and still record a very high potential bandwidth. 265 // divide-by-zero error and still record a very high potential bandwidth.
272 seconds_since_last_read = 0.00001; 266 seconds_since_last_read = 0.00001;
273 267
274 double actual_bandwidth = (*bytes_read)/seconds_since_last_read; 268 double actual_bandwidth = (bytes_read)/seconds_since_last_read;
275 double potential_bandwidth = last_buffer_size_/seconds_since_last_read; 269 double potential_bandwidth = last_buffer_size_/seconds_since_last_read;
276 download_stats::RecordBandwidth(actual_bandwidth, potential_bandwidth); 270 download_stats::RecordBandwidth(actual_bandwidth, potential_bandwidth);
277 } 271 }
278 last_read_time_ = now; 272 last_read_time_ = now;
279 273
280 if (!*bytes_read) 274 if (!bytes_read)
281 return true; 275 return true;
282 bytes_read_ += *bytes_read; 276 bytes_read_ += bytes_read;
283 DCHECK(read_buffer_); 277 DCHECK(read_buffer_);
284 278
285 // Take the data ship it down the stream. If the stream is full, pause the 279 // Take the data ship it down the stream. If the stream is full, pause the
286 // request; the stream callback will resume it. 280 // request; the stream callback will resume it.
287 if (!stream_writer_->Write(read_buffer_, *bytes_read)) { 281 if (!stream_writer_->Write(read_buffer_, bytes_read)) {
288 PauseRequest(); 282 PauseRequest();
289 *defer = was_deferred_ = true; 283 *defer = was_deferred_ = true;
290 last_stream_pause_time_ = now; 284 last_stream_pause_time_ = now;
291 } 285 }
292 286
293 read_buffer_ = NULL; // Drop our reference. 287 read_buffer_ = NULL; // Drop our reference.
294 288
295 return true; 289 return true;
296 } 290 }
297 291
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 // false somewhere in the chain of resource handlers. 439 // false somewhere in the chain of resource handlers.
446 CallStartedCB(DownloadId(), net::ERR_ACCESS_DENIED); 440 CallStartedCB(DownloadId(), net::ERR_ACCESS_DENIED);
447 441
448 // Remove output stream callback if a stream exists. 442 // Remove output stream callback if a stream exists.
449 if (stream_writer_.get()) 443 if (stream_writer_.get())
450 stream_writer_->RegisterCallback(base::Closure()); 444 stream_writer_->RegisterCallback(base::Closure());
451 445
452 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration", 446 UMA_HISTOGRAM_TIMES("SB2.DownloadDuration",
453 base::TimeTicks::Now() - download_start_time_); 447 base::TimeTicks::Now() - download_start_time_);
454 } 448 }
OLDNEW
« no previous file with comments | « content/browser/download/download_resource_handler.h ('k') | content/browser/download/save_file_resource_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698