Fire an error if a pref used in the UI is missing once all prefs are fetched.
[chromium-blink-merge.git] / chrome / browser / notifications / notification_ui_manager_android.h
blob7899f381b8aea5a1ef6baa5cfba742f87568fb70
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 <set>
11 #include <string>
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 {
21 public:
22 NotificationUIManagerAndroid();
23 ~NotificationUIManagerAndroid() override;
25 // Called by the Java implementation when a notification has been clicked on.
26 bool OnNotificationClicked(JNIEnv* env,
27 jobject java_object,
28 jstring notification_id,
29 jint platform_id,
30 jbyteArray serialized_notification_data);
32 // Called by the Java implementation when a notification has been closed.
33 bool OnNotificationClosed(JNIEnv* env,
34 jobject java_object,
35 jstring notification_id);
37 // NotificationUIManager implementation;
38 void Add(const Notification& notification, Profile* profile) override;
39 bool Update(const Notification& notification,
40 Profile* profile) override;
41 const Notification* FindById(const std::string& delegate_id,
42 ProfileID profile_id) const override;
43 bool CancelById(const std::string& delegate_id,
44 ProfileID profile_id) override;
45 std::set<std::string> GetAllIdsByProfileAndSourceOrigin(Profile* profile,
46 const GURL& source)
47 override;
48 bool CancelAllBySourceOrigin(const GURL& source_origin) override;
49 bool CancelAllByProfile(ProfileID profile_id) override;
50 void CancelAll() override;
52 static bool RegisterNotificationUIManager(JNIEnv* env);
54 private:
55 // Holds all information required to show or close a platform notification.
56 struct RegeneratedNotificationInfo {
57 RegeneratedNotificationInfo(const std::string& tag,
58 int platform_id,
59 const std::string& origin)
60 : tag(tag), platform_id(platform_id), origin(origin) {}
61 std::string tag;
62 int platform_id;
63 std::string origin;
66 // Closes the Notification as displayed on the Android system.
67 void PlatformCloseNotification(const std::string& notification_id);
69 // Helpers that add/remove the notification from local map.
70 // The local map takes ownership of profile_notification object.
71 void AddProfileNotification(ProfileNotification* profile_notification);
72 void RemoveProfileNotification(ProfileNotification* profile_notification);
74 // Returns the ProfileNotification for the |id|, or NULL if no such
75 // notification is found.
76 ProfileNotification* FindProfileNotification(const std::string& id) const;
78 // Map from a notification id to the associated ProfileNotification*.
79 std::map<std::string, ProfileNotification*> profile_notifications_;
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_