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
3 // found in the LICENSE file.
5 #ifndef CONTENT_PUBLIC_BROWSER_PLATFORM_NOTIFICATION_CONTEXT_H_
6 #define CONTENT_PUBLIC_BROWSER_PLATFORM_NOTIFICATION_CONTEXT_H_
11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h"
13 #include "content/public/browser/browser_thread.h"
14 #include "content/public/browser/notification_database_data.h"
20 // Represents the storage context for persistent Web Notifications, specific to
21 // the storage partition owning the instance. All methods defined in this
22 // interface may only be used on the IO thread.
23 class PlatformNotificationContext
24 : public base::RefCountedThreadSafe
<PlatformNotificationContext
,
25 BrowserThread::DeleteOnUIThread
> {
27 using ReadResultCallback
=
28 base::Callback
<void(bool /* success */,
29 const NotificationDatabaseData
&)>;
31 using ReadAllResultCallback
=
32 base::Callback
<void(bool /* success */,
33 const std::vector
<NotificationDatabaseData
>&)>;
35 using WriteResultCallback
=
36 base::Callback
<void(bool /* success */,
37 int64_t /* notification_id */)>;
39 using DeleteResultCallback
= base::Callback
<void(bool /* success */)>;
41 // Reads the data associated with |notification_id| belonging to |origin|
42 // from the database. |callback| will be invoked with the success status
43 // and a reference to the notification database data when completed.
44 virtual void ReadNotificationData(int64_t notification_id
,
46 const ReadResultCallback
& callback
) = 0;
48 // Reads all data associated with |service_worker_registration_id| belonging
49 // to |origin| from the database. |callback| will be invoked with the success
50 // status and a vector with all read notification data when completed.
51 virtual void ReadAllNotificationDataForServiceWorkerRegistration(
53 int64_t service_worker_registration_id
,
54 const ReadAllResultCallback
& callback
) = 0;
56 // Writes the data associated with a notification to a database. When this
57 // action completed, |callback| will be invoked with the success status and
58 // the persistent notification id when written successfully.
59 virtual void WriteNotificationData(
61 const NotificationDatabaseData
& database_data
,
62 const WriteResultCallback
& callback
) = 0;
64 // Deletes all data associated with |notification_id| belonging to |origin|
65 // from the database. |callback| will be invoked with the success status
66 // when the operation has completed.
67 virtual void DeleteNotificationData(int64_t notification_id
,
69 const DeleteResultCallback
& callback
) = 0;
72 friend class base::DeleteHelper
<PlatformNotificationContext
>;
73 friend struct BrowserThread::DeleteOnThread
<BrowserThread::UI
>;
75 virtual ~PlatformNotificationContext() {}
78 } // namespace content
80 #endif // CONTENT_PUBLIC_BROWSER_PLATFORM_NOTIFICATION_CONTEXT_H_