OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 // Download utility implementation | 5 // Download utility implementation |
6 | 6 |
7 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
11 #endif | 11 #endif |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "app/gfx/canvas.h" | 14 #include "app/gfx/canvas.h" |
15 #include "app/l10n_util.h" | 15 #include "app/l10n_util.h" |
16 #include "app/resource_bundle.h" | 16 #include "app/resource_bundle.h" |
17 #include "base/file_util.h" | 17 #include "base/file_util.h" |
| 18 #include "base/i18n/rtl.h" |
18 #include "base/i18n/time_formatting.h" | 19 #include "base/i18n/time_formatting.h" |
19 #include "base/path_service.h" | 20 #include "base/path_service.h" |
20 #include "base/singleton.h" | 21 #include "base/singleton.h" |
21 #include "base/string_util.h" | 22 #include "base/string_util.h" |
22 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
23 #include "base/values.h" | 24 #include "base/values.h" |
24 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
25 #include "chrome/browser/download/download_item_model.h" | 26 #include "chrome/browser/download/download_item_model.h" |
26 #include "chrome/browser/download/download_manager.h" | 27 #include "chrome/browser/download/download_manager.h" |
27 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 file_value->SetInteger(L"started", | 360 file_value->SetInteger(L"started", |
360 static_cast<int>(download->start_time().ToTimeT())); | 361 static_cast<int>(download->start_time().ToTimeT())); |
361 file_value->SetString(L"since_string", | 362 file_value->SetString(L"since_string", |
362 TimeFormat::RelativeDate(download->start_time(), NULL)); | 363 TimeFormat::RelativeDate(download->start_time(), NULL)); |
363 file_value->SetString(L"date_string", | 364 file_value->SetString(L"date_string", |
364 base::TimeFormatShortDate(download->start_time())); | 365 base::TimeFormatShortDate(download->start_time())); |
365 file_value->SetInteger(L"id", id); | 366 file_value->SetInteger(L"id", id); |
366 file_value->SetString(L"file_path", download->full_path().ToWStringHack()); | 367 file_value->SetString(L"file_path", download->full_path().ToWStringHack()); |
367 // Keep file names as LTR. | 368 // Keep file names as LTR. |
368 std::wstring file_name = download->GetFileName().ToWStringHack(); | 369 std::wstring file_name = download->GetFileName().ToWStringHack(); |
369 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) | 370 if (base::i18n::IsRTL()) |
370 l10n_util::WrapStringWithLTRFormatting(&file_name); | 371 base::i18n::WrapStringWithLTRFormatting(&file_name); |
371 file_value->SetString(L"file_name", file_name); | 372 file_value->SetString(L"file_name", file_name); |
372 file_value->SetString(L"url", download->url().spec()); | 373 file_value->SetString(L"url", download->url().spec()); |
373 file_value->SetBoolean(L"otr", download->is_otr()); | 374 file_value->SetBoolean(L"otr", download->is_otr()); |
374 | 375 |
375 if (download->state() == DownloadItem::IN_PROGRESS) { | 376 if (download->state() == DownloadItem::IN_PROGRESS) { |
376 if (download->safety_state() == DownloadItem::DANGEROUS) { | 377 if (download->safety_state() == DownloadItem::DANGEROUS) { |
377 file_value->SetString(L"state", L"DANGEROUS"); | 378 file_value->SetString(L"state", L"DANGEROUS"); |
378 } else if (download->is_paused()) { | 379 } else if (download->is_paused()) { |
379 file_value->SetString(L"state", L"PAUSED"); | 380 file_value->SetString(L"state", L"PAUSED"); |
380 } else { | 381 } else { |
(...skipping 26 matching lines...) Expand all Loading... |
407 std::wstring GetProgressStatusText(DownloadItem* download) { | 408 std::wstring GetProgressStatusText(DownloadItem* download) { |
408 int64 total = download->total_bytes(); | 409 int64 total = download->total_bytes(); |
409 int64 size = download->received_bytes(); | 410 int64 size = download->received_bytes(); |
410 DataUnits amount_units = GetByteDisplayUnits(size); | 411 DataUnits amount_units = GetByteDisplayUnits(size); |
411 std::wstring received_size = FormatBytes(size, amount_units, true); | 412 std::wstring received_size = FormatBytes(size, amount_units, true); |
412 std::wstring amount = received_size; | 413 std::wstring amount = received_size; |
413 | 414 |
414 // Adjust both strings for the locale direction since we don't yet know which | 415 // Adjust both strings for the locale direction since we don't yet know which |
415 // string we'll end up using for constructing the final progress string. | 416 // string we'll end up using for constructing the final progress string. |
416 std::wstring amount_localized; | 417 std::wstring amount_localized; |
417 if (l10n_util::AdjustStringForLocaleDirection(amount, &amount_localized)) { | 418 if (base::i18n::AdjustStringForLocaleDirection(amount, &amount_localized)) { |
418 amount.assign(amount_localized); | 419 amount.assign(amount_localized); |
419 received_size.assign(amount_localized); | 420 received_size.assign(amount_localized); |
420 } | 421 } |
421 | 422 |
422 if (total) { | 423 if (total) { |
423 amount_units = GetByteDisplayUnits(total); | 424 amount_units = GetByteDisplayUnits(total); |
424 std::wstring total_text = FormatBytes(total, amount_units, true); | 425 std::wstring total_text = FormatBytes(total, amount_units, true); |
425 std::wstring total_text_localized; | 426 std::wstring total_text_localized; |
426 if (l10n_util::AdjustStringForLocaleDirection(total_text, | 427 if (base::i18n::AdjustStringForLocaleDirection(total_text, |
427 &total_text_localized)) | 428 &total_text_localized)) |
428 total_text.assign(total_text_localized); | 429 total_text.assign(total_text_localized); |
429 | 430 |
430 amount = l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_SIZE, | 431 amount = l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_SIZE, |
431 received_size, | 432 received_size, |
432 total_text); | 433 total_text); |
433 } else { | 434 } else { |
434 amount.assign(received_size); | 435 amount.assign(received_size); |
435 } | 436 } |
436 amount_units = GetByteDisplayUnits(download->CurrentSpeed()); | 437 amount_units = GetByteDisplayUnits(download->CurrentSpeed()); |
437 std::wstring speed_text = FormatSpeed(download->CurrentSpeed(), | 438 std::wstring speed_text = FormatSpeed(download->CurrentSpeed(), |
438 amount_units, true); | 439 amount_units, true); |
439 std::wstring speed_text_localized; | 440 std::wstring speed_text_localized; |
440 if (l10n_util::AdjustStringForLocaleDirection(speed_text, | 441 if (base::i18n::AdjustStringForLocaleDirection(speed_text, |
441 &speed_text_localized)) | 442 &speed_text_localized)) |
442 speed_text.assign(speed_text_localized); | 443 speed_text.assign(speed_text_localized); |
443 | 444 |
444 base::TimeDelta remaining; | 445 base::TimeDelta remaining; |
445 std::wstring time_remaining; | 446 std::wstring time_remaining; |
446 if (download->is_paused()) | 447 if (download->is_paused()) |
447 time_remaining = l10n_util::GetString(IDS_DOWNLOAD_PROGRESS_PAUSED); | 448 time_remaining = l10n_util::GetString(IDS_DOWNLOAD_PROGRESS_PAUSED); |
448 else if (download->TimeRemaining(&remaining)) | 449 else if (download->TimeRemaining(&remaining)) |
449 time_remaining = TimeFormat::TimeRemaining(remaining); | 450 time_remaining = TimeFormat::TimeRemaining(remaining); |
450 | 451 |
451 if (time_remaining.empty()) { | 452 if (time_remaining.empty()) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 else if (!progress_known) | 489 else if (!progress_known) |
489 taskbar->SetProgressState(frame, TBPF_INDETERMINATE); | 490 taskbar->SetProgressState(frame, TBPF_INDETERMINATE); |
490 else | 491 else |
491 taskbar->SetProgressValue(frame, (int)(progress * 100), 100); | 492 taskbar->SetProgressValue(frame, (int)(progress * 100), 100); |
492 } | 493 } |
493 #endif | 494 #endif |
494 } | 495 } |
495 #endif | 496 #endif |
496 | 497 |
497 } // namespace download_util | 498 } // namespace download_util |
OLD | NEW |