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

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

Issue 14697023: downloads: Improve download rate estimation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improve unit tests Created 7 years, 7 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/base_file.h" 5 #include "content/browser/download/base_file.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 if (write_result < 0) 130 if (write_result < 0)
131 return LogNetError("Write", static_cast<net::Error>(write_result)); 131 return LogNetError("Write", static_cast<net::Error>(write_result));
132 } 132 }
133 133
134 // Update status. 134 // Update status.
135 size_t write_size = static_cast<size_t>(write_result); 135 size_t write_size = static_cast<size_t>(write_result);
136 DCHECK_LE(write_size, len); 136 DCHECK_LE(write_size, len);
137 len -= write_size; 137 len -= write_size;
138 current_data += write_size; 138 current_data += write_size;
139 bytes_so_far_ += write_size; 139 bytes_so_far_ += write_size;
140 rate_estimator_.AddBytes(write_size);
140 } 141 }
141 142
142 RecordDownloadWriteSize(data_len); 143 RecordDownloadWriteSize(data_len);
143 RecordDownloadWriteLoopCount(write_count); 144 RecordDownloadWriteLoopCount(write_count);
144 145
145 if (calculate_hash_) 146 if (calculate_hash_)
146 secure_hash_->Update(data, data_len); 147 secure_hash_->Update(data, data_len);
147 148
148 return DOWNLOAD_INTERRUPT_REASON_NONE; 149 return DOWNLOAD_INTERRUPT_REASON_NONE;
149 } 150 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 } 334 }
334 335
335 void BaseFile::ClearStream() { 336 void BaseFile::ClearStream() {
336 // This should only be called when we have a stream. 337 // This should only be called when we have a stream.
337 DCHECK(file_stream_.get() != NULL); 338 DCHECK(file_stream_.get() != NULL);
338 file_stream_.reset(); 339 file_stream_.reset();
339 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_OPENED); 340 bound_net_log_.EndEvent(net::NetLog::TYPE_DOWNLOAD_FILE_OPENED);
340 } 341 }
341 342
342 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const { 343 int64 BaseFile::CurrentSpeedAtTime(base::TimeTicks current_time) const {
343 base::TimeDelta diff = current_time - start_tick_; 344 return rate_estimator_.GetBytesPerSecond();
344 int64 diff_ms = diff.InMilliseconds();
345 return diff_ms == 0 ? 0 : bytes_so_far() * 1000 / diff_ms;
346 } 345 }
347 346
348 DownloadInterruptReason BaseFile::LogNetError( 347 DownloadInterruptReason BaseFile::LogNetError(
349 const char* operation, 348 const char* operation,
350 net::Error error) { 349 net::Error error) {
351 bound_net_log_.AddEvent( 350 bound_net_log_.AddEvent(
352 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, 351 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR,
353 base::Bind(&FileErrorNetLogCallback, operation, error)); 352 base::Bind(&FileErrorNetLogCallback, operation, error));
354 return ConvertNetErrorToInterruptReason(error, DOWNLOAD_INTERRUPT_FROM_DISK); 353 return ConvertNetErrorToInterruptReason(error, DOWNLOAD_INTERRUPT_FROM_DISK);
355 } 354 }
(...skipping 13 matching lines...) Expand all
369 const char* operation, 368 const char* operation,
370 int os_error, 369 int os_error,
371 DownloadInterruptReason reason) { 370 DownloadInterruptReason reason) {
372 bound_net_log_.AddEvent( 371 bound_net_log_.AddEvent(
373 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR, 372 net::NetLog::TYPE_DOWNLOAD_FILE_ERROR,
374 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason)); 373 base::Bind(&FileInterruptedNetLogCallback, operation, os_error, reason));
375 return reason; 374 return reason;
376 } 375 }
377 376
378 } // namespace content 377 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698