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

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: More cleanup and documentation 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 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::kRemaining,
bartfab (slow) 2014/02/18 12:04:04 Nit: The else branch now spans multiple lines. Hen
Thiemo Nagel 2014/02/19 17:08:44 Done.
341 ui::TimeFormat::kShort, remaining);
341 342
342 if (time_remaining.empty()) { 343 if (time_remaining.empty()) {
343 base::i18n::AdjustStringForLocaleDirection(&amount); 344 base::i18n::AdjustStringForLocaleDirection(&amount);
344 return l10n_util::GetStringFUTF16( 345 return l10n_util::GetStringFUTF16(
345 IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN, speed_text, amount); 346 IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN, speed_text, amount);
346 } 347 }
347 return l10n_util::GetStringFUTF16( 348 return l10n_util::GetStringFUTF16(
348 IDS_DOWNLOAD_TAB_PROGRESS_STATUS, speed_text, amount, time_remaining); 349 IDS_DOWNLOAD_TAB_PROGRESS_STATUS, speed_text, amount, time_remaining);
349 } 350 }
350 351
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED)); 621 l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED));
621 } 622 }
622 623
623 // A download scheduled to be opened when complete: "Opening in 10 secs" 624 // A download scheduled to be opened when complete: "Opening in 10 secs"
624 if (download_->GetOpenWhenComplete()) { 625 if (download_->GetOpenWhenComplete()) {
625 if (!time_remaining_known) 626 if (!time_remaining_known)
626 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE); 627 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE);
627 628
628 return l10n_util::GetStringFUTF16( 629 return l10n_util::GetStringFUTF16(
629 IDS_DOWNLOAD_STATUS_OPEN_IN, 630 IDS_DOWNLOAD_STATUS_OPEN_IN,
630 ui::TimeFormat::TimeDurationShort(time_remaining)); 631 ui::TimeFormat::Simple(ui::TimeFormat::kDuration,
632 ui::TimeFormat::kShort, time_remaining));
631 } 633 }
632 634
633 // In progress download with known time left: "100/120 MB, 10 secs left" 635 // In progress download with known time left: "100/120 MB, 10 secs left"
634 if (time_remaining_known) { 636 if (time_remaining_known) {
635 return l10n_util::GetStringFUTF16( 637 return l10n_util::GetStringFUTF16(
636 IDS_DOWNLOAD_STATUS_IN_PROGRESS, size_ratio, 638 IDS_DOWNLOAD_STATUS_IN_PROGRESS, size_ratio,
637 ui::TimeFormat::TimeRemaining(time_remaining)); 639 ui::TimeFormat::Simple(ui::TimeFormat::kRemaining,
640 ui::TimeFormat::kShort, time_remaining));
638 } 641 }
639 642
640 // In progress download with no known time left and non-zero completed bytes: 643 // In progress download with no known time left and non-zero completed bytes:
641 // "100/120 MB" or "100 MB" 644 // "100/120 MB" or "100 MB"
642 if (GetCompletedBytes() > 0) 645 if (GetCompletedBytes() > 0)
643 return size_ratio; 646 return size_ratio;
644 647
645 // Instead of displaying "0 B" we say "Starting..." 648 // Instead of displaying "0 B" we say "Starting..."
646 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING); 649 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING);
647 } 650 }
648 651
649 void DownloadItemModel::OpenUsingPlatformHandler() { 652 void DownloadItemModel::OpenUsingPlatformHandler() {
650 DownloadService* download_service = 653 DownloadService* download_service =
651 DownloadServiceFactory::GetForBrowserContext( 654 DownloadServiceFactory::GetForBrowserContext(
652 download_->GetBrowserContext()); 655 download_->GetBrowserContext());
653 if (!download_service) 656 if (!download_service)
654 return; 657 return;
655 658
656 ChromeDownloadManagerDelegate* delegate = 659 ChromeDownloadManagerDelegate* delegate =
657 download_service->GetDownloadManagerDelegate(); 660 download_service->GetDownloadManagerDelegate();
658 if (!delegate) 661 if (!delegate)
659 return; 662 return;
660 delegate->OpenDownloadUsingPlatformHandler(download_); 663 delegate->OpenDownloadUsingPlatformHandler(download_);
661 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); 664 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM);
662 } 665 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698