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