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

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

Issue 1010833002: Expose bits of the Web Notification database in the //content API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-DeleteInContext
Patch Set: update a comment Created 5 years, 9 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_H_ 5 #ifndef CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_
6 #define CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_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"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "content/common/content_export.h" 13 #include "content/common/content_export.h"
14 #include "content/public/browser/platform_notification_context.h"
14 15
15 class GURL; 16 class GURL;
16 17
17 namespace base { 18 namespace base {
18 class SequencedTaskRunner; 19 class SequencedTaskRunner;
19 } 20 }
20 21
21 namespace content { 22 namespace content {
22 23
23 class NotificationDatabase; 24 class NotificationDatabase;
24 struct NotificationDatabaseData; 25 struct NotificationDatabaseData;
25 26
26 // Implementation of the Web Notification storage context. 27 // Implementation of the Web Notification storage context. The public methods
27 // 28 // defined in this interface must only be called on the IO thread.
28 // Represents the storage context for persistent Web Notifications, specific to 29 class CONTENT_EXPORT PlatformNotificationContextImpl
29 // the storage partition owning the instance. The public methods defined in this 30 : public PlatformNotificationContext {
30 // interface must only be called on the IO thread.
31 class CONTENT_EXPORT PlatformNotificationContext
32 : public base::RefCountedThreadSafe<PlatformNotificationContext> {
33 public: 31 public:
34 // Constructs a new platform notification context. If |path| is non-empty, the 32 // Constructs a new platform notification context. If |path| is non-empty, the
35 // database will be initialized in the "Platform Notifications" subdirectory 33 // database will be initialized in the "Platform Notifications" subdirectory
36 // of |path|. Otherwise, the database will be initialized in memory. 34 // of |path|. Otherwise, the database will be initialized in memory.
37 explicit PlatformNotificationContext(const base::FilePath& path); 35 explicit PlatformNotificationContextImpl(const base::FilePath& path);
38 36
39 using ReadResultCallback = 37 // PlatformNotificationContext implementation.
40 base::Callback<void(bool /* success */,
41 const NotificationDatabaseData&)>;
42
43 using WriteResultCallback =
44 base::Callback<void(bool /* success */,
45 int64_t /* notification_id */)>;
46
47 using DeleteResultCallback = base::Callback<void(bool /* success */)>;
48
49 // Reads the data associated with |notification_id| belonging to |origin|
50 // from the database. |callback| will be invoked with the success status
51 // and a reference to the notification database data when completed.
52 void ReadNotificationData(int64_t notification_id, 38 void ReadNotificationData(int64_t notification_id,
53 const GURL& origin, 39 const GURL& origin,
54 const ReadResultCallback& callback); 40 const ReadResultCallback& callback) override;
55
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 void WriteNotificationData(const GURL& origin, 41 void WriteNotificationData(const GURL& origin,
60 const NotificationDatabaseData& database_data, 42 const NotificationDatabaseData& database_data,
61 const WriteResultCallback& callback); 43 const WriteResultCallback& callback) override;
62
63 // Deletes all data associated with |notification_id| belonging to |origin|
64 // from the database. |callback| will be invoked with the success status
65 // when the operation has completed.
66 void DeleteNotificationData(int64_t notification_id, 44 void DeleteNotificationData(int64_t notification_id,
67 const GURL& origin, 45 const GURL& origin,
68 const DeleteResultCallback& callback); 46 const DeleteResultCallback& callback) override;
69 47
70 private: 48 private:
71 friend class base::RefCountedThreadSafe<PlatformNotificationContext>;
72 friend class PlatformNotificationContextTest; 49 friend class PlatformNotificationContextTest;
73 50
74 virtual ~PlatformNotificationContext(); 51 ~PlatformNotificationContextImpl() override;
75 52
76 // Initializes the database if neccesary. Must be called on the IO thread. 53 // Initializes the database if neccesary. Must be called on the IO thread.
77 // |success_closure| will be invoked on a the |task_runner_| thread when 54 // |success_closure| will be invoked on a the |task_runner_| thread when
78 // everything is available, or |failure_closure_| will be invoked on the 55 // everything is available, or |failure_closure_| will be invoked on the
79 // IO thread when initialization fails. 56 // IO thread when initialization fails.
80 void LazyInitialize(const base::Closure& success_closure, 57 void LazyInitialize(const base::Closure& success_closure,
81 const base::Closure& failure_closure); 58 const base::Closure& failure_closure);
82 59
83 // Opens the database. Must be called on the |task_runner_| thread. When the 60 // Opens the database. Must be called on the |task_runner_| thread. When the
84 // database has been opened, |success_closure| will be invoked on the task 61 // database has been opened, |success_closure| will be invoked on the task
(...skipping 27 matching lines...) Expand all
112 89
113 // Sets the task runner to use for testing purposes. 90 // Sets the task runner to use for testing purposes.
114 void SetTaskRunnerForTesting( 91 void SetTaskRunnerForTesting(
115 const scoped_refptr<base::SequencedTaskRunner>& task_runner); 92 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
116 93
117 base::FilePath path_; 94 base::FilePath path_;
118 95
119 scoped_refptr<base::SequencedTaskRunner> task_runner_; 96 scoped_refptr<base::SequencedTaskRunner> task_runner_;
120 scoped_ptr<NotificationDatabase> database_; 97 scoped_ptr<NotificationDatabase> database_;
121 98
122 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContext); 99 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContextImpl);
123 }; 100 };
124 101
125 } // namespace content 102 } // namespace content
126 103
127 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_ 104 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698