| 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 // |
| 21 // The Android notification manager only operates reliably on notifications |
| 22 // that were opened or interacted with since the last restart of Chrome. |
| 20 class NotificationUIManagerAndroid : public NotificationUIManager { | 23 class NotificationUIManagerAndroid : public NotificationUIManager { |
| 21 public: | 24 public: |
| 22 NotificationUIManagerAndroid(); | 25 NotificationUIManagerAndroid(); |
| 23 ~NotificationUIManagerAndroid() override; | 26 ~NotificationUIManagerAndroid() override; |
| 24 | 27 |
| 25 // Called by the Java implementation when a notification has been clicked on. | 28 // Called by the Java implementation when the notification has been clicked. |
| 26 bool OnNotificationClicked(JNIEnv* env, | 29 bool OnNotificationClicked(JNIEnv* env, |
| 27 jobject java_object, | 30 jobject java_object, |
| 28 jstring notification_id, | 31 jlong persistent_notification_id, |
| 29 jbyteArray serialized_notification_data); | 32 jstring java_origin, |
| 33 jstring java_tag); |
| 30 | 34 |
| 31 // Called by the Java implementation when a notification has been closed. | 35 // Called by the Java implementation when the notification has been closed. |
| 32 bool OnNotificationClosed(JNIEnv* env, | 36 bool OnNotificationClosed(JNIEnv* env, |
| 33 jobject java_object, | 37 jobject java_object, |
| 34 jstring notification_id); | 38 jlong persistent_notification_id, |
| 39 jstring java_origin, |
| 40 jstring java_tag); |
| 35 | 41 |
| 36 // NotificationUIManager implementation; | 42 // NotificationUIManager implementation; |
| 37 void Add(const Notification& notification, Profile* profile) override; | 43 void Add(const Notification& notification, Profile* profile) override; |
| 38 bool Update(const Notification& notification, | 44 bool Update(const Notification& notification, |
| 39 Profile* profile) override; | 45 Profile* profile) override; |
| 40 const Notification* FindById(const std::string& delegate_id, | 46 const Notification* FindById(const std::string& delegate_id, |
| 41 ProfileID profile_id) const override; | 47 ProfileID profile_id) const override; |
| 42 bool CancelById(const std::string& delegate_id, | 48 bool CancelById(const std::string& delegate_id, |
| 43 ProfileID profile_id) override; | 49 ProfileID profile_id) override; |
| 44 std::set<std::string> GetAllIdsByProfileAndSourceOrigin(Profile* profile, | 50 std::set<std::string> GetAllIdsByProfileAndSourceOrigin(Profile* profile, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 68 ProfileNotification* FindProfileNotification(const std::string& id) const; | 74 ProfileNotification* FindProfileNotification(const std::string& id) const; |
| 69 | 75 |
| 70 // Returns the ProfileNotification for |profile| that has the same origin and | 76 // Returns the ProfileNotification for |profile| that has the same origin and |
| 71 // tag as |notification|. Returns NULL if no valid match is found. | 77 // tag as |notification|. Returns NULL if no valid match is found. |
| 72 ProfileNotification* FindNotificationToReplace( | 78 ProfileNotification* FindNotificationToReplace( |
| 73 const Notification& notification, Profile* profile) const; | 79 const Notification& notification, Profile* profile) const; |
| 74 | 80 |
| 75 // Map from a notification id to the associated ProfileNotification*. | 81 // Map from a notification id to the associated ProfileNotification*. |
| 76 std::map<std::string, ProfileNotification*> profile_notifications_; | 82 std::map<std::string, ProfileNotification*> profile_notifications_; |
| 77 | 83 |
| 78 // Holds the tag of a notification, and its origin. | 84 // Pair containing the information necessary in order to enable closing |
| 85 // notifications that were not created by this instance of the manager: the |
| 86 // notification's origin and tag. This list may not contain the notifications |
| 87 // that have not been interacted with since the last restart of Chrome. |
| 79 using RegeneratedNotificationInfo = std::pair<std::string, std::string>; | 88 using RegeneratedNotificationInfo = std::pair<std::string, std::string>; |
| 80 | 89 |
| 81 // Map from notification id to RegeneratedNotificationInfo. | 90 // Map from persistent notification id to RegeneratedNotificationInfo. |
| 82 std::map<std::string, RegeneratedNotificationInfo> | 91 std::map<int64_t, RegeneratedNotificationInfo> |
| 83 regenerated_notification_infos_; | 92 regenerated_notification_infos_; |
| 84 | 93 |
| 85 base::android::ScopedJavaGlobalRef<jobject> java_object_; | 94 base::android::ScopedJavaGlobalRef<jobject> java_object_; |
| 86 | 95 |
| 87 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid); | 96 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid); |
| 88 }; | 97 }; |
| 89 | 98 |
| 90 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ | 99 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ |
| OLD | NEW |