| 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 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1392 const ServiceWorkerNavigationPreloadState& state = | 1392 const ServiceWorkerNavigationPreloadState& state = |
| 1393 data.navigation_preload_state(); | 1393 data.navigation_preload_state(); |
| 1394 out->navigation_preload_state.enabled = state.enabled(); | 1394 out->navigation_preload_state.enabled = state.enabled(); |
| 1395 if (state.has_header()) | 1395 if (state.has_header()) |
| 1396 out->navigation_preload_state.header = state.header(); | 1396 out->navigation_preload_state.header = state.header(); |
| 1397 } | 1397 } |
| 1398 | 1398 |
| 1399 for (uint32_t feature : data.used_features()) | 1399 for (uint32_t feature : data.used_features()) |
| 1400 out->used_features.insert(feature); | 1400 out->used_features.insert(feature); |
| 1401 | 1401 |
| 1402 if (data.has_update_via_cache()) { |
| 1403 auto value = data.update_via_cache(); |
| 1404 if (!ServiceWorkerRegistrationData_ServiceWorkerUpdateViaCacheType_IsValid( |
| 1405 value)) { |
| 1406 DLOG(ERROR) << "Update via cache mode '" << value << "' is not valid."; |
| 1407 return ServiceWorkerDatabase::STATUS_ERROR_CORRUPTED; |
| 1408 } |
| 1409 out->update_via_cache = |
| 1410 static_cast<blink::WebServiceWorkerUpdateViaCache>(value); |
| 1411 } |
| 1412 |
| 1402 return ServiceWorkerDatabase::STATUS_OK; | 1413 return ServiceWorkerDatabase::STATUS_OK; |
| 1403 } | 1414 } |
| 1404 | 1415 |
| 1405 void ServiceWorkerDatabase::WriteRegistrationDataInBatch( | 1416 void ServiceWorkerDatabase::WriteRegistrationDataInBatch( |
| 1406 const RegistrationData& registration, | 1417 const RegistrationData& registration, |
| 1407 leveldb::WriteBatch* batch) { | 1418 leveldb::WriteBatch* batch) { |
| 1408 DCHECK(batch); | 1419 DCHECK(batch); |
| 1409 | 1420 |
| 1410 // The registration id and version id should be bumped before this. | 1421 // The registration id and version id should be bumped before this. |
| 1411 DCHECK_GT(next_avail_registration_id_, registration.registration_id); | 1422 DCHECK_GT(next_avail_registration_id_, registration.registration_id); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1441 } | 1452 } |
| 1442 } | 1453 } |
| 1443 ServiceWorkerNavigationPreloadState* state = | 1454 ServiceWorkerNavigationPreloadState* state = |
| 1444 data.mutable_navigation_preload_state(); | 1455 data.mutable_navigation_preload_state(); |
| 1445 state->set_enabled(registration.navigation_preload_state.enabled); | 1456 state->set_enabled(registration.navigation_preload_state.enabled); |
| 1446 state->set_header(registration.navigation_preload_state.header); | 1457 state->set_header(registration.navigation_preload_state.header); |
| 1447 | 1458 |
| 1448 for (uint32_t feature : registration.used_features) | 1459 for (uint32_t feature : registration.used_features) |
| 1449 data.add_used_features(feature); | 1460 data.add_used_features(feature); |
| 1450 | 1461 |
| 1462 data.set_update_via_cache( |
| 1463 static_cast< |
| 1464 ServiceWorkerRegistrationData_ServiceWorkerUpdateViaCacheType>( |
| 1465 registration.update_via_cache)); |
| 1466 |
| 1451 std::string value; | 1467 std::string value; |
| 1452 bool success = data.SerializeToString(&value); | 1468 bool success = data.SerializeToString(&value); |
| 1453 DCHECK(success); | 1469 DCHECK(success); |
| 1454 GURL origin = registration.scope.GetOrigin(); | 1470 GURL origin = registration.scope.GetOrigin(); |
| 1455 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); | 1471 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); |
| 1456 } | 1472 } |
| 1457 | 1473 |
| 1458 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords( | 1474 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords( |
| 1459 const RegistrationData& registration, | 1475 const RegistrationData& registration, |
| 1460 std::vector<ResourceRecord>* resources) { | 1476 std::vector<ResourceRecord>* resources) { |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1825 if (status != STATUS_OK) | 1841 if (status != STATUS_OK) |
| 1826 Disable(from_here, status); | 1842 Disable(from_here, status); |
| 1827 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1843 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
| 1828 } | 1844 } |
| 1829 | 1845 |
| 1830 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { | 1846 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { |
| 1831 return path_.empty(); | 1847 return path_.empty(); |
| 1832 } | 1848 } |
| 1833 | 1849 |
| 1834 } // namespace content | 1850 } // namespace content |
| OLD | NEW |