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

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

Issue 5959008: Remove wstring from l10n_util. Part 2.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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>
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 info->referrer_charset, 179 info->referrer_charset,
180 info->mime_type, 180 info->mime_type,
181 generated_name); 181 generated_name);
182 } 182 }
183 183
184 void GenerateFileName(const GURL& url, 184 void GenerateFileName(const GURL& url,
185 const std::string& content_disposition, 185 const std::string& content_disposition,
186 const std::string& referrer_charset, 186 const std::string& referrer_charset,
187 const std::string& mime_type, 187 const std::string& mime_type,
188 FilePath* generated_name) { 188 FilePath* generated_name) {
189 std::wstring default_name =
190 l10n_util::GetString(IDS_DEFAULT_DOWNLOAD_FILENAME);
191 #if defined(OS_WIN) 189 #if defined(OS_WIN)
192 FilePath default_file_path(default_name); 190 FilePath default_file_path(
191 l10n_util::GetStringUTF16(IDS_DEFAULT_DOWNLOAD_FILENAME));
193 #elif defined(OS_POSIX) 192 #elif defined(OS_POSIX)
194 FilePath default_file_path(base::SysWideToNativeMB(default_name)); 193 FilePath default_file_path(
194 l10n_util::GetStringUTF8(IDS_DEFAULT_DOWNLOAD_FILENAME));
Evan Stade 2010/12/28 21:23:09 I think this is wrong for encodings that are not u
Avi (use Gerrit) 2010/12/28 21:35:44 Done.
195 #endif 195 #endif
196 196
197 *generated_name = net::GetSuggestedFilename(GURL(url), 197 *generated_name = net::GetSuggestedFilename(GURL(url),
198 content_disposition, 198 content_disposition,
199 referrer_charset, 199 referrer_charset,
200 default_file_path); 200 default_file_path);
201 201
202 DCHECK(!generated_name->empty()); 202 DCHECK(!generated_name->empty());
203 203
204 GenerateSafeFileName(mime_type, generated_name); 204 GenerateSafeFileName(mime_type, generated_name);
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 if (download->state() == DownloadItem::IN_PROGRESS) { 504 if (download->state() == DownloadItem::IN_PROGRESS) {
505 if (download->safety_state() == DownloadItem::DANGEROUS) { 505 if (download->safety_state() == DownloadItem::DANGEROUS) {
506 file_value->SetString("state", "DANGEROUS"); 506 file_value->SetString("state", "DANGEROUS");
507 } else if (download->is_paused()) { 507 } else if (download->is_paused()) {
508 file_value->SetString("state", "PAUSED"); 508 file_value->SetString("state", "PAUSED");
509 } else { 509 } else {
510 file_value->SetString("state", "IN_PROGRESS"); 510 file_value->SetString("state", "IN_PROGRESS");
511 } 511 }
512 512
513 file_value->SetString("progress_status_text", 513 file_value->SetString("progress_status_text",
514 WideToUTF16Hack(GetProgressStatusText(download))); 514 GetProgressStatusText(download));
515 515
516 file_value->SetInteger("percent", 516 file_value->SetInteger("percent",
517 static_cast<int>(download->PercentComplete())); 517 static_cast<int>(download->PercentComplete()));
518 file_value->SetInteger("received", 518 file_value->SetInteger("received",
519 static_cast<int>(download->received_bytes())); 519 static_cast<int>(download->received_bytes()));
520 } else if (download->state() == DownloadItem::CANCELLED) { 520 } else if (download->state() == DownloadItem::CANCELLED) {
521 file_value->SetString("state", "CANCELLED"); 521 file_value->SetString("state", "CANCELLED");
522 } else if (download->state() == DownloadItem::COMPLETE) { 522 } else if (download->state() == DownloadItem::COMPLETE) {
523 if (download->safety_state() == DownloadItem::DANGEROUS) { 523 if (download->safety_state() == DownloadItem::DANGEROUS) {
524 file_value->SetString("state", "DANGEROUS"); 524 file_value->SetString("state", "DANGEROUS");
525 } else { 525 } else {
526 file_value->SetString("state", "COMPLETE"); 526 file_value->SetString("state", "COMPLETE");
527 } 527 }
528 } 528 }
529 529
530 file_value->SetInteger("total", 530 file_value->SetInteger("total",
531 static_cast<int>(download->total_bytes())); 531 static_cast<int>(download->total_bytes()));
532 532
533 return file_value; 533 return file_value;
534 } 534 }
535 535
536 std::wstring GetProgressStatusText(DownloadItem* download) { 536 string16 GetProgressStatusText(DownloadItem* download) {
537 int64 total = download->total_bytes(); 537 int64 total = download->total_bytes();
538 int64 size = download->received_bytes(); 538 int64 size = download->received_bytes();
539 DataUnits amount_units = GetByteDisplayUnits(size); 539 DataUnits amount_units = GetByteDisplayUnits(size);
540 std::wstring received_size = UTF16ToWideHack(FormatBytes(size, amount_units, 540 string16 received_size = FormatBytes(size, amount_units, true);
541 true)); 541 string16 amount = received_size;
542 std::wstring amount = received_size;
543 542
544 // Adjust both strings for the locale direction since we don't yet know which 543 // Adjust both strings for the locale direction since we don't yet know which
545 // string we'll end up using for constructing the final progress string. 544 // string we'll end up using for constructing the final progress string.
546 base::i18n::AdjustStringForLocaleDirection(&amount); 545 base::i18n::AdjustStringForLocaleDirection(&amount);
547 546
548 if (total) { 547 if (total) {
549 amount_units = GetByteDisplayUnits(total); 548 amount_units = GetByteDisplayUnits(total);
550 std::wstring total_text = 549 string16 total_text = FormatBytes(total, amount_units, true);
551 UTF16ToWideHack(FormatBytes(total, amount_units, true));
552 base::i18n::AdjustStringForLocaleDirection(&total_text); 550 base::i18n::AdjustStringForLocaleDirection(&total_text);
553 551
554 base::i18n::AdjustStringForLocaleDirection(&received_size); 552 base::i18n::AdjustStringForLocaleDirection(&received_size);
555 amount = l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_SIZE, 553 amount = l10n_util::GetStringFUTF16(IDS_DOWNLOAD_TAB_PROGRESS_SIZE,
556 received_size, 554 received_size,
557 total_text); 555 total_text);
558 } else { 556 } else {
559 amount.assign(received_size); 557 amount.assign(received_size);
560 } 558 }
561 int64 current_speed = download->CurrentSpeed(); 559 int64 current_speed = download->CurrentSpeed();
562 amount_units = GetByteDisplayUnits(current_speed); 560 amount_units = GetByteDisplayUnits(current_speed);
563 std::wstring speed_text = UTF16ToWideHack(FormatSpeed(current_speed, 561 string16 speed_text = FormatSpeed(current_speed, amount_units, true);
564 amount_units, true));
565 base::i18n::AdjustStringForLocaleDirection(&speed_text); 562 base::i18n::AdjustStringForLocaleDirection(&speed_text);
566 563
567 base::TimeDelta remaining; 564 base::TimeDelta remaining;
568 string16 time_remaining; 565 string16 time_remaining;
569 if (download->is_paused()) 566 if (download->is_paused())
570 time_remaining = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED); 567 time_remaining = l10n_util::GetStringUTF16(IDS_DOWNLOAD_PROGRESS_PAUSED);
571 else if (download->TimeRemaining(&remaining)) 568 else if (download->TimeRemaining(&remaining))
572 time_remaining = TimeFormat::TimeRemaining(remaining); 569 time_remaining = TimeFormat::TimeRemaining(remaining);
573 570
574 if (time_remaining.empty()) { 571 if (time_remaining.empty()) {
575 base::i18n::AdjustStringForLocaleDirection(&amount); 572 base::i18n::AdjustStringForLocaleDirection(&amount);
576 return l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN, 573 return l10n_util::GetStringFUTF16(
577 speed_text, amount); 574 IDS_DOWNLOAD_TAB_PROGRESS_STATUS_TIME_UNKNOWN, speed_text, amount);
578 } 575 }
579 return l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_STATUS, speed_text, 576 return l10n_util::GetStringFUTF16(IDS_DOWNLOAD_TAB_PROGRESS_STATUS,
580 amount, UTF16ToWideHack(time_remaining)); 577 speed_text, amount, time_remaining);
581 } 578 }
582 579
583 #if !defined(OS_MACOSX) 580 #if !defined(OS_MACOSX)
584 void UpdateAppIconDownloadProgress(int download_count, 581 void UpdateAppIconDownloadProgress(int download_count,
585 bool progress_known, 582 bool progress_known,
586 float progress) { 583 float progress) {
587 #if defined(OS_WIN) 584 #if defined(OS_WIN)
588 // Taskbar progress bar is only supported on Win7. 585 // Taskbar progress bar is only supported on Win7.
589 if (base::win::GetVersion() < base::win::VERSION_WIN7) 586 if (base::win::GetVersion() < base::win::VERSION_WIN7)
590 return; 587 return;
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 !service->IsDownloadFromGallery(info->url, info->referrer_url)) { 733 !service->IsDownloadFromGallery(info->url, info->referrer_url)) {
737 // Extensions that are not from the gallery are considered dangerous. 734 // Extensions that are not from the gallery are considered dangerous.
738 return true; 735 return true;
739 } 736 }
740 } 737 }
741 738
742 return false; 739 return false;
743 } 740 }
744 741
745 } // namespace download_util 742 } // namespace download_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698