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

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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 #endif 68 #endif
69 69
70 #if defined(USE_AURA) 70 #if defined(USE_AURA)
71 #include "ui/aura/client/drag_drop_client.h" 71 #include "ui/aura/client/drag_drop_client.h"
72 #include "ui/aura/root_window.h" 72 #include "ui/aura/root_window.h"
73 #include "ui/aura/window.h" 73 #include "ui/aura/window.h"
74 #endif 74 #endif
75 75
76 namespace { 76 namespace {
77 77
78 // Returns a string constant to be used as the |danger_type| value in
79 // CreateDownloadItemValue(). We only return strings for DANGEROUS_FILE,
80 // DANGEROUS_URL, DANGEROUS_CONTENT, and UNCOMMON_CONTENT because the
81 // |danger_type| value is only defined if the value of |state| is |DANGEROUS|.
82 const char* GetDangerTypeString(content::DownloadDangerType danger_type) {
83 switch (danger_type) {
84 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE:
85 return "DANGEROUS_FILE";
86 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL:
87 return "DANGEROUS_URL";
88 case content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT:
89 return "DANGEROUS_CONTENT";
90 case content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT:
91 return "UNCOMMON_CONTENT";
92 default:
93 // We shouldn't be returning a danger type string if it is
94 // NOT_DANGEROUS or MAYBE_DANGEROUS_CONTENT.
95 NOTREACHED();
96 return "";
97 }
98 }
99
100 // Get the opacity based on |animation_progress|, with values in [0.0, 1.0]. 78 // Get the opacity based on |animation_progress|, with values in [0.0, 1.0].
101 // Range of return value is [0, 255]. 79 // Range of return value is [0, 255].
102 int GetOpacity(double animation_progress) { 80 int GetOpacity(double animation_progress) {
103 DCHECK(animation_progress >= 0 && animation_progress <= 1); 81 DCHECK(animation_progress >= 0 && animation_progress <= 1);
104 82
105 // How many times to cycle the complete animation. This should be an odd 83 // How many times to cycle the complete animation. This should be an odd
106 // number so that the animation ends faded out. 84 // number so that the animation ends faded out.
107 static const int kCompleteAnimationCycles = 5; 85 static const int kCompleteAnimationCycles = 5;
108 double temp = animation_progress * kCompleteAnimationCycles * M_PI + M_PI_2; 86 double temp = animation_progress * kCompleteAnimationCycles * M_PI + M_PI_2;
109 temp = sin(temp) / 2 + 0.5; 87 temp = sin(temp) / 2 + 0.5;
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 #endif // TOOLKIT_GTK 391 #endif // TOOLKIT_GTK
414 } 392 }
415 #elif defined(USE_X11) 393 #elif defined(USE_X11)
416 void DragDownload(const DownloadItem* download, 394 void DragDownload(const DownloadItem* download,
417 gfx::Image* icon, 395 gfx::Image* icon,
418 gfx::NativeView view) { 396 gfx::NativeView view) {
419 DownloadItemDrag::BeginDrag(download, icon); 397 DownloadItemDrag::BeginDrag(download, icon);
420 } 398 }
421 #endif // USE_X11 399 #endif // USE_X11
422 400
423 DictionaryValue* CreateDownloadItemValue(DownloadItem* download, int id) {
424 DictionaryValue* file_value = new DictionaryValue();
425
426 file_value->SetInteger("started",
427 static_cast<int>(download->GetStartTime().ToTimeT()));
428 file_value->SetString("since_string",
429 TimeFormat::RelativeDate(download->GetStartTime(), NULL));
430 file_value->SetString("date_string",
431 base::TimeFormatShortDate(download->GetStartTime()));
432 file_value->SetInteger("id", id);
433
434 FilePath download_path(download->GetTargetFilePath());
435 file_value->Set("file_path", base::CreateFilePathValue(download_path));
436 file_value->SetString("file_url",
437 net::FilePathToFileURL(download_path).spec());
438
439 // Keep file names as LTR.
440 string16 file_name = download->GetFileNameToReportUser().LossyDisplayName();
441 file_name = base::i18n::GetDisplayStringInLTRDirectionality(file_name);
442 file_value->SetString("file_name", file_name);
443 file_value->SetString("url", download->GetURL().spec());
444 file_value->SetBoolean("otr", download->IsOtr());
445 file_value->SetInteger("total", static_cast<int>(download->GetTotalBytes()));
446 file_value->SetBoolean("file_externally_removed",
447 download->GetFileExternallyRemoved());
448
449 if (download->IsInProgress()) {
450 if (download->GetSafetyState() == DownloadItem::DANGEROUS) {
451 file_value->SetString("state", "DANGEROUS");
452 // These are the only danger states we expect to see (and the UI is
453 // equipped to handle):
454 DCHECK(download->GetDangerType() ==
455 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE ||
456 download->GetDangerType() ==
457 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_URL ||
458 download->GetDangerType() ==
459 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT ||
460 download->GetDangerType() ==
461 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT);
462 const char* danger_type_value =
463 GetDangerTypeString(download->GetDangerType());
464 file_value->SetString("danger_type", danger_type_value);
465 } else if (download->IsPaused()) {
466 file_value->SetString("state", "PAUSED");
467 } else {
468 file_value->SetString("state", "IN_PROGRESS");
469 }
470
471 file_value->SetString("progress_status_text",
472 GetProgressStatusText(download));
473
474 file_value->SetInteger("percent",
475 static_cast<int>(download->PercentComplete()));
476 file_value->SetInteger("received",
477 static_cast<int>(download->GetReceivedBytes()));
478 } else if (download->IsInterrupted()) {
479 file_value->SetString("state", "INTERRUPTED");
480
481 file_value->SetString("progress_status_text",
482 GetProgressStatusText(download));
483
484 file_value->SetInteger("percent",
485 static_cast<int>(download->PercentComplete()));
486 file_value->SetInteger("received",
487 static_cast<int>(download->GetReceivedBytes()));
488 file_value->SetString("last_reason_text",
489 BaseDownloadItemModel::InterruptReasonMessage(
490 download->GetLastReason()));
491 } else if (download->IsCancelled()) {
492 file_value->SetString("state", "CANCELLED");
493 } else if (download->IsComplete()) {
494 if (download->GetSafetyState() == DownloadItem::DANGEROUS)
495 file_value->SetString("state", "DANGEROUS");
496 else
497 file_value->SetString("state", "COMPLETE");
498 } else {
499 NOTREACHED() << "state undefined";
500 }
501
502 return file_value;
503 }
504
505 string16 GetProgressStatusText(DownloadItem* download) { 401 string16 GetProgressStatusText(DownloadItem* download) {
506 int64 total = download->GetTotalBytes(); 402 int64 total = download->GetTotalBytes();
507 int64 size = download->GetReceivedBytes(); 403 int64 size = download->GetReceivedBytes();
508 string16 received_size = ui::FormatBytes(size); 404 string16 received_size = ui::FormatBytes(size);
509 string16 amount = received_size; 405 string16 amount = received_size;
510 406
511 // Adjust both strings for the locale direction since we don't yet know which 407 // Adjust both strings for the locale direction since we don't yet know which
512 // string we'll end up using for constructing the final progress string. 408 // string we'll end up using for constructing the final progress string.
513 base::i18n::AdjustStringForLocaleDirection(&amount); 409 base::i18n::AdjustStringForLocaleDirection(&amount);
514 410
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 UMA_HISTOGRAM_ENUMERATION( 475 UMA_HISTOGRAM_ENUMERATION(
580 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY); 476 "Download.CountsChrome", type, CHROME_DOWNLOAD_COUNT_TYPES_LAST_ENTRY);
581 } 477 }
582 478
583 void RecordDownloadSource(ChromeDownloadSource source) { 479 void RecordDownloadSource(ChromeDownloadSource source) {
584 UMA_HISTOGRAM_ENUMERATION( 480 UMA_HISTOGRAM_ENUMERATION(
585 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY); 481 "Download.SourcesChrome", source, CHROME_DOWNLOAD_SOURCE_LAST_ENTRY);
586 } 482 }
587 483
588 } // namespace download_util 484 } // namespace download_util
OLDNEW
« no previous file with comments | « chrome/browser/download/download_util.h ('k') | chrome/browser/extensions/api/downloads/downloads_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698