1 // Copyright 2017 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 ASH_PUBLIC_CPP_EXTERNAL_ARC_MESSAGE_CENTER_ARC_NOTIFICATION_DELEGATE_H_
6 #define ASH_PUBLIC_CPP_EXTERNAL_ARC_MESSAGE_CENTER_ARC_NOTIFICATION_DELEGATE_H_
7 
8 #include "base/macros.h"
9 #include "base/memory/weak_ptr.h"
10 #include "ui/message_center/public/cpp/notification_delegate.h"
11 
12 namespace message_center {
13 
14 class MessageView;
15 class Notification;
16 
17 }  // namespace message_center
18 
19 namespace ash {
20 
21 class ArcNotificationItem;
22 
23 // Implementation of NotificationDelegate for ARC notifications.
24 class ArcNotificationDelegate : public message_center::NotificationDelegate {
25  public:
26   explicit ArcNotificationDelegate(base::WeakPtr<ArcNotificationItem> item);
27 
28   // Creates a view for the given notification (which must have been the one
29   // generated by |item_|).
30   std::unique_ptr<message_center::MessageView> CreateCustomMessageView(
31       const message_center::Notification& notification);
32 
33   // message_center::NotificationDelegate overrides:
34   void Close(bool by_user) override;
35   void Click(const base::Optional<int>& button_index,
36              const base::Optional<base::string16>& reply) override;
37   void SettingsClick() override;
38 
39  private:
40   // The destructor is private since this class is ref-counted.
41   ~ArcNotificationDelegate() override;
42 
43   // We use weak ptr to detect potential use-after-free. The lives of objects
44   // around ARC notification is somewhat complex so we want to use it until
45   // it gets stable.
46   base::WeakPtr<ArcNotificationItem> item_;
47 
48   DISALLOW_COPY_AND_ASSIGN(ArcNotificationDelegate);
49 };
50 
51 }  // namespace ash
52 
53 #endif  // ASH_PUBLIC_CPP_EXTERNAL_ARC_MESSAGE_CENTER_ARC_NOTIFICATION_DELEGATE_H_
54