| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ | 5 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ |
| 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ | 6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // with it from the database. Returns OK if they are successfully read. | 107 // with it from the database. Returns OK if they are successfully read. |
| 108 // Otherwise, returns an error. | 108 // Otherwise, returns an error. |
| 109 Status ReadRegistration( | 109 Status ReadRegistration( |
| 110 int64 registration_id, | 110 int64 registration_id, |
| 111 const GURL& origin, | 111 const GURL& origin, |
| 112 RegistrationData* registration, | 112 RegistrationData* registration, |
| 113 std::vector<ResourceRecord>* resources); | 113 std::vector<ResourceRecord>* resources); |
| 114 | 114 |
| 115 // Writes |registration| and |resources| into the database and does following | 115 // Writes |registration| and |resources| into the database and does following |
| 116 // things: | 116 // things: |
| 117 // - Deletes an old version of the registration if exists. | 117 // - If an old version of the registration exists, deletes it and sets |
| 118 // |deleted_version_id| to the old version id and |
| 119 // |newly_purgeable_resources| to its resources. Otherwise, sets |
| 120 // |deleted_version_id| to -1. |
| 118 // - Bumps the next registration id and the next version id if needed. | 121 // - Bumps the next registration id and the next version id if needed. |
| 119 // - Removes |resources| from the uncommitted list if exist. | 122 // - Removes |resources| from the uncommitted list if exist. |
| 120 // Returns OK they are successfully written. Otherwise, returns an error. | 123 // Returns OK they are successfully written. Otherwise, returns an error. |
| 121 Status WriteRegistration( | 124 Status WriteRegistration(const RegistrationData& registration, |
| 122 const RegistrationData& registration, | 125 const std::vector<ResourceRecord>& resources, |
| 123 const std::vector<ResourceRecord>& resources, | 126 int64* deleted_version_id, |
| 124 std::vector<int64>* newly_purgeable_resources); | 127 std::vector<int64>* newly_purgeable_resources); |
| 125 | 128 |
| 126 // Updates a registration for |registration_id| to an active state. Returns OK | 129 // Updates a registration for |registration_id| to an active state. Returns OK |
| 127 // if it's successfully updated. Otherwise, returns an error. | 130 // if it's successfully updated. Otherwise, returns an error. |
| 128 Status UpdateVersionToActive( | 131 Status UpdateVersionToActive( |
| 129 int64 registration_id, | 132 int64 registration_id, |
| 130 const GURL& origin); | 133 const GURL& origin); |
| 131 | 134 |
| 132 // Updates last check time of a registration for |registration_id| by |time|. | 135 // Updates last check time of a registration for |registration_id| by |time|. |
| 133 // Returns OK if it's successfully updated. Otherwise, returns an error. | 136 // Returns OK if it's successfully updated. Otherwise, returns an error. |
| 134 Status UpdateLastCheckTime( | 137 Status UpdateLastCheckTime( |
| 135 int64 registration_id, | 138 int64 registration_id, |
| 136 const GURL& origin, | 139 const GURL& origin, |
| 137 const base::Time& time); | 140 const base::Time& time); |
| 138 | 141 |
| 139 // Deletes a registration for |registration_id| and moves resource records | 142 // Deletes a registration for |registration_id| and moves resource records |
| 140 // associated with it into the purgeable list. Returns OK if it's successfully | 143 // associated with it into the purgeable list. If deletion occurred, sets |
| 141 // deleted or not found in the database. Otherwise, returns an error. | 144 // |version_id| to the id of the version that was deleted and |
| 142 Status DeleteRegistration( | 145 // |newly_purgeable_resources| to its resources; otherwise, sets |version_id| |
| 143 int64 registration_id, | 146 // to -1. Returns OK if it's successfully deleted or not found in the |
| 144 const GURL& origin, | 147 // database. Otherwise, returns an error. |
| 145 std::vector<int64>* newly_purgeable_resources); | 148 Status DeleteRegistration(int64 registration_id, |
| 149 const GURL& origin, |
| 150 int64* version_id, |
| 151 std::vector<int64>* newly_purgeable_resources); |
| 146 | 152 |
| 147 // As new resources are put into the diskcache, they go into an uncommitted | 153 // As new resources are put into the diskcache, they go into an uncommitted |
| 148 // list. When a registration is saved that refers to those ids, they're | 154 // list. When a registration is saved that refers to those ids, they're |
| 149 // removed from that list. When a resource no longer has any registrations or | 155 // removed from that list. When a resource no longer has any registrations or |
| 150 // caches referring to it, it's added to the purgeable list. Periodically, | 156 // caches referring to it, it's added to the purgeable list. Periodically, |
| 151 // the purgeable list can be purged from the diskcache. At system startup, all | 157 // the purgeable list can be purged from the diskcache. At system startup, all |
| 152 // uncommitted ids are moved to the purgeable list. | 158 // uncommitted ids are moved to the purgeable list. |
| 153 | 159 |
| 154 // Reads uncommitted resource ids from the database. Returns OK on success. | 160 // Reads uncommitted resource ids from the database. Returns OK on success. |
| 155 // Otherwise clears |ids| and returns an error. | 161 // Otherwise clears |ids| and returns an error. |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DatabaseVersion); | 321 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DatabaseVersion); |
| 316 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); | 322 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); |
| 317 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DestroyDatabase); | 323 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DestroyDatabase); |
| 318 | 324 |
| 319 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); | 325 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); |
| 320 }; | 326 }; |
| 321 | 327 |
| 322 } // namespace content | 328 } // namespace content |
| 323 | 329 |
| 324 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ | 330 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ |
| OLD | NEW |