Chromium Code Reviews| Index: content/browser/notifications/platform_notification_context.h |
| diff --git a/content/browser/notifications/platform_notification_context.h b/content/browser/notifications/platform_notification_context.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f3850a200afd4130ef042c0a33ea110da2513292 |
| --- /dev/null |
| +++ b/content/browser/notifications/platform_notification_context.h |
| @@ -0,0 +1,112 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_ |
| +#define CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include "base/callback.h" |
| +#include "base/files/file_path.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "content/common/content_export.h" |
| + |
| +class GURL; |
| + |
| +namespace base { |
| +class SequencedTaskRunner; |
| +} |
| + |
| +namespace content { |
| + |
| +class NotificationDatabase; |
| +struct NotificationDatabaseData; |
| + |
| +// Implementation of the Web Notification storage context. |
| +// |
| +// Represents the per-BrowserContext data for persistent Web Notifications. |
| +// The methods defined in this interface must only be called on the IO thread. |
| +class CONTENT_EXPORT PlatformNotificationContext |
| + : public base::RefCountedThreadSafe<PlatformNotificationContext> { |
|
Bernhard Bauer
2015/03/13 16:51:18
Is there a particular reason this class needs to b
Peter Beverloo
2015/03/13 16:57:07
It will be owned by StoragePartitionImpl (like the
Bernhard Bauer
2015/03/13 17:24:01
Urgh, so many refcounted classes :-( But fair enou
|
| + public: |
| + // Constructs a new platform notification context. If |path| is non-empty, the |
| + // database will be initialized in the "Platform Notifications" subdirectory |
| + // of |path|. Otherwise, the database will be initialized in memory. |
| + explicit PlatformNotificationContext(const base::FilePath& path); |
| + |
| + using ReadResultCallback = |
| + base::Callback<void(bool /* success */, |
| + const NotificationDatabaseData&)>; |
| + |
| + using WriteResultCallback = |
| + base::Callback<void(bool /* success */, |
| + int64_t /* notification_id */)>; |
| + |
| + // Reads the data associated with |notification_id| belonging to |origin| |
| + // from the database. |callback| will be invoked with the success status |
| + // and a reference to the notification database data when completed. |
| + void ReadNotificationData(int64_t notification_id, |
| + const GURL& origin, |
| + const ReadResultCallback& callback); |
| + |
| + // Writes the data associated with a notification to a database. When this |
| + // action completed, |callback| will be invoked with the success status and |
| + // the persistent notification id when written successfully. |
| + void WriteNotificationData(const GURL& origin, |
| + const NotificationDatabaseData& database_data, |
| + const WriteResultCallback& callback); |
| + |
| + protected: |
|
Bernhard Bauer
2015/03/13 16:51:18
Why is this protected?
Peter Beverloo
2015/03/13 16:57:07
Typo. Fixed!
|
| + friend class base::RefCountedThreadSafe<PlatformNotificationContext>; |
| + friend class PlatformNotificationContextTest; |
| + |
| + virtual ~PlatformNotificationContext(); |
| + |
| + // Initializes the database if neccesary. Must be called on the IO thread. |
| + // |success_closure| will be invoked on a the thread which must be used to |
|
Bernhard Bauer
2015/03/13 16:51:18
The "the thread which must be used to access |data
Peter Beverloo
2015/03/13 16:57:07
Done.
|
| + // access |database_| when everything is available, or |failure_closure_| |
| + // will be invoked on the IO thread when initialization fails. |
| + void LazyInitialize(const base::Closure& success_closure, |
| + const base::Closure& failure_closure); |
| + |
| + // Opens the database. Must be called on the |task_runner_| thread. When the |
| + // database has been opened, |success_closure| will be invoked on the task |
| + // thread, otherwise |failure_closure_ will be invoked on the IO thread. |
| + void OpenDatabase(const base::Closure& success_closure, |
| + const base::Closure& failure_closure); |
| + |
| + // Actually reads the notification data from the database. Must only be |
| + // called on the |task_runner_| thread. Will post a task to |callback| on |
| + // the IO thread when the operation has completed. |
| + void DoReadNotificationData(int64_t notification_id, |
| + const GURL& origin, |
| + const ReadResultCallback& callback); |
| + |
| + // Actually writes the notification database to the database. Must only be |
| + // called on the |task_runner_| thread. Will post a task to |callback| on |
| + // the IO thread when the operation has completed. |
| + void DoWriteNotificationData(const GURL& origin, |
| + const NotificationDatabaseData& database_data, |
| + const WriteResultCallback& callback); |
| + |
| + // Returns the path in which the database should be initialized. May be empty. |
| + base::FilePath GetDatabasePath() const; |
| + |
| + // Sets the task runner to use for testing purposes. |
| + void SetTaskRunnerForTesting( |
| + scoped_refptr<base::SequencedTaskRunner> task_runner); |
|
Bernhard Bauer
2015/03/13 16:51:18
Pass by const-ref?
Peter Beverloo
2015/03/13 16:57:07
Done.
|
| + |
| + base::FilePath path_; |
| + |
| + scoped_refptr<base::SequencedTaskRunner> task_runner_; |
| + scoped_ptr<NotificationDatabase> database_; |
| + |
| + int64_t next_notification_id_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContext); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_ |