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