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_
12 #include "base/android/scoped_java_ref.h"
13 #include "chrome/browser/notifications/notification_ui_manager.h"
15 // Implementation of the Notification UI Manager for Android, which defers to
16 // the Android framework for displaying notifications.
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.
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.
27 class NotificationUIManagerAndroid
: public NotificationUIManager
{
29 NotificationUIManagerAndroid();
30 ~NotificationUIManagerAndroid() override
;
32 // Called by the Java implementation when the notification has been clicked.
33 bool OnNotificationClicked(JNIEnv
* env
,
35 jlong persistent_notification_id
,
39 // Called by the Java implementation when the notification has been closed.
40 bool OnNotificationClosed(JNIEnv
* env
,
42 jlong persistent_notification_id
,
46 // NotificationUIManager implementation.
47 void Add(const Notification
& notification
, Profile
* profile
) override
;
48 bool Update(const Notification
& notification
,
49 Profile
* profile
) override
;
50 const Notification
* FindById(const std::string
& delegate_id
,
51 ProfileID profile_id
) const override
;
52 bool CancelById(const std::string
& delegate_id
,
53 ProfileID profile_id
) override
;
54 std::set
<std::string
> GetAllIdsByProfileAndSourceOrigin(Profile
* profile
,
57 bool CancelAllBySourceOrigin(const GURL
& source_origin
) override
;
58 bool CancelAllByProfile(ProfileID profile_id
) override
;
59 void CancelAll() override
;
61 static bool RegisterNotificationUIManager(JNIEnv
* env
);
64 // Pair containing the information necessary in order to enable closing
65 // notifications that were not created by this instance of the manager: the
66 // notification's origin and tag. This list may not contain the notifications
67 // that have not been interacted with since the last restart of Chrome.
68 using RegeneratedNotificationInfo
= std::pair
<std::string
, std::string
>;
70 // Mapping of a persistent notification id to renegerated notification info.
71 // TODO(peter): Remove this map once notification delegate ids for Web
72 // notifications are created by the content/ layer.
73 std::map
<int64_t, RegeneratedNotificationInfo
>
74 regenerated_notification_infos_
;
76 base::android::ScopedJavaGlobalRef
<jobject
> java_object_
;
78 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid
);
81 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_