Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Side by Side Diff: ui/arc/notification/arc_notification_item.h

Issue 2845003002: Merge ArcNotificationItem and ArcCustomNotificationItem (Closed)
Patch Set: Rebased Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
13 #include "base/threading/thread_checker.h"
14 #include "components/arc/common/notifications.mojom.h" 9 #include "components/arc/common/notifications.mojom.h"
15 #include "components/signin/core/account_id/account_id.h" 10 #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 11
20 namespace arc { 12 namespace arc {
21 13
22 // The class represents each ARC notification. One instance of this class
23 // corresponds to one ARC notification.
24 class ArcNotificationItem { 14 class ArcNotificationItem {
25 public: 15 public:
26 ArcNotificationItem(ArcNotificationManager* manager, 16 class Observer {
27 message_center::MessageCenter* message_center, 17 public:
28 const std::string& notification_key, 18 // Invoked when the notification data for this item has changed.
29 const AccountId& profile_id); 19 virtual void OnItemDestroying() = 0;
30 virtual ~ArcNotificationItem();
31 20
32 virtual void UpdateWithArcNotificationData( 21 // Invoked when the notification data for the item is updated.
33 mojom::ArcNotificationDataPtr data); 22 virtual void OnItemUpdated() = 0;
34 23
35 // Methods called from ArcNotificationManager: 24 protected:
36 void OnClosedFromAndroid(); 25 virtual ~Observer() = default;
26 };
37 27
38 // Methods called from ArcNotificationItemDelegate: 28 virtual ~ArcNotificationItem() = default;
39 void Close(bool by_user);
40 void Click();
41 void ButtonClick(int button_index);
42 void OpenSettings();
43 bool IsOpeningSettingsSupported() const;
44 void ToggleExpansion();
45 29
46 const std::string& notification_key() const { return notification_key_; } 30 // Called when the notification is closed on Android-side. This is called from
31 // ArcNotificationManager.
32 virtual void OnClosedFromAndroid() = 0;
33 // Called when the notification is updated on Android-side. This is called
34 // from ArcNotificationManager.
35 virtual void OnUpdatedFromAndroid(mojom::ArcNotificationDataPtr data) = 0;
47 36
48 protected: 37 // Called when the notification is closed on Chrome-side. This is called from
49 static int ConvertAndroidPriority( 38 // ArcNotificationDelegate.
50 mojom::ArcNotificationPriority android_priority); 39 virtual void Close(bool by_user) = 0;
40 // Called when the notification is clicked by user. This is called from
41 // ArcNotificationDelegate.
42 virtual void Click() = 0;
51 43
52 // Checks whether there is on-going |notification_|. 44 // Called when the user wants to open an intrinsic setting of notification.
53 bool HasPendingNotification(); 45 // This is called from ArcCustomNotificationView.
54 // Cache the |data| in |newer_data_|. 46 virtual void OpenSettings() = 0;
55 void CacheArcNotificationData(mojom::ArcNotificationDataPtr data); 47 // Called when the user wants to toggle expansio of notification. This is
48 // called from ArcCustomNotificationView.
49 virtual void ToggleExpansion() = 0;
50 // Returns true if this notification has an intrinsic setting which shown
51 // inside the notification content area. This is called from
52 // ArcCustomNotificationView.
53 virtual bool IsOpeningSettingsSupported() const = 0;
56 54
57 // Sets the pending |notification_|. 55 // Adds an observer.
58 void SetNotification( 56 virtual void AddObserver(Observer* observer) = 0;
59 std::unique_ptr<message_center::Notification> notification); 57 // Removes the observer.
58 virtual void RemoveObserver(Observer* observer) = 0;
60 59
61 // Add |notification_| to message center and update again if there is 60 // Increments |window_ref_count_| and a CreateNotificationWindow request
62 // |newer_data_|. 61 // is sent when |window_ref_count_| goes from zero to one.
63 void AddToMessageCenter(); 62 virtual void IncrementWindowRefCount() = 0;
64 63
65 bool CalledOnValidThread() const; 64 // Decrements |window_ref_count_| and a CloseNotificationWindow request
65 // is sent when |window_ref_count_| goes from one to zero.
66 virtual void DecrementWindowRefCount() = 0;
66 67
67 const AccountId& profile_id() const { return profile_id_; } 68 // Returns the current pinned state.
68 const std::string& notification_id() const { return notification_id_; } 69 virtual bool GetPinned() const = 0;
69 message_center::MessageCenter* message_center() { return message_center_; } 70 // Returns the current snapshot.
70 ArcNotificationManager* manager() { return manager_; } 71 virtual const gfx::ImageSkia& GetSnapshot() const = 0;
71 72 // Returns the current expand state.
72 message_center::Notification* pending_notification() { 73 virtual mojom::ArcNotificationExpandState GetExpandState() const = 0;
73 return notification_.get(); 74 // Returns the current type of shown contents.
74 } 75 virtual mojom::ArcNotificationShownContents GetShownContents() const = 0;
75 76 // Returns the notification key passed from Android-side.
76 private: 77 virtual const std::string& GetNotificationKey() const = 0;
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 }; 78 };
107 79
108 } // namespace arc 80 } // namespace arc
109 81
110 #endif // UI_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_H_ 82 #endif // UI_ARC_NOTIFICATION_ARC_NOTIFICATION_ITEM_H_
OLDNEW
« no previous file with comments | « ui/arc/notification/arc_notification_delegate.cc ('k') | ui/arc/notification/arc_notification_item.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698