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

Side by Side 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, 8 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 unified diff | Download patch
OLDNEW
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 #ifndef CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ 5 #ifndef CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_
6 #define CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ 6 #define CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_
7 7
8 #include "chrome/browser/download/notification/download_notification_item.h" 8 #include "chrome/browser/download/notification/download_notification_item.h"
9 9
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
11 #include "chrome/browser/download/download_commands.h" 11 #include "chrome/browser/download/download_commands.h"
12 #include "chrome/browser/notifications/notification.h"
13 #include "chrome/browser/notifications/notification_delegate.h"
14 #include "chrome/browser/notifications/notification_test_util.h"
12 #include "content/public/browser/download_item.h" 15 #include "content/public/browser/download_item.h"
13 #include "grit/theme_resources.h" 16 #include "grit/theme_resources.h"
14 #include "ui/message_center/message_center.h" 17 #include "ui/message_center/message_center.h"
15 #include "ui/message_center/message_center_observer.h" 18 #include "ui/message_center/message_center_observer.h"
16 #include "ui/message_center/notification.h"
17 #include "ui/message_center/notification_delegate.h"
18
19 using message_center::Notification;
20 19
21 namespace test { 20 namespace test {
22 class DownloadNotificationItemTest; 21 class DownloadNotificationItemTest;
23 } 22 }
24 23
25 class DownloadNotificationItem : public content::DownloadItem::Observer { 24 class DownloadNotificationItem
25 : public base::SupportsWeakPtr<DownloadNotificationItem>,
26 public content::DownloadItem::Observer {
26 public: 27 public:
27 class Delegate { 28 class Delegate {
28 public: 29 public:
29 virtual void OnDownloadStarted(DownloadNotificationItem* item) = 0; 30 virtual void OnDownloadStarted(DownloadNotificationItem* item) = 0;
30 virtual void OnDownloadStopped(DownloadNotificationItem* item) = 0; 31 virtual void OnDownloadStopped(DownloadNotificationItem* item) = 0;
31 virtual void OnDownloadRemoved(DownloadNotificationItem* item) = 0; 32 virtual void OnDownloadRemoved(DownloadNotificationItem* item) = 0;
32 }; 33 };
33 34
34 DownloadNotificationItem(content::DownloadItem* item, Delegate* delegate); 35 static const char kDownloadNotificationOrigin[];
36
37 DownloadNotificationItem(content::DownloadItem* item,
38 Profile* profile,
39 Delegate* delegate);
35 40
36 ~DownloadNotificationItem() override; 41 ~DownloadNotificationItem() override;
37 42
38 private: 43 private:
39 class NotificationWatcher : public message_center::NotificationDelegate, 44 class NotificationWatcher : public NotificationDelegate {
40 public message_center::MessageCenterObserver {
41 public: 45 public:
42 explicit NotificationWatcher(DownloadNotificationItem* item); 46 explicit NotificationWatcher(DownloadNotificationItem* item);
43 47
48 // NotificationDelegate overrides:
49 void Close(bool by_user) override;
50 void Click() override;
51 bool HasClickedListener() override;
52 void ButtonClick(int button_index) override;
53 std::string id() const override;
54
44 private: 55 private:
45 ~NotificationWatcher() override; 56 ~NotificationWatcher() override;
46 57
47 // message_center::NotificationDelegate overrides:
48 void Close(bool by_user) override;
49 void Click() override;
50 bool HasClickedListener() override;
51 void ButtonClick(int button_index) override;
52
53 // message_center::MessageCenterObserver overrides:
54 void OnNotificationRemoved(const std::string& id, bool by_user) override;
55
56 DownloadNotificationItem* item_; 58 DownloadNotificationItem* item_;
57 }; 59 };
58 60
61 // Replaces the NotificationUIManager for tests.
62 static void SetStubNotificationUIManagerForTesting(
63 StubNotificationUIManager* stub_notification_ui_manager) {
64 stub_notification_ui_manager_for_testing_ = stub_notification_ui_manager;
65 }
66 static StubNotificationUIManager* stub_notification_ui_manager_for_testing_;
67
68 friend class test::DownloadNotificationItemTest;
69
70 // Methods called from NotificationWatcher.
59 void OnNotificationClick(); 71 void OnNotificationClick();
60 void OnNotificationButtonClick(int button_index); 72 void OnNotificationButtonClick(int button_index);
61 void OnNotificationClose(bool by_user); 73 void OnNotificationClose(bool by_user);
62 void OnNotificationRemoved(bool by_user);
63 74
64 // DownloadItem::Observer overrides: 75 // DownloadItem::Observer overrides:
65 void OnDownloadUpdated(content::DownloadItem* item) override; 76 void OnDownloadUpdated(content::DownloadItem* item) override;
66 void OnDownloadOpened(content::DownloadItem* item) override; 77 void OnDownloadOpened(content::DownloadItem* item) override;
67 void OnDownloadRemoved(content::DownloadItem* item) override; 78 void OnDownloadRemoved(content::DownloadItem* item) override;
68 void OnDownloadDestroyed(content::DownloadItem* item) override; 79 void OnDownloadDestroyed(content::DownloadItem* item) override;
69 80
81 // Shows notification again if the notification has been closed.
82 void ShowNotificationAgain();
83
70 void UpdateNotificationData(); 84 void UpdateNotificationData();
71 void SetNotificationImage(int resource_id); 85 void SetNotificationImage(int resource_id);
72 86
87 NotificationUIManager* notification_ui_manager() const;
88
73 // Returns a short one-line status string for the download. 89 // Returns a short one-line status string for the download.
74 base::string16 GetTitle() const; 90 base::string16 GetTitle() const;
75 91
76 // Returns a short one-line status string for a download command. 92 // Returns a short one-line status string for a download command.
77 base::string16 GetCommandLabel(DownloadCommands::Command command) const; 93 base::string16 GetCommandLabel(DownloadCommands::Command command) const;
78 94
79 // Get the warning test to notify a dangerous download. Should only be called 95 // Get the warning test to notify a dangerous download. Should only be called
80 // if IsDangerous() is true. 96 // if IsDangerous() is true.
81 base::string16 GetWarningText() const; 97 base::string16 GetWarningText() const;
82 98
83 scoped_ptr<std::vector<DownloadCommands::Command>> GetPossibleActions() const; 99 scoped_ptr<std::vector<DownloadCommands::Command>> GetPossibleActions() const;
84 100
85 bool openable_; 101 bool openable_;
86 bool downloading_; 102 bool downloading_;
87 bool reshow_after_remove_;
88 int image_resource_id_; 103 int image_resource_id_;
104 Profile* profile_;
89 scoped_refptr<NotificationWatcher> watcher_; 105 scoped_refptr<NotificationWatcher> watcher_;
90 106
91 message_center::MessageCenter* message_center_;
92 scoped_ptr<Notification> notification_; 107 scoped_ptr<Notification> notification_;
93 108
94 content::DownloadItem* item_; 109 content::DownloadItem* item_;
95 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_; 110 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_;
96 111
97 Delegate* const delegate_; 112 Delegate* const delegate_;
98 113
99 friend class test::DownloadNotificationItemTest;
100
101 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem); 114 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem);
102 }; 115 };
103 116
104 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ 117 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698