| 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 #include "content/browser/service_worker/service_worker_database.h" | 5 #include "content/browser/service_worker/service_worker_database.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 case ServiceWorkerDatabase::STATUS_ERROR_MAX: | 270 case ServiceWorkerDatabase::STATUS_ERROR_MAX: |
| 271 NOTREACHED(); | 271 NOTREACHED(); |
| 272 return "Database unknown error"; | 272 return "Database unknown error"; |
| 273 } | 273 } |
| 274 NOTREACHED(); | 274 NOTREACHED(); |
| 275 return "Database unknown error"; | 275 return "Database unknown error"; |
| 276 } | 276 } |
| 277 | 277 |
| 278 ServiceWorkerDatabase::RegistrationData::RegistrationData() | 278 ServiceWorkerDatabase::RegistrationData::RegistrationData() |
| 279 : registration_id(kInvalidServiceWorkerRegistrationId), | 279 : registration_id(kInvalidServiceWorkerRegistrationId), |
| 280 use_cache(false), |
| 280 version_id(kInvalidServiceWorkerVersionId), | 281 version_id(kInvalidServiceWorkerVersionId), |
| 281 is_active(false), | 282 is_active(false), |
| 282 has_fetch_handler(false), | 283 has_fetch_handler(false), |
| 283 resources_total_size_bytes(0) { | 284 resources_total_size_bytes(0) {} |
| 284 } | |
| 285 | 285 |
| 286 ServiceWorkerDatabase::RegistrationData::RegistrationData( | 286 ServiceWorkerDatabase::RegistrationData::RegistrationData( |
| 287 const RegistrationData& other) = default; | 287 const RegistrationData& other) = default; |
| 288 | 288 |
| 289 ServiceWorkerDatabase::RegistrationData::~RegistrationData() { | 289 ServiceWorkerDatabase::RegistrationData::~RegistrationData() { |
| 290 } | 290 } |
| 291 | 291 |
| 292 ServiceWorkerDatabase::ServiceWorkerDatabase(const base::FilePath& path) | 292 ServiceWorkerDatabase::ServiceWorkerDatabase(const base::FilePath& path) |
| 293 : path_(path), | 293 : path_(path), |
| 294 next_avail_registration_id_(0), | 294 next_avail_registration_id_(0), |
| (...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1287 const ServiceWorkerNavigationPreloadState& state = | 1287 const ServiceWorkerNavigationPreloadState& state = |
| 1288 data.navigation_preload_state(); | 1288 data.navigation_preload_state(); |
| 1289 out->navigation_preload_state.enabled = state.enabled(); | 1289 out->navigation_preload_state.enabled = state.enabled(); |
| 1290 if (state.has_header()) | 1290 if (state.has_header()) |
| 1291 out->navigation_preload_state.header = state.header(); | 1291 out->navigation_preload_state.header = state.header(); |
| 1292 } | 1292 } |
| 1293 | 1293 |
| 1294 for (uint32_t feature : data.used_features()) | 1294 for (uint32_t feature : data.used_features()) |
| 1295 out->used_features.insert(feature); | 1295 out->used_features.insert(feature); |
| 1296 | 1296 |
| 1297 out->use_cache = data.use_cache(); |
| 1298 |
| 1297 return ServiceWorkerDatabase::STATUS_OK; | 1299 return ServiceWorkerDatabase::STATUS_OK; |
| 1298 } | 1300 } |
| 1299 | 1301 |
| 1300 void ServiceWorkerDatabase::WriteRegistrationDataInBatch( | 1302 void ServiceWorkerDatabase::WriteRegistrationDataInBatch( |
| 1301 const RegistrationData& registration, | 1303 const RegistrationData& registration, |
| 1302 leveldb::WriteBatch* batch) { | 1304 leveldb::WriteBatch* batch) { |
| 1303 DCHECK(batch); | 1305 DCHECK(batch); |
| 1304 | 1306 |
| 1305 // The registration id and version id should be bumped before this. | 1307 // The registration id and version id should be bumped before this. |
| 1306 DCHECK_GT(next_avail_registration_id_, registration.registration_id); | 1308 DCHECK_GT(next_avail_registration_id_, registration.registration_id); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1336 } | 1338 } |
| 1337 } | 1339 } |
| 1338 ServiceWorkerNavigationPreloadState* state = | 1340 ServiceWorkerNavigationPreloadState* state = |
| 1339 data.mutable_navigation_preload_state(); | 1341 data.mutable_navigation_preload_state(); |
| 1340 state->set_enabled(registration.navigation_preload_state.enabled); | 1342 state->set_enabled(registration.navigation_preload_state.enabled); |
| 1341 state->set_header(registration.navigation_preload_state.header); | 1343 state->set_header(registration.navigation_preload_state.header); |
| 1342 | 1344 |
| 1343 for (uint32_t feature : registration.used_features) | 1345 for (uint32_t feature : registration.used_features) |
| 1344 data.add_used_features(feature); | 1346 data.add_used_features(feature); |
| 1345 | 1347 |
| 1348 data.set_use_cache(registration.use_cache); |
| 1349 |
| 1346 std::string value; | 1350 std::string value; |
| 1347 bool success = data.SerializeToString(&value); | 1351 bool success = data.SerializeToString(&value); |
| 1348 DCHECK(success); | 1352 DCHECK(success); |
| 1349 GURL origin = registration.scope.GetOrigin(); | 1353 GURL origin = registration.scope.GetOrigin(); |
| 1350 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); | 1354 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); |
| 1351 } | 1355 } |
| 1352 | 1356 |
| 1353 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords( | 1357 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords( |
| 1354 const RegistrationData& registration, | 1358 const RegistrationData& registration, |
| 1355 std::vector<ResourceRecord>* resources) { | 1359 std::vector<ResourceRecord>* resources) { |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 if (status != STATUS_OK) | 1724 if (status != STATUS_OK) |
| 1721 Disable(from_here, status); | 1725 Disable(from_here, status); |
| 1722 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1726 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
| 1723 } | 1727 } |
| 1724 | 1728 |
| 1725 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { | 1729 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { |
| 1726 return path_.empty(); | 1730 return path_.empty(); |
| 1727 } | 1731 } |
| 1728 | 1732 |
| 1729 } // namespace content | 1733 } // namespace content |
| OLD | NEW |