OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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_IMPL_H_ |
6 #define UI_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_H_ | 6 #define UI_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_IMPL_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
14 #include "components/arc/common/notifications.mojom.h" | |
15 #include "components/signin/core/account_id/account_id.h" | 14 #include "components/signin/core/account_id/account_id.h" |
16 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
16 #include "ui/arc/notification/arc_notification_item.h" | |
17 #include "ui/arc/notification/arc_notification_manager.h" | 17 #include "ui/arc/notification/arc_notification_manager.h" |
18 #include "ui/message_center/message_center.h" | 18 #include "ui/message_center/message_center.h" |
19 | 19 |
20 namespace arc { | 20 namespace arc { |
21 | 21 |
22 // The class represents each ARC notification. One instance of this class | 22 // The class represents each ARC notification. One instance of this class |
23 // corresponds to one ARC notification. | 23 // corresponds to one ARC notification. |
24 class ArcNotificationItem { | 24 class ArcNotificationItemImpl : public ArcNotificationItem { |
25 public: | 25 public: |
26 ArcNotificationItem(ArcNotificationManager* manager, | 26 ArcNotificationItemImpl(ArcNotificationManager* manager, |
27 message_center::MessageCenter* message_center, | 27 message_center::MessageCenter* message_center, |
28 const std::string& notification_key, | 28 const std::string& notification_key, |
29 const AccountId& profile_id); | 29 const AccountId& profile_id); |
30 virtual ~ArcNotificationItem(); | 30 ~ArcNotificationItemImpl() override; |
31 | 31 |
32 virtual void UpdateWithArcNotificationData( | 32 void UpdateWithArcNotificationData( |
33 mojom::ArcNotificationDataPtr data); | 33 mojom::ArcNotificationDataPtr data) override; |
34 | 34 |
35 // Methods called from ArcNotificationManager: | 35 void OnClosedFromAndroid() override; |
hidehiko
2017/05/01 12:29:18
// ArcNotificationItem overrides:
yoshiki
2017/05/08 06:24:53
Done.
| |
36 void OnClosedFromAndroid(); | 36 void Close(bool by_user) override; |
37 void Click() override; | |
38 void CloseFromCloseButton() override; | |
39 void OpenSettings() override; | |
40 bool IsOpeningSettingsSupported() const override; | |
41 void ToggleExpansion() override; | |
37 | 42 |
38 // Methods called from ArcNotificationItemDelegate: | 43 void AddObserver(Observer* observer) override; |
39 void Close(bool by_user); | 44 void RemoveObserver(Observer* observer) override; |
40 void Click(); | |
41 void ButtonClick(int button_index); | |
42 void OpenSettings(); | |
43 bool IsOpeningSettingsSupported() const; | |
44 void ToggleExpansion(); | |
45 | 45 |
46 const std::string& notification_key() const { return notification_key_; } | 46 void IncrementWindowRefCount() override; |
47 void DecrementWindowRefCount() override; | |
48 | |
49 bool GetPinned() const override; | |
50 const gfx::ImageSkia& GetSnapshot() const override; | |
51 mojom::ArcNotificationExpandState GetExpandState() const override; | |
52 mojom::ArcNotificationShownContents GetShownContents() const override; | |
53 const std::string& GetNotificationKey() const override; | |
47 | 54 |
48 protected: | 55 protected: |
hidehiko
2017/05/01 12:29:18
Because ArcNotificationItemImpl is no longer inher
yoshiki
2017/05/08 06:24:53
Done.
| |
49 static int ConvertAndroidPriority( | |
50 mojom::ArcNotificationPriority android_priority); | |
51 | |
52 // Checks whether there is on-going |notification_|. | 56 // Checks whether there is on-going |notification_|. |
hidehiko
2017/05/01 12:29:18
(optional): Also, several util functions can be in
yoshiki
2017/05/08 06:24:53
Removed unnecessary util methods
| |
53 bool HasPendingNotification(); | 57 bool HasPendingNotification(); |
54 // Cache the |data| in |newer_data_|. | 58 // Cache the |data| in |newer_data_|. |
55 void CacheArcNotificationData(mojom::ArcNotificationDataPtr data); | 59 void CacheArcNotificationData(mojom::ArcNotificationDataPtr data); |
56 | 60 |
57 // Sets the pending |notification_|. | 61 // Sets the pending |notification_|. |
58 void SetNotification( | 62 void SetNotification( |
59 std::unique_ptr<message_center::Notification> notification); | 63 std::unique_ptr<message_center::Notification> notification); |
60 | 64 |
61 // Add |notification_| to message center and update again if there is | 65 // Add |notification_| to message center and update again if there is |
62 // |newer_data_|. | 66 // |newer_data_|. |
63 void AddToMessageCenter(); | 67 void AddToMessageCenter(); |
64 | 68 |
65 bool CalledOnValidThread() const; | 69 bool CalledOnValidThread() const; |
66 | 70 |
67 const AccountId& profile_id() const { return profile_id_; } | 71 const AccountId& profile_id() const { return profile_id_; } |
hidehiko
2017/05/01 12:29:18
Also, do not need these accessors?
yoshiki
2017/05/08 06:24:53
Removed
| |
68 const std::string& notification_id() const { return notification_id_; } | 72 const std::string& notification_id() const { return notification_id_; } |
69 message_center::MessageCenter* message_center() { return message_center_; } | 73 message_center::MessageCenter* message_center() { return message_center_; } |
70 ArcNotificationManager* manager() { return manager_; } | 74 ArcNotificationManager* manager() { return manager_; } |
71 | 75 |
72 message_center::Notification* pending_notification() { | 76 message_center::Notification* pending_notification() { |
73 return notification_.get(); | 77 return notification_.get(); |
74 } | 78 } |
75 | 79 |
76 private: | 80 private: |
77 void OnImageDecoded(const SkBitmap& bitmap); | 81 void OnImageDecoded(const SkBitmap& bitmap); |
78 | 82 |
79 ArcNotificationManager* const manager_; | 83 ArcNotificationManager* const manager_; |
80 message_center::MessageCenter* const message_center_; | 84 message_center::MessageCenter* const message_center_; |
81 const AccountId profile_id_; | 85 const AccountId profile_id_; |
82 | 86 |
87 bool pinned_ = false; | |
hidehiko
2017/05/01 12:29:18
Comments for each field, please?
yoshiki
2017/05/08 06:24:53
Done.
| |
88 gfx::ImageSkia snapshot_; | |
89 mojom::ArcNotificationExpandState expand_state_ = | |
90 mojom::ArcNotificationExpandState::FIXED_SIZE; | |
91 mojom::ArcNotificationShownContents shown_contents_ = | |
92 mojom::ArcNotificationShownContents::CONTENTS_SHOWN; | |
93 int window_ref_count_ = 0; | |
94 | |
95 base::ObserverList<Observer> observers_; | |
hidehiko
2017/05/01 12:29:18
include base/observer_list.h ?
yoshiki
2017/05/08 06:24:53
Done.
| |
96 | |
83 const std::string notification_key_; | 97 const std::string notification_key_; |
84 const std::string notification_id_; | 98 const std::string notification_id_; |
85 | 99 |
86 // Stores on-going notification data during the image decoding. | 100 // Stores on-going notification data during the image decoding. |
87 // This field will be removed after removing async task of image decoding. | 101 // This field will be removed after removing async task of image decoding. |
88 std::unique_ptr<message_center::Notification> notification_; | 102 std::unique_ptr<message_center::Notification> notification_; |
89 | 103 |
90 // The flag to indicate that the removing is initiated by the manager and we | 104 // 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. | 105 // don't need to notify a remove event to the manager. |
92 // This is true only when: | 106 // This is true only when: |
93 // (1) the notification is being removed | 107 // (1) the notification is being removed |
94 // (2) the removing is initiated by manager | 108 // (2) the removing is initiated by manager |
95 bool being_removed_by_manager_ = false; | 109 bool being_removed_by_manager_ = false; |
96 | 110 |
97 // Stores the latest notification data which is newer than the on-going data. | 111 // 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. | 112 // 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. | 113 // This field will be removed after removing async task of image decoding. |
100 mojom::ArcNotificationDataPtr newer_data_; | 114 mojom::ArcNotificationDataPtr newer_data_; |
101 | 115 |
102 base::ThreadChecker thread_checker_; | 116 base::ThreadChecker thread_checker_; |
103 base::WeakPtrFactory<ArcNotificationItem> weak_ptr_factory_; | 117 base::WeakPtrFactory<ArcNotificationItemImpl> weak_ptr_factory_; |
104 | 118 |
105 DISALLOW_COPY_AND_ASSIGN(ArcNotificationItem); | 119 DISALLOW_COPY_AND_ASSIGN(ArcNotificationItemImpl); |
106 }; | 120 }; |
107 | 121 |
108 } // namespace arc | 122 } // namespace arc |
109 | 123 |
110 #endif // UI_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_H_ | 124 #endif // UI_ARC_NOTIFICATION_ARC_NOTIFICATION_IMPL_ITEM_H_ |
OLD | NEW |