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 #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_; | |
Randy Smith (Not in Mondays)
2015/04/10 21:43:19
According to the style guide, all data members sho
yoshiki
2015/04/13 15:51:53
Done.
| |
67 | |
68 friend class test::DownloadNotificationItemTest; | |
Randy Smith (Not in Mondays)
2015/04/10 21:43:19
I'm used to friending being the first thing in eac
yoshiki
2015/04/13 15:51:53
I agree that. Done.
| |
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); | |
62 void OnNotificationRemoved(bool by_user); | |
63 | 73 |
64 // DownloadItem::Observer overrides: | 74 // DownloadItem::Observer overrides: |
65 void OnDownloadUpdated(content::DownloadItem* item) override; | 75 void OnDownloadUpdated(content::DownloadItem* item) override; |
66 void OnDownloadOpened(content::DownloadItem* item) override; | 76 void OnDownloadOpened(content::DownloadItem* item) override; |
67 void OnDownloadRemoved(content::DownloadItem* item) override; | 77 void OnDownloadRemoved(content::DownloadItem* item) override; |
68 void OnDownloadDestroyed(content::DownloadItem* item) override; | 78 void OnDownloadDestroyed(content::DownloadItem* item) override; |
69 | 79 |
70 void UpdateNotificationData(); | 80 void UpdateNotificationData(); |
71 void SetNotificationImage(int resource_id); | 81 void SetNotificationImage(int resource_id); |
72 | 82 |
83 NotificationUIManager* notification_ui_manager() const; | |
84 | |
73 // Returns a short one-line status string for the download. | 85 // Returns a short one-line status string for the download. |
74 base::string16 GetTitle() const; | 86 base::string16 GetTitle() const; |
75 | 87 |
76 // Returns a short one-line status string for a download command. | 88 // Returns a short one-line status string for a download command. |
77 base::string16 GetCommandLabel(DownloadCommands::Command command) const; | 89 base::string16 GetCommandLabel(DownloadCommands::Command command) const; |
78 | 90 |
79 // Get the warning test to notify a dangerous download. Should only be called | 91 // Get the warning test to notify a dangerous download. Should only be called |
80 // if IsDangerous() is true. | 92 // if IsDangerous() is true. |
81 base::string16 GetWarningText() const; | 93 base::string16 GetWarningText() const; |
82 | 94 |
83 scoped_ptr<std::vector<DownloadCommands::Command>> GetPossibleActions() const; | 95 scoped_ptr<std::vector<DownloadCommands::Command>> GetPossibleActions() const; |
84 | 96 |
85 bool openable_; | 97 bool openable_; |
86 bool downloading_; | 98 bool downloading_; |
87 bool reshow_after_remove_; | |
88 int image_resource_id_; | 99 int image_resource_id_; |
100 Profile* profile_; | |
89 scoped_refptr<NotificationWatcher> watcher_; | 101 scoped_refptr<NotificationWatcher> watcher_; |
90 | 102 |
91 message_center::MessageCenter* message_center_; | |
92 scoped_ptr<Notification> notification_; | 103 scoped_ptr<Notification> notification_; |
93 | 104 |
94 content::DownloadItem* item_; | 105 content::DownloadItem* item_; |
95 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_; | 106 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_; |
96 | 107 |
97 Delegate* const delegate_; | 108 Delegate* const delegate_; |
98 | 109 |
99 friend class test::DownloadNotificationItemTest; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem); | 110 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem); |
102 }; | 111 }; |
103 | 112 |
104 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ | 113 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ |
OLD | NEW |