OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/string16.h" | 9 #include "base/string16.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 | 23 |
24 DownloadItemModel::DownloadItemModel(DownloadItem* download) | 24 DownloadItemModel::DownloadItemModel(DownloadItem* download) |
25 : BaseDownloadItemModel(download) { | 25 : BaseDownloadItemModel(download) { |
26 } | 26 } |
27 | 27 |
28 void DownloadItemModel::CancelTask() { | 28 void DownloadItemModel::CancelTask() { |
29 download_->Cancel(true /* update history service */); | 29 download_->Cancel(true /* update history service */); |
30 } | 30 } |
31 | 31 |
32 string16 DownloadItemModel::GetStatusText() { | 32 string16 DownloadItemModel::GetStatusText() { |
33 int64 size = download_->received_bytes(); | 33 int64 size = download_->GetReceivedBytes(); |
34 int64 total = download_->total_bytes(); | 34 int64 total = download_->GetTotalBytes(); |
35 | 35 |
36 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total); | 36 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total); |
37 string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, false); | 37 string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, false); |
38 | 38 |
39 // In RTL locales, we render the text "size/total" in an RTL context. This | 39 // In RTL locales, we render the text "size/total" in an RTL context. This |
40 // is problematic since a string such as "123/456 MB" is displayed | 40 // is problematic since a string such as "123/456 MB" is displayed |
41 // as "MB 123/456" because it ends with an LTR run. In order to solve this, | 41 // as "MB 123/456" because it ends with an LTR run. In order to solve this, |
42 // we mark the total string as an LTR string if the UI layout is | 42 // we mark the total string as an LTR string if the UI layout is |
43 // right-to-left so that the string "456 MB" is treated as an LTR run. | 43 // right-to-left so that the string "456 MB" is treated as an LTR run. |
44 string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality( | 44 string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality( |
45 ui::FormatBytesWithUnits(total, amount_units, true)); | 45 ui::FormatBytesWithUnits(total, amount_units, true)); |
46 | 46 |
47 TimeDelta remaining; | 47 TimeDelta remaining; |
48 string16 simple_time; | 48 string16 simple_time; |
49 if (download_->IsInProgress() && download_->is_paused()) { | 49 if (download_->IsInProgress() && download_->IsPaused()) { |
50 simple_time = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); | 50 simple_time = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); |
51 } else if (download_->TimeRemaining(&remaining)) { | 51 } else if (download_->TimeRemaining(&remaining)) { |
52 simple_time = download_->open_when_complete() ? | 52 simple_time = download_->GetOpenWhenComplete() ? |
53 TimeFormat::TimeRemainingShort(remaining) : | 53 TimeFormat::TimeRemainingShort(remaining) : |
54 TimeFormat::TimeRemaining(remaining); | 54 TimeFormat::TimeRemaining(remaining); |
55 } | 55 } |
56 | 56 |
57 string16 status_text; | 57 string16 status_text; |
58 switch (download_->state()) { | 58 switch (download_->GetState()) { |
59 case DownloadItem::IN_PROGRESS: | 59 case DownloadItem::IN_PROGRESS: |
60 if (ChromeDownloadManagerDelegate::IsExtensionDownload(download_) && | 60 if (ChromeDownloadManagerDelegate::IsExtensionDownload(download_) && |
61 download_->all_data_saved() && | 61 download_->AllDataSaved() && |
62 download_->state() == DownloadItem::IN_PROGRESS) { | 62 download_->GetState() == DownloadItem::IN_PROGRESS) { |
63 // The download is a CRX (app, extension, theme, ...) and it is | 63 // The download is a CRX (app, extension, theme, ...) and it is |
64 // being unpacked and validated. | 64 // being unpacked and validated. |
65 status_text = l10n_util::GetStringUTF16( | 65 status_text = l10n_util::GetStringUTF16( |
66 IDS_DOWNLOAD_STATUS_CRX_INSTALL_RUNNING); | 66 IDS_DOWNLOAD_STATUS_CRX_INSTALL_RUNNING); |
67 } else if (download_->open_when_complete()) { | 67 } else if (download_->GetOpenWhenComplete()) { |
68 if (simple_time.empty()) { | 68 if (simple_time.empty()) { |
69 status_text = | 69 status_text = |
70 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE); | 70 l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_OPEN_WHEN_COMPLETE); |
71 } else { | 71 } else { |
72 status_text = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPEN_IN, | 72 status_text = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_STATUS_OPEN_IN, |
73 simple_time); | 73 simple_time); |
74 } | 74 } |
75 } else { | 75 } else { |
76 if (simple_time.empty()) { | 76 if (simple_time.empty()) { |
77 // Instead of displaying "0 B" we keep the "Starting..." string. | 77 // Instead of displaying "0 B" we keep the "Starting..." string. |
78 status_text = (size == 0) | 78 status_text = (size == 0) |
79 ? l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING) | 79 ? l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_STARTING) |
80 : ui::FormatBytes(size); | 80 : ui::FormatBytes(size); |
81 } else { | 81 } else { |
82 status_text = l10n_util::GetStringFUTF16( | 82 status_text = l10n_util::GetStringFUTF16( |
83 IDS_DOWNLOAD_STATUS_IN_PROGRESS, simple_size, simple_total, | 83 IDS_DOWNLOAD_STATUS_IN_PROGRESS, simple_size, simple_total, |
84 simple_time); | 84 simple_time); |
85 } | 85 } |
86 } | 86 } |
87 break; | 87 break; |
88 case DownloadItem::COMPLETE: | 88 case DownloadItem::COMPLETE: |
89 if (download_->file_externally_removed()) { | 89 if (download_->GetFileExternallyRemoved()) { |
90 status_text = l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED); | 90 status_text = l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_REMOVED); |
91 } else { | 91 } else { |
92 status_text.clear(); | 92 status_text.clear(); |
93 } | 93 } |
94 break; | 94 break; |
95 case DownloadItem::CANCELLED: | 95 case DownloadItem::CANCELLED: |
96 status_text = l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_CANCELED); | 96 status_text = l10n_util::GetStringUTF16(IDS_DOWNLOAD_STATUS_CANCELED); |
97 break; | 97 break; |
98 case DownloadItem::REMOVING: | 98 case DownloadItem::REMOVING: |
99 break; | 99 break; |
(...skipping 15 matching lines...) Expand all Loading... |
115 SavePageModel::SavePageModel(SavePackage* save, DownloadItem* download) | 115 SavePageModel::SavePageModel(SavePackage* save, DownloadItem* download) |
116 : BaseDownloadItemModel(download), | 116 : BaseDownloadItemModel(download), |
117 save_(save) { | 117 save_(save) { |
118 } | 118 } |
119 | 119 |
120 void SavePageModel::CancelTask() { | 120 void SavePageModel::CancelTask() { |
121 save_->Cancel(true); | 121 save_->Cancel(true); |
122 } | 122 } |
123 | 123 |
124 string16 SavePageModel::GetStatusText() { | 124 string16 SavePageModel::GetStatusText() { |
125 int64 size = download_->received_bytes(); | 125 int64 size = download_->GetReceivedBytes(); |
126 int64 total_size = download_->total_bytes(); | 126 int64 total_size = download_->GetTotalBytes(); |
127 | 127 |
128 string16 status_text; | 128 string16 status_text; |
129 switch (download_->state()) { | 129 switch (download_->GetState()) { |
130 case DownloadItem::IN_PROGRESS: | 130 case DownloadItem::IN_PROGRESS: |
131 status_text = l10n_util::GetStringFUTF16( | 131 status_text = l10n_util::GetStringFUTF16( |
132 IDS_SAVE_PAGE_PROGRESS, | 132 IDS_SAVE_PAGE_PROGRESS, |
133 base::FormatNumber(size), | 133 base::FormatNumber(size), |
134 base::FormatNumber(total_size)); | 134 base::FormatNumber(total_size)); |
135 break; | 135 break; |
136 case DownloadItem::COMPLETE: | 136 case DownloadItem::COMPLETE: |
137 status_text = l10n_util::GetStringUTF16(IDS_SAVE_PAGE_STATUS_COMPLETED); | 137 status_text = l10n_util::GetStringUTF16(IDS_SAVE_PAGE_STATUS_COMPLETED); |
138 break; | 138 break; |
139 case DownloadItem::CANCELLED: | 139 case DownloadItem::CANCELLED: |
140 status_text = l10n_util::GetStringUTF16(IDS_SAVE_PAGE_STATUS_CANCELED); | 140 status_text = l10n_util::GetStringUTF16(IDS_SAVE_PAGE_STATUS_CANCELED); |
141 break; | 141 break; |
142 case DownloadItem::REMOVING: | 142 case DownloadItem::REMOVING: |
143 break; | 143 break; |
144 case DownloadItem::INTERRUPTED: | 144 case DownloadItem::INTERRUPTED: |
145 status_text = l10n_util::GetStringFUTF16( | 145 status_text = l10n_util::GetStringFUTF16( |
146 IDS_SAVE_PAGE_STATUS_INTERRUPTED, | 146 IDS_SAVE_PAGE_STATUS_INTERRUPTED, |
147 base::FormatNumber(size), | 147 base::FormatNumber(size), |
148 base::FormatNumber(total_size)); | 148 base::FormatNumber(total_size)); |
149 break; | 149 break; |
150 default: | 150 default: |
151 NOTREACHED(); | 151 NOTREACHED(); |
152 } | 152 } |
153 | 153 |
154 return status_text; | 154 return status_text; |
155 } | 155 } |
OLD | NEW |