Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / notifications / notification_ui_manager_android.h
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.
4
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_
6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_
7
8 #include <jni.h>
9 #include <map>
10 #include <set>
11 #include <string>
12
13 #include "base/android/scoped_java_ref.h"
14 #include "chrome/browser/notifications/notification_ui_manager.h"
15
16 class ProfileNotification;
17
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;
24
25   // Called by the Java implementation when a notification has been clicked on.
26   void OnNotificationClicked(JNIEnv* env,
27                              jobject java_object,
28                              jstring notification_id);
29
30   // Called by the Java implementation when a notification has been closed.
31   void OnNotificationClosed(JNIEnv* env,
32                             jobject java_object,
33                             jstring notification_id);
34
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,
44                                                           const GURL& source)
45       override;
46   bool CancelAllBySourceOrigin(const GURL& source_origin) override;
47   bool CancelAllByProfile(ProfileID profile_id) override;
48   void CancelAll() override;
49
50   static bool RegisterNotificationUIManager(JNIEnv* env);
51
52  private:
53   // Closes the Notification as displayed on the Android system.
54   void PlatformCloseNotification(ProfileNotification* profile_notification);
55
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);
60
61   // Returns the ProfileNotification for the |id|, or NULL if no such
62   // notification is found.
63   ProfileNotification* FindProfileNotification(const std::string& id) const;
64
65   // Map from a notification id to the associated ProfileNotification*.
66   std::map<std::string, ProfileNotification*> profile_notifications_;
67
68   // Map from notification id to the associated platform Id.
69   std::map<std::string, int> platform_notifications_;
70
71   base::android::ScopedJavaGlobalRef<jobject> java_object_;
72
73   DISALLOW_COPY_AND_ASSIGN(NotificationUIManagerAndroid);
74 };
75
76 #endif  // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_UI_MANAGER_ANDROID_H_