| OLD | NEW |
| 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_file_impl.h" | 5 #include "content/browser/download/download_file_impl.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 DownloadInterruptReason DownloadFileImpl::AppendDataToFile( | 92 DownloadInterruptReason DownloadFileImpl::AppendDataToFile( |
| 93 const char* data, size_t data_len) { | 93 const char* data, size_t data_len) { |
| 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 95 | 95 |
| 96 if (!update_timer_->IsRunning()) { | 96 if (!update_timer_->IsRunning()) { |
| 97 update_timer_->Start(FROM_HERE, | 97 update_timer_->Start(FROM_HERE, |
| 98 base::TimeDelta::FromMilliseconds(kUpdatePeriodMs), | 98 base::TimeDelta::FromMilliseconds(kUpdatePeriodMs), |
| 99 this, &DownloadFileImpl::SendUpdate); | 99 this, &DownloadFileImpl::SendUpdate); |
| 100 } | 100 } |
| 101 rate_estimator_.Increment(data_len); |
| 101 return file_.AppendDataToFile(data, data_len); | 102 return file_.AppendDataToFile(data, data_len); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void DownloadFileImpl::RenameAndUniquify( | 105 void DownloadFileImpl::RenameAndUniquify( |
| 105 const base::FilePath& full_path, | 106 const base::FilePath& full_path, |
| 106 const RenameCompletionCallback& callback) { | 107 const RenameCompletionCallback& callback) { |
| 107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 108 | 109 |
| 109 base::FilePath new_path(full_path); | 110 base::FilePath new_path(full_path); |
| 110 | 111 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 185 |
| 185 bool DownloadFileImpl::InProgress() const { | 186 bool DownloadFileImpl::InProgress() const { |
| 186 return file_.in_progress(); | 187 return file_.in_progress(); |
| 187 } | 188 } |
| 188 | 189 |
| 189 int64 DownloadFileImpl::BytesSoFar() const { | 190 int64 DownloadFileImpl::BytesSoFar() const { |
| 190 return file_.bytes_so_far(); | 191 return file_.bytes_so_far(); |
| 191 } | 192 } |
| 192 | 193 |
| 193 int64 DownloadFileImpl::CurrentSpeed() const { | 194 int64 DownloadFileImpl::CurrentSpeed() const { |
| 194 return file_.CurrentSpeed(); | 195 return rate_estimator_.GetCountPerSecond(); |
| 195 } | 196 } |
| 196 | 197 |
| 197 bool DownloadFileImpl::GetHash(std::string* hash) { | 198 bool DownloadFileImpl::GetHash(std::string* hash) { |
| 198 return file_.GetHash(hash); | 199 return file_.GetHash(hash); |
| 199 } | 200 } |
| 200 | 201 |
| 201 std::string DownloadFileImpl::GetHashState() { | 202 std::string DownloadFileImpl::GetHashState() { |
| 202 return file_.GetHashState(); | 203 return file_.GetHashState(); |
| 203 } | 204 } |
| 204 | 205 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 base::Bind(&DownloadDestinationObserver::DestinationUpdate, | 309 base::Bind(&DownloadDestinationObserver::DestinationUpdate, |
| 309 observer_, BytesSoFar(), CurrentSpeed(), GetHashState())); | 310 observer_, BytesSoFar(), CurrentSpeed(), GetHashState())); |
| 310 } | 311 } |
| 311 | 312 |
| 312 // static | 313 // static |
| 313 int DownloadFile::GetNumberOfDownloadFiles() { | 314 int DownloadFile::GetNumberOfDownloadFiles() { |
| 314 return number_active_objects_; | 315 return number_active_objects_; |
| 315 } | 316 } |
| 316 | 317 |
| 317 } // namespace content | 318 } // namespace content |
| OLD | NEW |