| 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 case ServiceWorkerDatabase::STATUS_ERROR_MAX: | 269 case ServiceWorkerDatabase::STATUS_ERROR_MAX: |
| 270 NOTREACHED(); | 270 NOTREACHED(); |
| 271 return "Database unknown error"; | 271 return "Database unknown error"; |
| 272 } | 272 } |
| 273 NOTREACHED(); | 273 NOTREACHED(); |
| 274 return "Database unknown error"; | 274 return "Database unknown error"; |
| 275 } | 275 } |
| 276 | 276 |
| 277 ServiceWorkerDatabase::RegistrationData::RegistrationData() | 277 ServiceWorkerDatabase::RegistrationData::RegistrationData() |
| 278 : registration_id(kInvalidServiceWorkerRegistrationId), | 278 : registration_id(kInvalidServiceWorkerRegistrationId), |
| 279 update_via_cache(blink::WebServiceWorkerUpdateViaCache::kImports), |
| 279 version_id(kInvalidServiceWorkerVersionId), | 280 version_id(kInvalidServiceWorkerVersionId), |
| 280 is_active(false), | 281 is_active(false), |
| 281 has_fetch_handler(false), | 282 has_fetch_handler(false), |
| 282 resources_total_size_bytes(0) { | 283 resources_total_size_bytes(0) {} |
| 283 } | |
| 284 | 284 |
| 285 ServiceWorkerDatabase::RegistrationData::RegistrationData( | 285 ServiceWorkerDatabase::RegistrationData::RegistrationData( |
| 286 const RegistrationData& other) = default; | 286 const RegistrationData& other) = default; |
| 287 | 287 |
| 288 ServiceWorkerDatabase::RegistrationData::~RegistrationData() { | 288 ServiceWorkerDatabase::RegistrationData::~RegistrationData() { |
| 289 } | 289 } |
| 290 | 290 |
| 291 ServiceWorkerDatabase::ServiceWorkerDatabase(const base::FilePath& path) | 291 ServiceWorkerDatabase::ServiceWorkerDatabase(const base::FilePath& path) |
| 292 : path_(path), | 292 : path_(path), |
| 293 next_avail_registration_id_(0), | 293 next_avail_registration_id_(0), |
| (...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1395 const ServiceWorkerNavigationPreloadState& state = | 1395 const ServiceWorkerNavigationPreloadState& state = |
| 1396 data.navigation_preload_state(); | 1396 data.navigation_preload_state(); |
| 1397 out->navigation_preload_state.enabled = state.enabled(); | 1397 out->navigation_preload_state.enabled = state.enabled(); |
| 1398 if (state.has_header()) | 1398 if (state.has_header()) |
| 1399 out->navigation_preload_state.header = state.header(); | 1399 out->navigation_preload_state.header = state.header(); |
| 1400 } | 1400 } |
| 1401 | 1401 |
| 1402 for (uint32_t feature : data.used_features()) | 1402 for (uint32_t feature : data.used_features()) |
| 1403 out->used_features.insert(feature); | 1403 out->used_features.insert(feature); |
| 1404 | 1404 |
| 1405 if (data.has_update_via_cache()) { |
| 1406 auto value = data.update_via_cache(); |
| 1407 if (ServiceWorkerRegistrationData_ServiceWorkerUpdateViaCacheType_IsValid( |
| 1408 value)) { |
| 1409 DLOG(ERROR) << "Update via cache mode '" << value << "' is not valid."; |
| 1410 return ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED; |
| 1411 } |
| 1412 out->update_via_cache = |
| 1413 static_cast<blink::WebServiceWorkerUpdateViaCache>(value); |
| 1414 } |
| 1415 |
| 1405 return ServiceWorkerDatabase::STATUS_OK; | 1416 return ServiceWorkerDatabase::STATUS_OK; |
| 1406 } | 1417 } |
| 1407 | 1418 |
| 1408 void ServiceWorkerDatabase::WriteRegistrationDataInBatch( | 1419 void ServiceWorkerDatabase::WriteRegistrationDataInBatch( |
| 1409 const RegistrationData& registration, | 1420 const RegistrationData& registration, |
| 1410 leveldb::WriteBatch* batch) { | 1421 leveldb::WriteBatch* batch) { |
| 1411 DCHECK(batch); | 1422 DCHECK(batch); |
| 1412 | 1423 |
| 1413 // The registration id and version id should be bumped before this. | 1424 // The registration id and version id should be bumped before this. |
| 1414 DCHECK_GT(next_avail_registration_id_, registration.registration_id); | 1425 DCHECK_GT(next_avail_registration_id_, registration.registration_id); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1444 } | 1455 } |
| 1445 } | 1456 } |
| 1446 ServiceWorkerNavigationPreloadState* state = | 1457 ServiceWorkerNavigationPreloadState* state = |
| 1447 data.mutable_navigation_preload_state(); | 1458 data.mutable_navigation_preload_state(); |
| 1448 state->set_enabled(registration.navigation_preload_state.enabled); | 1459 state->set_enabled(registration.navigation_preload_state.enabled); |
| 1449 state->set_header(registration.navigation_preload_state.header); | 1460 state->set_header(registration.navigation_preload_state.header); |
| 1450 | 1461 |
| 1451 for (uint32_t feature : registration.used_features) | 1462 for (uint32_t feature : registration.used_features) |
| 1452 data.add_used_features(feature); | 1463 data.add_used_features(feature); |
| 1453 | 1464 |
| 1465 data.set_update_via_cache( |
| 1466 static_cast< |
| 1467 ServiceWorkerRegistrationData_ServiceWorkerUpdateViaCacheType>( |
| 1468 registration.update_via_cache)); |
| 1469 |
| 1454 std::string value; | 1470 std::string value; |
| 1455 bool success = data.SerializeToString(&value); | 1471 bool success = data.SerializeToString(&value); |
| 1456 DCHECK(success); | 1472 DCHECK(success); |
| 1457 GURL origin = registration.scope.GetOrigin(); | 1473 GURL origin = registration.scope.GetOrigin(); |
| 1458 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); | 1474 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); |
| 1459 } | 1475 } |
| 1460 | 1476 |
| 1461 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords( | 1477 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords( |
| 1462 const RegistrationData& registration, | 1478 const RegistrationData& registration, |
| 1463 std::vector<ResourceRecord>* resources) { | 1479 std::vector<ResourceRecord>* resources) { |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1828 if (status != STATUS_OK) | 1844 if (status != STATUS_OK) |
| 1829 Disable(from_here, status); | 1845 Disable(from_here, status); |
| 1830 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1846 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
| 1831 } | 1847 } |
| 1832 | 1848 |
| 1833 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { | 1849 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { |
| 1834 return path_.empty(); | 1850 return path_.empty(); |
| 1835 } | 1851 } |
| 1836 | 1852 |
| 1837 } // namespace content | 1853 } // namespace content |
| OLD | NEW |