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> |
8 #include <string> | 9 #include <string> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
13 #include "components/signin/core/account_id/account_id.h" | 14 #include "components/signin/core/account_id/account_id.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
15 #include "ui/arc/notification/arc_notification_manager.h" | 16 #include "ui/arc/notification/arc_notification_manager.h" |
16 #include "ui/message_center/message_center.h" | 17 #include "ui/message_center/message_center.h" |
17 | 18 |
18 namespace arc { | 19 namespace arc { |
19 | 20 |
20 // The class represents each ARC notification. One instance of this class | 21 // The class represents each ARC notification. One instance of this class |
21 // corresponds to one ARC notification. | 22 // corresponds to one ARC notification. |
22 class ArcNotificationItem { | 23 class ArcNotificationItem { |
23 public: | 24 public: |
24 ArcNotificationItem(ArcNotificationManager* manager, | 25 ArcNotificationItem(ArcNotificationManager* manager, |
25 message_center::MessageCenter* message_center, | 26 message_center::MessageCenter* message_center, |
26 const std::string& notification_key, | 27 const std::string& notification_key, |
27 const AccountId& profile_id); | 28 const AccountId& profile_id); |
28 ~ArcNotificationItem(); | 29 virtual ~ArcNotificationItem(); |
29 | 30 |
30 void UpdateWithArcNotificationData(const mojom::ArcNotificationData& data); | 31 virtual void UpdateWithArcNotificationData( |
| 32 const mojom::ArcNotificationData& data); |
31 | 33 |
32 // Methods called from ArcNotificationManager: | 34 // Methods called from ArcNotificationManager: |
33 void OnClosedFromAndroid(bool by_user); | 35 void OnClosedFromAndroid(bool by_user); |
34 | 36 |
35 // Methods called from ArcNotificationItemDelegate: | 37 // Methods called from ArcNotificationItemDelegate: |
36 void Close(bool by_user); | 38 void Close(bool by_user); |
37 void Click(); | 39 void Click(); |
38 void ButtonClick(int button_index); | 40 void ButtonClick(int button_index); |
39 | 41 |
| 42 protected: |
| 43 static int ConvertAndroidPriority(int android_priority); |
| 44 |
| 45 // Checks whether there is on-going |notification_|. If so, cache the |data| |
| 46 // in |newer_data_| and returns true. Otherwise, returns false. |
| 47 bool CacheArcNotificationData(const mojom::ArcNotificationData& data); |
| 48 |
| 49 // Sets the pending |notification_|. |
| 50 void SetNotification( |
| 51 std::unique_ptr<message_center::Notification> notification); |
| 52 |
| 53 // Add |notification_| to message center and update again if there is |
| 54 // |newer_data_|. |
| 55 void AddToMessageCenter(); |
| 56 |
| 57 bool CalledOnValidThread() const; |
| 58 |
| 59 const AccountId& profile_id() const { return profile_id_; } |
| 60 const std::string& notification_key() const { return notification_key_; } |
| 61 const std::string& notification_id() const { return notification_id_; } |
| 62 |
| 63 message_center::Notification* pending_notification() { |
| 64 return notification_.get(); |
| 65 } |
| 66 |
40 private: | 67 private: |
41 void OnImageDecoded(const SkBitmap& bitmap); | 68 void OnImageDecoded(const SkBitmap& bitmap); |
42 | 69 |
43 ArcNotificationManager* const manager_; | 70 ArcNotificationManager* const manager_; |
44 message_center::MessageCenter* const message_center_; | 71 message_center::MessageCenter* const message_center_; |
45 const AccountId profile_id_; | 72 const AccountId profile_id_; |
46 | 73 |
47 const std::string notification_key_; | 74 const std::string notification_key_; |
48 const std::string notification_id_; | 75 const std::string notification_id_; |
49 | 76 |
(...skipping 15 matching lines...) Expand all Loading... |
65 | 92 |
66 base::ThreadChecker thread_checker_; | 93 base::ThreadChecker thread_checker_; |
67 base::WeakPtrFactory<ArcNotificationItem> weak_ptr_factory_; | 94 base::WeakPtrFactory<ArcNotificationItem> weak_ptr_factory_; |
68 | 95 |
69 DISALLOW_COPY_AND_ASSIGN(ArcNotificationItem); | 96 DISALLOW_COPY_AND_ASSIGN(ArcNotificationItem); |
70 }; | 97 }; |
71 | 98 |
72 } // namespace arc | 99 } // namespace arc |
73 | 100 |
74 #endif // UI_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_H_ | 101 #endif // UI_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_H_ |
OLD | NEW |