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

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

Powered by Google App Engine
This is Rietveld 408576698