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(); |
28 | 28 |
29 // To be called when the desktop notification cannot be shown due to an | 29 // To be called when the desktop notification cannot be shown due to an |
30 // error. | 30 // error. |
31 virtual void Error() = 0; | 31 virtual void Error(); |
32 | 32 |
33 // To be called when the desktop notification is closed. If closed by a | 33 // 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. | 34 // user explicitly (as opposed to timeout/script), |by_user| should be true. |
35 virtual void Close(bool by_user) = 0; | 35 virtual void Close(bool by_user); |
36 | 36 |
37 // Returns true if the delegate can handle click event. | 37 // Returns true if the delegate can handle click event. |
38 virtual bool HasClickedListener(); | 38 virtual bool HasClickedListener(); |
39 | 39 |
40 // To be called when a desktop notification is clicked. | 40 // To be called when a desktop notification is clicked. |
41 virtual void Click() = 0; | 41 virtual void Click(); |
42 | 42 |
43 // To be called when the user clicks a button in a notification. TODO(miket): | 43 // To be called when the user clicks a button in a notification. |
44 // consider providing default implementations of the pure virtuals of this | |
45 // interface, to avoid pinging so many OWNERs each time we enhance it. | |
46 virtual void ButtonClick(int button_index); | 44 virtual void ButtonClick(int button_index); |
47 | 45 |
48 protected: | 46 protected: |
49 virtual ~NotificationDelegate() {} | 47 virtual ~NotificationDelegate() {} |
50 | 48 |
51 private: | 49 private: |
52 friend class base::RefCountedThreadSafe<NotificationDelegate>; | 50 friend class base::RefCountedThreadSafe<NotificationDelegate>; |
53 }; | 51 }; |
54 | 52 |
55 // A simple notification delegate which invokes the passed closure when clicked. | 53 // A simple notification delegate which invokes the passed closure when clicked. |
56 class MESSAGE_CENTER_EXPORT HandleNotificationClickedDelegate | 54 class MESSAGE_CENTER_EXPORT HandleNotificationClickedDelegate |
57 : public NotificationDelegate { | 55 : public NotificationDelegate { |
58 public: | 56 public: |
59 explicit HandleNotificationClickedDelegate(const base::Closure& closure); | 57 explicit HandleNotificationClickedDelegate(const base::Closure& closure); |
60 | 58 |
61 // message_center::NotificationDelegate overrides: | 59 // message_center::NotificationDelegate overrides: |
62 void Display() override; | 60 void Click() override; |
63 void Error() override; | |
64 void Close(bool by_user) override; | |
65 bool HasClickedListener() override; | 61 bool HasClickedListener() override; |
66 void Click() override; | |
67 void ButtonClick(int button_index) override; | |
68 | 62 |
69 protected: | 63 protected: |
70 ~HandleNotificationClickedDelegate() override; | 64 ~HandleNotificationClickedDelegate() override; |
71 | 65 |
72 private: | 66 private: |
73 std::string id_; | 67 std::string id_; |
74 base::Closure closure_; | 68 base::Closure closure_; |
75 | 69 |
76 DISALLOW_COPY_AND_ASSIGN(HandleNotificationClickedDelegate); | 70 DISALLOW_COPY_AND_ASSIGN(HandleNotificationClickedDelegate); |
77 }; | 71 }; |
78 | 72 |
79 // A notification delegate which invokes a callback when a notification button | 73 // A notification delegate which invokes a callback when a notification button |
80 // has been clicked. | 74 // has been clicked. |
81 class MESSAGE_CENTER_EXPORT HandleNotificationButtonClickDelegate | 75 class MESSAGE_CENTER_EXPORT HandleNotificationButtonClickDelegate |
82 : public NotificationDelegate { | 76 : public NotificationDelegate { |
83 public: | 77 public: |
84 typedef base::Callback<void(int)> ButtonClickCallback; | 78 typedef base::Callback<void(int)> ButtonClickCallback; |
85 | 79 |
86 explicit HandleNotificationButtonClickDelegate( | 80 explicit HandleNotificationButtonClickDelegate( |
87 const ButtonClickCallback& button_callback); | 81 const ButtonClickCallback& button_callback); |
88 | 82 |
89 // message_center::NotificationDelegate overrides: | 83 // message_center::NotificationDelegate overrides: |
90 void Display() override; | |
91 void Error() override; | |
92 void Close(bool by_user) override; | |
93 void Click() override; | |
94 void ButtonClick(int button_index) override; | 84 void ButtonClick(int button_index) override; |
95 | 85 |
96 protected: | 86 protected: |
97 ~HandleNotificationButtonClickDelegate() override; | 87 ~HandleNotificationButtonClickDelegate() override; |
98 | 88 |
99 private: | 89 private: |
100 ButtonClickCallback button_callback_; | 90 ButtonClickCallback button_callback_; |
101 | 91 |
102 DISALLOW_COPY_AND_ASSIGN(HandleNotificationButtonClickDelegate); | 92 DISALLOW_COPY_AND_ASSIGN(HandleNotificationButtonClickDelegate); |
103 }; | 93 }; |
104 | 94 |
105 } // namespace message_center | 95 } // namespace message_center |
106 | 96 |
107 #endif // UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_ | 97 #endif // UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_ |
OLD | NEW |