OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_H_ | 5 #ifndef UI_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_H_ |
6 #define UI_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_H_ | 6 #define UI_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_H_ |
7 | 7 |
8 #include <memory> | |
9 #include <string> | |
10 | |
11 #include "base/macros.h" | 8 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 9 #include "base/observer_list.h" |
13 #include "base/threading/thread_checker.h" | 10 #include "components/arc/common/notifications.mojom.h" |
14 #include "components/signin/core/account_id/account_id.h" | 11 #include "ui/gfx/image/image_skia.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | |
16 #include "ui/arc/notification/arc_notification_manager.h" | |
17 #include "ui/message_center/message_center.h" | |
18 | 12 |
19 namespace arc { | 13 namespace arc { |
20 | 14 |
21 // The class represents each ARC notification. One instance of this class | |
22 // corresponds to one ARC notification. | |
23 class ArcNotificationItem { | 15 class ArcNotificationItem { |
24 public: | 16 public: |
25 ArcNotificationItem(ArcNotificationManager* manager, | 17 class Observer { |
26 message_center::MessageCenter* message_center, | 18 public: |
27 const std::string& notification_key, | 19 // Invoked when the notification data for this item has changed. |
28 const AccountId& profile_id); | 20 virtual void OnItemDestroying() = 0; |
29 virtual ~ArcNotificationItem(); | 21 |
22 // Invoked when the notification data for the item is updated. | |
23 virtual void OnItemUpdated() = 0; | |
24 | |
25 protected: | |
26 virtual ~Observer() = default; | |
27 }; | |
28 | |
29 virtual ~ArcNotificationItem() {} | |
hidehiko
2017/03/02 15:38:16
ditto.
| |
30 | 30 |
31 virtual void UpdateWithArcNotificationData( | 31 virtual void UpdateWithArcNotificationData( |
hidehiko
2017/03/02 15:38:16
As you change this to interface, could you documen
| |
32 mojom::ArcNotificationDataPtr data); | 32 mojom::ArcNotificationDataPtr data) = 0; |
33 | 33 |
34 // Methods called from ArcNotificationManager: | 34 // Methods called from ArcNotificationManager: |
35 void OnClosedFromAndroid(); | 35 virtual void OnClosedFromAndroid() = 0; |
36 | 36 |
37 // Methods called from ArcNotificationItemDelegate: | 37 // Methods called from ArcNotificationItemDelegate: |
38 void Close(bool by_user); | 38 virtual void Close(bool by_user) = 0; |
39 void Click(); | 39 virtual void OpenSettings() = 0; |
40 void ButtonClick(int button_index); | |
41 void OpenSettings(); | |
42 | 40 |
43 const std::string& notification_key() const { return notification_key_; } | 41 virtual void CloseFromCloseButton() = 0; |
44 | 42 |
45 protected: | 43 virtual void AddObserver(Observer* observer) = 0; |
46 static int ConvertAndroidPriority(int android_priority); | 44 virtual void RemoveObserver(Observer* observer) = 0; |
47 | 45 |
48 // Checks whether there is on-going |notification_|. | 46 // Increment |window_ref_count_| and a CreateNotificationWindow request |
49 bool HasPendingNotification(); | 47 // is sent when |window_ref_count_| goes from zero to one. |
50 // Cache the |data| in |newer_data_|. | 48 virtual void IncrementWindowRefCount() = 0; |
51 void CacheArcNotificationData(mojom::ArcNotificationDataPtr data); | |
52 | 49 |
53 // Sets the pending |notification_|. | 50 // Decrement |window_ref_count_| and a CloseNotificationWindow request |
54 void SetNotification( | 51 // is sent when |window_ref_count_| goes from one to zero. |
55 std::unique_ptr<message_center::Notification> notification); | 52 virtual void DecrementWindowRefCount() = 0; |
56 | 53 |
57 // Add |notification_| to message center and update again if there is | 54 virtual bool pinned() const = 0; |
58 // |newer_data_|. | 55 virtual const gfx::ImageSkia& snapshot() const = 0; |
59 void AddToMessageCenter(); | |
60 | 56 |
61 bool CalledOnValidThread() const; | 57 virtual const std::string& notification_key() const = 0; |
62 | |
63 const AccountId& profile_id() const { return profile_id_; } | |
64 const std::string& notification_id() const { return notification_id_; } | |
65 message_center::MessageCenter* message_center() { return message_center_; } | |
66 ArcNotificationManager* manager() { return manager_; } | |
67 | |
68 message_center::Notification* pending_notification() { | |
69 return notification_.get(); | |
70 } | |
71 | |
72 private: | |
73 void OnImageDecoded(const SkBitmap& bitmap); | |
74 | |
75 ArcNotificationManager* const manager_; | |
76 message_center::MessageCenter* const message_center_; | |
77 const AccountId profile_id_; | |
78 | |
79 const std::string notification_key_; | |
80 const std::string notification_id_; | |
81 | |
82 // Stores on-going notification data during the image decoding. | |
83 // This field will be removed after removing async task of image decoding. | |
84 std::unique_ptr<message_center::Notification> notification_; | |
85 | |
86 // The flag to indicate that the removing is initiated by the manager and we | |
87 // don't need to notify a remove event to the manager. | |
88 // This is true only when: | |
89 // (1) the notification is being removed | |
90 // (2) the removing is initiated by manager | |
91 bool being_removed_by_manager_ = false; | |
92 | |
93 // Stores the latest notification data which is newer than the on-going data. | |
94 // If the on-going data is either none or the latest, this is null. | |
95 // This field will be removed after removing async task of image decoding. | |
96 mojom::ArcNotificationDataPtr newer_data_; | |
97 | |
98 base::ThreadChecker thread_checker_; | |
99 base::WeakPtrFactory<ArcNotificationItem> weak_ptr_factory_; | |
100 | |
101 DISALLOW_COPY_AND_ASSIGN(ArcNotificationItem); | |
102 }; | 58 }; |
103 | 59 |
104 } // namespace arc | 60 } // namespace arc |
105 | 61 |
106 #endif // UI_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_H_ | 62 #endif // UI_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_H_ |
OLD | NEW |