| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/notification/download_notification_manager.h" | 5 #include "chrome/browser/download/notification/download_notification_manager.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/location.h" |
| 9 #include "base/single_thread_task_runner.h" |
| 8 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" |
| 9 #include "chrome/browser/browser_process.h" | 12 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/download/download_item_model.h" | 13 #include "chrome/browser/download/download_item_model.h" |
| 11 #include "chrome/browser/download/notification/download_item_notification.h" | 14 #include "chrome/browser/download/notification/download_item_notification.h" |
| 12 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 13 #include "chrome/grit/chromium_strings.h" | 16 #include "chrome/grit/chromium_strings.h" |
| 14 #include "content/public/browser/download_item.h" | 17 #include "content/public/browser/download_item.h" |
| 15 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 18 #include "ui/message_center/message_center.h" | 21 #include "ui/message_center/message_center.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 34 } | 37 } |
| 35 | 38 |
| 36 DownloadNotificationManager::~DownloadNotificationManager() { | 39 DownloadNotificationManager::~DownloadNotificationManager() { |
| 37 } | 40 } |
| 38 | 41 |
| 39 void DownloadNotificationManager::OnAllDownloadsRemoving(Profile* profile) { | 42 void DownloadNotificationManager::OnAllDownloadsRemoving(Profile* profile) { |
| 40 DownloadNotificationManagerForProfile* manager_for_profile = | 43 DownloadNotificationManagerForProfile* manager_for_profile = |
| 41 manager_for_profile_[profile]; | 44 manager_for_profile_[profile]; |
| 42 manager_for_profile_.erase(profile); | 45 manager_for_profile_.erase(profile); |
| 43 | 46 |
| 44 base::MessageLoop::current()->DeleteSoon(FROM_HERE, manager_for_profile); | 47 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, |
| 48 manager_for_profile); |
| 45 } | 49 } |
| 46 | 50 |
| 47 void DownloadNotificationManager::OnNewDownloadReady( | 51 void DownloadNotificationManager::OnNewDownloadReady( |
| 48 content::DownloadItem* download) { | 52 content::DownloadItem* download) { |
| 49 Profile* profile = Profile::FromBrowserContext(download->GetBrowserContext()); | 53 Profile* profile = Profile::FromBrowserContext(download->GetBrowserContext()); |
| 50 | 54 |
| 51 if (manager_for_profile_.find(profile) == manager_for_profile_.end()) { | 55 if (manager_for_profile_.find(profile) == manager_for_profile_.end()) { |
| 52 manager_for_profile_[profile] = | 56 manager_for_profile_[profile] = |
| 53 new DownloadNotificationManagerForProfile(profile, this); | 57 new DownloadNotificationManagerForProfile(profile, this); |
| 54 } | 58 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 DownloadItemNotification* item = items_[download]; | 104 DownloadItemNotification* item = items_[download]; |
| 101 items_.erase(download); | 105 items_.erase(download); |
| 102 | 106 |
| 103 download->RemoveObserver(this); | 107 download->RemoveObserver(this); |
| 104 | 108 |
| 105 // notify | 109 // notify |
| 106 item->OnDownloadRemoved(download); | 110 item->OnDownloadRemoved(download); |
| 107 | 111 |
| 108 // This removing might be initiated from DownloadNotificationItem, so delaying | 112 // This removing might be initiated from DownloadNotificationItem, so delaying |
| 109 // deleting for item to do remaining cleanups. | 113 // deleting for item to do remaining cleanups. |
| 110 base::MessageLoop::current()->DeleteSoon(FROM_HERE, item); | 114 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, item); |
| 111 | 115 |
| 112 if (items_.size() == 0 && parent_manager_) | 116 if (items_.size() == 0 && parent_manager_) |
| 113 parent_manager_->OnAllDownloadsRemoving(profile_); | 117 parent_manager_->OnAllDownloadsRemoving(profile_); |
| 114 } | 118 } |
| 115 | 119 |
| 116 void DownloadNotificationManagerForProfile::OnDownloadDestroyed( | 120 void DownloadNotificationManagerForProfile::OnDownloadDestroyed( |
| 117 content::DownloadItem* download) { | 121 content::DownloadItem* download) { |
| 118 // Do nothing. Cleanup is done in OnDownloadRemoved(). | 122 // Do nothing. Cleanup is done in OnDownloadRemoved(). |
| 119 DownloadItemNotification* item = items_[download]; | 123 DownloadItemNotification* item = items_[download]; |
| 120 items_.erase(download); | 124 items_.erase(download); |
| 121 | 125 |
| 122 item->OnDownloadRemoved(download); | 126 item->OnDownloadRemoved(download); |
| 123 | 127 |
| 124 // This removing might be initiated from DownloadNotificationItem, so delaying | 128 // This removing might be initiated from DownloadNotificationItem, so delaying |
| 125 // deleting for item to do remaining cleanups. | 129 // deleting for item to do remaining cleanups. |
| 126 base::MessageLoop::current()->DeleteSoon(FROM_HERE, item); | 130 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, item); |
| 127 | 131 |
| 128 if (items_.size() == 0 && parent_manager_) | 132 if (items_.size() == 0 && parent_manager_) |
| 129 parent_manager_->OnAllDownloadsRemoving(profile_); | 133 parent_manager_->OnAllDownloadsRemoving(profile_); |
| 130 } | 134 } |
| 131 | 135 |
| 132 void DownloadNotificationManagerForProfile::OnNewDownloadReady( | 136 void DownloadNotificationManagerForProfile::OnNewDownloadReady( |
| 133 content::DownloadItem* download) { | 137 content::DownloadItem* download) { |
| 134 DCHECK_EQ(profile_, | 138 DCHECK_EQ(profile_, |
| 135 Profile::FromBrowserContext(download->GetBrowserContext())); | 139 Profile::FromBrowserContext(download->GetBrowserContext())); |
| 136 | 140 |
| 137 download->AddObserver(this); | 141 download->AddObserver(this); |
| 138 | 142 |
| 139 for (auto& item : items_) { | 143 for (auto& item : items_) { |
| 140 content::DownloadItem* download_item = item.first; | 144 content::DownloadItem* download_item = item.first; |
| 141 DownloadItemNotification* download_notification = item.second; | 145 DownloadItemNotification* download_notification = item.second; |
| 142 if (download_item->GetState() == content::DownloadItem::IN_PROGRESS) | 146 if (download_item->GetState() == content::DownloadItem::IN_PROGRESS) |
| 143 download_notification->DisablePopup(); | 147 download_notification->DisablePopup(); |
| 144 } | 148 } |
| 145 | 149 |
| 146 DownloadItemNotification* item = new DownloadItemNotification(download, this); | 150 DownloadItemNotification* item = new DownloadItemNotification(download, this); |
| 147 items_.insert(std::make_pair(download, item)); | 151 items_.insert(std::make_pair(download, item)); |
| 148 } | 152 } |
| 149 | 153 |
| 150 void DownloadNotificationManagerForProfile::OverrideMessageCenterForTest( | 154 void DownloadNotificationManagerForProfile::OverrideMessageCenterForTest( |
| 151 message_center::MessageCenter* message_center) { | 155 message_center::MessageCenter* message_center) { |
| 152 DCHECK(message_center); | 156 DCHECK(message_center); |
| 153 message_center_ = message_center; | 157 message_center_ = message_center; |
| 154 } | 158 } |
| OLD | NEW |