| 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 <set> | |
| 10 #include <string> | 9 #include <string> |
| 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/service_worker/service_worker_context_observer.h" | 17 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/platform_notification_context.h" | 20 #include "content/public/browser/platform_notification_context.h" |
| 21 #include "third_party/WebKit/public/platform/modules/notifications/notification_
service.mojom.h" |
| 21 | 22 |
| 22 class GURL; | 23 class GURL; |
| 23 | 24 |
| 24 namespace base { | 25 namespace base { |
| 25 class SequencedTaskRunner; | 26 class SequencedTaskRunner; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace content { | 29 namespace content { |
| 29 | 30 |
| 31 class BlinkNotificationServiceImpl; |
| 30 class BrowserContext; | 32 class BrowserContext; |
| 31 class NotificationDatabase; | 33 class NotificationDatabase; |
| 32 struct NotificationDatabaseData; | 34 struct NotificationDatabaseData; |
| 35 class ResourceContext; |
| 33 class ServiceWorkerContextWrapper; | 36 class ServiceWorkerContextWrapper; |
| 34 | 37 |
| 35 // Implementation of the Web Notification storage context. The public methods | 38 // Implementation of the Web Notification storage context. The public methods |
| 36 // defined in this interface must only be called on the IO thread unless | 39 // defined in this interface must only be called on the IO thread unless |
| 37 // otherwise specified. | 40 // otherwise specified. |
| 38 class CONTENT_EXPORT PlatformNotificationContextImpl | 41 class CONTENT_EXPORT PlatformNotificationContextImpl |
| 39 : NON_EXPORTED_BASE(public PlatformNotificationContext), | 42 : NON_EXPORTED_BASE(public PlatformNotificationContext), |
| 40 NON_EXPORTED_BASE(public ServiceWorkerContextObserver) { | 43 NON_EXPORTED_BASE(public ServiceWorkerContextObserver) { |
| 41 public: | 44 public: |
| 42 // Constructs a new platform notification context. If |path| is non-empty, the | 45 // Constructs a new platform notification context. If |path| is non-empty, the |
| 43 // database will be initialized in the "Platform Notifications" subdirectory | 46 // database will be initialized in the "Platform Notifications" subdirectory |
| 44 // of |path|. Otherwise, the database will be initialized in memory. The | 47 // of |path|. Otherwise, the database will be initialized in memory. The |
| 45 // constructor must only be called on the IO thread. | 48 // constructor must only be called on the IO thread. |
| 46 PlatformNotificationContextImpl( | 49 PlatformNotificationContextImpl( |
| 47 const base::FilePath& path, | 50 const base::FilePath& path, |
| 48 BrowserContext* browser_context, | 51 BrowserContext* browser_context, |
| 49 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); | 52 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); |
| 50 | 53 |
| 51 // To be called on the UI thread to initialize the instance. | 54 // To be called on the UI thread to initialize the instance. |
| 52 void Initialize(); | 55 void Initialize(); |
| 53 | 56 |
| 54 // To be called on the UI thread when the context is being shut down. | 57 // To be called on the UI thread when the context is being shut down. |
| 55 void Shutdown(); | 58 void Shutdown(); |
| 56 | 59 |
| 60 // Creates a BlinkNotificationServiceImpl that is owned by this context. Must |
| 61 // be called on the UI thread, although the service will be created on and |
| 62 // bound to the IO thread. |
| 63 void CreateService( |
| 64 int render_process_id, |
| 65 mojo::InterfaceRequest<blink::mojom::NotificationService> request); |
| 66 |
| 67 // Removes |service| from the list of owned services, for example because the |
| 68 // Mojo pipe disconnected. Must be called on the IO thread. |
| 69 void RemoveService(BlinkNotificationServiceImpl* service); |
| 70 |
| 57 // PlatformNotificationContext implementation. | 71 // PlatformNotificationContext implementation. |
| 58 void ReadNotificationData(int64_t notification_id, | 72 void ReadNotificationData(int64_t notification_id, |
| 59 const GURL& origin, | 73 const GURL& origin, |
| 60 const ReadResultCallback& callback) override; | 74 const ReadResultCallback& callback) override; |
| 61 void WriteNotificationData(const GURL& origin, | 75 void WriteNotificationData(const GURL& origin, |
| 62 const NotificationDatabaseData& database_data, | 76 const NotificationDatabaseData& database_data, |
| 63 const WriteResultCallback& callback) override; | 77 const WriteResultCallback& callback) override; |
| 64 void DeleteNotificationData(int64_t notification_id, | 78 void DeleteNotificationData(int64_t notification_id, |
| 65 const GURL& origin, | 79 const GURL& origin, |
| 66 const DeleteResultCallback& callback) override; | 80 const DeleteResultCallback& callback) override; |
| 67 void ReadAllNotificationDataForServiceWorkerRegistration( | 81 void ReadAllNotificationDataForServiceWorkerRegistration( |
| 68 const GURL& origin, | 82 const GURL& origin, |
| 69 int64_t service_worker_registration_id, | 83 int64_t service_worker_registration_id, |
| 70 const ReadAllResultCallback& callback) override; | 84 const ReadAllResultCallback& callback) override; |
| 71 | 85 |
| 72 // ServiceWorkerContextObserver implementation. | 86 // ServiceWorkerContextObserver implementation. |
| 73 void OnRegistrationDeleted(int64_t registration_id, | 87 void OnRegistrationDeleted(int64_t registration_id, |
| 74 const GURL& pattern) override; | 88 const GURL& pattern) override; |
| 75 void OnStorageWiped() override; | 89 void OnStorageWiped() override; |
| 76 | 90 |
| 77 private: | 91 private: |
| 78 friend class PlatformNotificationContextTest; | 92 friend class PlatformNotificationContextTest; |
| 79 | 93 |
| 80 ~PlatformNotificationContextImpl() override; | 94 ~PlatformNotificationContextImpl() override; |
| 81 | 95 |
| 82 void InitializeOnIO(); | 96 void InitializeOnIO(); |
| 83 void ShutdownOnIO(); | 97 void ShutdownOnIO(); |
| 98 void CreateServiceOnIO( |
| 99 int render_process_id, |
| 100 ResourceContext* resource_context, |
| 101 mojo::InterfaceRequest<blink::mojom::NotificationService> request); |
| 84 | 102 |
| 85 // Initializes the database if neccesary. Must be called on the IO thread. | 103 // Initializes the database if neccesary. Must be called on the IO thread. |
| 86 // |success_closure| will be invoked on a the |task_runner_| thread when | 104 // |success_closure| will be invoked on a the |task_runner_| thread when |
| 87 // everything is available, or |failure_closure_| will be invoked on the | 105 // everything is available, or |failure_closure_| will be invoked on the |
| 88 // IO thread when initialization fails. | 106 // IO thread when initialization fails. |
| 89 void LazyInitialize(const base::Closure& success_closure, | 107 void LazyInitialize(const base::Closure& success_closure, |
| 90 const base::Closure& failure_closure); | 108 const base::Closure& failure_closure); |
| 91 | 109 |
| 92 // Opens the database. Must be called on the |task_runner_| thread. When the | 110 // Opens the database. Must be called on the |task_runner_| thread. When the |
| 93 // database has been opened, |success_closure| will be invoked on the task | 111 // database has been opened, |success_closure| will be invoked on the task |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 BrowserContext* browser_context_; | 164 BrowserContext* browser_context_; |
| 147 | 165 |
| 148 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 166 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| 149 | 167 |
| 150 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 168 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| 151 std::unique_ptr<NotificationDatabase> database_; | 169 std::unique_ptr<NotificationDatabase> database_; |
| 152 | 170 |
| 153 // Indicates whether the database should be pruned when it's opened. | 171 // Indicates whether the database should be pruned when it's opened. |
| 154 bool prune_database_on_open_ = false; | 172 bool prune_database_on_open_ = false; |
| 155 | 173 |
| 174 // 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. |
| 176 std::vector<std::unique_ptr<BlinkNotificationServiceImpl>> services_; |
| 177 |
| 156 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContextImpl); | 178 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContextImpl); |
| 157 }; | 179 }; |
| 158 | 180 |
| 159 } // namespace content | 181 } // namespace content |
| 160 | 182 |
| 161 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_ | 183 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_ |
| OLD | NEW |