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

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

Issue 2300093002: Make //content responsible for generating notification Ids (Closed)
Patch Set: comments Created 4 years, 3 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 <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
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 &notification_id_generator_;
75 }
76
71 // PlatformNotificationContext implementation. 77 // PlatformNotificationContext implementation.
72 void ReadNotificationData(int64_t notification_id, 78 void ReadNotificationData(const std::string& notification_id,
73 const GURL& origin, 79 const GURL& origin,
74 const ReadResultCallback& callback) override; 80 const ReadResultCallback& callback) override;
75 void WriteNotificationData(const GURL& origin, 81 void WriteNotificationData(const GURL& origin,
76 const NotificationDatabaseData& database_data, 82 const NotificationDatabaseData& database_data,
77 const WriteResultCallback& callback) override; 83 const WriteResultCallback& callback) override;
78 void DeleteNotificationData(int64_t notification_id, 84 void DeleteNotificationData(const std::string& notification_id,
79 const GURL& origin, 85 const GURL& origin,
80 const DeleteResultCallback& callback) override; 86 const DeleteResultCallback& callback) override;
81 void ReadAllNotificationDataForServiceWorkerRegistration( 87 void ReadAllNotificationDataForServiceWorkerRegistration(
82 const GURL& origin, 88 const GURL& origin,
83 int64_t service_worker_registration_id, 89 int64_t service_worker_registration_id,
84 const ReadAllResultCallback& callback) override; 90 const ReadAllResultCallback& callback) override;
85 91
86 // ServiceWorkerContextObserver implementation. 92 // ServiceWorkerContextObserver implementation.
87 void OnRegistrationDeleted(int64_t registration_id, 93 void OnRegistrationDeleted(int64_t registration_id,
88 const GURL& pattern) override; 94 const GURL& pattern) override;
(...skipping 20 matching lines...) Expand all
109 115
110 // Opens the database. Must be called on the |task_runner_| thread. When the 116 // 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 117 // database has been opened, |success_closure| will be invoked on the task
112 // thread, otherwise |failure_closure_| will be invoked on the IO thread. 118 // thread, otherwise |failure_closure_| will be invoked on the IO thread.
113 void OpenDatabase(const base::Closure& success_closure, 119 void OpenDatabase(const base::Closure& success_closure,
114 const base::Closure& failure_closure); 120 const base::Closure& failure_closure);
115 121
116 // Actually reads the notification data from the database. Must only be 122 // Actually reads the notification data from the database. Must only be
117 // called on the |task_runner_| thread. |callback| will be invoked on the 123 // called on the |task_runner_| thread. |callback| will be invoked on the
118 // IO thread when the operation has completed. 124 // IO thread when the operation has completed.
119 void DoReadNotificationData(int64_t notification_id, 125 void DoReadNotificationData(const std::string& notification_id,
120 const GURL& origin, 126 const GURL& origin,
121 const ReadResultCallback& callback); 127 const ReadResultCallback& callback);
122 128
123 // Actually reads all notification data from the database. Must only be 129 // Actually reads all notification data from the database. Must only be
124 // called on the |task_runner_| thread. |callback| will be invoked on the 130 // called on the |task_runner_| thread. |callback| will be invoked on the
125 // IO thread when the operation has completed. 131 // IO thread when the operation has completed.
126 void DoReadAllNotificationDataForServiceWorkerRegistration( 132 void DoReadAllNotificationDataForServiceWorkerRegistration(
127 const GURL& origin, 133 const GURL& origin,
128 int64_t service_worker_registration_id, 134 int64_t service_worker_registration_id,
129 const ReadAllResultCallback& callback); 135 const ReadAllResultCallback& callback);
130 136
131 // Actually writes the notification database to the database. Must only be 137 // Actually writes the notification database to the database. Must only be
132 // called on the |task_runner_| thread. |callback| will be invoked on the 138 // called on the |task_runner_| thread. |callback| will be invoked on the
133 // IO thread when the operation has completed. 139 // IO thread when the operation has completed.
134 void DoWriteNotificationData(const GURL& origin, 140 void DoWriteNotificationData(const GURL& origin,
135 const NotificationDatabaseData& database_data, 141 const NotificationDatabaseData& database_data,
136 const WriteResultCallback& callback); 142 const WriteResultCallback& callback);
137 143
138 // Actually deletes the notification information from the database. Must only 144 // Actually deletes the notification information from the database. Must only
139 // be called on the |task_runner_| thread. |callback| will be invoked on the 145 // be called on the |task_runner_| thread. |callback| will be invoked on the
140 // IO thread when the operation has completed. 146 // IO thread when the operation has completed.
141 void DoDeleteNotificationData(int64_t notification_id, 147 void DoDeleteNotificationData(const std::string& notification_id,
142 const GURL& origin, 148 const GURL& origin,
143 const DeleteResultCallback& callback); 149 const DeleteResultCallback& callback);
144 150
145 // Deletes all notifications associated with |service_worker_registration_id| 151 // Deletes all notifications associated with |service_worker_registration_id|
146 // belonging to |origin|. Must be called on the |task_runner_| thread. 152 // belonging to |origin|. Must be called on the |task_runner_| thread.
147 void DoDeleteNotificationsForServiceWorkerRegistration( 153 void DoDeleteNotificationsForServiceWorkerRegistration(
148 const GURL& origin, 154 const GURL& origin,
149 int64_t service_worker_registration_id); 155 int64_t service_worker_registration_id);
150 156
151 // Destroys the database regardless of its initialization status. This method 157 // Destroys the database regardless of its initialization status. This method
152 // must only be called on the |task_runner_| thread. Returns if the directory 158 // must only be called on the |task_runner_| thread. Returns if the directory
153 // the database was stored in could be emptied. 159 // the database was stored in could be emptied.
154 bool DestroyDatabase(); 160 bool DestroyDatabase();
155 161
156 // Returns the path in which the database should be initialized. May be empty. 162 // Returns the path in which the database should be initialized. May be empty.
157 base::FilePath GetDatabasePath() const; 163 base::FilePath GetDatabasePath() const;
158 164
159 // Sets the task runner to use for testing purposes. 165 // Sets the task runner to use for testing purposes.
160 void SetTaskRunnerForTesting( 166 void SetTaskRunnerForTesting(
161 const scoped_refptr<base::SequencedTaskRunner>& task_runner); 167 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
162 168
163 base::FilePath path_; 169 base::FilePath path_;
164 BrowserContext* browser_context_; 170 BrowserContext* browser_context_;
165 171
166 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; 172 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
167 173
168 scoped_refptr<base::SequencedTaskRunner> task_runner_; 174 scoped_refptr<base::SequencedTaskRunner> task_runner_;
169 std::unique_ptr<NotificationDatabase> database_; 175 std::unique_ptr<NotificationDatabase> database_;
170 176
177 NotificationIdGenerator notification_id_generator_;
178
171 // Indicates whether the database should be pruned when it's opened. 179 // Indicates whether the database should be pruned when it's opened.
172 bool prune_database_on_open_ = false; 180 bool prune_database_on_open_ = false;
173 181
174 // The notification services are owned by the platform context, and will be 182 // 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. 183 // removed when either this class is destroyed or the Mojo pipe disconnects.
176 std::vector<std::unique_ptr<BlinkNotificationServiceImpl>> services_; 184 std::vector<std::unique_ptr<BlinkNotificationServiceImpl>> services_;
177 185
178 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContextImpl); 186 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContextImpl);
179 }; 187 };
180 188
181 } // namespace content 189 } // namespace content
182 190
183 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_ 191 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698