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

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

Issue 977473002: downloads: break downloads.js into more classes/files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: thestig@ review Created 5 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
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 #include "chrome/browser/download/download_item_model.h" 5 #include "chrome/browser/download/download_item_model.h"
6 6
7 #include "base/i18n/number_formatting.h" 7 #include "base/i18n/number_formatting.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 bool was_ui_notified_; 56 bool was_ui_notified_;
57 57
58 // Whether the download should be opened in the browser vs. the system handler 58 // Whether the download should be opened in the browser vs. the system handler
59 // for the file type. 59 // for the file type.
60 bool should_prefer_opening_in_browser_; 60 bool should_prefer_opening_in_browser_;
61 61
62 // Whether the download should be considered dangerous if SafeBrowsing doesn't 62 // Whether the download should be considered dangerous if SafeBrowsing doesn't
63 // come up with a verdict. 63 // come up with a verdict.
64 bool is_dangerous_file_based_on_type_; 64 bool is_dangerous_file_based_on_type_;
65 65
66 // Whether the download is currently being revived.
67 bool is_being_revived_;
68
66 private: 69 private:
67 DownloadItemModelData(); 70 DownloadItemModelData();
68 ~DownloadItemModelData() override {} 71 ~DownloadItemModelData() override {}
69 72
70 static const char kKey[]; 73 static const char kKey[];
71 }; 74 };
72 75
73 // static 76 // static
74 const char DownloadItemModelData::kKey[] = "DownloadItemModelData key"; 77 const char DownloadItemModelData::kKey[] = "DownloadItemModelData key";
75 78
(...skipping 12 matching lines...) Expand all
88 data = new DownloadItemModelData(); 91 data = new DownloadItemModelData();
89 download->SetUserData(kKey, data); 92 download->SetUserData(kKey, data);
90 } 93 }
91 return data; 94 return data;
92 } 95 }
93 96
94 DownloadItemModelData::DownloadItemModelData() 97 DownloadItemModelData::DownloadItemModelData()
95 : should_show_in_shelf_(true), 98 : should_show_in_shelf_(true),
96 was_ui_notified_(false), 99 was_ui_notified_(false),
97 should_prefer_opening_in_browser_(false), 100 should_prefer_opening_in_browser_(false),
98 is_dangerous_file_based_on_type_(false) { 101 is_dangerous_file_based_on_type_(false),
102 is_being_revived_(false) {
99 } 103 }
100 104
101 base::string16 InterruptReasonStatusMessage(int reason) { 105 base::string16 InterruptReasonStatusMessage(int reason) {
102 int string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS; 106 int string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS;
103 107
104 switch (static_cast<content::DownloadInterruptReason>(reason)) { 108 switch (static_cast<content::DownloadInterruptReason>(reason)) {
105 case content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED: 109 case content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED:
106 string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_ACCESS_DENIED; 110 string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_ACCESS_DENIED;
107 break; 111 break;
108 case content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE: 112 case content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE:
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 bool DownloadItemModel::IsDangerousFileBasedOnType() const { 607 bool DownloadItemModel::IsDangerousFileBasedOnType() const {
604 const DownloadItemModelData* data = DownloadItemModelData::Get(download_); 608 const DownloadItemModelData* data = DownloadItemModelData::Get(download_);
605 return data && data->is_dangerous_file_based_on_type_; 609 return data && data->is_dangerous_file_based_on_type_;
606 } 610 }
607 611
608 void DownloadItemModel::SetIsDangerousFileBasedOnType(bool dangerous) { 612 void DownloadItemModel::SetIsDangerousFileBasedOnType(bool dangerous) {
609 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_); 613 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_);
610 data->is_dangerous_file_based_on_type_ = dangerous; 614 data->is_dangerous_file_based_on_type_ = dangerous;
611 } 615 }
612 616
617 bool DownloadItemModel::IsBeingRevived() const {
618 const DownloadItemModelData* data = DownloadItemModelData::Get(download_);
619 return data && data->is_being_revived_;
620 }
621
622 void DownloadItemModel::SetIsBeingRevived(bool is_being_revived) {
623 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_);
624 data->is_being_revived_ = is_being_revived;
625 }
626
613 base::string16 DownloadItemModel::GetProgressSizesString() const { 627 base::string16 DownloadItemModel::GetProgressSizesString() const {
614 base::string16 size_ratio; 628 base::string16 size_ratio;
615 int64 size = GetCompletedBytes(); 629 int64 size = GetCompletedBytes();
616 int64 total = GetTotalBytes(); 630 int64 total = GetTotalBytes();
617 if (total > 0) { 631 if (total > 0) {
618 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total); 632 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total);
619 base::string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, fa lse); 633 base::string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, fa lse);
620 634
621 // In RTL locales, we render the text "size/total" in an RTL context. This 635 // In RTL locales, we render the text "size/total" in an RTL context. This
622 // is problematic since a string such as "123/456 MB" is displayed 636 // is problematic since a string such as "123/456 MB" is displayed
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 if (!download_service) 707 if (!download_service)
694 return; 708 return;
695 709
696 ChromeDownloadManagerDelegate* delegate = 710 ChromeDownloadManagerDelegate* delegate =
697 download_service->GetDownloadManagerDelegate(); 711 download_service->GetDownloadManagerDelegate();
698 if (!delegate) 712 if (!delegate)
699 return; 713 return;
700 delegate->OpenDownloadUsingPlatformHandler(download_); 714 delegate->OpenDownloadUsingPlatformHandler(download_);
701 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); 715 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM);
702 } 716 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_item_model.h ('k') | chrome/browser/resources/downloads/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698