| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_ | 5 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_ |
| 6 #define UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_ | 6 #define UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "ui/message_center/message_center_export.h" | 12 #include "ui/message_center/message_center_export.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 class RenderViewHost; | 15 class RenderViewHost; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace message_center { | 18 namespace message_center { |
| 19 | 19 |
| 20 // Delegate for a notification. This class has two roles: to implement callback | 20 // Delegate for a notification. This class has two roles: to implement callback |
| 21 // methods for notification, and to provide an identity of the associated | 21 // methods for notification, and to provide an identity of the associated |
| 22 // notification. | 22 // notification. |
| 23 class MESSAGE_CENTER_EXPORT NotificationDelegate | 23 class MESSAGE_CENTER_EXPORT NotificationDelegate |
| 24 : public base::RefCountedThreadSafe<NotificationDelegate> { | 24 : public base::RefCountedThreadSafe<NotificationDelegate> { |
| 25 public: | 25 public: |
| 26 // To be called when the desktop notification is actually shown. | 26 // To be called when the desktop notification is actually shown. |
| 27 virtual void Display() = 0; | 27 virtual void Display() = 0; |
| 28 | 28 |
| 29 // To be called when the desktop notification cannot be shown due to an | |
| 30 // error. | |
| 31 virtual void Error() = 0; | |
| 32 | |
| 33 // To be called when the desktop notification is closed. If closed by a | 29 // To be called when the desktop notification is closed. If closed by a |
| 34 // user explicitly (as opposed to timeout/script), |by_user| should be true. | 30 // user explicitly (as opposed to timeout/script), |by_user| should be true. |
| 35 virtual void Close(bool by_user) = 0; | 31 virtual void Close(bool by_user) = 0; |
| 36 | 32 |
| 37 // Returns true if the delegate can handle click event. | 33 // Returns true if the delegate can handle click event. |
| 38 virtual bool HasClickedListener(); | 34 virtual bool HasClickedListener(); |
| 39 | 35 |
| 40 // To be called when a desktop notification is clicked. | 36 // To be called when a desktop notification is clicked. |
| 41 virtual void Click() = 0; | 37 virtual void Click() = 0; |
| 42 | 38 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 53 }; | 49 }; |
| 54 | 50 |
| 55 // A simple notification delegate which invokes the passed closure when clicked. | 51 // A simple notification delegate which invokes the passed closure when clicked. |
| 56 class MESSAGE_CENTER_EXPORT HandleNotificationClickedDelegate | 52 class MESSAGE_CENTER_EXPORT HandleNotificationClickedDelegate |
| 57 : public NotificationDelegate { | 53 : public NotificationDelegate { |
| 58 public: | 54 public: |
| 59 explicit HandleNotificationClickedDelegate(const base::Closure& closure); | 55 explicit HandleNotificationClickedDelegate(const base::Closure& closure); |
| 60 | 56 |
| 61 // message_center::NotificationDelegate overrides: | 57 // message_center::NotificationDelegate overrides: |
| 62 void Display() override; | 58 void Display() override; |
| 63 void Error() override; | |
| 64 void Close(bool by_user) override; | 59 void Close(bool by_user) override; |
| 65 bool HasClickedListener() override; | 60 bool HasClickedListener() override; |
| 66 void Click() override; | 61 void Click() override; |
| 67 void ButtonClick(int button_index) override; | 62 void ButtonClick(int button_index) override; |
| 68 | 63 |
| 69 protected: | 64 protected: |
| 70 ~HandleNotificationClickedDelegate() override; | 65 ~HandleNotificationClickedDelegate() override; |
| 71 | 66 |
| 72 private: | 67 private: |
| 73 std::string id_; | 68 std::string id_; |
| 74 base::Closure closure_; | 69 base::Closure closure_; |
| 75 | 70 |
| 76 DISALLOW_COPY_AND_ASSIGN(HandleNotificationClickedDelegate); | 71 DISALLOW_COPY_AND_ASSIGN(HandleNotificationClickedDelegate); |
| 77 }; | 72 }; |
| 78 | 73 |
| 79 // A notification delegate which invokes a callback when a notification button | 74 // A notification delegate which invokes a callback when a notification button |
| 80 // has been clicked. | 75 // has been clicked. |
| 81 class MESSAGE_CENTER_EXPORT HandleNotificationButtonClickDelegate | 76 class MESSAGE_CENTER_EXPORT HandleNotificationButtonClickDelegate |
| 82 : public NotificationDelegate { | 77 : public NotificationDelegate { |
| 83 public: | 78 public: |
| 84 typedef base::Callback<void(int)> ButtonClickCallback; | 79 typedef base::Callback<void(int)> ButtonClickCallback; |
| 85 | 80 |
| 86 explicit HandleNotificationButtonClickDelegate( | 81 explicit HandleNotificationButtonClickDelegate( |
| 87 const ButtonClickCallback& button_callback); | 82 const ButtonClickCallback& button_callback); |
| 88 | 83 |
| 89 // message_center::NotificationDelegate overrides: | 84 // message_center::NotificationDelegate overrides: |
| 90 void Display() override; | 85 void Display() override; |
| 91 void Error() override; | |
| 92 void Close(bool by_user) override; | 86 void Close(bool by_user) override; |
| 93 void Click() override; | 87 void Click() override; |
| 94 void ButtonClick(int button_index) override; | 88 void ButtonClick(int button_index) override; |
| 95 | 89 |
| 96 protected: | 90 protected: |
| 97 ~HandleNotificationButtonClickDelegate() override; | 91 ~HandleNotificationButtonClickDelegate() override; |
| 98 | 92 |
| 99 private: | 93 private: |
| 100 ButtonClickCallback button_callback_; | 94 ButtonClickCallback button_callback_; |
| 101 | 95 |
| 102 DISALLOW_COPY_AND_ASSIGN(HandleNotificationButtonClickDelegate); | 96 DISALLOW_COPY_AND_ASSIGN(HandleNotificationButtonClickDelegate); |
| 103 }; | 97 }; |
| 104 | 98 |
| 105 } // namespace message_center | 99 } // namespace message_center |
| 106 | 100 |
| 107 #endif // UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_ | 101 #endif // UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_ |
| OLD | NEW |