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

Side by Side Diff: chrome/browser/notifications/notification_ui_manager_android.h

Issue 1072043003: Clean up the NotificationUIManagerAndroid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-Integrate
Patch Set: Created 5 years, 8 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 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>
11 #include <string> 10 #include <string>
12 11
13 #include "base/android/scoped_java_ref.h" 12 #include "base/android/scoped_java_ref.h"
14 #include "chrome/browser/notifications/notification_ui_manager.h" 13 #include "chrome/browser/notifications/notification_ui_manager.h"
15 14
16 class ProfileNotification;
17
18 // Implementation of the Notification UI Manager for Android, which defers to 15 // Implementation of the Notification UI Manager for Android, which defers to
19 // the Android framework for displaying notifications. 16 // the Android framework for displaying notifications.
17 //
18 // Android does not support getting the notifications currently shown by an
19 // app without very intrusive permissions, which means that it's not possible
20 // to provide reliable implementations for methods which have to iterate over
21 // the existing notifications. Because of this, these have not been implemented.
22 //
23 // The UI manager implementation *is* reliable for adding and canceling single
24 // notifications based on their delegate id. Finally, events for persistent Web
25 // Notifications will be forwarded directly to the associated event handlers,
26 // as such notifications may outlive the browser process on Android.
20 class NotificationUIManagerAndroid : public NotificationUIManager { 27 class NotificationUIManagerAndroid : public NotificationUIManager {
johnme 2015/04/09 17:00:01 With all the NOTIMPLEMENTEDs, the only methods of
Peter Beverloo 2015/04/09 17:34:42 That could work out, but requires some additional
21 public: 28 public:
22 NotificationUIManagerAndroid(); 29 NotificationUIManagerAndroid();
23 ~NotificationUIManagerAndroid() override; 30 ~NotificationUIManagerAndroid() override;
24 31
25 // Called by the Java implementation when the notification has been clicked. 32 // Called by the Java implementation when the notification has been clicked.
26 bool OnNotificationClicked(JNIEnv* env, 33 bool OnNotificationClicked(JNIEnv* env,
27 jobject java_object, 34 jobject java_object,
28 jlong persistent_notification_id, 35 jlong persistent_notification_id,
29 jstring java_origin, 36 jstring java_origin,
30 jstring java_tag); 37 jstring java_tag);
31 38
32 // Called by the Java implementation when the notification has been closed. 39 // Called by the Java implementation when the notification has been closed.
33 bool OnNotificationClosed(JNIEnv* env, 40 bool OnNotificationClosed(JNIEnv* env,
34 jobject java_object, 41 jobject java_object,
35 jlong persistent_notification_id, 42 jlong persistent_notification_id,
36 jstring java_origin, 43 jstring java_origin,
37 jstring java_tag); 44 jstring java_tag);
38 45
39 // NotificationUIManager implementation; 46 // NotificationUIManager implementation.
40 void Add(const Notification& notification, Profile* profile) override; 47 void Add(const Notification& notification, Profile* profile) override;
41 bool Update(const Notification& notification, 48 bool Update(const Notification& notification,
42 Profile* profile) override; 49 Profile* profile) override;
43 const Notification* FindById(const std::string& delegate_id, 50 const Notification* FindById(const std::string& delegate_id,
44 ProfileID profile_id) const override; 51 ProfileID profile_id) const override;
45 bool CancelById(const std::string& delegate_id, 52 bool CancelById(const std::string& delegate_id,
46 ProfileID profile_id) override; 53 ProfileID profile_id) override;
47 std::set<std::string> GetAllIdsByProfileAndSourceOrigin(Profile* profile, 54 std::set<std::string> GetAllIdsByProfileAndSourceOrigin(Profile* profile,
48 const GURL& source) 55 const GURL& source)
49 override; 56 override;
50 bool CancelAllBySourceOrigin(const GURL& source_origin) override; 57 bool CancelAllBySourceOrigin(const GURL& source_origin) override;
51 bool CancelAllByProfile(ProfileID profile_id) override; 58 bool CancelAllByProfile(ProfileID profile_id) override;
52 void CancelAll() override; 59 void CancelAll() override;
53 60
54 static bool RegisterNotificationUIManager(JNIEnv* env); 61 static bool RegisterNotificationUIManager(JNIEnv* env);
55 62
56 private: 63 private:
57 // Closes the Notification as displayed on the Android system. 64 // Pair containing the origin and tag of a notification event received from
58 void PlatformCloseNotification(const std::string& notification_id); 65 // Java. This information is required in order to support closing such
59 66 // notifications again.
60 // Adds |profile_notification| to a private local map. The map takes ownership
61 // of the notification object.
62 void AddProfileNotification(ProfileNotification* profile_notification);
63
64 // Erases |profile_notification| from the private local map and deletes it.
65 // If |close| is true, also closes the notification.
66 void RemoveProfileNotification(ProfileNotification* profile_notification,
67 bool close);
68
69 // Returns the ProfileNotification for the |id|, or NULL if no such
70 // notification is found.
71 ProfileNotification* FindProfileNotification(const std::string& id) const;
72
73 // Returns the ProfileNotification for |profile| that has the same origin and
74 // tag as |notification|. Returns NULL if no valid match is found.
75 ProfileNotification* FindNotificationToReplace(
76 const Notification& notification, Profile* profile) const;
77
78 // Map from a notification id to the associated ProfileNotification*.
79 std::map<std::string, ProfileNotification*> profile_notifications_;
80
81 // Pair containing a regenerated notification's origin and tag.
82 using RegeneratedNotificationInfo = std::pair<std::string, std::string>; 67 using RegeneratedNotificationInfo = std::pair<std::string, std::string>;
83 68
84 // Map from persistent notification id to RegeneratedNotificationInfo. 69 // Mapping of a persistent notification id to renegerated notification info.
70 // TODO(peter): Remove this map once notification delegate ids for Web
71 // notifications are created by the content/ layer.
85 std::map<int64_t, RegeneratedNotificationInfo> 72 std::map<int64_t, RegeneratedNotificationInfo>
86 regenerated_notification_infos_; 73 regenerated_notification_infos_;
87 74
88 base::android::ScopedJavaGlobalRef<jobject> java_object_; 75 base::android::ScopedJavaGlobalRef<jobject> java_object_;
89 76
90 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid); 77 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid);
91 }; 78 };
92 79
93 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_ 80 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698