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 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 void WriteNotificationData(const GURL& origin, | 51 void WriteNotificationData(const GURL& origin, |
52 const NotificationDatabaseData& database_data, | 52 const NotificationDatabaseData& database_data, |
53 const WriteResultCallback& callback) override; | 53 const WriteResultCallback& callback) override; |
54 void DeleteNotificationData(int64_t notification_id, | 54 void DeleteNotificationData(int64_t notification_id, |
55 const GURL& origin, | 55 const GURL& origin, |
56 const DeleteResultCallback& callback) override; | 56 const DeleteResultCallback& callback) override; |
57 | 57 |
58 // ServiceWorkerContextObserver implementation. | 58 // ServiceWorkerContextObserver implementation. |
59 void OnRegistrationDeleted(int64_t registration_id, | 59 void OnRegistrationDeleted(int64_t registration_id, |
60 const GURL& pattern) override; | 60 const GURL& pattern) override; |
| 61 void OnStorageWiped() override; |
61 | 62 |
62 private: | 63 private: |
63 friend class PlatformNotificationContextTest; | 64 friend class PlatformNotificationContextTest; |
64 | 65 |
65 ~PlatformNotificationContextImpl() override; | 66 ~PlatformNotificationContextImpl() override; |
66 | 67 |
67 void InitializeOnIO(); | 68 void InitializeOnIO(); |
68 void ShutdownOnIO(); | 69 void ShutdownOnIO(); |
69 | 70 |
70 // Initializes the database if neccesary. Must be called on the IO thread. | 71 // Initializes the database if neccesary. Must be called on the IO thread. |
71 // |success_closure| will be invoked on a the |task_runner_| thread when | 72 // |success_closure| will be invoked on a the |task_runner_| thread when |
72 // everything is available, or |failure_closure_| will be invoked on the | 73 // everything is available, or |failure_closure_| will be invoked on the |
73 // IO thread when initialization fails. | 74 // IO thread when initialization fails. |
74 void LazyInitialize(const base::Closure& success_closure, | 75 void LazyInitialize(const base::Closure& success_closure, |
75 const base::Closure& failure_closure); | 76 const base::Closure& failure_closure); |
76 | 77 |
77 // Opens the database. Must be called on the |task_runner_| thread. When the | 78 // Opens the database. Must be called on the |task_runner_| thread. When the |
78 // database has been opened, |success_closure| will be invoked on the task | 79 // database has been opened, |success_closure| will be invoked on the task |
79 // thread, otherwise |failure_closure_| will be invoked on the IO thread. | 80 // thread, otherwise |failure_closure_| will be invoked on the IO thread. |
80 void OpenDatabase(const base::Closure& success_closure, | 81 void OpenDatabase(const base::Closure& success_closure, |
81 const base::Closure& failure_closure); | 82 const base::Closure& failure_closure, |
| 83 bool delete_on_corruption); |
82 | 84 |
83 // Deletes all notifications associated with |service_worker_registration_id| | 85 // Deletes all notifications associated with |service_worker_registration_id| |
84 // belonging to |origin|. Must be called on the |task_runner_| thread. | 86 // belonging to |origin|. Must be called on the |task_runner_| thread. |
85 void DoDeleteNotificationsForServiceWorkerRegistration( | 87 void DoDeleteNotificationsForServiceWorkerRegistration( |
86 const GURL& origin, | 88 const GURL& origin, |
87 int64_t service_worker_registration_id); | 89 int64_t service_worker_registration_id); |
88 | 90 |
89 // Actually reads the notification data from the database. Must only be | 91 // Actually reads the notification data from the database. Must only be |
90 // called on the |task_runner_| thread. |callback| will be invoked on the | 92 // called on the |task_runner_| thread. |callback| will be invoked on the |
91 // IO thread when the operation has completed. | 93 // IO thread when the operation has completed. |
92 void DoReadNotificationData(int64_t notification_id, | 94 void DoReadNotificationData(int64_t notification_id, |
93 const GURL& origin, | 95 const GURL& origin, |
94 const ReadResultCallback& callback); | 96 const ReadResultCallback& callback); |
95 | 97 |
96 // Actually writes the notification database to the database. Must only be | 98 // Actually writes the notification database to the database. Must only be |
97 // called on the |task_runner_| thread. |callback| will be invoked on the | 99 // called on the |task_runner_| thread. |callback| will be invoked on the |
98 // IO thread when the operation has completed. | 100 // IO thread when the operation has completed. |
99 void DoWriteNotificationData(const GURL& origin, | 101 void DoWriteNotificationData(const GURL& origin, |
100 const NotificationDatabaseData& database_data, | 102 const NotificationDatabaseData& database_data, |
101 const WriteResultCallback& callback); | 103 const WriteResultCallback& callback); |
102 | 104 |
103 // Actually deletes the notification information from the database. Must only | 105 // Actually deletes the notification information from the database. Must only |
104 // be called on the |task_runner_| thread. |callback| will be invoked on the | 106 // be called on the |task_runner_| thread. |callback| will be invoked on the |
105 // IO thread when the operation has completed. | 107 // IO thread when the operation has completed. |
106 void DoDeleteNotificationData(int64_t notification_id, | 108 void DoDeleteNotificationData(int64_t notification_id, |
107 const GURL& origin, | 109 const GURL& origin, |
108 const DeleteResultCallback& callback); | 110 const DeleteResultCallback& callback); |
109 | 111 |
| 112 // Destroys the database regardless of its initialization status. This method |
| 113 // must only be called on the |task_runner_| thread. |
| 114 void DestroyDatabase(); |
| 115 |
110 // Returns the path in which the database should be initialized. May be empty. | 116 // Returns the path in which the database should be initialized. May be empty. |
111 base::FilePath GetDatabasePath() const; | 117 base::FilePath GetDatabasePath() const; |
112 | 118 |
113 // Sets the task runner to use for testing purposes. | 119 // Sets the task runner to use for testing purposes. |
114 void SetTaskRunnerForTesting( | 120 void SetTaskRunnerForTesting( |
115 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 121 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
116 | 122 |
117 base::FilePath path_; | 123 base::FilePath path_; |
118 | 124 |
119 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 125 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
120 | 126 |
121 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 127 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
122 scoped_ptr<NotificationDatabase> database_; | 128 scoped_ptr<NotificationDatabase> database_; |
123 | 129 |
124 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContextImpl); | 130 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContextImpl); |
125 }; | 131 }; |
126 | 132 |
127 } // namespace content | 133 } // namespace content |
128 | 134 |
129 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_ | 135 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_ |
OLD | NEW |