| 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 1273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 out->origin_trial_tokens = origin_trial_tokens; | 1284 out->origin_trial_tokens = origin_trial_tokens; |
| 1285 } | 1285 } |
| 1286 if (data.has_navigation_preload_state()) { | 1286 if (data.has_navigation_preload_state()) { |
| 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()) |
| 1295 out->used_features.insert(feature); |
| 1296 |
| 1294 return ServiceWorkerDatabase::STATUS_OK; | 1297 return ServiceWorkerDatabase::STATUS_OK; |
| 1295 } | 1298 } |
| 1296 | 1299 |
| 1297 void ServiceWorkerDatabase::WriteRegistrationDataInBatch( | 1300 void ServiceWorkerDatabase::WriteRegistrationDataInBatch( |
| 1298 const RegistrationData& registration, | 1301 const RegistrationData& registration, |
| 1299 leveldb::WriteBatch* batch) { | 1302 leveldb::WriteBatch* batch) { |
| 1300 DCHECK(batch); | 1303 DCHECK(batch); |
| 1301 | 1304 |
| 1302 // The registration id and version id should be bumped before this. | 1305 // The registration id and version id should be bumped before this. |
| 1303 DCHECK_GT(next_avail_registration_id_, registration.registration_id); | 1306 DCHECK_GT(next_avail_registration_id_, registration.registration_id); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1330 feature_out->set_name(feature.first); | 1333 feature_out->set_name(feature.first); |
| 1331 for (const auto& token : feature.second) | 1334 for (const auto& token : feature.second) |
| 1332 feature_out->add_tokens(token); | 1335 feature_out->add_tokens(token); |
| 1333 } | 1336 } |
| 1334 } | 1337 } |
| 1335 ServiceWorkerNavigationPreloadState* state = | 1338 ServiceWorkerNavigationPreloadState* state = |
| 1336 data.mutable_navigation_preload_state(); | 1339 data.mutable_navigation_preload_state(); |
| 1337 state->set_enabled(registration.navigation_preload_state.enabled); | 1340 state->set_enabled(registration.navigation_preload_state.enabled); |
| 1338 state->set_header(registration.navigation_preload_state.header); | 1341 state->set_header(registration.navigation_preload_state.header); |
| 1339 | 1342 |
| 1343 for (uint32_t feature : registration.used_features) |
| 1344 data.add_used_features(feature); |
| 1345 |
| 1340 std::string value; | 1346 std::string value; |
| 1341 bool success = data.SerializeToString(&value); | 1347 bool success = data.SerializeToString(&value); |
| 1342 DCHECK(success); | 1348 DCHECK(success); |
| 1343 GURL origin = registration.scope.GetOrigin(); | 1349 GURL origin = registration.scope.GetOrigin(); |
| 1344 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); | 1350 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); |
| 1345 } | 1351 } |
| 1346 | 1352 |
| 1347 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords( | 1353 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords( |
| 1348 const RegistrationData& registration, | 1354 const RegistrationData& registration, |
| 1349 std::vector<ResourceRecord>* resources) { | 1355 std::vector<ResourceRecord>* resources) { |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1714 if (status != STATUS_OK) | 1720 if (status != STATUS_OK) |
| 1715 Disable(from_here, status); | 1721 Disable(from_here, status); |
| 1716 ServiceWorkerMetrics::CountWriteDatabaseResult(status); | 1722 ServiceWorkerMetrics::CountWriteDatabaseResult(status); |
| 1717 } | 1723 } |
| 1718 | 1724 |
| 1719 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { | 1725 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { |
| 1720 return path_.empty(); | 1726 return path_.empty(); |
| 1721 } | 1727 } |
| 1722 | 1728 |
| 1723 } // namespace content | 1729 } // namespace content |
| OLD | NEW |