OLD | NEW |
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_H_ |
6 #define CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_ | 6 #define CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 explicit PlatformNotificationContext(const base::FilePath& path); | 37 explicit PlatformNotificationContext(const base::FilePath& path); |
38 | 38 |
39 using ReadResultCallback = | 39 using ReadResultCallback = |
40 base::Callback<void(bool /* success */, | 40 base::Callback<void(bool /* success */, |
41 const NotificationDatabaseData&)>; | 41 const NotificationDatabaseData&)>; |
42 | 42 |
43 using WriteResultCallback = | 43 using WriteResultCallback = |
44 base::Callback<void(bool /* success */, | 44 base::Callback<void(bool /* success */, |
45 int64_t /* notification_id */)>; | 45 int64_t /* notification_id */)>; |
46 | 46 |
| 47 using DeleteResultCallback = base::Callback<void(bool /* success */)>; |
| 48 |
47 // Reads the data associated with |notification_id| belonging to |origin| | 49 // Reads the data associated with |notification_id| belonging to |origin| |
48 // from the database. |callback| will be invoked with the success status | 50 // from the database. |callback| will be invoked with the success status |
49 // and a reference to the notification database data when completed. | 51 // and a reference to the notification database data when completed. |
50 void ReadNotificationData(int64_t notification_id, | 52 void ReadNotificationData(int64_t notification_id, |
51 const GURL& origin, | 53 const GURL& origin, |
52 const ReadResultCallback& callback); | 54 const ReadResultCallback& callback); |
53 | 55 |
54 // Writes the data associated with a notification to a database. When this | 56 // Writes the data associated with a notification to a database. When this |
55 // action completed, |callback| will be invoked with the success status and | 57 // action completed, |callback| will be invoked with the success status and |
56 // the persistent notification id when written successfully. | 58 // the persistent notification id when written successfully. |
57 void WriteNotificationData(const GURL& origin, | 59 void WriteNotificationData(const GURL& origin, |
58 const NotificationDatabaseData& database_data, | 60 const NotificationDatabaseData& database_data, |
59 const WriteResultCallback& callback); | 61 const WriteResultCallback& callback); |
60 | 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, |
| 67 const GURL& origin, |
| 68 const DeleteResultCallback& callback); |
| 69 |
61 private: | 70 private: |
62 friend class base::RefCountedThreadSafe<PlatformNotificationContext>; | 71 friend class base::RefCountedThreadSafe<PlatformNotificationContext>; |
63 friend class PlatformNotificationContextTest; | 72 friend class PlatformNotificationContextTest; |
64 | 73 |
65 virtual ~PlatformNotificationContext(); | 74 virtual ~PlatformNotificationContext(); |
66 | 75 |
67 // Initializes the database if neccesary. Must be called on the IO thread. | 76 // 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 | 77 // |success_closure| will be invoked on a the |task_runner_| thread when |
69 // everything is available, or |failure_closure_| will be invoked on the | 78 // everything is available, or |failure_closure_| will be invoked on the |
70 // IO thread when initialization fails. | 79 // IO thread when initialization fails. |
71 void LazyInitialize(const base::Closure& success_closure, | 80 void LazyInitialize(const base::Closure& success_closure, |
72 const base::Closure& failure_closure); | 81 const base::Closure& failure_closure); |
73 | 82 |
74 // Opens the database. Must be called on the |task_runner_| thread. When the | 83 // 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 | 84 // database has been opened, |success_closure| will be invoked on the task |
76 // thread, otherwise |failure_closure_| will be invoked on the IO thread. | 85 // thread, otherwise |failure_closure_| will be invoked on the IO thread. |
77 void OpenDatabase(const base::Closure& success_closure, | 86 void OpenDatabase(const base::Closure& success_closure, |
78 const base::Closure& failure_closure); | 87 const base::Closure& failure_closure); |
79 | 88 |
80 // Actually reads the notification data from the database. Must only be | 89 // 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 | 90 // called on the |task_runner_| thread. |callback| will be invoked on the |
82 // the IO thread when the operation has completed. | 91 // IO thread when the operation has completed. |
83 void DoReadNotificationData(int64_t notification_id, | 92 void DoReadNotificationData(int64_t notification_id, |
84 const GURL& origin, | 93 const GURL& origin, |
85 const ReadResultCallback& callback); | 94 const ReadResultCallback& callback); |
86 | 95 |
87 // Actually writes the notification database to the database. Must only be | 96 // 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 | 97 // called on the |task_runner_| thread. |callback| will be invoked on the |
89 // the IO thread when the operation has completed. | 98 // IO thread when the operation has completed. |
90 void DoWriteNotificationData(const GURL& origin, | 99 void DoWriteNotificationData(const GURL& origin, |
91 const NotificationDatabaseData& database_data, | 100 const NotificationDatabaseData& database_data, |
92 const WriteResultCallback& callback); | 101 const WriteResultCallback& callback); |
93 | 102 |
| 103 // Actually deletes the notification information from the database. Must only |
| 104 // be called on the |task_runner_| thread. |callback| will be invoked on the |
| 105 // IO thread when the operation has completed. |
| 106 void DoDeleteNotificationData(int64_t notification_id, |
| 107 const GURL& origin, |
| 108 const DeleteResultCallback& callback); |
| 109 |
94 // Returns the path in which the database should be initialized. May be empty. | 110 // Returns the path in which the database should be initialized. May be empty. |
95 base::FilePath GetDatabasePath() const; | 111 base::FilePath GetDatabasePath() const; |
96 | 112 |
97 // Sets the task runner to use for testing purposes. | 113 // Sets the task runner to use for testing purposes. |
98 void SetTaskRunnerForTesting( | 114 void SetTaskRunnerForTesting( |
99 const scoped_refptr<base::SequencedTaskRunner>& task_runner); | 115 const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
100 | 116 |
101 base::FilePath path_; | 117 base::FilePath path_; |
102 | 118 |
103 scoped_refptr<base::SequencedTaskRunner> task_runner_; | 119 scoped_refptr<base::SequencedTaskRunner> task_runner_; |
104 scoped_ptr<NotificationDatabase> database_; | 120 scoped_ptr<NotificationDatabase> database_; |
105 | 121 |
106 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContext); | 122 DISALLOW_COPY_AND_ASSIGN(PlatformNotificationContext); |
107 }; | 123 }; |
108 | 124 |
109 } // namespace content | 125 } // namespace content |
110 | 126 |
111 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_ | 127 #endif // CONTENT_BROWSER_NOTIFICATIONS_PLATFORM_NOTIFICATION_CONTEXT_H_ |
OLD | NEW |