Chromium Code Reviews| 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>, | |
|
Randy Smith (Not in Mondays)
2015/04/14 00:02:00
Ok, I'll bite. What is this used for? After poki
yoshiki
2015/04/15 02:59:51
That was no longer used in the this patchset. Remo
| |
| 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 friend class test::DownloadNotificationItemTest; |
| 40 public message_center::MessageCenterObserver { | 45 |
| 46 class NotificationWatcher : public NotificationDelegate { | |
| 41 public: | 47 public: |
| 42 explicit NotificationWatcher(DownloadNotificationItem* item); | 48 explicit NotificationWatcher(DownloadNotificationItem* item); |
| 43 | 49 |
| 50 // NotificationDelegate overrides: | |
| 51 void Close(bool by_user) override; | |
| 52 void Click() override; | |
| 53 bool HasClickedListener() override; | |
| 54 void ButtonClick(int button_index) override; | |
| 55 std::string id() const override; | |
| 56 | |
| 44 private: | 57 private: |
| 45 ~NotificationWatcher() override; | 58 ~NotificationWatcher() override; |
| 46 | 59 |
| 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_; | 60 DownloadNotificationItem* item_; |
| 57 }; | 61 }; |
| 58 | 62 |
| 63 // Replaces the NotificationUIManager for tests. | |
| 64 static void SetStubNotificationUIManagerForTesting( | |
| 65 StubNotificationUIManager* stub_notification_ui_manager) { | |
| 66 stub_notification_ui_manager_for_testing_ = stub_notification_ui_manager; | |
| 67 } | |
| 68 | |
| 69 // Methods called from NotificationWatcher. | |
| 59 void OnNotificationClick(); | 70 void OnNotificationClick(); |
| 60 void OnNotificationButtonClick(int button_index); | 71 void OnNotificationButtonClick(int button_index); |
| 61 void OnNotificationClose(bool by_user); | |
| 62 void OnNotificationRemoved(bool by_user); | |
| 63 | 72 |
| 64 // DownloadItem::Observer overrides: | 73 // DownloadItem::Observer overrides: |
| 65 void OnDownloadUpdated(content::DownloadItem* item) override; | 74 void OnDownloadUpdated(content::DownloadItem* item) override; |
| 66 void OnDownloadOpened(content::DownloadItem* item) override; | 75 void OnDownloadOpened(content::DownloadItem* item) override; |
| 67 void OnDownloadRemoved(content::DownloadItem* item) override; | 76 void OnDownloadRemoved(content::DownloadItem* item) override; |
| 68 void OnDownloadDestroyed(content::DownloadItem* item) override; | 77 void OnDownloadDestroyed(content::DownloadItem* item) override; |
| 69 | 78 |
| 70 void UpdateNotificationData(); | 79 void UpdateNotificationData(); |
| 71 void SetNotificationImage(int resource_id); | 80 void SetNotificationImage(int resource_id); |
| 72 | 81 |
| 82 NotificationUIManager* notification_ui_manager() const; | |
| 83 | |
| 84 // For testing. This is set by SetStubNotificationUIManagerForTesting method. | |
| 85 static StubNotificationUIManager* stub_notification_ui_manager_for_testing_; | |
|
Randy Smith (Not in Mondays)
2015/04/14 00:02:00
nit: The style guide specifies that routines need
yoshiki
2015/04/15 02:59:51
Thank you for guidance. Done.
| |
| 86 | |
| 73 // Returns a short one-line status string for the download. | 87 // Returns a short one-line status string for the download. |
| 74 base::string16 GetTitle() const; | 88 base::string16 GetTitle() const; |
| 75 | 89 |
| 76 // Returns a short one-line status string for a download command. | 90 // Returns a short one-line status string for a download command. |
| 77 base::string16 GetCommandLabel(DownloadCommands::Command command) const; | 91 base::string16 GetCommandLabel(DownloadCommands::Command command) const; |
| 78 | 92 |
| 79 // Get the warning test to notify a dangerous download. Should only be called | 93 // Get the warning test to notify a dangerous download. Should only be called |
| 80 // if IsDangerous() is true. | 94 // if IsDangerous() is true. |
| 81 base::string16 GetWarningText() const; | 95 base::string16 GetWarningText() const; |
| 82 | 96 |
| 83 scoped_ptr<std::vector<DownloadCommands::Command>> GetPossibleActions() const; | 97 scoped_ptr<std::vector<DownloadCommands::Command>> GetPossibleActions() const; |
| 84 | 98 |
| 85 bool openable_; | 99 bool openable_; |
| 86 bool downloading_; | 100 bool downloading_; |
| 87 bool reshow_after_remove_; | |
| 88 int image_resource_id_; | 101 int image_resource_id_; |
| 102 Profile* profile_; | |
| 89 scoped_refptr<NotificationWatcher> watcher_; | 103 scoped_refptr<NotificationWatcher> watcher_; |
| 90 | 104 |
| 91 message_center::MessageCenter* message_center_; | |
| 92 scoped_ptr<Notification> notification_; | 105 scoped_ptr<Notification> notification_; |
| 93 | 106 |
| 94 content::DownloadItem* item_; | 107 content::DownloadItem* item_; |
| 95 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_; | 108 scoped_ptr<std::vector<DownloadCommands::Command>> button_actions_; |
| 96 | 109 |
| 97 Delegate* const delegate_; | 110 Delegate* const delegate_; |
| 98 | 111 |
| 99 friend class test::DownloadNotificationItemTest; | |
| 100 | |
| 101 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem); | 112 DISALLOW_COPY_AND_ASSIGN(DownloadNotificationItem); |
| 102 }; | 113 }; |
| 103 | 114 |
| 104 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ | 115 #endif // CHROME_BROWSER_DOWNLOAD_NOTIFICATION_DOWNLOAD_NOTIFICATION_ITEM_H_ |
| OLD | NEW |