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 "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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 break; | 312 break; |
313 } | 313 } |
314 default: | 314 default: |
315 NOTREACHED(); | 315 NOTREACHED(); |
316 } | 316 } |
317 | 317 |
318 return status_text; | 318 return status_text; |
319 } | 319 } |
320 | 320 |
321 base::string16 DownloadItemModel::GetTabProgressStatusText() const { | 321 base::string16 DownloadItemModel::GetTabProgressStatusText() const { |
322 int64 total = GetTotalBytes(); | 322 int64_t total = GetTotalBytes(); |
323 int64 size = download_->GetReceivedBytes(); | 323 int64_t size = download_->GetReceivedBytes(); |
324 base::string16 received_size = ui::FormatBytes(size); | 324 base::string16 received_size = ui::FormatBytes(size); |
325 base::string16 amount = received_size; | 325 base::string16 amount = received_size; |
326 | 326 |
327 // Adjust both strings for the locale direction since we don't yet know which | 327 // Adjust both strings for the locale direction since we don't yet know which |
328 // string we'll end up using for constructing the final progress string. | 328 // string we'll end up using for constructing the final progress string. |
329 base::i18n::AdjustStringForLocaleDirection(&amount); | 329 base::i18n::AdjustStringForLocaleDirection(&amount); |
330 | 330 |
331 if (total) { | 331 if (total) { |
332 base::string16 total_text = ui::FormatBytes(total); | 332 base::string16 total_text = ui::FormatBytes(total); |
333 base::i18n::AdjustStringForLocaleDirection(&total_text); | 333 base::i18n::AdjustStringForLocaleDirection(&total_text); |
334 | 334 |
335 base::i18n::AdjustStringForLocaleDirection(&received_size); | 335 base::i18n::AdjustStringForLocaleDirection(&received_size); |
336 amount = l10n_util::GetStringFUTF16( | 336 amount = l10n_util::GetStringFUTF16( |
337 IDS_DOWNLOAD_TAB_PROGRESS_SIZE, received_size, total_text); | 337 IDS_DOWNLOAD_TAB_PROGRESS_SIZE, received_size, total_text); |
338 } else { | 338 } else { |
339 amount.assign(received_size); | 339 amount.assign(received_size); |
340 } | 340 } |
341 int64 current_speed = download_->CurrentSpeed(); | 341 int64_t current_speed = download_->CurrentSpeed(); |
342 base::string16 speed_text = ui::FormatSpeed(current_speed); | 342 base::string16 speed_text = ui::FormatSpeed(current_speed); |
343 base::i18n::AdjustStringForLocaleDirection(&speed_text); | 343 base::i18n::AdjustStringForLocaleDirection(&speed_text); |
344 | 344 |
345 base::TimeDelta remaining; | 345 base::TimeDelta remaining; |
346 base::string16 time_remaining; | 346 base::string16 time_remaining; |
347 if (download_->IsPaused()) { | 347 if (download_->IsPaused()) { |
348 time_remaining = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); | 348 time_remaining = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); |
349 } else if (download_->TimeRemaining(&remaining)) { | 349 } else if (download_->TimeRemaining(&remaining)) { |
350 time_remaining = ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_REMAINING, | 350 time_remaining = ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_REMAINING, |
351 ui::TimeFormat::LENGTH_SHORT, | 351 ui::TimeFormat::LENGTH_SHORT, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 DCHECK(IsDangerous()); | 424 DCHECK(IsDangerous()); |
425 if (download_->GetDangerType() == | 425 if (download_->GetDangerType() == |
426 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE && | 426 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE && |
427 download_crx_util::IsExtensionDownload(*download_)) { | 427 download_crx_util::IsExtensionDownload(*download_)) { |
428 return l10n_util::GetStringUTF16(IDS_CONTINUE_EXTENSION_DOWNLOAD); | 428 return l10n_util::GetStringUTF16(IDS_CONTINUE_EXTENSION_DOWNLOAD); |
429 } else { | 429 } else { |
430 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD); | 430 return l10n_util::GetStringUTF16(IDS_CONFIRM_DOWNLOAD); |
431 } | 431 } |
432 } | 432 } |
433 | 433 |
434 int64 DownloadItemModel::GetCompletedBytes() const { | 434 int64_t DownloadItemModel::GetCompletedBytes() const { |
435 return download_->GetReceivedBytes(); | 435 return download_->GetReceivedBytes(); |
436 } | 436 } |
437 | 437 |
438 int64 DownloadItemModel::GetTotalBytes() const { | 438 int64_t DownloadItemModel::GetTotalBytes() const { |
439 return download_->AllDataSaved() ? download_->GetReceivedBytes() : | 439 return download_->AllDataSaved() ? download_->GetReceivedBytes() : |
440 download_->GetTotalBytes(); | 440 download_->GetTotalBytes(); |
441 } | 441 } |
442 | 442 |
443 // TODO(asanka,rdsmith): Once 'open' moves exclusively to the | 443 // TODO(asanka,rdsmith): Once 'open' moves exclusively to the |
444 // ChromeDownloadManagerDelegate, we should calculate the percentage here | 444 // ChromeDownloadManagerDelegate, we should calculate the percentage here |
445 // instead of calling into the DownloadItem. | 445 // instead of calling into the DownloadItem. |
446 int DownloadItemModel::PercentComplete() const { | 446 int DownloadItemModel::PercentComplete() const { |
447 return download_->PercentComplete(); | 447 return download_->PercentComplete(); |
448 } | 448 } |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 return data && data->is_being_revived_; | 624 return data && data->is_being_revived_; |
625 } | 625 } |
626 | 626 |
627 void DownloadItemModel::SetIsBeingRevived(bool is_being_revived) { | 627 void DownloadItemModel::SetIsBeingRevived(bool is_being_revived) { |
628 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_); | 628 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_); |
629 data->is_being_revived_ = is_being_revived; | 629 data->is_being_revived_ = is_being_revived; |
630 } | 630 } |
631 | 631 |
632 base::string16 DownloadItemModel::GetProgressSizesString() const { | 632 base::string16 DownloadItemModel::GetProgressSizesString() const { |
633 base::string16 size_ratio; | 633 base::string16 size_ratio; |
634 int64 size = GetCompletedBytes(); | 634 int64_t size = GetCompletedBytes(); |
635 int64 total = GetTotalBytes(); | 635 int64_t total = GetTotalBytes(); |
636 if (total > 0) { | 636 if (total > 0) { |
637 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total); | 637 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total); |
638 base::string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, fa
lse); | 638 base::string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, fa
lse); |
639 | 639 |
640 // In RTL locales, we render the text "size/total" in an RTL context. This | 640 // In RTL locales, we render the text "size/total" in an RTL context. This |
641 // is problematic since a string such as "123/456 MB" is displayed | 641 // is problematic since a string such as "123/456 MB" is displayed |
642 // as "MB 123/456" because it ends with an LTR run. In order to solve this, | 642 // as "MB 123/456" because it ends with an LTR run. In order to solve this, |
643 // we mark the total string as an LTR string if the UI layout is | 643 // we mark the total string as an LTR string if the UI layout is |
644 // right-to-left so that the string "456 MB" is treated as an LTR run. | 644 // right-to-left so that the string "456 MB" is treated as an LTR run. |
645 base::string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionalit
y( | 645 base::string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionalit
y( |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 if (!download_service) | 712 if (!download_service) |
713 return; | 713 return; |
714 | 714 |
715 ChromeDownloadManagerDelegate* delegate = | 715 ChromeDownloadManagerDelegate* delegate = |
716 download_service->GetDownloadManagerDelegate(); | 716 download_service->GetDownloadManagerDelegate(); |
717 if (!delegate) | 717 if (!delegate) |
718 return; | 718 return; |
719 delegate->OpenDownloadUsingPlatformHandler(download_); | 719 delegate->OpenDownloadUsingPlatformHandler(download_); |
720 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); | 720 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); |
721 } | 721 } |
OLD | NEW |