OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ |
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/android/scoped_java_ref.h" | 13 #include "base/android/scoped_java_ref.h" |
14 #include "chrome/browser/notifications/notification_ui_manager.h" | 14 #include "chrome/browser/notifications/notification_ui_manager.h" |
15 | 15 |
16 class ProfileNotification; | 16 class ProfileNotification; |
17 | 17 |
18 // Implementation of the Notification UI Manager for Android, which defers to | 18 // Implementation of the Notification UI Manager for Android, which defers to |
19 // the Android framework for displaying notifications. | 19 // the Android framework for displaying notifications. |
20 class NotificationUIManagerAndroid : public NotificationUIManager { | 20 class NotificationUIManagerAndroid : public NotificationUIManager { |
21 public: | 21 public: |
22 NotificationUIManagerAndroid(); | 22 NotificationUIManagerAndroid(); |
23 ~NotificationUIManagerAndroid() override; | 23 ~NotificationUIManagerAndroid() override; |
24 | 24 |
25 // Called by the Java implementation when a notification has been clicked on. | 25 // Called by the Java implementation when the notification has been clicked. |
26 bool OnNotificationClicked(JNIEnv* env, | 26 bool OnNotificationClicked(JNIEnv* env, |
27 jobject java_object, | 27 jobject java_object, |
28 jstring notification_id, | 28 jlong persistent_notification_id, |
29 jbyteArray serialized_notification_data); | 29 jstring java_origin, |
30 jstring java_tag); | |
30 | 31 |
31 // Called by the Java implementation when a notification has been closed. | 32 // Called by the Java implementation when the notification has been closed. |
32 bool OnNotificationClosed(JNIEnv* env, | 33 bool OnNotificationClosed(JNIEnv* env, |
33 jobject java_object, | 34 jobject java_object, |
34 jstring notification_id); | 35 jlong persistent_notification_id, |
36 jstring java_origin, | |
37 jstring java_tag); | |
35 | 38 |
36 // NotificationUIManager implementation; | 39 // NotificationUIManager implementation; |
37 void Add(const Notification& notification, Profile* profile) override; | 40 void Add(const Notification& notification, Profile* profile) override; |
38 bool Update(const Notification& notification, | 41 bool Update(const Notification& notification, |
39 Profile* profile) override; | 42 Profile* profile) override; |
40 const Notification* FindById(const std::string& delegate_id, | 43 const Notification* FindById(const std::string& delegate_id, |
41 ProfileID profile_id) const override; | 44 ProfileID profile_id) const override; |
42 bool CancelById(const std::string& delegate_id, | 45 bool CancelById(const std::string& delegate_id, |
43 ProfileID profile_id) override; | 46 ProfileID profile_id) override; |
44 std::set<std::string> GetAllIdsByProfileAndSourceOrigin(Profile* profile, | 47 std::set<std::string> GetAllIdsByProfileAndSourceOrigin(Profile* profile, |
45 const GURL& source) | 48 const GURL& source) |
46 override; | 49 override; |
47 bool CancelAllBySourceOrigin(const GURL& source_origin) override; | 50 bool CancelAllBySourceOrigin(const GURL& source_origin) override; |
48 bool CancelAllByProfile(ProfileID profile_id) override; | 51 bool CancelAllByProfile(ProfileID profile_id) override; |
49 void CancelAll() override; | 52 void CancelAll() override; |
dewittj
2015/04/13 18:58:53
please document that these functions will only ope
Peter Beverloo
2015/04/14 14:09:29
Done. Added it to the class-level comment.
| |
50 | 53 |
51 static bool RegisterNotificationUIManager(JNIEnv* env); | 54 static bool RegisterNotificationUIManager(JNIEnv* env); |
52 | 55 |
53 private: | 56 private: |
54 // Closes the Notification as displayed on the Android system. | 57 // Closes the Notification as displayed on the Android system. |
55 void PlatformCloseNotification(const std::string& notification_id); | 58 void PlatformCloseNotification(const std::string& notification_id); |
56 | 59 |
57 // Adds |profile_notification| to a private local map. The map takes ownership | 60 // Adds |profile_notification| to a private local map. The map takes ownership |
58 // of the notification object. | 61 // of the notification object. |
59 void AddProfileNotification(ProfileNotification* profile_notification); | 62 void AddProfileNotification(ProfileNotification* profile_notification); |
60 | 63 |
61 // Erases |profile_notification| from the private local map and deletes it. | 64 // Erases |profile_notification| from the private local map and deletes it. |
62 // If |close| is true, also closes the notification. | 65 // If |close| is true, also closes the notification. |
63 void RemoveProfileNotification(ProfileNotification* profile_notification, | 66 void RemoveProfileNotification(ProfileNotification* profile_notification, |
64 bool close); | 67 bool close); |
65 | 68 |
66 // Returns the ProfileNotification for the |id|, or NULL if no such | 69 // Returns the ProfileNotification for the |id|, or NULL if no such |
67 // notification is found. | 70 // notification is found. |
68 ProfileNotification* FindProfileNotification(const std::string& id) const; | 71 ProfileNotification* FindProfileNotification(const std::string& id) const; |
69 | 72 |
70 // Returns the ProfileNotification for |profile| that has the same origin and | 73 // Returns the ProfileNotification for |profile| that has the same origin and |
71 // tag as |notification|. Returns NULL if no valid match is found. | 74 // tag as |notification|. Returns NULL if no valid match is found. |
72 ProfileNotification* FindNotificationToReplace( | 75 ProfileNotification* FindNotificationToReplace( |
73 const Notification& notification, Profile* profile) const; | 76 const Notification& notification, Profile* profile) const; |
74 | 77 |
75 // Map from a notification id to the associated ProfileNotification*. | 78 // Map from a notification id to the associated ProfileNotification*. |
76 std::map<std::string, ProfileNotification*> profile_notifications_; | 79 std::map<std::string, ProfileNotification*> profile_notifications_; |
77 | 80 |
78 // Holds the tag of a notification, and its origin. | 81 // Pair containing the information necessary in order to enable working with |
dewittj
2015/04/13 18:58:53
nit: this is only used for closing notifications (
Peter Beverloo
2015/04/14 14:09:29
Done.
| |
82 // notifications which were not created by this instance of the manager: the | |
83 // notification's origin and tag. | |
79 using RegeneratedNotificationInfo = std::pair<std::string, std::string>; | 84 using RegeneratedNotificationInfo = std::pair<std::string, std::string>; |
80 | 85 |
81 // Map from notification id to RegeneratedNotificationInfo. | 86 // Map from persistent notification id to RegeneratedNotificationInfo. |
82 std::map<std::string, RegeneratedNotificationInfo> | 87 std::map<int64_t, RegeneratedNotificationInfo> |
83 regenerated_notification_infos_; | 88 regenerated_notification_infos_; |
84 | 89 |
85 base::android::ScopedJavaGlobalRef<jobject> java_object_; | 90 base::android::ScopedJavaGlobalRef<jobject> java_object_; |
86 | 91 |
87 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid); | 92 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid); |
88 }; | 93 }; |
89 | 94 |
90 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ | 95 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ |
OLD | NEW |