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

Side by Side Diff: chrome/browser/download/download_item_model.cc

Issue 147443007: Add support for localized time strings with two units, eg. "2 hours 17 minutes" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Bartosz' comments Created 6 years, 10 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
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 "chrome/browser/download/download_item_model.h" 5 #include "chrome/browser/download/download_item_model.h"
6 6
7 #include "base/i18n/number_formatting.h" 7 #include "base/i18n/number_formatting.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 IDS_DOWNLOAD_TAB_PROGRESS_SIZE, received_size, total_text); 327 IDS_DOWNLOAD_TAB_PROGRESS_SIZE, received_size, total_text);
328 } else { 328 } else {
329 amount.assign(received_size); 329 amount.assign(received_size);
330 } 330 }
331 int64 current_speed = download_->CurrentSpeed(); 331 int64 current_speed = download_->CurrentSpeed();
332 base::string16 speed_text = ui::FormatSpeed(current_speed); 332 base::string16 speed_text = ui::FormatSpeed(current_speed);
333 base::i18n::AdjustStringForLocaleDirection(&speed_text); 333 base::i18n::AdjustStringForLocaleDirection(&speed_text);
334 334
335 base::TimeDelta remaining; 335 base::TimeDelta remaining;
336 base::string16 time_remaining; 336 base::string16 time_remaining;
337 if (download_->IsPaused()) 337 if (download_->IsPaused()) {
338 time_remaining = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); 338 time_remaining = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED);
339 else if (download_->TimeRemaining(&remaining)) 339 } else if (download_->TimeRemaining(&remaining)) {
340 time_remaining = ui::TimeFormat::TimeRemaining(remaining); 340 time_remaining = ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_REMAINING,
341 ui::TimeFormat::LENGTH_SHORT,
342 remaining);
343 }
341 344
342 if (time_remaining.empty()) { 345 if (time_remaining.empty()) {
343 base::i18n::AdjustStringForLocaleDirection(&amount); 346 base::i18n::AdjustStringForLocaleDirection(&amount);
344 return l10n_util::GetStringFUTF16( 347 return l10n_util::GetStringFUTF16(
345 IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN, speed_text, amount); 348 IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN, speed_text, amount);
346 } 349 }
347 return l10n_util::GetStringFUTF16( 350 return l10n_util::GetStringFUTF16(
348 IDS_DOWNLOAD_TAB_PROGRESS_STATUS, speed_text, amount, time_remaining); 351 IDS_DOWNLOAD_TAB_PROGRESS_STATUS, speed_text, amount, time_remaining);
349 } 352 }
350 353
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED)); 623 l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED));
621 } 624 }
622 625
623 // A download scheduled to be opened when complete: "Opening in 10 secs" 626 // A download scheduled to be opened when complete: "Opening in 10 secs"
624 if (download_->GetOpenWhenComplete()) { 627 if (download_->GetOpenWhenComplete()) {
625 if (!time_remaining_known) 628 if (!time_remaining_known)
626 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE); 629 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE);
627 630
628 return l10n_util::GetStringFUTF16( 631 return l10n_util::GetStringFUTF16(
629 IDS_DOWNLOAD_STATUS_OPEN_IN, 632 IDS_DOWNLOAD_STATUS_OPEN_IN,
630 ui::TimeFormat::TimeDurationShort(time_remaining)); 633 ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_DURATION,
634 ui::TimeFormat::LENGTH_SHORT, time_remaining));
631 } 635 }
632 636
633 // In progress download with known time left: "100/120 MB, 10 secs left" 637 // In progress download with known time left: "100/120 MB, 10 secs left"
634 if (time_remaining_known) { 638 if (time_remaining_known) {
635 return l10n_util::GetStringFUTF16( 639 return l10n_util::GetStringFUTF16(
636 IDS_DOWNLOAD_STATUS_IN_PROGRESS, size_ratio, 640 IDS_DOWNLOAD_STATUS_IN_PROGRESS, size_ratio,
637 ui::TimeFormat::TimeRemaining(time_remaining)); 641 ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_REMAINING,
642 ui::TimeFormat::LENGTH_SHORT, time_remaining));
638 } 643 }
639 644
640 // In progress download with no known time left and non-zero completed bytes: 645 // In progress download with no known time left and non-zero completed bytes:
641 // "100/120 MB" or "100 MB" 646 // "100/120 MB" or "100 MB"
642 if (GetCompletedBytes() > 0) 647 if (GetCompletedBytes() > 0)
643 return size_ratio; 648 return size_ratio;
644 649
645 // Instead of displaying "0 B" we say "Starting..." 650 // Instead of displaying "0 B" we say "Starting..."
646 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); 651 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING);
647 } 652 }
648 653
649 void DownloadItemModel::OpenUsingPlatformHandler() { 654 void DownloadItemModel::OpenUsingPlatformHandler() {
650 DownloadService* download_service = 655 DownloadService* download_service =
651 DownloadServiceFactory::GetForBrowserContext( 656 DownloadServiceFactory::GetForBrowserContext(
652 download_->GetBrowserContext()); 657 download_->GetBrowserContext());
653 if (!download_service) 658 if (!download_service)
654 return; 659 return;
655 660
656 ChromeDownloadManagerDelegate* delegate = 661 ChromeDownloadManagerDelegate* delegate =
657 download_service->GetDownloadManagerDelegate(); 662 download_service->GetDownloadManagerDelegate();
658 if (!delegate) 663 if (!delegate)
659 return; 664 return;
660 delegate->OpenDownloadUsingPlatformHandler(download_); 665 delegate->OpenDownloadUsingPlatformHandler(download_);
661 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); 666 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM);
662 } 667 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698