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 bool OnNotificationClicked(JNIEnv
* env
,
28 jstring notification_id
,
29 jbyteArray serialized_notification_data
);
31 // Called by the Java implementation when a notification has been closed.
32 bool OnNotificationClosed(JNIEnv
* env
,
34 jstring notification_id
);
36 // NotificationUIManager implementation;
37 void Add(const Notification
& notification
, Profile
* profile
) override
;
38 bool Update(const Notification
& notification
,
39 Profile
* profile
) override
;
40 const Notification
* FindById(const std::string
& delegate_id
,
41 ProfileID profile_id
) const override
;
42 bool CancelById(const std::string
& delegate_id
,
43 ProfileID profile_id
) override
;
44 std::set
<std::string
> GetAllIdsByProfileAndSourceOrigin(Profile
* profile
,
47 bool CancelAllBySourceOrigin(const GURL
& source_origin
) override
;
48 bool CancelAllByProfile(ProfileID profile_id
) override
;
49 void CancelAll() override
;
51 static bool RegisterNotificationUIManager(JNIEnv
* env
);
54 // Closes the Notification as displayed on the Android system.
55 void PlatformCloseNotification(const std::string
& notification_id
);
57 // Adds |profile_notification| to a private local map. The map takes ownership
58 // of the notification object.
59 void AddProfileNotification(ProfileNotification
* profile_notification
);
61 // Erases |profile_notification| from the private local map and deletes it.
62 // If |close| is true, also closes the notification.
63 void RemoveProfileNotification(ProfileNotification
* profile_notification
,
66 // Returns the ProfileNotification for the |id|, or NULL if no such
67 // notification is found.
68 ProfileNotification
* FindProfileNotification(const std::string
& id
) const;
70 // Returns the ProfileNotification for |profile| that has the same origin and
71 // tag as |notification|. Returns NULL if no valid match is found.
72 ProfileNotification
* FindNotificationToReplace(
73 const Notification
& notification
, Profile
* profile
) const;
75 // Map from a notification id to the associated ProfileNotification*.
76 std::map
<std::string
, ProfileNotification
*> profile_notifications_
;
78 // Holds the tag of a notification, and its origin.
79 using RegeneratedNotificationInfo
= std::pair
<std::string
, std::string
>;
81 // Map from notification id to RegeneratedNotificationInfo.
82 std::map
<std::string
, RegeneratedNotificationInfo
>
83 regenerated_notification_infos_
;
85 base::android::ScopedJavaGlobalRef
<jobject
> java_object_
;
87 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid
);
90 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_