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

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

Issue 1006493005: Introduce the PlatformNotificationContext class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-db-ReadWriteDelete
Patch Set: y 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
(Empty)
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.
4
5 #ifndef CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_
6 #define CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_
7
8 #include <stdint.h>
9
10 #include "base/callback.h"
11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h"
13 #include "content/common/content_export.h"
14
15 class GURL;
16
17 namespace base {
18 class SequencedTaskRunner;
19 }
20
21 namespace content {
22
23 class NotificationDatabase;
24 struct NotificationDatabaseData;
25
26 // Implementation of the Web Notification storage context.
27 //
28 // Represents the storage context for persistent Web Notifications, specific to
29 // the storage partition owning the instance. The public methods defined in this
30 // interface must only be called on the IO thread.
31 class CONTENT_EXPORT PlatformNotificationContext
32 : public base::RefCountedThreadSafe<PlatformNotificationContext> {
33 public:
34 // Constructs a new platform notification context. If |path| is non-empty, the
35 // database will be initialized in the "Platform Notifications" subdirectory
36 // of |path|. Otherwise, the database will be initialized in memory.
37 explicit PlatformNotificationContext(const base::FilePath& path);
38
39 using ReadResultCallback =
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 // Reads the data associated with |notification_id| belonging to |origin|
48 // from the database. |callback| will be invoked with the success status
49 // and a reference to the notification database data when completed.
50 void ReadNotificationData(int64_t notification_id,
51 const GURL& origin,
52 const ReadResultCallback& callback);
53
54 // Writes the data associated with a notification to a database. When this
55 // action completed, |callback| will be invoked with the success status and
56 // the persistent notification id when written successfully.
57 void WriteNotificationData(const GURL& origin,
58 const NotificationDatabaseData& database_data,
59 const WriteResultCallback& callback);
60
61 private:
62 friend class base::RefCountedThreadSafe<PlatformNotificationContext>;
63 friend class PlatformNotificationContextTest;
64
65 virtual ~PlatformNotificationContext();
66
67 // Initializes the database if neccesary. Must be called on the IO thread.
68 // |success_closure| will be invoked on a the |task_runner_| thread when
69 // everything is available, or |failure_closure_| will be invoked on the
70 // IO thread when initialization fails.
71 void LazyInitialize(const base::Closure& success_closure,
72 const base::Closure& failure_closure);
73
74 // Opens the database. Must be called on the |task_runner_| thread. When the
75 // database has been opened, |success_closure| will be invoked on the task
76 // thread, otherwise |failure_closure_| will be invoked on the IO thread.
77 void OpenDatabase(const base::Closure& success_closure,
78 const base::Closure& failure_closure);
79
80 // Actually reads the notification data from the database. Must only be
81 // called on the |task_runner_| thread. Will post a task to |callback| on
82 // the IO thread when the operation has completed.
83 void DoReadNotificationData(int64_t notification_id,
84 const GURL& origin,
85 const ReadResultCallback& callback);
86
87 // Actually writes the notification database to the database. Must only be
88 // called on the |task_runner_| thread. Will post a task to |callback| on
89 // the IO thread when the operation has completed.
90 void DoWriteNotificationData(const GURL& origin,
91 const NotificationDatabaseData& database_data,
92 const WriteResultCallback& callback);
93
94 // Returns the path in which the database should be initialized. May be empty.
95 base::FilePath GetDatabasePath() const;
96
97 // Sets the task runner to use for testing purposes.
98 void SetTaskRunnerForTesting(
99 const scoped_refptr<base::SequencedTaskRunner>& task_runner);
100
101 base::FilePath path_;
102
103 scoped_refptr<base::SequencedTaskRunner> task_runner_;
104 scoped_ptr<NotificationDatabase> database_;
105
106 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContext);
107 };
108
109 } // namespace content
110
111 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_
OLDNEW
« no previous file with comments | « content/browser/notifications/notification_database.cc ('k') | content/browser/notifications/platform_notification_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698