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

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

Issue 209613002: Download shelf autohides on showing in shell, just same as regular open Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added browser and unit tests. Renamed 'UserActed' to 'OpenedOrShown'. Created 4 years, 1 month 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 // for the file type. 63 // for the file type.
64 bool should_prefer_opening_in_browser_; 64 bool should_prefer_opening_in_browser_;
65 65
66 // Danger level of the file determined based on the file type and whether 66 // Danger level of the file determined based on the file type and whether
67 // there was a user action associated with the download. 67 // there was a user action associated with the download.
68 DownloadFileType::DangerLevel danger_level_; 68 DownloadFileType::DangerLevel danger_level_;
69 69
70 // Whether the download is currently being revived. 70 // Whether the download is currently being revived.
71 bool is_being_revived_; 71 bool is_being_revived_;
72 72
73 // Whether download was opened or shown in the shell.
74 bool opened_or_shown_;
75
73 private: 76 private:
74 DownloadItemModelData(); 77 DownloadItemModelData();
75 ~DownloadItemModelData() override {} 78 ~DownloadItemModelData() override {}
76 79
77 static const char kKey[]; 80 static const char kKey[];
78 }; 81 };
79 82
80 // static 83 // static
81 const char DownloadItemModelData::kKey[] = "DownloadItemModelData key"; 84 const char DownloadItemModelData::kKey[] = "DownloadItemModelData key";
82 85
(...skipping 13 matching lines...) Expand all
96 download->SetUserData(kKey, data); 99 download->SetUserData(kKey, data);
97 } 100 }
98 return data; 101 return data;
99 } 102 }
100 103
101 DownloadItemModelData::DownloadItemModelData() 104 DownloadItemModelData::DownloadItemModelData()
102 : should_show_in_shelf_(true), 105 : should_show_in_shelf_(true),
103 was_ui_notified_(false), 106 was_ui_notified_(false),
104 should_prefer_opening_in_browser_(false), 107 should_prefer_opening_in_browser_(false),
105 danger_level_(DownloadFileType::NOT_DANGEROUS), 108 danger_level_(DownloadFileType::NOT_DANGEROUS),
106 is_being_revived_(false) {} 109 is_being_revived_(false),
110 opened_or_shown_(false) {}
107 111
108 base::string16 InterruptReasonStatusMessage( 112 base::string16 InterruptReasonStatusMessage(
109 content::DownloadInterruptReason reason) { 113 content::DownloadInterruptReason reason) {
110 int string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS; 114 int string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS;
111 115
112 switch (reason) { 116 switch (reason) {
113 case content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED: 117 case content::DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED:
114 string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_ACCESS_DENIED; 118 string_id = IDS_DOWNLOAD_INTERRUPTED_STATUS_ACCESS_DENIED;
115 break; 119 break;
116 case content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE: 120 case content::DOWNLOAD_INTERRUPT_REASON_FILE_NO_SPACE:
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 bool DownloadItemModel::IsBeingRevived() const { 656 bool DownloadItemModel::IsBeingRevived() const {
653 const DownloadItemModelData* data = DownloadItemModelData::Get(download_); 657 const DownloadItemModelData* data = DownloadItemModelData::Get(download_);
654 return data && data->is_being_revived_; 658 return data && data->is_being_revived_;
655 } 659 }
656 660
657 void DownloadItemModel::SetIsBeingRevived(bool is_being_revived) { 661 void DownloadItemModel::SetIsBeingRevived(bool is_being_revived) {
658 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_); 662 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_);
659 data->is_being_revived_ = is_being_revived; 663 data->is_being_revived_ = is_being_revived;
660 } 664 }
661 665
666 bool DownloadItemModel::GetOpenedOrShown() const {
667 const DownloadItemModelData* data = DownloadItemModelData::Get(download_);
668 return download_->GetOpened() || (data && data->opened_or_shown_);
669 }
670
671 void DownloadItemModel::SetOpenedOrShown(bool opened_or_shown) {
672 DownloadItemModelData* data = DownloadItemModelData::GetOrCreate(download_);
673 data->opened_or_shown_ = opened_or_shown;
674 }
675
662 base::string16 DownloadItemModel::GetProgressSizesString() const { 676 base::string16 DownloadItemModel::GetProgressSizesString() const {
663 base::string16 size_ratio; 677 base::string16 size_ratio;
664 int64_t size = GetCompletedBytes(); 678 int64_t size = GetCompletedBytes();
665 int64_t total = GetTotalBytes(); 679 int64_t total = GetTotalBytes();
666 if (total > 0) { 680 if (total > 0) {
667 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total); 681 ui::DataUnits amount_units = ui::GetByteDisplayUnits(total);
668 base::string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, fa lse); 682 base::string16 simple_size = ui::FormatBytesWithUnits(size, amount_units, fa lse);
669 683
670 // In RTL locales, we render the text "size/total" in an RTL context. This 684 // In RTL locales, we render the text "size/total" in an RTL context. This
671 // is problematic since a string such as "123/456 MB" is displayed 685 // is problematic since a string such as "123/456 MB" is displayed
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 if (!download_service) 756 if (!download_service)
743 return; 757 return;
744 758
745 ChromeDownloadManagerDelegate* delegate = 759 ChromeDownloadManagerDelegate* delegate =
746 download_service->GetDownloadManagerDelegate(); 760 download_service->GetDownloadManagerDelegate();
747 if (!delegate) 761 if (!delegate)
748 return; 762 return;
749 delegate->OpenDownloadUsingPlatformHandler(download_); 763 delegate->OpenDownloadUsingPlatformHandler(download_);
750 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM); 764 RecordDownloadOpenMethod(DOWNLOAD_OPEN_METHOD_USER_PLATFORM);
751 } 765 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_item_model.h ('k') | chrome/browser/download/download_item_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698