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

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

Issue 9968090: Added download error descriptions to tooltips for Mac & Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed GCC compile issue. Created 8 years, 8 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 | Annotate | Revision Log
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/string16.h" 9 #include "base/string16.h"
10 #include "base/sys_string_conversions.h" 10 #include "base/sys_string_conversions.h"
(...skipping 20 matching lines...) Expand all
31 // DownloadItemModel 31 // DownloadItemModel
32 32
33 DownloadItemModel::DownloadItemModel(DownloadItem* download) 33 DownloadItemModel::DownloadItemModel(DownloadItem* download)
34 : BaseDownloadItemModel(download) { 34 : BaseDownloadItemModel(download) {
35 } 35 }
36 36
37 void DownloadItemModel::CancelTask() { 37 void DownloadItemModel::CancelTask() {
38 download_->Cancel(true /* update history service */); 38 download_->Cancel(true /* update history service */);
39 } 39 }
40 40
41 string16 DownloadItemModel::GetProgressText() {
42 int64 size = 0;
43 int64 total= 0;
sky 2012/04/04 16:55:34 nit: 'total ='
ahendrickson 2012/04/04 17:49:32 Done.
44 string16 simple_size;
45 string16 simple_total;
46 GetStatusData(&size, &total, &simple_size, &simple_total);
47
48 if (total > 0) {
49 // We know the total.
50 return l10n_util::GetStringFUTF16(
51 IDS_DOWNLOAD_STATUS_IN_PROGRESS_SIZES_ONLY, simple_size, simple_total);
52 }
53
54 return ui::FormatBytes(size);
55 }
56
41 string16 DownloadItemModel::GetStatusText() { 57 string16 DownloadItemModel::GetStatusText() {
42 int64 size = download_->GetReceivedBytes(); 58 int64 size = 0;
43 int64 total = download_->AllDataSaved() ? size : download_->GetTotalBytes(); 59 int64 total= 0;
44 bool is_gdata = false; 60 string16 simple_size;
45 #if defined(OS_CHROMEOS) 61 string16 simple_total;
46 is_gdata = gdata::GDataDownloadObserver::IsGDataDownload(download_); 62 bool is_gdata = GetStatusData(&size, &total, &simple_size, &simple_total);
47 // For GData downloads, the size is the count of bytes uploaded.
48 if (is_gdata)
49 size = gdata::GDataDownloadObserver::GetUploadedBytes(download_);
50 #endif
51
52 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total);
53 string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, false);
54
55 // In RTL locales, we render the text "size/total" in an RTL context. This
56 // is problematic since a string such as "123/456 MB" is displayed
57 // as "MB 123/456" because it ends with an LTR run. In order to solve this,
58 // we mark the total string as an LTR string if the UI layout is
59 // right-to-left so that the string "456 MB" is treated as an LTR run.
60 string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality(
61 ui::FormatBytesWithUnits(total, amount_units, true));
62 63
63 // TODO(asanka): Calculate a TimeRemaining() for GData uploads. 64 // TODO(asanka): Calculate a TimeRemaining() for GData uploads.
64 TimeDelta remaining; 65 TimeDelta remaining;
65 string16 simple_time; 66 string16 simple_time;
66 if (download_->IsInProgress() && download_->IsPaused()) { 67 if (download_->IsInProgress() && download_->IsPaused()) {
67 simple_time = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); 68 simple_time = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED);
68 } else if (!is_gdata && download_->TimeRemaining(&remaining)) { 69 } else if (!is_gdata && download_->TimeRemaining(&remaining)) {
69 simple_time = download_->GetOpenWhenComplete() ? 70 simple_time = download_->GetOpenWhenComplete() ?
70 TimeFormat::TimeRemainingShort(remaining) : 71 TimeFormat::TimeRemainingShort(remaining) :
71 TimeFormat::TimeRemaining(remaining); 72 TimeFormat::TimeRemaining(remaining);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 return false; 231 return false;
231 } 232 }
232 NOTREACHED(); 233 NOTREACHED();
233 return false; 234 return false;
234 } 235 }
235 236
236 bool DownloadItemModel::IsDangerous() { 237 bool DownloadItemModel::IsDangerous() {
237 return download_->GetSafetyState() == DownloadItem::DANGEROUS; 238 return download_->GetSafetyState() == DownloadItem::DANGEROUS;
238 } 239 }
239 240
241 bool DownloadItemModel::GetStatusData(int64* size_return,
242 int64* total_return,
243 string16* simple_size_return,
244 string16* simple_total_return) {
245 int64 size = download_->GetReceivedBytes();
246 int64 total = download_->AllDataSaved() ? size : download_->GetTotalBytes();
247 bool is_gdata = false;
248
249 #if defined(OS_CHROMEOS)
250 is_gdata = gdata::GDataDownloadObserver::IsGDataDownload(download_);
251 // For GData downloads, the size is the count of bytes uploaded.
252 if (is_gdata)
253 size = gdata::GDataDownloadObserver::GetUploadedBytes(download_);
254 #endif
255
256 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total);
257 string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, false);
258
259 // In RTL locales, we render the text "size/total" in an RTL context. This
260 // is problematic since a string such as "123/456 MB" is displayed
261 // as "MB 123/456" because it ends with an LTR run. In order to solve this,
262 // we mark the total string as an LTR string if the UI layout is
263 // right-to-left so that the string "456 MB" is treated as an LTR run.
264 string16 simple_total = base::i18n::GetDisplayStringInLTRDirectionality(
265 ui::FormatBytesWithUnits(total, amount_units, true));
266
267 if (size_return)
268 *size_return = size;
269 if (total_return)
270 *total_return = total;
271 if (simple_size_return)
272 *simple_size_return = simple_size;
273 if (simple_total_return)
274 *simple_total_return = simple_total;
275
276 return is_gdata;
277 }
278
240 // static 279 // static
241 string16 BaseDownloadItemModel::InterruptReasonStatusMessage(int reason) { 280 string16 BaseDownloadItemModel::InterruptReasonStatusMessage(int reason) {
242 int string_id = 0; 281 int string_id = 0;
243 282
244 switch (reason) { 283 switch (reason) {
245 case content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED: 284 case content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED:
246 string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_ACCESS_DENIED; 285 string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_ACCESS_DENIED;
247 break; 286 break;
248 case content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE: 287 case content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE:
249 string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_DISK_FULL; 288 string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_DISK_FULL;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 break; 385 break;
347 default: 386 default:
348 string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS; 387 string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS;
349 break; 388 break;
350 } 389 }
351 390
352 status_text = l10n_util::GetStringUTF16(string_id); 391 status_text = l10n_util::GetStringUTF16(string_id);
353 392
354 return status_text; 393 return status_text;
355 } 394 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698