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

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, 4 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 #endif // TOOLKIT_GTK 402 #endif // TOOLKIT_GTK
425 } 403 }
426 #elif defined(USE_X11) 404 #elif defined(USE_X11)
427 void DragDownload(const DownloadItem* download, 405 void DragDownload(const DownloadItem* download,
428 gfx::Image* icon, 406 gfx::Image* icon,
429 gfx::NativeView view) { 407 gfx::NativeView view) {
430 DownloadItemDrag::BeginDrag(download, icon); 408 DownloadItemDrag::BeginDrag(download, icon);
431 } 409 }
432 #endif // USE_X11 410 #endif // USE_X11
433 411
434 DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id) {
435 DictionaryValue* file_value = new DictionaryValue();
436
437 file_value->SetInteger("started",
438 static_cast<int>(download->GetStartTime().ToTimeT()));
439 file_value->SetString("since_string",
440 TimeFormat::RelativeDate(download->GetStartTime(), NULL));
441 file_value->SetString("date_string",
442 base::TimeFormatShortDate(download->GetStartTime()));
443 file_value->SetInteger("id", id);
444
445 FilePath download_path(download->GetTargetFilePath());
446 file_value->Set("file_path", base::CreateFilePathValue(download_path));
447 file_value->SetString("file_url",
448 net::FilePathToFileURL(download_path).spec());
449
450 // Keep file names as LTR.
451 string16 file_name = download->GetFileNameToReportUser().LossyDisplayName();
452 file_name = base::i18n::GetDisplayStringInLTRDirectionality(file_name);
453 file_value->SetString("file_name", file_name);
454 file_value->SetString("url", download->GetURL().spec());
455 file_value->SetBoolean("otr", download->IsOtr());
456 file_value->SetInteger("total", static_cast<int>(download->GetTotalBytes()));
457 file_value->SetBoolean("file_externally_removed",
458 download->GetFileExternallyRemoved());
459
460 if (download->IsInProgress()) {
461 if (download->GetSafetyState() == DownloadItem::DANGEROUS) {
462 file_value->SetString("state", "DANGEROUS");
463 // These are the only danger states we expect to see (and the UI is
464 // equipped to handle):
465 DCHECK(download->GetDangerType() ==
466 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE ||
467 download->GetDangerType() ==
468 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL ||
469 download->GetDangerType() ==
470 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT ||
471 download->GetDangerType() ==
472 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT);
473 const char* danger_type_value =
474 GetDangerTypeString(download->GetDangerType());
475 file_value->SetString("danger_type", danger_type_value);
476 } else if (download->IsPaused()) {
477 file_value->SetString("state", "PAUSED");
478 } else {
479 file_value->SetString("state", "IN_PROGRESS");
480 }
481
482 file_value->SetString("progress_status_text",
483 GetProgressStatusText(download));
484
485 file_value->SetInteger("percent",
486 static_cast<int>(download->PercentComplete()));
487 file_value->SetInteger("received",
488 static_cast<int>(download->GetReceivedBytes()));
489 } else if (download->IsInterrupted()) {
490 file_value->SetString("state", "INTERRUPTED");
491
492 file_value->SetString("progress_status_text",
493 GetProgressStatusText(download));
494
495 file_value->SetInteger("percent",
496 static_cast<int>(download->PercentComplete()));
497 file_value->SetInteger("received",
498 static_cast<int>(download->GetReceivedBytes()));
499 file_value->SetString("last_reason_text",
500 BaseDownloadItemModel::InterruptReasonMessage(
501 download->GetLastReason()));
502 } else if (download->IsCancelled()) {
503 file_value->SetString("state", "CANCELLED");
504 } else if (download->IsComplete()) {
505 if (download->GetSafetyState() == DownloadItem::DANGEROUS)
506 file_value->SetString("state", "DANGEROUS");
507 else
508 file_value->SetString("state", "COMPLETE");
509 } else if (download->GetState() == DownloadItem::REMOVING) {
510 file_value->SetString("state", "REMOVING");
511 } else {
512 NOTREACHED() << "state undefined";
513 }
514
515 return file_value;
516 }
517
518 string16 GetProgressStatusText(DownloadItem* download) { 412 string16 GetProgressStatusText(DownloadItem* download) {
519 int64 total = download->GetTotalBytes(); 413 int64 total = download->GetTotalBytes();
520 int64 size = download->GetReceivedBytes(); 414 int64 size = download->GetReceivedBytes();
521 string16 received_size = ui::FormatBytes(size); 415 string16 received_size = ui::FormatBytes(size);
522 string16 amount = received_size; 416 string16 amount = received_size;
523 417
524 // Adjust both strings for the locale direction since we don't yet know which 418 // Adjust both strings for the locale direction since we don't yet know which
525 // string we'll end up using for constructing the final progress string. 419 // string we'll end up using for constructing the final progress string.
526 base::i18n::AdjustStringForLocaleDirection(&amount); 420 base::i18n::AdjustStringForLocaleDirection(&amount);
527 421
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 UMA_HISTOGRAM_ENUMERATION( 533 UMA_HISTOGRAM_ENUMERATION(
640 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY); 534 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
641 } 535 }
642 536
643 void RecordDownloadSource(ChromeDownloadSource source) { 537 void RecordDownloadSource(ChromeDownloadSource source) {
644 UMA_HISTOGRAM_ENUMERATION( 538 UMA_HISTOGRAM_ENUMERATION(
645 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY); 539 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY);
646 } 540 }
647 541
648 } // namespace download_util 542 } // namespace download_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698