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

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

Issue 2300093002: Make //content responsible for generating notification Ids (Closed)
Patch Set: Make //content responsible for generating notification Ids Created 4 years, 3 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_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 9
10 #include <memory> 10 #include <memory>
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 explicit NotificationDatabase(const base::FilePath& path); 72 explicit NotificationDatabase(const base::FilePath& path);
73 ~NotificationDatabase(); 73 ~NotificationDatabase();
74 74
75 // Opens the database. If |path| is non-empty, it will be created on the given 75 // Opens the database. If |path| is non-empty, it will be created on the given
76 // directory on the filesystem. If |path| is empty, the database will be 76 // directory on the filesystem. If |path| is empty, the database will be
77 // created in memory instead, and its lifetime will be tied to this instance. 77 // created in memory instead, and its lifetime will be tied to this instance.
78 // |create_if_missing| determines whether to create the database if necessary. 78 // |create_if_missing| determines whether to create the database if necessary.
79 Status Open(bool create_if_missing); 79 Status Open(bool create_if_missing);
80 80
81 // Reads the notification data for the notification identified by 81 // Reads the notification data for the notification identified by
82 // |notification_id| and belonging to |origin| from the database, and stores 82 // |persistent_notification_id| and belonging to |origin| from the database,
83 // it in |notification_database_data|. Returns the status code. 83 // and stores it in |notification_database_data|. Returns the status code.
84 Status ReadNotificationData( 84 Status ReadNotificationData(
85 int64_t notification_id, 85 int64_t persistent_notification_id,
86 const GURL& origin, 86 const GURL& origin,
87 NotificationDatabaseData* notification_database_data) const; 87 NotificationDatabaseData* notification_database_data) const;
88 88
89 // Reads all notification data for all origins from the database, and appends 89 // Reads all notification data for all origins from the database, and appends
90 // the data to |notification_data_vector|. Returns the status code. 90 // the data to |notification_data_vector|. Returns the status code.
91 Status ReadAllNotificationData( 91 Status ReadAllNotificationData(
92 std::vector<NotificationDatabaseData>* notification_data_vector) const; 92 std::vector<NotificationDatabaseData>* notification_data_vector) const;
93 93
94 // Reads all notification data associated with |origin| from the database, and 94 // Reads all notification data associated with |origin| from the database, and
95 // appends the data to |notification_data_vector|. Returns the status code. 95 // appends the data to |notification_data_vector|. Returns the status code.
96 Status ReadAllNotificationDataForOrigin( 96 Status ReadAllNotificationDataForOrigin(
97 const GURL& origin, 97 const GURL& origin,
98 std::vector<NotificationDatabaseData>* notification_data_vector) const; 98 std::vector<NotificationDatabaseData>* notification_data_vector) const;
99 99
100 // Reads all notification data associated to |service_worker_registration_id| 100 // Reads all notification data associated to |service_worker_registration_id|
101 // belonging to |origin| from the database, and appends the data to the 101 // belonging to |origin| from the database, and appends the data to the
102 // |notification_data_vector|. Returns the status code. 102 // |notification_data_vector|. Returns the status code.
103 Status ReadAllNotificationDataForServiceWorkerRegistration( 103 Status ReadAllNotificationDataForServiceWorkerRegistration(
104 const GURL& origin, 104 const GURL& origin,
105 int64_t service_worker_registration_id, 105 int64_t service_worker_registration_id,
106 std::vector<NotificationDatabaseData>* notification_data_vector) const; 106 std::vector<NotificationDatabaseData>* notification_data_vector) const;
107 107
108 // Writes the |notification_database_data| for a new notification belonging to 108 // Writes the |notification_database_data| for a new notification belonging to
109 // |origin| to the database, and returns the status code of the writing 109 // |origin| to the database, and returns the status code of the writing
110 // operation. The id of the new notification will be set in |notification_id|. 110 // operation. The id of the new notification will be written to
111 // |persistent_notification_id|.
111 Status WriteNotificationData( 112 Status WriteNotificationData(
112 const GURL& origin, 113 const GURL& origin,
113 const NotificationDatabaseData& notification_database_data, 114 const NotificationDatabaseData& notification_database_data,
114 int64_t* notification_id); 115 int64_t* persistent_notification_id);
115 116
116 // Deletes all data associated with the notification identified by 117 // Deletes all data associated with the notification identified by
117 // |notification_id| belonging to |origin| from the database. Returns the 118 // |persistent_notification_id| belonging to |origin| from the database.
118 // status code of the deletion operation. Note that it is not considered a 119 // Returns the status code of the deletion operation. Note that it is not
119 // failure if the to-be-deleted notification does not exist. 120 // considered a failure if the to-be-deleted notification does not exist.
120 Status DeleteNotificationData(int64_t notification_id, const GURL& origin); 121 Status DeleteNotificationData(int64_t persistent_notification_id,
122 const GURL& origin);
121 123
122 // Deletes all data associated with |origin| from the database, optionally 124 // Deletes all data associated with |origin| from the database, optionally
123 // filtered by the |tag|, and appends the deleted notification ids to 125 // filtered by the |tag|, and appends the deleted notification ids to
124 // |deleted_notification_set|. Returns the status code of the deletion 126 // |deleted_notification_set|. Returns the status code of the deletion
125 // operation. 127 // operation.
126 Status DeleteAllNotificationDataForOrigin( 128 Status DeleteAllNotificationDataForOrigin(
127 const GURL& origin, 129 const GURL& origin,
128 const std::string& tag, 130 const std::string& tag,
129 std::set<int64_t>* deleted_notification_set); 131 std::set<int64_t>* deleted_notification_set);
130 132
131 // Deletes all data associated with the |service_worker_registration_id| 133 // Deletes all data associated with the |service_worker_registration_id|
132 // belonging to |origin| from the database, and appends the deleted 134 // belonging to |origin| from the database, and appends the deleted
133 // notification ids to |deleted_notification_set|. Returns the status code 135 // notification ids to |deleted_notification_set|. Returns the status code
134 // of the deletion operation. 136 // of the deletion operation.
135 Status DeleteAllNotificationDataForServiceWorkerRegistration( 137 Status DeleteAllNotificationDataForServiceWorkerRegistration(
136 const GURL& origin, 138 const GURL& origin,
137 int64_t service_worker_registration_id, 139 int64_t service_worker_registration_id,
138 std::set<int64_t>* deleted_notification_set); 140 std::set<int64_t>* deleted_notification_set);
139 141
142 // Stores an association of |notification_id| to |persistent_notification_id|
143 // to the database. Returns the status code of the operation.
144 Status StoreIdAssociation(const std::string& notification_id,
145 int64_t persistent_notification_id);
146
147 // Reads the |*persistent_notification_id| that is associated with the
148 // |notification_id|. Returns the status code of the operation.
149 Status ReadIdAssociation(const std::string& notification_id,
150 int64_t* persistent_notification_id);
151
152 // Removes the association stored for the given |notification_id|.
153 Status DeleteIdAssociation(const std::string& notification_id);
154
140 // Completely destroys the contents of this database. 155 // Completely destroys the contents of this database.
141 Status Destroy(); 156 Status Destroy();
142 157
143 private: 158 private:
144 friend class NotificationDatabaseTest; 159 friend class NotificationDatabaseTest;
145 160
146 // TODO(peter): Convert to an enum class when DCHECK_EQ supports this. 161 // TODO(peter): Convert to an enum class when DCHECK_EQ supports this.
147 // See https://crbug.com/463869. 162 // See https://crbug.com/463869.
148 enum State { 163 enum State {
149 STATE_UNINITIALIZED, 164 STATE_UNINITIALIZED,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 State state_ = STATE_UNINITIALIZED; 216 State state_ = STATE_UNINITIALIZED;
202 217
203 base::SequenceChecker sequence_checker_; 218 base::SequenceChecker sequence_checker_;
204 219
205 DISALLOW_COPY_AND_ASSIGN(NotificationDatabase); 220 DISALLOW_COPY_AND_ASSIGN(NotificationDatabase);
206 }; 221 };
207 222
208 } // namespace content 223 } // namespace content
209 224
210 #endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_ 225 #endif // CONTENT_BROWSER_NOTIFICATIONS_NOTIFICATION_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698