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