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

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

Issue 1019073002: The notification database should be able to read or delete multiple items. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | content/browser/notifications/notification_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_NOTIFICATION_DATABASE_H_ 5 #ifndef CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_
6 #define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_ 6 #define CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <set>
10 #include <vector>
9 11
10 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
11 #include "base/sequence_checker.h" 13 #include "base/sequence_checker.h"
12 #include "content/common/content_export.h" 14 #include "content/common/content_export.h"
13 15
14 class GURL; 16 class GURL;
15 17
16 namespace leveldb { 18 namespace leveldb {
17 class DB; 19 class DB;
18 class Env; 20 class Env;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 Status Open(bool create_if_missing); 62 Status Open(bool create_if_missing);
61 63
62 // Reads the notification data for the notification identified by 64 // Reads the notification data for the notification identified by
63 // |notification_id| and belonging to |origin| from the database, and stores 65 // |notification_id| and belonging to |origin| from the database, and stores
64 // it in |notification_database_data|. Returns the status code. 66 // it in |notification_database_data|. Returns the status code.
65 Status ReadNotificationData( 67 Status ReadNotificationData(
66 int64_t notification_id, 68 int64_t notification_id,
67 const GURL& origin, 69 const GURL& origin,
68 NotificationDatabaseData* notification_database_data) const; 70 NotificationDatabaseData* notification_database_data) const;
69 71
72 // Reads all notification data for all origins from the database, and appends
73 // the data to |notification_data_vector|. Returns the status code.
74 Status ReadAllNotificationData(
75 std::vector<NotificationDatabaseData>* notification_data_vector) const;
76
77 // Reads all notification data associated with |origin| from the database, and
78 // appends the data to |notification_data_vector|. Returns the status code.
79 Status ReadAllNotificationDataForOrigin(
80 const GURL& origin,
81 std::vector<NotificationDatabaseData>* notification_data_vector) const;
82
83 // Reads all notification data associated to |service_worker_registration_id|
84 // belonging to |origin| from the database, and appends the data to the
85 // |notification_data_vector|. Returns the status code.
86 Status ReadAllNotificationDataForServiceWorkerRegistration(
87 const GURL& origin,
88 int64_t service_worker_registration_id,
89 std::vector<NotificationDatabaseData>* notification_data_vector) const;
90
70 // Writes the |notification_database_data| for a new notification belonging to 91 // Writes the |notification_database_data| for a new notification belonging to
71 // |origin| to the database, and returns the status code of the writing 92 // |origin| to the database, and returns the status code of the writing
72 // operation. The id of the new notification will be set in |notification_id|. 93 // operation. The id of the new notification will be set in |notification_id|.
73 Status WriteNotificationData( 94 Status WriteNotificationData(
74 const GURL& origin, 95 const GURL& origin,
75 const NotificationDatabaseData& notification_database_data, 96 const NotificationDatabaseData& notification_database_data,
76 int64_t* notification_id); 97 int64_t* notification_id);
77 98
78 // Deletes all data associated with the notification identified by 99 // Deletes all data associated with the notification identified by
79 // |notification_id| belonging to |origin| from the database. Returns the 100 // |notification_id| belonging to |origin| from the database. Returns the
80 // status code of the deletion operation. Note that it is not considered a 101 // status code of the deletion operation. Note that it is not considered a
81 // failure if the to-be-deleted notification does not exist. 102 // failure if the to-be-deleted notification does not exist.
82 Status DeleteNotificationData(int64_t notification_id, const GURL& origin); 103 Status DeleteNotificationData(int64_t notification_id, const GURL& origin);
83 104
105 // Deletes all data associated with |origin| from the database, and appends
106 // the deleted notification ids to |deleted_notification_set|. Returns the
107 // status code of the deletion operation.
108 Status DeleteAllNotificationDataForOrigin(
109 const GURL& origin,
110 std::set<int64_t>* deleted_notification_set);
111
112 // Deletes all data associated with the |service_worker_registration_id|
113 // belonging to |origin| from the database, and appends the deleted
114 // notification ids to |deleted_notification_set|. Returns the status code
115 // of the deletion operation.
116 Status DeleteAllNotificationDataForServiceWorkerRegistration(
117 const GURL& origin,
118 int64_t service_worker_registration_id,
119 std::set<int64_t>* deleted_notification_set);
120
84 // Completely destroys the contents of this database. 121 // Completely destroys the contents of this database.
85 Status Destroy(); 122 Status Destroy();
86 123
87 private: 124 private:
88 friend class NotificationDatabaseTest; 125 friend class NotificationDatabaseTest;
89 126
90 // TODO(peter): Convert to an enum class when DCHECK_EQ supports this. 127 // TODO(peter): Convert to an enum class when DCHECK_EQ supports this.
91 // See https://crbug.com/463869. 128 // See https://crbug.com/463869.
92 enum State { 129 enum State {
93 STATE_UNINITIALIZED, 130 STATE_UNINITIALIZED,
94 STATE_INITIALIZED, 131 STATE_INITIALIZED,
95 STATE_DISABLED, 132 STATE_DISABLED,
96 }; 133 };
97 134
98 // Reads the next available notification id from the database and returns 135 // Reads the next available notification id from the database and returns
99 // the status code of the reading operation. The value will be stored in 136 // the status code of the reading operation. The value will be stored in
100 // the |next_notification_id_| member. 137 // the |next_notification_id_| member.
101 Status ReadNextNotificationId(); 138 Status ReadNextNotificationId();
102 139
140 // Reads all notification data with the given constraints. |origin| may be
141 // empty to read all notification data from all origins. If |origin| is
142 // set, but |service_worker_registration_id| is invalid, then all notification
143 // data for |origin| will be read. If both are set, then all notification data
144 // for the given |service_worker_registration_id| will be read.
145 Status ReadAllNotificationDataInternal(
146 const GURL& origin,
147 int64_t service_worker_registration_id,
148 std::vector<NotificationDatabaseData>* notification_data_vector) const;
149
150 // Deletes all notification data with the given constraints. |origin| must
151 // always be set - use Destroy() when the goal is to empty the database. If
152 // |service_worker_registration_id| is invalid, all notification data for the
153 // |origin| will be deleted.
154 // All deleted notification ids will be written to |deleted_notification_set|.
155 Status DeleteAllNotificationDataInternal(
156 const GURL& origin,
157 int64_t service_worker_registration_id,
158 std::set<int64_t>* deleted_notification_set);
159
103 // Returns whether the database has been opened. 160 // Returns whether the database has been opened.
104 bool IsOpen() const { return db_ != nullptr; } 161 bool IsOpen() const { return db_ != nullptr; }
105 162
106 // Returns whether the database should only exist in memory. 163 // Returns whether the database should only exist in memory.
107 bool IsInMemoryDatabase() const { return path_.empty(); } 164 bool IsInMemoryDatabase() const { return path_.empty(); }
108 165
109 // Exposes the LevelDB database used to back this notification database. 166 // Exposes the LevelDB database used to back this notification database.
110 // Should only be used for testing purposes. 167 // Should only be used for testing purposes.
111 leveldb::DB* GetDBForTesting() const { return db_.get(); } 168 leveldb::DB* GetDBForTesting() const { return db_.get(); }
112 169
113 base::FilePath path_; 170 base::FilePath path_;
114 171
115 int64_t next_notification_id_ = 0; 172 int64_t next_notification_id_ = 0;
116 173
117 // The declaration order for these members matters, as |db_| depends on |env_| 174 // The declaration order for these members matters, as |db_| depends on |env_|
118 // and thus has to be destructed first. 175 // and thus has to be destructed first.
119 scoped_ptr<leveldb::Env> env_; 176 scoped_ptr<leveldb::Env> env_;
120 scoped_ptr<leveldb::DB> db_; 177 scoped_ptr<leveldb::DB> db_;
121 178
122 State state_ = STATE_UNINITIALIZED; 179 State state_ = STATE_UNINITIALIZED;
123 180
124 base::SequenceChecker sequence_checker_; 181 base::SequenceChecker sequence_checker_;
125 182
126 DISALLOW_COPY_AND_ASSIGN(NotificationDatabase); 183 DISALLOW_COPY_AND_ASSIGN(NotificationDatabase);
127 }; 184 };
128 185
129 } // namespace content 186 } // namespace content
130 187
131 #endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_ 188 #endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/notifications/notification_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698