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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_
13 #include "base/android/scoped_java_ref.h"
14 #include "chrome/browser/notifications/notification_ui_manager.h"
16 class ProfileNotification;
18 // Implementation of the Notification UI Manager for Android, which defers to
19 // the Android framework for displaying notifications.
20 class NotificationUIManagerAndroid : public NotificationUIManager {
22 NotificationUIManagerAndroid();
23 ~NotificationUIManagerAndroid() override;
25 // Called by the Java implementation when a notification has been clicked on.
26 void OnNotificationClicked(JNIEnv* env,
28 jstring notification_id);
30 // Called by the Java implementation when a notification has been closed.
31 void OnNotificationClosed(JNIEnv* env,
33 jstring notification_id);
35 // NotificationUIManager implementation;
36 void Add(const Notification& notification, Profile* profile) override;
37 bool Update(const Notification& notification,
38 Profile* profile) override;
39 const Notification* FindById(const std::string& delegate_id,
40 ProfileID profile_id) const override;
41 bool CancelById(const std::string& delegate_id,
42 ProfileID profile_id) override;
43 std::set<std::string> GetAllIdsByProfileAndSourceOrigin(Profile* profile,
46 bool CancelAllBySourceOrigin(const GURL& source_origin) override;
47 bool CancelAllByProfile(ProfileID profile_id) override;
48 void CancelAll() override;
50 static bool RegisterNotificationUIManager(JNIEnv* env);
53 // Closes the Notification as displayed on the Android system.
54 void PlatformCloseNotification(ProfileNotification* profile_notification);
56 // Helpers that add/remove the notification from local map.
57 // The local map takes ownership of profile_notification object.
58 void AddProfileNotification(ProfileNotification* profile_notification);
59 void RemoveProfileNotification(ProfileNotification* profile_notification);
61 // Returns the ProfileNotification for the |id|, or NULL if no such
62 // notification is found.
63 ProfileNotification* FindProfileNotification(const std::string& id) const;
65 // Map from a notification id to the associated ProfileNotification*.
66 std::map<std::string, ProfileNotification*> profile_notifications_;
68 // Map from notification id to the associated platform Id.
69 std::map<std::string, int> platform_notifications_;
71 base::android::ScopedJavaGlobalRef<jobject> java_object_;
73 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid);
76 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_