Popular sites on the NTP: check that experiment group StartsWith (rather than IS...
[chromium-blink-merge.git] / chrome / browser / notifications / notification_ui_manager_android.h
blob9c43dce03cf68aef86455aa1bea231db20f4c2e9
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_
8 #include <jni.h>
9 #include <map>
10 #include <string>
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 {
28 public:
29 NotificationUIManagerAndroid();
30 ~NotificationUIManagerAndroid() override;
32 // Called by the Java implementation when the notification has been clicked.
33 bool OnNotificationClicked(JNIEnv* env,
34 jobject java_object,
35 jlong persistent_notification_id,
36 jstring java_origin,
37 jstring java_tag);
39 // Called by the Java implementation when the notification has been closed.
40 bool OnNotificationClosed(JNIEnv* env,
41 jobject java_object,
42 jlong persistent_notification_id,
43 jstring java_origin,
44 jstring java_tag);
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(
55 ProfileID profile_id,
56 const GURL& source) override;
57 std::set<std::string> GetAllIdsByProfile(ProfileID profile_id) override;
58 bool CancelAllBySourceOrigin(const GURL& source_origin) override;
59 bool CancelAllByProfile(ProfileID profile_id) override;
60 void CancelAll() override;
62 static bool RegisterNotificationUIManager(JNIEnv* env);
64 private:
65 // Pair containing the information necessary in order to enable closing
66 // notifications that were not created by this instance of the manager: the
67 // notification's origin and tag. This list may not contain the notifications
68 // that have not been interacted with since the last restart of Chrome.
69 using RegeneratedNotificationInfo = std::pair<std::string, std::string>;
71 // Mapping of a persistent notification id to renegerated notification info.
72 // TODO(peter): Remove this map once notification delegate ids for Web
73 // notifications are created by the content/ layer.
74 std::map<int64_t, RegeneratedNotificationInfo>
75 regenerated_notification_infos_;
77 base::android::ScopedJavaGlobalRef<jobject> java_object_;
79 DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid);
82 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_