Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: content/browser/notifications/platform_notification_context_impl.h

Issue 1948223004: Introduce the Blink NotificationService, move permission checks there (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/memory/weak_ptr.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"
22 #include "third_party/WebKit/public/platform/modules/notifications/notification_ service.mojom.h"
21 23
22 class GURL; 24 class GURL;
23 25
24 namespace base { 26 namespace base {
25 class SequencedTaskRunner; 27 class SequencedTaskRunner;
26 } 28 }
27 29
28 namespace content { 30 namespace content {
29 31
32 class BlinkNotificationServiceImpl;
30 class BrowserContext; 33 class BrowserContext;
31 class NotificationDatabase; 34 class NotificationDatabase;
32 struct NotificationDatabaseData; 35 struct NotificationDatabaseData;
36 class ResourceContext;
33 class ServiceWorkerContextWrapper; 37 class ServiceWorkerContextWrapper;
34 38
35 // Implementation of the Web Notification storage context. The public methods 39 // Implementation of the Web Notification storage context. The public methods
36 // defined in this interface must only be called on the IO thread unless 40 // defined in this interface must only be called on the IO thread unless
37 // otherwise specified. 41 // otherwise specified.
38 class CONTENT_EXPORT PlatformNotificationContextImpl 42 class CONTENT_EXPORT PlatformNotificationContextImpl
39 : NON_EXPORTED_BASE(public PlatformNotificationContext), 43 : NON_EXPORTED_BASE(public PlatformNotificationContext),
40 NON_EXPORTED_BASE(public ServiceWorkerContextObserver) { 44 NON_EXPORTED_BASE(public ServiceWorkerContextObserver) {
41 public: 45 public:
42 // Constructs a new platform notification context. If |path| is non-empty, the 46 // Constructs a new platform notification context. If |path| is non-empty, the
43 // database will be initialized in the "Platform Notifications" subdirectory 47 // database will be initialized in the "Platform Notifications" subdirectory
44 // of |path|. Otherwise, the database will be initialized in memory. The 48 // of |path|. Otherwise, the database will be initialized in memory. The
45 // constructor must only be called on the IO thread. 49 // constructor must only be called on the IO thread.
46 PlatformNotificationContextImpl( 50 PlatformNotificationContextImpl(
47 const base::FilePath& path, 51 const base::FilePath& path,
48 BrowserContext* browser_context, 52 BrowserContext* browser_context,
49 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); 53 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context);
50 54
51 // To be called on the UI thread to initialize the instance. 55 // To be called on the UI thread to initialize the instance.
52 void Initialize(); 56 void Initialize();
53 57
54 // To be called on the UI thread when the context is being shut down. 58 // To be called on the UI thread when the context is being shut down.
55 void Shutdown(); 59 void Shutdown();
56 60
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
57 // PlatformNotificationContext implementation. 72 // PlatformNotificationContext implementation.
58 void ReadNotificationData(int64_t notification_id, 73 void ReadNotificationData(int64_t notification_id,
59 const GURL& origin, 74 const GURL& origin,
60 const ReadResultCallback& callback) override; 75 const ReadResultCallback& callback) override;
61 void WriteNotificationData(const GURL& origin, 76 void WriteNotificationData(const GURL& origin,
62 const NotificationDatabaseData& database_data, 77 const NotificationDatabaseData& database_data,
63 const WriteResultCallback& callback) override; 78 const WriteResultCallback& callback) override;
64 void DeleteNotificationData(int64_t notification_id, 79 void DeleteNotificationData(int64_t notification_id,
65 const GURL& origin, 80 const GURL& origin,
66 const DeleteResultCallback& callback) override; 81 const DeleteResultCallback& callback) override;
67 void ReadAllNotificationDataForServiceWorkerRegistration( 82 void ReadAllNotificationDataForServiceWorkerRegistration(
68 const GURL& origin, 83 const GURL& origin,
69 int64_t service_worker_registration_id, 84 int64_t service_worker_registration_id,
70 const ReadAllResultCallback& callback) override; 85 const ReadAllResultCallback& callback) override;
71 86
72 // ServiceWorkerContextObserver implementation. 87 // ServiceWorkerContextObserver implementation.
73 void OnRegistrationDeleted(int64_t registration_id, 88 void OnRegistrationDeleted(int64_t registration_id,
74 const GURL& pattern) override; 89 const GURL& pattern) override;
75 void OnStorageWiped() override; 90 void OnStorageWiped() override;
76 91
77 private: 92 private:
78 friend class PlatformNotificationContextTest; 93 friend class PlatformNotificationContextTest;
79 94
80 ~PlatformNotificationContextImpl() override; 95 ~PlatformNotificationContextImpl() override;
81 96
82 void InitializeOnIO(); 97 void InitializeOnIO();
83 void ShutdownOnIO(); 98 void ShutdownOnIO();
99 void CreateServiceOnIO(
100 int render_process_id,
101 ResourceContext* resource_context,
102 mojo::InterfaceRequest<blink::mojom::NotificationService> request);
84 103
85 // Initializes the database if neccesary. Must be called on the IO thread. 104 // 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 105 // |success_closure| will be invoked on a the |task_runner_| thread when
87 // everything is available, or |failure_closure_| will be invoked on the 106 // everything is available, or |failure_closure_| will be invoked on the
88 // IO thread when initialization fails. 107 // IO thread when initialization fails.
89 void LazyInitialize(const base::Closure& success_closure, 108 void LazyInitialize(const base::Closure& success_closure,
90 const base::Closure& failure_closure); 109 const base::Closure& failure_closure);
91 110
92 // Opens the database. Must be called on the |task_runner_| thread. When the 111 // 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 112 // database has been opened, |success_closure| will be invoked on the task
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 BrowserContext* browser_context_; 165 BrowserContext* browser_context_;
147 166
148 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; 167 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
149 168
150 scoped_refptr<base::SequencedTaskRunner> task_runner_; 169 scoped_refptr<base::SequencedTaskRunner> task_runner_;
151 std::unique_ptr<NotificationDatabase> database_; 170 std::unique_ptr<NotificationDatabase> database_;
152 171
153 // Indicates whether the database should be pruned when it's opened. 172 // Indicates whether the database should be pruned when it's opened.
154 bool prune_database_on_open_ = false; 173 bool prune_database_on_open_ = false;
155 174
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
156 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContextImpl); 181 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContextImpl);
157 }; 182 };
158 183
159 } // namespace content 184 } // namespace content
160 185
161 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_ 186 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698