| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/download/download_item.h" | 5 #include "chrome/browser/download/download_item.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/timer.h" | 10 #include "base/timer.h" |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 int64 speed = CurrentSpeed(); | 318 int64 speed = CurrentSpeed(); |
| 319 if (speed == 0) | 319 if (speed == 0) |
| 320 return false; | 320 return false; |
| 321 | 321 |
| 322 *remaining = | 322 *remaining = |
| 323 base::TimeDelta::FromSeconds((total_bytes_ - received_bytes_) / speed); | 323 base::TimeDelta::FromSeconds((total_bytes_ - received_bytes_) / speed); |
| 324 return true; | 324 return true; |
| 325 } | 325 } |
| 326 | 326 |
| 327 int64 DownloadItem::CurrentSpeed() const { | 327 int64 DownloadItem::CurrentSpeed() const { |
| 328 if (is_paused_) |
| 329 return 0; |
| 328 base::TimeDelta diff = base::TimeTicks::Now() - start_tick_; | 330 base::TimeDelta diff = base::TimeTicks::Now() - start_tick_; |
| 329 int64 diff_ms = diff.InMilliseconds(); | 331 int64 diff_ms = diff.InMilliseconds(); |
| 330 return diff_ms == 0 ? 0 : received_bytes_ * 1000 / diff_ms; | 332 return diff_ms == 0 ? 0 : received_bytes_ * 1000 / diff_ms; |
| 331 } | 333 } |
| 332 | 334 |
| 333 int DownloadItem::PercentComplete() const { | 335 int DownloadItem::PercentComplete() const { |
| 334 int percent = -1; | 336 int percent = -1; |
| 335 if (total_bytes_ > 0) | 337 if (total_bytes_ > 0) |
| 336 percent = static_cast<int>(received_bytes_ * 100.0 / total_bytes_); | 338 percent = static_cast<int>(received_bytes_ * 100.0 / total_bytes_); |
| 337 return percent; | 339 return percent; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 return target_name_; | 436 return target_name_; |
| 435 return full_path_.BaseName(); | 437 return full_path_.BaseName(); |
| 436 } | 438 } |
| 437 | 439 |
| 438 void DownloadItem::Init(bool start_timer) { | 440 void DownloadItem::Init(bool start_timer) { |
| 439 if (target_name_.value().empty()) | 441 if (target_name_.value().empty()) |
| 440 target_name_ = full_path_.BaseName(); | 442 target_name_ = full_path_.BaseName(); |
| 441 if (start_timer) | 443 if (start_timer) |
| 442 StartProgressTimer(); | 444 StartProgressTimer(); |
| 443 } | 445 } |
| OLD | NEW |