| 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 #include <unordered_set> | 12 #include <unordered_set> |
| 13 | 13 |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
| 18 #include "base/strings/string16.h" | 18 #include "base/strings/string16.h" |
| 19 #include "chrome/browser/notifications/notification.h" | 19 #include "chrome/browser/notifications/notification.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 21 #include "content/public/browser/platform_notification_service.h" | 21 #include "content/public/browser/platform_notification_service.h" |
| 22 #include "content/public/common/persistent_notification_status.h" | 22 #include "content/public/common/persistent_notification_status.h" |
| 23 | 23 |
| 24 class NotificationDelegate; | 24 class NotificationDelegate; |
| 25 class NotificationUIManager; | |
| 26 | 25 |
| 27 namespace content { | 26 namespace content { |
| 28 class BrowserContext; | 27 class BrowserContext; |
| 29 struct NotificationResources; | 28 struct NotificationResources; |
| 30 } | 29 } |
| 31 | 30 |
| 32 namespace gcm { | 31 namespace gcm { |
| 33 class PushMessagingBrowserTest; | 32 class PushMessagingBrowserTest; |
| 34 } | 33 } |
| 35 | 34 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 69 |
| 71 // To be called when a persistent notification has been closed. The data | 70 // To be called when a persistent notification has been closed. The data |
| 72 // associated with the notification has to be pruned from the database in this | 71 // associated with the notification has to be pruned from the database in this |
| 73 // case, to make sure that it continues to be in sync. Must be called on the | 72 // case, to make sure that it continues to be in sync. Must be called on the |
| 74 // UI thread. | 73 // UI thread. |
| 75 void OnPersistentNotificationClose(content::BrowserContext* browser_context, | 74 void OnPersistentNotificationClose(content::BrowserContext* browser_context, |
| 76 int64_t persistent_notification_id, | 75 int64_t persistent_notification_id, |
| 77 const GURL& origin, | 76 const GURL& origin, |
| 78 bool by_user); | 77 bool by_user); |
| 79 | 78 |
| 80 // Returns the Notification UI Manager through which notifications can be | |
| 81 // displayed to the user. Can be overridden for testing. | |
| 82 NotificationUIManager* GetNotificationUIManager() const; | |
| 83 | |
| 84 // Open the Notification settings screen when clicking the right button. | 79 // Open the Notification settings screen when clicking the right button. |
| 85 void OpenNotificationSettings(content::BrowserContext* browser_context); | 80 void OpenNotificationSettings(content::BrowserContext* browser_context); |
| 86 | 81 |
| 87 // content::PlatformNotificationService implementation. | 82 // content::PlatformNotificationService implementation. |
| 88 blink::WebNotificationPermission CheckPermissionOnUIThread( | 83 blink::WebNotificationPermission CheckPermissionOnUIThread( |
| 89 content::BrowserContext* browser_context, | 84 content::BrowserContext* browser_context, |
| 90 const GURL& origin, | 85 const GURL& origin, |
| 91 int render_process_id) override; | 86 int render_process_id) override; |
| 92 blink::WebNotificationPermission CheckPermissionOnIOThread( | 87 blink::WebNotificationPermission CheckPermissionOnIOThread( |
| 93 content::ResourceContext* resource_context, | 88 content::ResourceContext* resource_context, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // Creates a new Web Notification-based Notification object. | 124 // Creates a new Web Notification-based Notification object. |
| 130 // TODO(peter): |delegate| can be a scoped_refptr, but properly passing this | 125 // TODO(peter): |delegate| can be a scoped_refptr, but properly passing this |
| 131 // through requires changing a whole lot of Notification constructor calls. | 126 // through requires changing a whole lot of Notification constructor calls. |
| 132 Notification CreateNotificationFromData( | 127 Notification CreateNotificationFromData( |
| 133 Profile* profile, | 128 Profile* profile, |
| 134 const GURL& origin, | 129 const GURL& origin, |
| 135 const content::PlatformNotificationData& notification_data, | 130 const content::PlatformNotificationData& notification_data, |
| 136 const content::NotificationResources& notification_resources, | 131 const content::NotificationResources& notification_resources, |
| 137 NotificationDelegate* delegate) const; | 132 NotificationDelegate* delegate) const; |
| 138 | 133 |
| 139 // Overrides the Notification UI Manager to use to |manager|. Only to be | |
| 140 // used by tests. Tests are responsible for cleaning up after themselves. | |
| 141 void SetNotificationUIManagerForTesting(NotificationUIManager* manager); | |
| 142 | |
| 143 // Returns a display name for an origin, to be used in the context message | 134 // Returns a display name for an origin, to be used in the context message |
| 144 base::string16 DisplayNameForContextMessage(Profile* profile, | 135 base::string16 DisplayNameForContextMessage(Profile* profile, |
| 145 const GURL& origin) const; | 136 const GURL& origin) const; |
| 146 | 137 |
| 147 // Platforms that display native notification interact with them through this | |
| 148 // object. | |
| 149 scoped_ptr<NotificationUIManager> native_notification_ui_manager_; | |
| 150 | |
| 151 // Weak reference. Ownership maintains with the test. | |
| 152 NotificationUIManager* notification_ui_manager_for_tests_; | |
| 153 | 138 |
| 154 // Mapping between a persistent notification id and the id of the associated | 139 // Mapping between a persistent notification id and the id of the associated |
| 155 // message_center::Notification object. Must only be used on the UI thread. | 140 // message_center::Notification object. Must only be used on the UI thread. |
| 156 std::map<int64_t, std::string> persistent_notifications_; | 141 std::map<int64_t, std::string> persistent_notifications_; |
| 157 | 142 |
| 158 // Tracks the id of persistent notifications that have been closed | 143 // Tracks the id of persistent notifications that have been closed |
| 159 // programmatically to avoid dispatching close events for them. | 144 // programmatically to avoid dispatching close events for them. |
| 160 std::unordered_set<int64_t> closed_notifications_; | 145 std::unordered_set<int64_t> closed_notifications_; |
| 161 | 146 |
| 162 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); | 147 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationServiceImpl); |
| 163 }; | 148 }; |
| 164 | 149 |
| 165 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ | 150 #endif // CHROME_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_SERVICE_IMPL_H_ |
| OLD | NEW |