Index: chrome/browser/ui/webui/downloads_dom_handler.cc |
diff --git a/chrome/browser/ui/webui/downloads_dom_handler.cc b/chrome/browser/ui/webui/downloads_dom_handler.cc |
index 83c753e117528f88fbe891c6801d22dc592253f5..e60e2a63dafdb11400c5308252252a0ce9c91042 100644 |
--- a/chrome/browser/ui/webui/downloads_dom_handler.cc |
+++ b/chrome/browser/ui/webui/downloads_dom_handler.cc |
@@ -77,35 +77,6 @@ enum DownloadsDOMEvent { |
DOWNLOADS_DOM_EVENT_MAX |
}; |
-static const char kKey[] = "DownloadsDOMHandlerData"; |
- |
-class DownloadsDOMHandlerData : public base::SupportsUserData::Data { |
- public: |
- static DownloadsDOMHandlerData* Get(content::DownloadItem* item) { |
- return static_cast<DownloadsDOMHandlerData*>(item->GetUserData(kKey)); |
- } |
- |
- static const DownloadsDOMHandlerData* Get(const content::DownloadItem* item) { |
- return static_cast<DownloadsDOMHandlerData*>(item->GetUserData(kKey)); |
- } |
- |
- static void Set(content::DownloadItem* item, DownloadsDOMHandlerData* data) { |
- item->SetUserData(kKey, data); |
- } |
- |
- static DownloadsDOMHandlerData* Create(content::DownloadItem* item) { |
- DownloadsDOMHandlerData* data = new DownloadsDOMHandlerData; |
- item->SetUserData(kKey, data); |
- return data; |
- } |
- |
- void set_is_removed(bool is_removed) { is_removed_ = is_removed; } |
- bool is_removed() const { return is_removed_; } |
- |
- private: |
- bool is_removed_; |
-}; |
- |
void CountDownloadsDOMEvents(DownloadsDOMEvent event) { |
UMA_HISTOGRAM_ENUMERATION("Download.DOMEvent", |
event, |
@@ -267,18 +238,14 @@ base::DictionaryValue* CreateDownloadItemValue( |
return file_value; |
} |
-bool IsRemoved(const content::DownloadItem& item) { |
- const DownloadsDOMHandlerData* data = DownloadsDOMHandlerData::Get(&item); |
- return data && data->is_removed(); |
-} |
- |
// Filters out extension downloads and downloads that don't have a filename yet. |
bool IsDownloadDisplayable(const content::DownloadItem& item) { |
return !download_crx_util::IsExtensionDownload(item) && |
!item.IsTemporary() && |
!item.GetFileNameToReportUser().empty() && |
!item.GetTargetFilePath().empty() && |
- !IsRemoved(item); |
+ DownloadItemModel( |
+ const_cast<content::DownloadItem*>(&item)).ShouldShowInShelf(); |
Dan Beam
2015/03/02 18:50:09
open to suggestions if you don't like this
|
} |
} // namespace |
@@ -398,7 +365,7 @@ void DownloadsDOMHandler::OnDownloadUpdated( |
void DownloadsDOMHandler::OnDownloadRemoved( |
content::DownloadManager* manager, |
content::DownloadItem* download_item) { |
- if (IsRemoved(*download_item)) |
+ if (!DownloadItemModel(download_item).ShouldShowInShelf()) |
return; |
// This relies on |download_item| being removed from DownloadManager in this |
@@ -513,7 +480,7 @@ void DownloadsDOMHandler::HandleUndo(const base::ListValue* args) { |
content::DownloadItem* download = GetDownloadById(id); |
if (!download) |
continue; |
- DownloadsDOMHandlerData::Set(download, nullptr); |
+ DownloadItemModel(download).SetShouldShowInShelf(true); |
download->UpdateObservers(); |
} |
} |
@@ -543,12 +510,13 @@ void DownloadsDOMHandler::RemoveDownloads( |
const std::vector<content::DownloadItem*>& to_remove) { |
std::set<uint32> ids; |
for (auto* download : to_remove) { |
- if (IsRemoved(*download) || |
+ DownloadItemModel item_model(download); |
+ if (!item_model.ShouldShowInShelf() || |
download->GetState() == content::DownloadItem::IN_PROGRESS) { |
continue; |
} |
- DownloadsDOMHandlerData::Create(download)->set_is_removed(true); |
+ item_model.SetShouldShowInShelf(false); |
ids.insert(download->GetId()); |
download->UpdateObservers(); |
} |