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 <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 const std::vector<ResourceRecord>& resources); | 89 const std::vector<ResourceRecord>& resources); |
90 | 90 |
91 bool UpdateVersionToActive(int64 registration_id, | 91 bool UpdateVersionToActive(int64 registration_id, |
92 const GURL& origin); | 92 const GURL& origin); |
93 bool UpdateLastCheckTime(int64 registration_id, | 93 bool UpdateLastCheckTime(int64 registration_id, |
94 const GURL& origin, | 94 const GURL& origin, |
95 const base::Time& time); | 95 const base::Time& time); |
96 bool DeleteRegistration(int64 registration_id, | 96 bool DeleteRegistration(int64 registration_id, |
97 const GURL& origin); | 97 const GURL& origin); |
98 | 98 |
| 99 // As new resources are put into the diskcache, they go into an uncommitted |
| 100 // list. When a registration is saved that refers to those ids, they're |
| 101 // removed from that list. When a resource no longer has any registrations or |
| 102 // caches referring to it, it's added to the purgeable list. Periodically, |
| 103 // the purgeable list can be purged from the diskcache. At system startup, all |
| 104 // uncommitted ids are moved to the purgeable list. |
| 105 |
| 106 // Reads uncommitted resource ids from the database. Returns true on success. |
| 107 // Otherwise clears |ids| and returns false. |
| 108 bool GetUncommittedResourceIds(std::set<int64>* ids); |
| 109 |
| 110 // Writes |ids| into the database as uncommitted resources. Returns true on |
| 111 // success. Otherwise writes nothing and returns false. |
| 112 bool WriteUncommittedResourceIds(const std::set<int64>& ids); |
| 113 |
| 114 // Deletes uncommitted resource ids specified by |ids| from the database. |
| 115 // Returns true on success. Otherwise deletes nothing and returns false. |
| 116 bool ClearUncommittedResourceIds(const std::set<int64>& ids); |
| 117 |
| 118 // Reads purgeable resource ids from the database. Returns true on success. |
| 119 // Otherwise clears |ids| and returns false. |
| 120 bool GetPurgeableResourceIds(std::set<int64>* ids); |
| 121 |
| 122 // Writes |ids| into the database as purgeable resources. Returns true on |
| 123 // success. Otherwise writes nothing and returns false. |
| 124 bool WritePurgeableResourceIds(const std::set<int64>& ids); |
| 125 |
| 126 // Deletes purgeable resource ids specified by |ids| from the database. |
| 127 // Returns true on success. Otherwise deletes nothing and returns false. |
| 128 bool ClearPurgeableResourceIds(const std::set<int64>& ids); |
| 129 |
99 bool is_disabled() const { return is_disabled_; } | 130 bool is_disabled() const { return is_disabled_; } |
100 bool was_corruption_detected() const { return was_corruption_detected_; } | 131 bool was_corruption_detected() const { return was_corruption_detected_; } |
101 | 132 |
102 private: | 133 private: |
103 // Opens the database at the |path_|. This is lazily called when the first | 134 // Opens the database at the |path_|. This is lazily called when the first |
104 // database API is called. Returns true if the database was opened. Returns | 135 // database API is called. Returns true if the database was opened. Returns |
105 // false if the opening failed or was not neccessary, that is, the database | 136 // false if the opening failed or was not neccessary, that is, the database |
106 // does not exist and |create_if_needed| is false. | 137 // does not exist and |create_if_needed| is false. |
107 bool LazyOpen(bool create_if_needed); | 138 bool LazyOpen(bool create_if_needed); |
108 | 139 |
109 bool ReadNextAvailableId(const char* id_key, | 140 bool ReadNextAvailableId(const char* id_key, |
110 int64* next_avail_id); | 141 int64* next_avail_id); |
111 bool ReadRegistrationData(int64 registration_id, | 142 bool ReadRegistrationData(int64 registration_id, |
112 const GURL& origin, | 143 const GURL& origin, |
113 RegistrationData* registration); | 144 RegistrationData* registration); |
| 145 bool ReadResourceIds(const char* id_key_prefix, |
| 146 std::set<int64>* ids); |
| 147 bool WriteResourceIds(const char* id_key_prefix, |
| 148 const std::set<int64>& ids); |
| 149 bool DeleteResourceIds(const char* id_key_prefix, |
| 150 const std::set<int64>& ids); |
114 bool ReadDatabaseVersion(int64* db_version); | 151 bool ReadDatabaseVersion(int64* db_version); |
115 | 152 |
116 // Write a batch into the database. | 153 // Write a batch into the database. |
117 // NOTE: You must call this when you want to put something into the database | 154 // NOTE: You must call this when you want to put something into the database |
118 // because this initializes the database if needed. | 155 // because this initializes the database if needed. |
119 bool WriteBatch(leveldb::WriteBatch* batch); | 156 bool WriteBatch(leveldb::WriteBatch* batch); |
120 | 157 |
121 // Bumps the next available id if |used_id| is greater than or equal to the | 158 // Bumps the next available id if |used_id| is greater than or equal to the |
122 // cached one. | 159 // cached one. |
123 void BumpNextRegistrationIdIfNeeded(int64 used_id, | 160 void BumpNextRegistrationIdIfNeeded(int64 used_id, |
(...skipping 30 matching lines...) Expand all Loading... |
154 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase); | 191 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase); |
155 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase_InMemory); | 192 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, OpenDatabase_InMemory); |
156 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); | 193 FRIEND_TEST_ALL_PREFIXES(ServiceWorkerDatabaseTest, GetNextAvailableIds); |
157 | 194 |
158 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); | 195 DISALLOW_COPY_AND_ASSIGN(ServiceWorkerDatabase); |
159 }; | 196 }; |
160 | 197 |
161 } // namespace content | 198 } // namespace content |
162 | 199 |
163 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ | 200 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_DATABASE_H_ |
OLD | NEW |