- add sources.
[platform/framework/web/crosswalk.git] / src / ui / message_center / notification_delegate.h
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.
4
5 #ifndef UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_
6 #define UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_
7
8 #include <string>
9
10 #include "base/callback.h"
11 #include "base/memory/ref_counted.h"
12 #include "ui/message_center/message_center_export.h"
13
14 namespace content {
15 class RenderViewHost;
16 }
17
18 namespace message_center {
19
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
22 // notification.
23 class MESSAGE_CENTER_EXPORT NotificationDelegate
24     : public base::RefCountedThreadSafe<NotificationDelegate> {
25  public:
26   // To be called when the desktop notification is actually shown.
27   virtual void Display() = 0;
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
34   // user explicitly (as opposed to timeout/script), |by_user| should be true.
35   virtual void Close(bool by_user) = 0;
36
37   // Returns true if the delegate can handle click event.
38   virtual bool HasClickedListener();
39
40   // To be called when a desktop notification is clicked.
41   virtual void Click() = 0;
42
43   // To be called when the user clicks a button in a notification. TODO(miket):
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);
47
48  protected:
49   virtual ~NotificationDelegate() {}
50
51  private:
52   friend class base::RefCountedThreadSafe<NotificationDelegate>;
53 };
54
55 // A simple notification delegate which invokes the passed closure when clicked.
56 class MESSAGE_CENTER_EXPORT HandleNotificationClickedDelegate
57     : public NotificationDelegate {
58  public:
59   explicit HandleNotificationClickedDelegate(const base::Closure& closure);
60
61   // message_center::NotificationDelegate overrides:
62   virtual void Display() OVERRIDE;
63   virtual void Error() OVERRIDE;
64   virtual void Close(bool by_user) OVERRIDE;
65   virtual bool HasClickedListener() OVERRIDE;
66   virtual void Click() OVERRIDE;
67   virtual void ButtonClick(int button_index) OVERRIDE;
68
69  protected:
70   virtual ~HandleNotificationClickedDelegate();
71
72  private:
73   std::string id_;
74   base::Closure closure_;
75
76   DISALLOW_COPY_AND_ASSIGN(HandleNotificationClickedDelegate);
77 };
78
79 }  //  namespace message_center
80
81 #endif  // UI_MESSAGE_CENTER_NOTIFICATION_DELEGATE_H_