OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ |
6 #define CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
11 #include <string> | 11 #include <string> |
12 | 12 |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/strings/string16.h" | 17 #include "base/strings/string16.h" |
18 #include "chrome/browser/notifications/notification.h" | 18 #include "chrome/browser/notifications/notification.h" |
19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
20 #include "content/public/browser/platform_notification_service.h" | 20 #include "content/public/browser/platform_notification_service.h" |
21 #include "content/public/common/persistent_notification_status.h" | 21 #include "content/public/common/persistent_notification_status.h" |
22 | 22 |
23 class NotificationDelegate; | 23 class NotificationDelegate; |
24 class NotificationUIManager; | 24 class NotificationUIManager; |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 class BrowserContext; | 27 class BrowserContext; |
| 28 struct NotificationResources; |
28 } | 29 } |
29 | 30 |
30 namespace gcm { | 31 namespace gcm { |
31 class PushMessagingBrowserTest; | 32 class PushMessagingBrowserTest; |
32 } | 33 } |
33 | 34 |
34 // The platform notification service is the profile-agnostic entry point through | 35 // The platform notification service is the profile-agnostic entry point through |
35 // which Web Notifications can be controlled. | 36 // which Web Notifications can be controlled. |
36 class PlatformNotificationServiceImpl | 37 class PlatformNotificationServiceImpl |
37 : public content::PlatformNotificationService { | 38 : public content::PlatformNotificationService { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 content::BrowserContext* browser_context, | 89 content::BrowserContext* browser_context, |
89 const GURL& origin, | 90 const GURL& origin, |
90 int render_process_id) override; | 91 int render_process_id) override; |
91 blink::WebNotificationPermission CheckPermissionOnIOThread( | 92 blink::WebNotificationPermission CheckPermissionOnIOThread( |
92 content::ResourceContext* resource_context, | 93 content::ResourceContext* resource_context, |
93 const GURL& origin, | 94 const GURL& origin, |
94 int render_process_id) override; | 95 int render_process_id) override; |
95 void DisplayNotification( | 96 void DisplayNotification( |
96 content::BrowserContext* browser_context, | 97 content::BrowserContext* browser_context, |
97 const GURL& origin, | 98 const GURL& origin, |
98 const SkBitmap& icon, | |
99 const content::PlatformNotificationData& notification_data, | 99 const content::PlatformNotificationData& notification_data, |
| 100 const content::NotificationResources& notification_resources, |
100 scoped_ptr<content::DesktopNotificationDelegate> delegate, | 101 scoped_ptr<content::DesktopNotificationDelegate> delegate, |
101 base::Closure* cancel_callback) override; | 102 base::Closure* cancel_callback) override; |
102 void DisplayPersistentNotification( | 103 void DisplayPersistentNotification( |
103 content::BrowserContext* browser_context, | 104 content::BrowserContext* browser_context, |
104 int64_t persistent_notification_id, | 105 int64_t persistent_notification_id, |
105 const GURL& origin, | 106 const GURL& origin, |
106 const SkBitmap& icon, | 107 const content::PlatformNotificationData& notification_data, |
107 const content::PlatformNotificationData& notification_data) override; | 108 const content::NotificationResources& notification_resources) override; |
108 void ClosePersistentNotification( | 109 void ClosePersistentNotification( |
109 content::BrowserContext* browser_context, | 110 content::BrowserContext* browser_context, |
110 int64_t persistent_notification_id) override; | 111 int64_t persistent_notification_id) override; |
111 bool GetDisplayedPersistentNotifications( | 112 bool GetDisplayedPersistentNotifications( |
112 content::BrowserContext* browser_context, | 113 content::BrowserContext* browser_context, |
113 std::set<std::string>* displayed_notifications) override; | 114 std::set<std::string>* displayed_notifications) override; |
114 | 115 |
115 private: | 116 private: |
116 friend struct base::DefaultSingletonTraits<PlatformNotificationServiceImpl>; | 117 friend struct base::DefaultSingletonTraits<PlatformNotificationServiceImpl>; |
117 friend class PlatformNotificationServiceBrowserTest; | 118 friend class PlatformNotificationServiceBrowserTest; |
118 friend class PlatformNotificationServiceTest; | 119 friend class PlatformNotificationServiceTest; |
119 friend class PushMessagingBrowserTest; | 120 friend class PushMessagingBrowserTest; |
120 FRIEND_TEST_ALL_PREFIXES(PlatformNotificationServiceTest, | 121 FRIEND_TEST_ALL_PREFIXES(PlatformNotificationServiceTest, |
121 CreateNotificationFromData); | 122 CreateNotificationFromData); |
122 FRIEND_TEST_ALL_PREFIXES(PlatformNotificationServiceTest, | 123 FRIEND_TEST_ALL_PREFIXES(PlatformNotificationServiceTest, |
123 DisplayNameForContextMessage); | 124 DisplayNameForContextMessage); |
124 | 125 |
125 PlatformNotificationServiceImpl(); | 126 PlatformNotificationServiceImpl(); |
126 ~PlatformNotificationServiceImpl() override; | 127 ~PlatformNotificationServiceImpl() override; |
127 | 128 |
128 // Creates a new Web Notification-based Notification object. | 129 // Creates a new Web Notification-based Notification object. |
129 // TODO(peter): |delegate| can be a scoped_refptr, but properly passing this | 130 // TODO(peter): |delegate| can be a scoped_refptr, but properly passing this |
130 // through requires changing a whole lot of Notification constructor calls. | 131 // through requires changing a whole lot of Notification constructor calls. |
131 Notification CreateNotificationFromData( | 132 Notification CreateNotificationFromData( |
132 Profile* profile, | 133 Profile* profile, |
133 const GURL& origin, | 134 const GURL& origin, |
134 const SkBitmap& icon, | |
135 const content::PlatformNotificationData& notification_data, | 135 const content::PlatformNotificationData& notification_data, |
| 136 const content::NotificationResources& notification_resources, |
136 NotificationDelegate* delegate) const; | 137 NotificationDelegate* delegate) const; |
137 | 138 |
138 // Overrides the Notification UI Manager to use to |manager|. Only to be | 139 // Overrides the Notification UI Manager to use to |manager|. Only to be |
139 // used by tests. Tests are responsible for cleaning up after themselves. | 140 // used by tests. Tests are responsible for cleaning up after themselves. |
140 void SetNotificationUIManagerForTesting(NotificationUIManager* manager); | 141 void SetNotificationUIManagerForTesting(NotificationUIManager* manager); |
141 | 142 |
142 // Returns a display name for an origin, to be used in the context message | 143 // Returns a display name for an origin, to be used in the context message |
143 base::string16 DisplayNameForContextMessage(Profile* profile, | 144 base::string16 DisplayNameForContextMessage(Profile* profile, |
144 const GURL& origin) const; | 145 const GURL& origin) const; |
145 | 146 |
146 // Platforms that display native notification interact with them through this | 147 // Platforms that display native notification interact with them through this |
147 // object. | 148 // object. |
148 scoped_ptr<NotificationUIManager> native_notification_ui_manager_; | 149 scoped_ptr<NotificationUIManager> native_notification_ui_manager_; |
149 | 150 |
150 // Weak reference. Ownership maintains with the test. | 151 // Weak reference. Ownership maintains with the test. |
151 NotificationUIManager* notification_ui_manager_for_tests_; | 152 NotificationUIManager* notification_ui_manager_for_tests_; |
152 | 153 |
153 // Mapping between a persistent notification id and the id of the associated | 154 // Mapping between a persistent notification id and the id of the associated |
154 // message_center::Notification object. Must only be used on the UI thread. | 155 // message_center::Notification object. Must only be used on the UI thread. |
155 std::map<int64_t, std::string> persistent_notifications_; | 156 std::map<int64_t, std::string> persistent_notifications_; |
156 | 157 |
157 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); | 158 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); |
158 }; | 159 }; |
159 | 160 |
160 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ | 161 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ |
OLD | NEW |