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
3 // found in the LICENSE file.
5 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_
6 #define UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "ui/message_center/message_center_export.h"
18 namespace message_center
{
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
23 class MESSAGE_CENTER_EXPORT NotificationDelegate
24 : public base::RefCountedThreadSafe
<NotificationDelegate
> {
26 // To be called when the desktop notification is actually shown.
27 virtual void Display();
29 // To be called when the desktop notification is closed. If closed by a
30 // user explicitly (as opposed to timeout/script), |by_user| should be true.
31 virtual void Close(bool by_user
);
33 // Returns true if the delegate can handle click event.
34 virtual bool HasClickedListener();
36 // To be called when a desktop notification is clicked.
39 // To be called when the user clicks a button in a notification.
40 virtual void ButtonClick(int button_index
);
43 virtual ~NotificationDelegate() {}
46 friend class base::RefCountedThreadSafe
<NotificationDelegate
>;
49 // A simple notification delegate which invokes the passed closure when clicked.
50 class MESSAGE_CENTER_EXPORT HandleNotificationClickedDelegate
51 : public NotificationDelegate
{
53 explicit HandleNotificationClickedDelegate(const base::Closure
& closure
);
55 // message_center::NotificationDelegate overrides:
56 void Click() override
;
57 bool HasClickedListener() override
;
60 ~HandleNotificationClickedDelegate() override
;
64 base::Closure closure_
;
66 DISALLOW_COPY_AND_ASSIGN(HandleNotificationClickedDelegate
);
69 // A notification delegate which invokes a callback when a notification button
71 class MESSAGE_CENTER_EXPORT HandleNotificationButtonClickDelegate
72 : public NotificationDelegate
{
74 typedef base::Callback
<void(int)> ButtonClickCallback
;
76 explicit HandleNotificationButtonClickDelegate(
77 const ButtonClickCallback
& button_callback
);
79 // message_center::NotificationDelegate overrides:
80 void ButtonClick(int button_index
) override
;
83 ~HandleNotificationButtonClickDelegate() override
;
86 ButtonClickCallback button_callback_
;
88 DISALLOW_COPY_AND_ASSIGN(HandleNotificationButtonClickDelegate
);
91 } // namespace message_center
93 #endif // UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_