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

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

Issue 10805020: Kill DownloadItem::IsOtr() (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: . Created 8 years, 5 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 // Download utility implementation 5 // Download utility implementation
6 6
7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. 7 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
8 8
9 #include "chrome/browser/download/download_util.h" 9 #include "chrome/browser/download/download_util.h"
10 10
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 #endif 79 #endif
80 80
81 #if defined(USE_AURA) 81 #if defined(USE_AURA)
82 #include "ui/aura/client/drag_drop_client.h" 82 #include "ui/aura/client/drag_drop_client.h"
83 #include "ui/aura/root_window.h" 83 #include "ui/aura/root_window.h"
84 #include "ui/aura/window.h" 84 #include "ui/aura/window.h"
85 #endif 85 #endif
86 86
87 namespace { 87 namespace {
88 88
89 // Returns a string constant to be used as the |danger_type| value in
90 // CreateDownloadItemValue(). We only return strings for DANGEROUS_FILE,
91 // DANGEROUS_URL, DANGEROUS_CONTENT, and UNCOMMON_CONTENT because the
92 // |danger_type| value is only defined if the value of |state| is |DANGEROUS|.
93 const char* GetDangerTypeString(content::DownloadDangerType danger_type) {
94 switch (danger_type) {
95 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE:
96 return "DANGEROUS_FILE";
97 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL:
98 return "DANGEROUS_URL";
99 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT:
100 return "DANGEROUS_CONTENT";
101 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT:
102 return "UNCOMMON_CONTENT";
103 default:
104 // We shouldn't be returning a danger type string if it is
105 // NOT_DANGEROUS or MAYBE_DANGEROUS_CONTENT.
106 NOTREACHED();
107 return "";
108 }
109 }
110
111 // Get the opacity based on |animation_progress|, with values in [0.0, 1.0]. 89 // Get the opacity based on |animation_progress|, with values in [0.0, 1.0].
112 // Range of return value is [0, 255]. 90 // Range of return value is [0, 255].
113 int GetOpacity(double animation_progress) { 91 int GetOpacity(double animation_progress) {
114 DCHECK(animation_progress >= 0 && animation_progress <= 1); 92 DCHECK(animation_progress >= 0 && animation_progress <= 1);
115 93
116 // How many times to cycle the complete animation. This should be an odd 94 // How many times to cycle the complete animation. This should be an odd
117 // number so that the animation ends faded out. 95 // number so that the animation ends faded out.
118 static const int kCompleteAnimationCycles = 5; 96 static const int kCompleteAnimationCycles = 5;
119 double temp = animation_progress * kCompleteAnimationCycles * M_PI + M_PI_2; 97 double temp = animation_progress * kCompleteAnimationCycles * M_PI + M_PI_2;
120 temp = sin(temp) / 2 + 0.5; 98 temp = sin(temp) / 2 + 0.5;
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 #endif // TOOLKIT_GTK 410 #endif // TOOLKIT_GTK
433 } 411 }
434 #elif defined(USE_X11) 412 #elif defined(USE_X11)
435 void DragDownload(const DownloadItem* download, 413 void DragDownload(const DownloadItem* download,
436 gfx::Image* icon, 414 gfx::Image* icon,
437 gfx::NativeView view) { 415 gfx::NativeView view) {
438 DownloadItemDrag::BeginDrag(download, icon); 416 DownloadItemDrag::BeginDrag(download, icon);
439 } 417 }
440 #endif // USE_X11 418 #endif // USE_X11
441 419
442 DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id) {
443 DictionaryValue* file_value = new DictionaryValue();
444
445 file_value->SetInteger("started",
446 static_cast<int>(download->GetStartTime().ToTimeT()));
447 file_value->SetString("since_string",
448 TimeFormat::RelativeDate(download->GetStartTime(), NULL));
449 file_value->SetString("date_string",
450 base::TimeFormatShortDate(download->GetStartTime()));
451 file_value->SetInteger("id", id);
452
453 FilePath download_path(download->GetTargetFilePath());
454 file_value->Set("file_path", base::CreateFilePathValue(download_path));
455 file_value->SetString("file_url",
456 net::FilePathToFileURL(download_path).spec());
457
458 // Keep file names as LTR.
459 string16 file_name = download->GetFileNameToReportUser().LossyDisplayName();
460 file_name = base::i18n::GetDisplayStringInLTRDirectionality(file_name);
461 file_value->SetString("file_name", file_name);
462 file_value->SetString("url", download->GetURL().spec());
463 file_value->SetBoolean("otr", download->IsOtr());
464 file_value->SetInteger("total", static_cast<int>(download->GetTotalBytes()));
465 file_value->SetBoolean("file_externally_removed",
466 download->GetFileExternallyRemoved());
467
468 if (download->IsInProgress()) {
469 if (download->GetSafetyState() == DownloadItem::DANGEROUS) {
470 file_value->SetString("state", "DANGEROUS");
471 // These are the only danger states we expect to see (and the UI is
472 // equipped to handle):
473 DCHECK(download->GetDangerType() ==
474 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE ||
475 download->GetDangerType() ==
476 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL ||
477 download->GetDangerType() ==
478 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT ||
479 download->GetDangerType() ==
480 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT);
481 const char* danger_type_value =
482 GetDangerTypeString(download->GetDangerType());
483 file_value->SetString("danger_type", danger_type_value);
484 } else if (download->IsPaused()) {
485 file_value->SetString("state", "PAUSED");
486 } else {
487 file_value->SetString("state", "IN_PROGRESS");
488 }
489
490 file_value->SetString("progress_status_text",
491 GetProgressStatusText(download));
492
493 file_value->SetInteger("percent",
494 static_cast<int>(download->PercentComplete()));
495 file_value->SetInteger("received",
496 static_cast<int>(download->GetReceivedBytes()));
497 } else if (download->IsInterrupted()) {
498 file_value->SetString("state", "INTERRUPTED");
499
500 file_value->SetString("progress_status_text",
501 GetProgressStatusText(download));
502
503 file_value->SetInteger("percent",
504 static_cast<int>(download->PercentComplete()));
505 file_value->SetInteger("received",
506 static_cast<int>(download->GetReceivedBytes()));
507 file_value->SetString("last_reason_text",
508 BaseDownloadItemModel::InterruptReasonMessage(
509 download->GetLastReason()));
510 } else if (download->IsCancelled()) {
511 file_value->SetString("state", "CANCELLED");
512 } else if (download->IsComplete()) {
513 if (download->GetSafetyState() == DownloadItem::DANGEROUS)
514 file_value->SetString("state", "DANGEROUS");
515 else
516 file_value->SetString("state", "COMPLETE");
517 } else if (download->GetState() == DownloadItem::REMOVING) {
518 file_value->SetString("state", "REMOVING");
519 } else {
520 NOTREACHED() << "state undefined";
521 }
522
523 return file_value;
524 }
525
526 string16 GetProgressStatusText(DownloadItem* download) { 420 string16 GetProgressStatusText(DownloadItem* download) {
527 int64 total = download->GetTotalBytes(); 421 int64 total = download->GetTotalBytes();
528 int64 size = download->GetReceivedBytes(); 422 int64 size = download->GetReceivedBytes();
529 string16 received_size = ui::FormatBytes(size); 423 string16 received_size = ui::FormatBytes(size);
530 string16 amount = received_size; 424 string16 amount = received_size;
531 425
532 // Adjust both strings for the locale direction since we don't yet know which 426 // Adjust both strings for the locale direction since we don't yet know which
533 // string we'll end up using for constructing the final progress string. 427 // string we'll end up using for constructing the final progress string.
534 base::i18n::AdjustStringForLocaleDirection(&amount); 428 base::i18n::AdjustStringForLocaleDirection(&amount);
535 429
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 UMA_HISTOGRAM_ENUMERATION( 541 UMA_HISTOGRAM_ENUMERATION(
648 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY); 542 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
649 } 543 }
650 544
651 void RecordDownloadSource(ChromeDownloadSource source) { 545 void RecordDownloadSource(ChromeDownloadSource source) {
652 UMA_HISTOGRAM_ENUMERATION( 546 UMA_HISTOGRAM_ENUMERATION(
653 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY); 547 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY);
654 } 548 }
655 549
656 } // namespace download_util 550 } // namespace download_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698