| 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 // Download utility implementation | 5 // Download utility implementation |
| 6 | 6 |
| 7 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
| (...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 file_value->SetInteger("total", | 583 file_value->SetInteger("total", |
| 584 static_cast<int>(download->total_bytes())); | 584 static_cast<int>(download->total_bytes())); |
| 585 | 585 |
| 586 return file_value; | 586 return file_value; |
| 587 } | 587 } |
| 588 | 588 |
| 589 std::wstring GetProgressStatusText(DownloadItem* download) { | 589 std::wstring GetProgressStatusText(DownloadItem* download) { |
| 590 int64 total = download->total_bytes(); | 590 int64 total = download->total_bytes(); |
| 591 int64 size = download->received_bytes(); | 591 int64 size = download->received_bytes(); |
| 592 DataUnits amount_units = GetByteDisplayUnits(size); | 592 DataUnits amount_units = GetByteDisplayUnits(size); |
| 593 std::wstring received_size = FormatBytes(size, amount_units, true); | 593 std::wstring received_size = UTF16ToWideHack(FormatBytes(size, amount_units, |
| 594 true)); |
| 594 std::wstring amount = received_size; | 595 std::wstring amount = received_size; |
| 595 | 596 |
| 596 // Adjust both strings for the locale direction since we don't yet know which | 597 // Adjust both strings for the locale direction since we don't yet know which |
| 597 // string we'll end up using for constructing the final progress string. | 598 // string we'll end up using for constructing the final progress string. |
| 598 std::wstring amount_localized; | 599 std::wstring amount_localized; |
| 599 if (base::i18n::AdjustStringForLocaleDirection(amount, &amount_localized)) { | 600 if (base::i18n::AdjustStringForLocaleDirection(amount, &amount_localized)) { |
| 600 amount.assign(amount_localized); | 601 amount.assign(amount_localized); |
| 601 received_size.assign(amount_localized); | 602 received_size.assign(amount_localized); |
| 602 } | 603 } |
| 603 | 604 |
| 604 if (total) { | 605 if (total) { |
| 605 amount_units = GetByteDisplayUnits(total); | 606 amount_units = GetByteDisplayUnits(total); |
| 606 std::wstring total_text = FormatBytes(total, amount_units, true); | 607 std::wstring total_text = |
| 608 UTF16ToWideHack(FormatBytes(total, amount_units, true)); |
| 607 std::wstring total_text_localized; | 609 std::wstring total_text_localized; |
| 608 if (base::i18n::AdjustStringForLocaleDirection(total_text, | 610 if (base::i18n::AdjustStringForLocaleDirection(total_text, |
| 609 &total_text_localized)) | 611 &total_text_localized)) |
| 610 total_text.assign(total_text_localized); | 612 total_text.assign(total_text_localized); |
| 611 | 613 |
| 612 amount = l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_SIZE, | 614 amount = l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_SIZE, |
| 613 received_size, | 615 received_size, |
| 614 total_text); | 616 total_text); |
| 615 } else { | 617 } else { |
| 616 amount.assign(received_size); | 618 amount.assign(received_size); |
| 617 } | 619 } |
| 618 amount_units = GetByteDisplayUnits(download->CurrentSpeed()); | 620 amount_units = GetByteDisplayUnits(download->CurrentSpeed()); |
| 619 std::wstring speed_text = FormatSpeed(download->CurrentSpeed(), | 621 std::wstring speed_text = |
| 620 amount_units, true); | 622 UTF16ToWideHack(FormatSpeed(download->CurrentSpeed(), amount_units, |
| 623 true)); |
| 621 std::wstring speed_text_localized; | 624 std::wstring speed_text_localized; |
| 622 if (base::i18n::AdjustStringForLocaleDirection(speed_text, | 625 if (base::i18n::AdjustStringForLocaleDirection(speed_text, |
| 623 &speed_text_localized)) | 626 &speed_text_localized)) |
| 624 speed_text.assign(speed_text_localized); | 627 speed_text.assign(speed_text_localized); |
| 625 | 628 |
| 626 base::TimeDelta remaining; | 629 base::TimeDelta remaining; |
| 627 string16 time_remaining; | 630 string16 time_remaining; |
| 628 if (download->is_paused()) | 631 if (download->is_paused()) |
| 629 time_remaining = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); | 632 time_remaining = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); |
| 630 else if (download->TimeRemaining(&remaining)) | 633 else if (download->TimeRemaining(&remaining)) |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 } | 757 } |
| 755 | 758 |
| 756 FilePath GetCrDownloadPath(const FilePath& suggested_path) { | 759 FilePath GetCrDownloadPath(const FilePath& suggested_path) { |
| 757 FilePath::StringType file_name; | 760 FilePath::StringType file_name; |
| 758 SStringPrintf(&file_name, PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"), | 761 SStringPrintf(&file_name, PRFilePathLiteral FILE_PATH_LITERAL(".crdownload"), |
| 759 suggested_path.value().c_str()); | 762 suggested_path.value().c_str()); |
| 760 return FilePath(file_name); | 763 return FilePath(file_name); |
| 761 } | 764 } |
| 762 | 765 |
| 763 } // namespace download_util | 766 } // namespace download_util |
| OLD | NEW |