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 "base/strings/string16.h" |
14 #include "chrome/browser/notifications/notification_ui_manager.h" | 15 #include "chrome/browser/notifications/notification_ui_manager.h" |
15 | 16 |
16 class ProfileNotification; | 17 class ProfileNotification; |
17 | 18 |
18 // Implementation of the Notification UI Manager for Android, which defers to | 19 // Implementation of the Notification UI Manager for Android, which defers to |
19 // the Android framework for displaying notifications. | 20 // the Android framework for displaying notifications. |
20 class NotificationUIManagerAndroid : public NotificationUIManager { | 21 class NotificationUIManagerAndroid : public NotificationUIManager { |
21 public: | 22 public: |
22 NotificationUIManagerAndroid(); | 23 NotificationUIManagerAndroid(); |
23 ~NotificationUIManagerAndroid() override; | 24 ~NotificationUIManagerAndroid() override; |
(...skipping 21 matching lines...) Expand all Loading... |
45 std::set<std::string> GetAllIdsByProfileAndSourceOrigin(Profile* profile, | 46 std::set<std::string> GetAllIdsByProfileAndSourceOrigin(Profile* profile, |
46 const GURL& source) | 47 const GURL& source) |
47 override; | 48 override; |
48 bool CancelAllBySourceOrigin(const GURL& source_origin) override; | 49 bool CancelAllBySourceOrigin(const GURL& source_origin) override; |
49 bool CancelAllByProfile(ProfileID profile_id) override; | 50 bool CancelAllByProfile(ProfileID profile_id) override; |
50 void CancelAll() override; | 51 void CancelAll() override; |
51 | 52 |
52 static bool RegisterNotificationUIManager(JNIEnv* env); | 53 static bool RegisterNotificationUIManager(JNIEnv* env); |
53 | 54 |
54 private: | 55 private: |
| 56 // Holds all information required to show or close a platform notification. |
| 57 struct RegeneratedNotificationInfo { |
| 58 RegeneratedNotificationInfo(const base::string16& tag, |
| 59 int platform_id, |
| 60 const std::string& origin) |
| 61 : tag(tag), platform_id(platform_id), origin(origin) {} |
| 62 base::string16 tag; |
| 63 int platform_id; |
| 64 std::string origin; |
| 65 }; |
| 66 |
55 // Closes the Notification as displayed on the Android system. | 67 // Closes the Notification as displayed on the Android system. |
56 void PlatformCloseNotification(const std::string& notification_id); | 68 void PlatformCloseNotification(const std::string& notification_id); |
57 | 69 |
58 // Helpers that add/remove the notification from local map. | 70 // Helpers that add/remove the notification from local map. |
59 // The local map takes ownership of profile_notification object. | 71 // The local map takes ownership of profile_notification object. |
60 void AddProfileNotification(ProfileNotification* profile_notification); | 72 void AddProfileNotification(ProfileNotification* profile_notification); |
61 void RemoveProfileNotification(ProfileNotification* profile_notification); | 73 void RemoveProfileNotification(ProfileNotification* profile_notification); |
62 | 74 |
63 // Returns the ProfileNotification for the |id|, or NULL if no such | 75 // Returns the ProfileNotification for the |id|, or NULL if no such |
64 // notification is found. | 76 // notification is found. |
65 ProfileNotification* FindProfileNotification(const std::string& id) const; | 77 ProfileNotification* FindProfileNotification(const std::string& id) const; |
66 | 78 |
67 // Map from a notification id to the associated ProfileNotification*. | 79 // Map from a notification id to the associated ProfileNotification*. |
68 std::map<std::string, ProfileNotification*> profile_notifications_; | 80 std::map<std::string, ProfileNotification*> profile_notifications_; |
69 | 81 |
70 // Map from notification id to the associated platform Id. | 82 // Map from notification id to RegeneratedNotificationInfo. |
71 std::map<std::string, int> platform_notifications_; | 83 std::map<std::string, RegeneratedNotificationInfo> |
| 84 regenerated_notification_infos_; |
72 | 85 |
73 base::android::ScopedJavaGlobalRef<jobject> java_object_; | 86 base::android::ScopedJavaGlobalRef<jobject> java_object_; |
74 | 87 |
75 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid); | 88 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid); |
76 }; | 89 }; |
77 | 90 |
78 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ | 91 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ |
OLD | NEW |