Chromium Code Reviews| Index: content/browser/download/download_file_impl.cc |
| diff --git a/content/browser/download/download_file_impl.cc b/content/browser/download/download_file_impl.cc |
| index e4ec806f7718c8b4de357eb9977f329a852834a7..3530c649666ce90eeb68f19ee80be6cff09626fa 100644 |
| --- a/content/browser/download/download_file_impl.cc |
| +++ b/content/browser/download/download_file_impl.cc |
| @@ -71,6 +71,10 @@ DownloadFileImpl::DownloadFileImpl( |
| default_download_directory_(default_download_directory), |
| is_sparse_file_(is_sparse_file), |
| bytes_seen_(0), |
| + num_active_streams_(0), |
| + record_stream_bandwidth_(true), |
| + bytes_seen_with_parallel_streams_(0), |
| + bytes_seen_without_parallel_streams_(0), |
| received_slices_(received_slices), |
| observer_(observer), |
| weak_factory_(this) { |
| @@ -116,6 +120,7 @@ void DownloadFileImpl::Initialize(const InitializeCallback& callback) { |
| } |
| download_start_ = base::TimeTicks::Now(); |
| + last_update_time_ = download_start_; |
| // Primarily to make reset to zero in restart visible to owner. |
| SendUpdate(); |
| @@ -279,6 +284,10 @@ bool DownloadFileImpl::InProgress() const { |
| return file_.in_progress(); |
| } |
| +void DownloadFileImpl::Pause() { |
| + record_stream_bandwidth_ = false; |
|
xingliu
2017/03/17 00:02:15
I think we didn't set it to true again, and didn't
David Trainor- moved to gerrit
2017/03/17 07:25:40
Do we need to reset last_update_time_ on resume as
qinmin
2017/03/17 19:52:54
We don't record UMA even if resume is called, the
qinmin
2017/03/17 19:52:55
we should stop recording if a download is ever pau
|
| +} |
| + |
| void DownloadFileImpl::StreamActive(SourceStream* source_stream) { |
| DCHECK(source_stream->stream_reader()); |
| base::TimeTicks start(base::TimeTicks::Now()); |
| @@ -367,10 +376,12 @@ void DownloadFileImpl::StreamActive(SourceStream* source_stream) { |
| BrowserThread::UI, FROM_HERE, |
| base::Bind(&DownloadDestinationObserver::DestinationError, observer_, |
| reason, TotalBytesReceived(), base::Passed(&hash_state))); |
| + num_active_streams_--; |
| } else if (state == ByteStreamReader::STREAM_COMPLETE || should_terminate) { |
| // Signal successful completion or termination of the current stream. |
| source_stream->stream_reader()->RegisterCallback(base::Closure()); |
| source_stream->set_finished(true); |
| + num_active_streams_--; |
| // Inform observers. |
| SendUpdate(); |
| @@ -389,6 +400,12 @@ void DownloadFileImpl::StreamActive(SourceStream* source_stream) { |
| if (all_stream_complete) { |
| RecordFileBandwidth(bytes_seen_, disk_writes_time_, |
| base::TimeTicks::Now() - download_start_); |
| + if (is_sparse_file_) { |
| + RecordParallelDownloadStats(bytes_seen_with_parallel_streams_, |
| + download_time_with_parallel_streams_, |
| + bytes_seen_without_parallel_streams_, |
| + download_time_without_parallel_streams_); |
| + } |
| weak_factory_.InvalidateWeakPtrs(); |
| std::unique_ptr<crypto::SecureHash> hash_state = file_.Finish(); |
| update_timer_.reset(); |
| @@ -414,6 +431,7 @@ void DownloadFileImpl::RegisterAndActivateStream(SourceStream* source_stream) { |
| weak_factory_.GetWeakPtr(), |
| source_stream)); |
| StreamActive(source_stream); |
| + num_active_streams_++; |
| } |
| } |
| @@ -438,6 +456,18 @@ void DownloadFileImpl::WillWriteToDisk(size_t data_len) { |
| this, &DownloadFileImpl::SendUpdate); |
| } |
| rate_estimator_.Increment(data_len); |
| + if (is_sparse_file_) { |
| + base::TimeTicks now = base::TimeTicks::Now(); |
| + base::TimeDelta time_elapsed = (now - last_update_time_); |
| + last_update_time_ = now; |
| + if (num_active_streams_ > 1) { |
| + download_time_with_parallel_streams_ += time_elapsed; |
| + bytes_seen_with_parallel_streams_ += data_len; |
| + } else { |
| + download_time_without_parallel_streams_ += time_elapsed; |
| + bytes_seen_without_parallel_streams_ += data_len; |
| + } |
| + } |
| } |
| DownloadFileImpl::RenameParameters::RenameParameters( |