| 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..c011a59798f87d3ae398a4c930ccfaf0d4e2f7db 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();
|
| }
|
|
|
| } // 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,8 @@ 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();
|
| }
|
| }
|
| @@ -542,16 +510,22 @@ void DownloadsDOMHandler::HandleClearAll(const base::ListValue* args) {
|
| 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);
|
| ids.insert(download->GetId());
|
| +
|
| + item_model.SetShouldShowInShelf(false);
|
| + item_model.SetWasUINotified(false);
|
| +
|
| download->UpdateObservers();
|
| }
|
| +
|
| removes_.push_back(ids);
|
| }
|
|
|
|
|