Index: chrome/browser/download/download_item_model.cc |
diff --git a/chrome/browser/download/download_item_model.cc b/chrome/browser/download/download_item_model.cc |
index 87785ea66190ede4af9ec9db2d819e118a9ea11e..0eb9a8230f186ecdc6c71524c827a5c8c40cfd8c 100644 |
--- a/chrome/browser/download/download_item_model.cc |
+++ b/chrome/browser/download/download_item_model.cc |
@@ -38,27 +38,28 @@ void DownloadItemModel::CancelTask() { |
download_->Cancel(true /* update history service */); |
} |
-string16 DownloadItemModel::GetStatusText() { |
- int64 size = download_->GetReceivedBytes(); |
- int64 total = download_->AllDataSaved() ? size : download_->GetTotalBytes(); |
- bool is_gdata = false; |
-#if defined(OS_CHROMEOS) |
- is_gdata = gdata::GDataDownloadObserver::IsGDataDownload(download_); |
- // For GData downloads, the size is the count of bytes uploaded. |
- if (is_gdata) |
- size = gdata::GDataDownloadObserver::GetUploadedBytes(download_); |
-#endif |
+string16 DownloadItemModel::GetProgressText() { |
+ int64 size = 0; |
+ int64 total= 0; |
sky
2012/04/04 16:55:34
nit: 'total ='
ahendrickson
2012/04/04 17:49:32
Done.
|
+ string16 simple_size; |
+ string16 simple_total; |
+ GetStatusData(&size, &total, &simple_size, &simple_total); |
- ui::DataUnits amount_units = ui::GetByteDisplayUnits(total); |
- string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, false); |
+ if (total > 0) { |
+ // We know the total. |
+ return l10n_util::GetStringFUTF16( |
+ IDS_DOWNLOAD_STATUS_IN_PROGRESS_SIZES_ONLY, simple_size, simple_total); |
+ } |
- // In RTL locales, we render the text "size/total" in an RTL context. This |
- // is problematic since a string such as "123/456 MB" is displayed |
- // as "MB 123/456" because it ends with an LTR run. In order to solve this, |
- // we mark the total string as an LTR string if the UI layout is |
- // right-to-left so that the string "456 MB" is treated as an LTR run. |
- string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality( |
- ui::FormatBytesWithUnits(total, amount_units, true)); |
+ return ui::FormatBytes(size); |
+} |
+ |
+string16 DownloadItemModel::GetStatusText() { |
+ int64 size = 0; |
+ int64 total= 0; |
+ string16 simple_size; |
+ string16 simple_total; |
+ bool is_gdata = GetStatusData(&size, &total, &simple_size, &simple_total); |
// TODO(asanka): Calculate a TimeRemaining() for GData uploads. |
TimeDelta remaining; |
@@ -237,6 +238,44 @@ bool DownloadItemModel::IsDangerous() { |
return download_->GetSafetyState() == DownloadItem::DANGEROUS; |
} |
+bool DownloadItemModel::GetStatusData(int64* size_return, |
+ int64* total_return, |
+ string16* simple_size_return, |
+ string16* simple_total_return) { |
+ int64 size = download_->GetReceivedBytes(); |
+ int64 total = download_->AllDataSaved() ? size : download_->GetTotalBytes(); |
+ bool is_gdata = false; |
+ |
+#if defined(OS_CHROMEOS) |
+ is_gdata = gdata::GDataDownloadObserver::IsGDataDownload(download_); |
+ // For GData downloads, the size is the count of bytes uploaded. |
+ if (is_gdata) |
+ size = gdata::GDataDownloadObserver::GetUploadedBytes(download_); |
+#endif |
+ |
+ ui::DataUnits amount_units = ui::GetByteDisplayUnits(total); |
+ string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, false); |
+ |
+ // In RTL locales, we render the text "size/total" in an RTL context. This |
+ // is problematic since a string such as "123/456 MB" is displayed |
+ // as "MB 123/456" because it ends with an LTR run. In order to solve this, |
+ // we mark the total string as an LTR string if the UI layout is |
+ // right-to-left so that the string "456 MB" is treated as an LTR run. |
+ string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality( |
+ ui::FormatBytesWithUnits(total, amount_units, true)); |
+ |
+ if (size_return) |
+ *size_return = size; |
+ if (total_return) |
+ *total_return = total; |
+ if (simple_size_return) |
+ *simple_size_return = simple_size; |
+ if (simple_total_return) |
+ *simple_total_return = simple_total; |
+ |
+ return is_gdata; |
+} |
+ |
// static |
string16 BaseDownloadItemModel::InterruptReasonStatusMessage(int reason) { |
int string_id = 0; |