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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 // Versions are first stored once they successfully install and become | 58 // Versions are first stored once they successfully install and become |
59 // the waiting version. Then transition to the active version. The stored | 59 // the waiting version. Then transition to the active version. The stored |
60 // version may be in the ACTIVATED state or in the INSTALLED state. | 60 // version may be in the ACTIVATED state or in the INSTALLED state. |
61 GURL script; | 61 GURL script; |
62 int64 version_id; | 62 int64 version_id; |
63 bool is_active; | 63 bool is_active; |
64 bool has_fetch_handler; | 64 bool has_fetch_handler; |
65 base::Time last_update_check; | 65 base::Time last_update_check; |
66 | 66 |
67 // Not populated until ServiceWorkerStorage::StoreRegistration is called. | 67 // Not populated until ServiceWorkerStorage::StoreRegistration is called. |
68 uint64 resources_total_size_bytes; | 68 int64_t resources_total_size_bytes; |
69 | 69 |
70 RegistrationData(); | 70 RegistrationData(); |
71 ~RegistrationData(); | 71 ~RegistrationData(); |
72 }; | 72 }; |
73 | 73 |
74 struct ResourceRecord { | 74 struct ResourceRecord { |
75 int64 resource_id; | 75 int64 resource_id; |
76 GURL url; | 76 GURL url; |
77 // Signed so we can store -1 to specify an unknown or error state. When | 77 // Signed so we can store -1 to specify an unknown or error state. When |
78 // stored to the database, this value should always be >= 0. | 78 // stored to the database, this value should always be >= 0. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // Otherwise, returns an error. | 116 // Otherwise, returns an error. |
117 Status ReadRegistration( | 117 Status ReadRegistration( |
118 int64 registration_id, | 118 int64 registration_id, |
119 const GURL& origin, | 119 const GURL& origin, |
120 RegistrationData* registration, | 120 RegistrationData* registration, |
121 std::vector<ResourceRecord>* resources); | 121 std::vector<ResourceRecord>* resources); |
122 | 122 |
123 // Writes |registration| and |resources| into the database and does following | 123 // Writes |registration| and |resources| into the database and does following |
124 // things: | 124 // things: |
125 // - If an old version of the registration exists, deletes it and sets | 125 // - If an old version of the registration exists, deletes it and sets |
126 // |deleted_version_id| to the old version id and | 126 // |deleted_version| to the old version registration data object |
127 // |newly_purgeable_resources| to its resources. Otherwise, sets | 127 // |newly_purgeable_resources| to its resources. Otherwise, sets |
128 // |deleted_version_id| to -1. | 128 // |deleted_version->version_id| to -1. |
129 // - Bumps the next registration id and the next version id if needed. | 129 // - Bumps the next registration id and the next version id if needed. |
130 // - Removes |resources| from the uncommitted list if exist. | 130 // - Removes |resources| from the uncommitted list if exist. |
131 // Returns OK they are successfully written. Otherwise, returns an error. | 131 // Returns OK they are successfully written. Otherwise, returns an error. |
132 Status WriteRegistration(const RegistrationData& registration, | 132 Status WriteRegistration(const RegistrationData& registration, |
133 const std::vector<ResourceRecord>& resources, | 133 const std::vector<ResourceRecord>& resources, |
134 int64* deleted_version_id, | 134 RegistrationData* deleted_version, |
135 std::vector<int64>* newly_purgeable_resources); | 135 std::vector<int64>* newly_purgeable_resources); |
136 | 136 |
137 // Updates a registration for |registration_id| to an active state. Returns OK | 137 // Updates a registration for |registration_id| to an active state. Returns OK |
138 // if it's successfully updated. Otherwise, returns an error. | 138 // if it's successfully updated. Otherwise, returns an error. |
139 Status UpdateVersionToActive( | 139 Status UpdateVersionToActive( |
140 int64 registration_id, | 140 int64 registration_id, |
141 const GURL& origin); | 141 const GURL& origin); |
142 | 142 |
143 // Updates last check time of a registration for |registration_id| by |time|. | 143 // Updates last check time of a registration for |registration_id| by |time|. |
144 // Returns OK if it's successfully updated. Otherwise, returns an error. | 144 // Returns OK if it's successfully updated. Otherwise, returns an error. |
145 Status UpdateLastCheckTime( | 145 Status UpdateLastCheckTime( |
146 int64 registration_id, | 146 int64 registration_id, |
147 const GURL& origin, | 147 const GURL& origin, |
148 const base::Time& time); | 148 const base::Time& time); |
149 | 149 |
150 // Deletes a registration for |registration_id| and moves resource records | 150 // Deletes a registration for |registration_id| and moves resource records |
151 // associated with it into the purgeable list. If deletion occurred, sets | 151 // associated with it into the purgeable list. If deletion occurred, sets |
152 // |version_id| to the id of the version that was deleted and | 152 // |version_id| to the id of the version that was deleted and |
153 // |newly_purgeable_resources| to its resources; otherwise, sets |version_id| | 153 // |newly_purgeable_resources| to its resources; otherwise, sets |version_id| |
154 // to -1. Returns OK if it's successfully deleted or not found in the | 154 // to -1. Returns OK if it's successfully deleted or not found in the |
155 // database. Otherwise, returns an error. | 155 // database. Otherwise, returns an error. |
156 Status DeleteRegistration(int64 registration_id, | 156 Status DeleteRegistration(int64 registration_id, |
157 const GURL& origin, | 157 const GURL& origin, |
158 int64* version_id, | 158 RegistrationData* deleted_version, |
159 std::vector<int64>* newly_purgeable_resources); | 159 std::vector<int64>* newly_purgeable_resources); |
160 | 160 |
161 // As new resources are put into the diskcache, they go into an uncommitted | 161 // As new resources are put into the diskcache, they go into an uncommitted |
162 // list. When a registration is saved that refers to those ids, they're | 162 // list. When a registration is saved that refers to those ids, they're |
163 // removed from that list. When a resource no longer has any registrations or | 163 // removed from that list. When a resource no longer has any registrations or |
164 // caches referring to it, it's added to the purgeable list. Periodically, | 164 // caches referring to it, it's added to the purgeable list. Periodically, |
165 // the purgeable list can be purged from the diskcache. At system startup, all | 165 // the purgeable list can be purged from the diskcache. At system startup, all |
166 // uncommitted ids are moved to the purgeable list. | 166 // uncommitted ids are moved to the purgeable list. |
167 | 167 |
168 // Reads uncommitted resource ids from the database. Returns OK on success. | 168 // Reads uncommitted resource ids from the database. Returns OK on success. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DatabaseVersion); | 331 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DatabaseVersion); |
332 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); | 332 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); |
333 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DestroyDatabase); | 333 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, DestroyDatabase); |
334 | 334 |
335 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); | 335 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); |
336 }; | 336 }; |
337 | 337 |
338 } // namespace content | 338 } // namespace content |
339 | 339 |
340 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ | 340 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ |
OLD | NEW |