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

Side by Side Diff: chrome/browser/dom_ui/downloads_ui.cc

Issue 42550: Add a progress meter to the downloads page.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/dom_ui/downloads_ui.h" 5 #include "chrome/browser/dom_ui/downloads_ui.h"
6 6
7 #include "base/gfx/png_encoder.h" 7 #include "base/gfx/png_encoder.h"
8 #include "base/string_piece.h" 8 #include "base/string_piece.h"
9 #include "base/thread.h" 9 #include "base/thread.h"
10 #include "base/time_format.h" 10 #include "base/time_format.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 171
172 // Clear all download items and their observers. 172 // Clear all download items and their observers.
173 void ClearDownloadItems(); 173 void ClearDownloadItems();
174 174
175 // Return the download that corresponds to a given id. 175 // Return the download that corresponds to a given id.
176 DownloadItem* GetDownloadById(int id); 176 DownloadItem* GetDownloadById(int id);
177 177
178 // Return the download that is referred to in a given value. 178 // Return the download that is referred to in a given value.
179 DownloadItem* GetDownloadByValue(const Value* value); 179 DownloadItem* GetDownloadByValue(const Value* value);
180 180
181 // Get the localized status text for an in-progress download.
182 std::wstring GetProgressStatusText(DownloadItem* download);
183
181 // Current search text. 184 // Current search text.
182 std::wstring search_text_; 185 std::wstring search_text_;
183 186
184 // Our model 187 // Our model
185 DownloadManager* download_manager_; 188 DownloadManager* download_manager_;
186 189
187 // The current set of visible DownloadItems for this view received from the 190 // The current set of visible DownloadItems for this view received from the
188 // DownloadManager. DownloadManager owns the DownloadItems. The vector is 191 // DownloadManager. DownloadManager owns the DownloadItems. The vector is
189 // kept in order, sorted by ascending start time. 192 // kept in order, sorted by ascending start time.
190 typedef std::vector<DownloadItem*> OrderedDownloads; 193 typedef std::vector<DownloadItem*> OrderedDownloads;
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 file_value->SetString(L"url", download->url().spec()); 385 file_value->SetString(L"url", download->url().spec());
383 386
384 if (download->state() == DownloadItem::IN_PROGRESS) { 387 if (download->state() == DownloadItem::IN_PROGRESS) {
385 if (download->safety_state() == DownloadItem::DANGEROUS) { 388 if (download->safety_state() == DownloadItem::DANGEROUS) {
386 file_value->SetString(L"state", L"DANGEROUS"); 389 file_value->SetString(L"state", L"DANGEROUS");
387 } else if (download->is_paused()) { 390 } else if (download->is_paused()) {
388 file_value->SetString(L"state", L"PAUSED"); 391 file_value->SetString(L"state", L"PAUSED");
389 } else { 392 } else {
390 file_value->SetString(L"state", L"IN_PROGRESS"); 393 file_value->SetString(L"state", L"IN_PROGRESS");
391 } 394 }
392 file_value->SetInteger(L"speed", 395
393 static_cast<int>(download->CurrentSpeed())); 396 file_value->SetString(L"progress_status_text",
397 GetProgressStatusText(download));
398
394 file_value->SetInteger(L"percent", 399 file_value->SetInteger(L"percent",
395 static_cast<int>(download->PercentComplete())); 400 static_cast<int>(download->PercentComplete()));
396 file_value->SetInteger(L"received", 401 file_value->SetInteger(L"received",
397 static_cast<int>(download->received_bytes())); 402 static_cast<int>(download->received_bytes()));
398 } else if (download->state() == DownloadItem::CANCELLED) { 403 } else if (download->state() == DownloadItem::CANCELLED) {
399 file_value->SetString(L"state", L"CANCELLED"); 404 file_value->SetString(L"state", L"CANCELLED");
400 } else if (download->state() == DownloadItem::COMPLETE) { 405 } else if (download->state() == DownloadItem::COMPLETE) {
401 if (download->safety_state() == DownloadItem::DANGEROUS) { 406 if (download->safety_state() == DownloadItem::DANGEROUS) {
402 file_value->SetString(L"state", L"DANGEROUS"); 407 file_value->SetString(L"state", L"DANGEROUS");
403 } else { 408 } else {
(...skipping 28 matching lines...) Expand all
432 } 437 }
433 438
434 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const Value* value) { 439 DownloadItem* DownloadsDOMHandler::GetDownloadByValue(const Value* value) {
435 int id; 440 int id;
436 if (ExtractIntegerValue(value, &id)) { 441 if (ExtractIntegerValue(value, &id)) {
437 return GetDownloadById(id); 442 return GetDownloadById(id);
438 } 443 }
439 return NULL; 444 return NULL;
440 } 445 }
441 446
447 std::wstring DownloadsDOMHandler::GetProgressStatusText(DownloadItem* download) {
448 int64 total = download->total_bytes();
449 int64 size = download->received_bytes();
450 DataUnits amount_units = GetByteDisplayUnits(size);
451 std::wstring received_size = FormatBytes(size, amount_units, true);
452 std::wstring amount = received_size;
453
454 // Adjust both strings for the locale direction since we don't yet know which
455 // string we'll end up using for constructing the final progress string.
456 std::wstring amount_localized;
457 if (l10n_util::AdjustStringForLocaleDirection(amount, &amount_localized)) {
458 amount.assign(amount_localized);
459 received_size.assign(amount_localized);
460 }
461
462 amount_units = GetByteDisplayUnits(total);
463 std::wstring total_text = FormatBytes(total, amount_units, true);
464 std::wstring total_text_localized;
465 if (l10n_util::AdjustStringForLocaleDirection(total_text,
466 &total_text_localized))
Ben Goodger (Google) 2009/03/24 05:14:29 can you indent this to the next (?
467 total_text.assign(total_text_localized);
468
469 amount = l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_SIZE,
470 received_size,
471 total_text);
472
473 amount_units = GetByteDisplayUnits(download->CurrentSpeed());
474 std::wstring speed_text = FormatSpeed(download->CurrentSpeed(),
475 amount_units, true);
Ben Goodger (Google) 2009/03/24 05:14:29 4 space indent
476 std::wstring speed_text_localized;
477 if (l10n_util::AdjustStringForLocaleDirection(speed_text,
478 &speed_text_localized))
Ben Goodger (Google) 2009/03/24 05:14:29 indent to next (
479 speed_text.assign(speed_text_localized);
480
481 return l10n_util::GetStringF(IDS_DOWNLOAD_TAB_PROGRESS_SPEED,
482 speed_text,
483 amount);
484 }
485
442 } // namespace 486 } // namespace
443 487
444 /////////////////////////////////////////////////////////////////////////////// 488 ///////////////////////////////////////////////////////////////////////////////
445 // 489 //
446 // DownloadsUI 490 // DownloadsUI
447 // 491 //
448 /////////////////////////////////////////////////////////////////////////////// 492 ///////////////////////////////////////////////////////////////////////////////
449 493
450 DownloadsUI::DownloadsUI(WebContents* contents) : DOMUI(contents) { 494 DownloadsUI::DownloadsUI(WebContents* contents) : DOMUI(contents) {
451 DownloadManager* dlm = GetProfile()->GetDownloadManager(); 495 DownloadManager* dlm = GetProfile()->GetDownloadManager();
452 496
453 DownloadsDOMHandler* handler = new DownloadsDOMHandler(this, dlm); 497 DownloadsDOMHandler* handler = new DownloadsDOMHandler(this, dlm);
454 AddMessageHandler(handler); 498 AddMessageHandler(handler);
455 handler->Init(); 499 handler->Init();
456 500
457 DownloadsUIHTMLSource* html_source = new DownloadsUIHTMLSource(); 501 DownloadsUIHTMLSource* html_source = new DownloadsUIHTMLSource();
458 502
459 // Set up the chrome-ui://downloads/ source. 503 // Set up the chrome-ui://downloads/ source.
460 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE, 504 g_browser_process->io_thread()->message_loop()->PostTask(FROM_HERE,
461 NewRunnableMethod(&chrome_url_data_manager, 505 NewRunnableMethod(&chrome_url_data_manager,
462 &ChromeURLDataManager::AddDataSource, 506 &ChromeURLDataManager::AddDataSource,
463 html_source)); 507 html_source));
464 } 508 }
OLDNEW
« no previous file with comments | « chrome/app/theme/download_progress_foreground32.png ('k') | chrome/browser/resources/downloads.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698