| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_ | 5 #ifndef CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_ |
| 6 #define CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_ | 6 #define CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "content/browser/notifications/notification_id_generator.h" |
| 17 #include "content/browser/service_worker/service_worker_context_observer.h" | 18 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 18 #include "content/common/content_export.h" | 19 #include "content/common/content_export.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/platform_notification_context.h" | 21 #include "content/public/browser/platform_notification_context.h" |
| 21 #include "third_party/WebKit/public/platform/modules/notifications/notification_
service.mojom.h" | 22 #include "third_party/WebKit/public/platform/modules/notifications/notification_
service.mojom.h" |
| 22 | 23 |
| 23 class GURL; | 24 class GURL; |
| 24 | 25 |
| 25 namespace base { | 26 namespace base { |
| 26 class SequencedTaskRunner; | 27 class SequencedTaskRunner; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // be called on the UI thread, although the service will be created on and | 62 // be called on the UI thread, although the service will be created on and |
| 62 // bound to the IO thread. | 63 // bound to the IO thread. |
| 63 void CreateService( | 64 void CreateService( |
| 64 int render_process_id, | 65 int render_process_id, |
| 65 mojo::InterfaceRequest<blink::mojom::NotificationService> request); | 66 mojo::InterfaceRequest<blink::mojom::NotificationService> request); |
| 66 | 67 |
| 67 // Removes |service| from the list of owned services, for example because the | 68 // Removes |service| from the list of owned services, for example because the |
| 68 // Mojo pipe disconnected. Must be called on the IO thread. | 69 // Mojo pipe disconnected. Must be called on the IO thread. |
| 69 void RemoveService(BlinkNotificationServiceImpl* service); | 70 void RemoveService(BlinkNotificationServiceImpl* service); |
| 70 | 71 |
| 72 // Returns the notification Id generator owned by the context. |
| 73 NotificationIdGenerator* notification_id_generator() { |
| 74 return ¬ification_id_generator_; |
| 75 } |
| 76 |
| 71 // PlatformNotificationContext implementation. | 77 // PlatformNotificationContext implementation. |
| 72 void ReadNotificationData(int64_t notification_id, | 78 std::string GenerateNotificationId( |
| 79 const GURL& origin, |
| 80 const std::string& tag, |
| 81 int64_t persistent_notification_id) override; |
| 82 void ReadNotificationData(const std::string& notification_id, |
| 73 const GURL& origin, | 83 const GURL& origin, |
| 74 const ReadResultCallback& callback) override; | 84 const ReadResultCallback& callback) override; |
| 75 void WriteNotificationData(const GURL& origin, | 85 void WriteNotificationData(const GURL& origin, |
| 76 const NotificationDatabaseData& database_data, | 86 const NotificationDatabaseData& database_data, |
| 77 const WriteResultCallback& callback) override; | 87 const WriteResultCallback& callback) override; |
| 78 void DeleteNotificationData(int64_t notification_id, | 88 void DeleteNotificationData(const std::string& notification_id, |
| 79 const GURL& origin, | 89 const GURL& origin, |
| 80 const DeleteResultCallback& callback) override; | 90 const DeleteResultCallback& callback) override; |
| 81 void ReadAllNotificationDataForServiceWorkerRegistration( | 91 void ReadAllNotificationDataForServiceWorkerRegistration( |
| 82 const GURL& origin, | 92 const GURL& origin, |
| 83 int64_t service_worker_registration_id, | 93 int64_t service_worker_registration_id, |
| 84 const ReadAllResultCallback& callback) override; | 94 const ReadAllResultCallback& callback) override; |
| 85 | 95 |
| 86 // ServiceWorkerContextObserver implementation. | 96 // ServiceWorkerContextObserver implementation. |
| 87 void OnRegistrationDeleted(int64_t registration_id, | 97 void OnRegistrationDeleted(int64_t registration_id, |
| 88 const GURL& pattern) override; | 98 const GURL& pattern) override; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 109 | 119 |
| 110 // Opens the database. Must be called on the |task_runner_| thread. When the | 120 // Opens the database. Must be called on the |task_runner_| thread. When the |
| 111 // database has been opened, |success_closure| will be invoked on the task | 121 // database has been opened, |success_closure| will be invoked on the task |
| 112 // thread, otherwise |failure_closure_| will be invoked on the IO thread. | 122 // thread, otherwise |failure_closure_| will be invoked on the IO thread. |
| 113 void OpenDatabase(const base::Closure& success_closure, | 123 void OpenDatabase(const base::Closure& success_closure, |
| 114 const base::Closure& failure_closure); | 124 const base::Closure& failure_closure); |
| 115 | 125 |
| 116 // Actually reads the notification data from the database. Must only be | 126 // Actually reads the notification data from the database. Must only be |
| 117 // called on the |task_runner_| thread. |callback| will be invoked on the | 127 // called on the |task_runner_| thread. |callback| will be invoked on the |
| 118 // IO thread when the operation has completed. | 128 // IO thread when the operation has completed. |
| 119 void DoReadNotificationData(int64_t notification_id, | 129 void DoReadNotificationData(const std::string& notification_id, |
| 120 const GURL& origin, | 130 const GURL& origin, |
| 121 const ReadResultCallback& callback); | 131 const ReadResultCallback& callback); |
| 122 | 132 |
| 123 // Actually reads all notification data from the database. Must only be | 133 // Actually reads all notification data from the database. Must only be |
| 124 // called on the |task_runner_| thread. |callback| will be invoked on the | 134 // called on the |task_runner_| thread. |callback| will be invoked on the |
| 125 // IO thread when the operation has completed. | 135 // IO thread when the operation has completed. |
| 126 void DoReadAllNotificationDataForServiceWorkerRegistration( | 136 void DoReadAllNotificationDataForServiceWorkerRegistration( |
| 127 const GURL& origin, | 137 const GURL& origin, |
| 128 int64_t service_worker_registration_id, | 138 int64_t service_worker_registration_id, |
| 129 const ReadAllResultCallback& callback); | 139 const ReadAllResultCallback& callback); |
| 130 | 140 |
| 131 // Actually writes the notification database to the database. Must only be | 141 // Actually writes the notification database to the database. Must only be |
| 132 // called on the |task_runner_| thread. |callback| will be invoked on the | 142 // called on the |task_runner_| thread. |callback| will be invoked on the |
| 133 // IO thread when the operation has completed. | 143 // IO thread when the operation has completed. |
| 134 void DoWriteNotificationData(const GURL& origin, | 144 void DoWriteNotificationData(const GURL& origin, |
| 135 const NotificationDatabaseData& database_data, | 145 const NotificationDatabaseData& database_data, |
| 136 const WriteResultCallback& callback); | 146 const WriteResultCallback& callback); |
| 137 | 147 |
| 138 // Actually deletes the notification information from the database. Must only | 148 // Actually deletes the notification information from the database. Must only |
| 139 // be called on the |task_runner_| thread. |callback| will be invoked on the | 149 // be called on the |task_runner_| thread. |callback| will be invoked on the |
| 140 // IO thread when the operation has completed. | 150 // IO thread when the operation has completed. |
| 141 void DoDeleteNotificationData(int64_t notification_id, | 151 void DoDeleteNotificationData(const std::string& notification_id, |
| 142 const GURL& origin, | 152 const GURL& origin, |
| 143 const DeleteResultCallback& callback); | 153 const DeleteResultCallback& callback); |
| 144 | 154 |
| 145 // Deletes all notifications associated with |service_worker_registration_id| | 155 // Deletes all notifications associated with |service_worker_registration_id| |
| 146 // belonging to |origin|. Must be called on the |task_runner_| thread. | 156 // belonging to |origin|. Must be called on the |task_runner_| thread. |
| 147 void DoDeleteNotificationsForServiceWorkerRegistration( | 157 void DoDeleteNotificationsForServiceWorkerRegistration( |
| 148 const GURL& origin, | 158 const GURL& origin, |
| 149 int64_t service_worker_registration_id); | 159 int64_t service_worker_registration_id); |
| 150 | 160 |
| 151 // Destroys the database regardless of its initialization status. This method | 161 // Destroys the database regardless of its initialization status. This method |
| 152 // must only be called on the |task_runner_| thread. Returns if the directory | 162 // must only be called on the |task_runner_| thread. Returns if the directory |
| 153 // the database was stored in could be emptied. | 163 // the database was stored in could be emptied. |
| 154 bool DestroyDatabase(); | 164 bool DestroyDatabase(); |
| 155 | 165 |
| 156 // Returns the path in which the database should be initialized. May be empty. | 166 // Returns the path in which the database should be initialized. May be empty. |
| 157 base::FilePath GetDatabasePath() const; | 167 base::FilePath GetDatabasePath() const; |
| 158 | 168 |
| 159 // Sets the task runner to use for testing purposes. | 169 // Sets the task runner to use for testing purposes. |
| 160 void SetTaskRunnerForTesting( | 170 void SetTaskRunnerForTesting( |
| 161 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 171 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 162 | 172 |
| 163 base::FilePath path_; | 173 base::FilePath path_; |
| 164 BrowserContext* browser_context_; | 174 BrowserContext* browser_context_; |
| 165 | 175 |
| 166 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 176 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| 167 | 177 |
| 168 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 178 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 169 std::unique_ptr<NotificationDatabase> database_; | 179 std::unique_ptr<NotificationDatabase> database_; |
| 170 | 180 |
| 181 NotificationIdGenerator notification_id_generator_; |
| 182 |
| 171 // Indicates whether the database should be pruned when it's opened. | 183 // Indicates whether the database should be pruned when it's opened. |
| 172 bool prune_database_on_open_ = false; | 184 bool prune_database_on_open_ = false; |
| 173 | 185 |
| 174 // The notification services are owned by the platform context, and will be | 186 // The notification services are owned by the platform context, and will be |
| 175 // removed when either this class is destroyed or the Mojo pipe disconnects. | 187 // removed when either this class is destroyed or the Mojo pipe disconnects. |
| 176 std::vector<std::unique_ptr<BlinkNotificationServiceImpl>> services_; | 188 std::vector<std::unique_ptr<BlinkNotificationServiceImpl>> services_; |
| 177 | 189 |
| 178 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContextImpl); | 190 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContextImpl); |
| 179 }; | 191 }; |
| 180 | 192 |
| 181 } // namespace content | 193 } // namespace content |
| 182 | 194 |
| 183 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_ | 195 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_ |
| OLD | NEW |