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

Unified Diff: chrome/browser/download/notification/download_notification_item.h

Issue 1005393003: [Download Notification] Use NotificationUIManager instead of MessageCenter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use NotificationUIManager instead of message_center::MessageCenter 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/download/notification/download_notification_item.h
diff --git a/chrome/browser/download/notification/download_notification_item.h b/chrome/browser/download/notification/download_notification_item.h
index 6470e7a69ea8ed8def17030c7c866539d5f89f86..444ff74c501a6b6e1af6b0f11eec0504c14bf0f7 100644
--- a/chrome/browser/download/notification/download_notification_item.h
+++ b/chrome/browser/download/notification/download_notification_item.h
@@ -9,20 +9,21 @@
#include "base/strings/string_number_conversions.h"
#include "chrome/browser/download/download_commands.h"
+#include "chrome/browser/notifications/notification.h"
+#include "chrome/browser/notifications/notification_delegate.h"
+#include "chrome/browser/notifications/notification_test_util.h"
#include "content/public/browser/download_item.h"
#include "grit/theme_resources.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/message_center_observer.h"
-#include "ui/message_center/notification.h"
-#include "ui/message_center/notification_delegate.h"
-
-using message_center::Notification;
namespace test {
class DownloadNotificationItemTest;
}
-class DownloadNotificationItem : public content::DownloadItem::Observer {
+class DownloadNotificationItem
+ : public base::SupportsWeakPtr<DownloadNotificationItem>,
+ public content::DownloadItem::Observer {
public:
class Delegate {
public:
@@ -31,35 +32,45 @@ class DownloadNotificationItem : public content::DownloadItem::Observer {
virtual void OnDownloadRemoved(DownloadNotificationItem* item) = 0;
};
- DownloadNotificationItem(content::DownloadItem* item, Delegate* delegate);
+ static const char kDownloadNotificationOrigin[];
+
+ DownloadNotificationItem(content::DownloadItem* item,
+ Profile* profile,
+ Delegate* delegate);
~DownloadNotificationItem() override;
private:
- class NotificationWatcher : public message_center::NotificationDelegate,
- public message_center::MessageCenterObserver {
+ class NotificationWatcher : public NotificationDelegate {
public:
explicit NotificationWatcher(DownloadNotificationItem* item);
- private:
- ~NotificationWatcher() override;
-
- // message_center::NotificationDelegate overrides:
+ // NotificationDelegate overrides:
void Close(bool by_user) override;
void Click() override;
bool HasClickedListener() override;
void ButtonClick(int button_index) override;
+ std::string id() const override;
- // message_center::MessageCenterObserver overrides:
- void OnNotificationRemoved(const std::string& id, bool by_user) override;
+ private:
+ ~NotificationWatcher() override;
DownloadNotificationItem* item_;
};
+ // Replaces the NotificationUIManager for tests.
+ static void SetStubNotificationUIManagerForTesting(
+ StubNotificationUIManager* stub_notification_ui_manager) {
+ stub_notification_ui_manager_for_testing_ = stub_notification_ui_manager;
+ }
+ static StubNotificationUIManager* stub_notification_ui_manager_for_testing_;
+
+ friend class test::DownloadNotificationItemTest;
+
+ // Methods called from NotificationWatcher.
void OnNotificationClick();
void OnNotificationButtonClick(int button_index);
void OnNotificationClose(bool by_user);
- void OnNotificationRemoved(bool by_user);
// DownloadItem::Observer overrides:
void OnDownloadUpdated(content::DownloadItem* item) override;
@@ -67,9 +78,14 @@ class DownloadNotificationItem : public content::DownloadItem::Observer {
void OnDownloadRemoved(content::DownloadItem* item) override;
void OnDownloadDestroyed(content::DownloadItem* item) override;
+ // Shows notification again if the notification has been closed.
+ void ShowNotificationAgain();
+
void UpdateNotificationData();
void SetNotificationImage(int resource_id);
+ NotificationUIManager* notification_ui_manager() const;
+
// Returns a short one-line status string for the download.
base::string16 GetTitle() const;
@@ -84,11 +100,10 @@ class DownloadNotificationItem : public content::DownloadItem::Observer {
bool openable_;
bool downloading_;
- bool reshow_after_remove_;
int image_resource_id_;
+ Profile* profile_;
scoped_refptr<NotificationWatcher> watcher_;
- message_center::MessageCenter* message_center_;
scoped_ptr<Notification> notification_;
content::DownloadItem* item_;
@@ -96,8 +111,6 @@ class DownloadNotificationItem : public content::DownloadItem::Observer {
Delegate* const delegate_;
- friend class test::DownloadNotificationItemTest;
-
DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem);
};

Powered by Google App Engine
This is Rietveld 408576698