Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(688)

Side by Side Diff: content/browser/service_worker/service_worker_database.cc

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: change useCache to updateViaCache Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 update_via_cache(blink::WebServiceWorkerUpdateViaCache::kImports),
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 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1396 const ServiceWorkerNavigationPreloadState& state = 1396 const ServiceWorkerNavigationPreloadState& state =
1397 data.navigation_preload_state(); 1397 data.navigation_preload_state();
1398 out->navigation_preload_state.enabled = state.enabled(); 1398 out->navigation_preload_state.enabled = state.enabled();
1399 if (state.has_header()) 1399 if (state.has_header())
1400 out->navigation_preload_state.header = state.header(); 1400 out->navigation_preload_state.header = state.header();
1401 } 1401 }
1402 1402
1403 for (uint32_t feature : data.used_features()) 1403 for (uint32_t feature : data.used_features())
1404 out->used_features.insert(feature); 1404 out->used_features.insert(feature);
1405 1405
1406 if (data.has_update_via_cache())
1407 out->update_via_cache = static_cast<blink::WebServiceWorkerUpdateViaCache>(
1408 data.update_via_cache());
1409
1406 return ServiceWorkerDatabase::STATUS_OK; 1410 return ServiceWorkerDatabase::STATUS_OK;
1407 } 1411 }
1408 1412
1409 void ServiceWorkerDatabase::WriteRegistrationDataInBatch( 1413 void ServiceWorkerDatabase::WriteRegistrationDataInBatch(
1410 const RegistrationData& registration, 1414 const RegistrationData& registration,
1411 leveldb::WriteBatch* batch) { 1415 leveldb::WriteBatch* batch) {
1412 DCHECK(batch); 1416 DCHECK(batch);
1413 1417
1414 // The registration id and version id should be bumped before this. 1418 // The registration id and version id should be bumped before this.
1415 DCHECK_GT(next_avail_registration_id_, registration.registration_id); 1419 DCHECK_GT(next_avail_registration_id_, registration.registration_id);
(...skipping 29 matching lines...) Expand all
1445 } 1449 }
1446 } 1450 }
1447 ServiceWorkerNavigationPreloadState* state = 1451 ServiceWorkerNavigationPreloadState* state =
1448 data.mutable_navigation_preload_state(); 1452 data.mutable_navigation_preload_state();
1449 state->set_enabled(registration.navigation_preload_state.enabled); 1453 state->set_enabled(registration.navigation_preload_state.enabled);
1450 state->set_header(registration.navigation_preload_state.header); 1454 state->set_header(registration.navigation_preload_state.header);
1451 1455
1452 for (uint32_t feature : registration.used_features) 1456 for (uint32_t feature : registration.used_features)
1453 data.add_used_features(feature); 1457 data.add_used_features(feature);
1454 1458
1459 data.set_update_via_cache(
1460 static_cast<uint32_t>(registration.update_via_cache));
1461
1455 std::string value; 1462 std::string value;
1456 bool success = data.SerializeToString(&value); 1463 bool success = data.SerializeToString(&value);
1457 DCHECK(success); 1464 DCHECK(success);
1458 GURL origin = registration.scope.GetOrigin(); 1465 GURL origin = registration.scope.GetOrigin();
1459 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value); 1466 batch->Put(CreateRegistrationKey(data.registration_id(), origin), value);
1460 } 1467 }
1461 1468
1462 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords( 1469 ServiceWorkerDatabase::Status ServiceWorkerDatabase::ReadResourceRecords(
1463 const RegistrationData& registration, 1470 const RegistrationData& registration,
1464 std::vector<ResourceRecord>* resources) { 1471 std::vector<ResourceRecord>* resources) {
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 if (status != STATUS_OK) 1836 if (status != STATUS_OK)
1830 Disable(from_here, status); 1837 Disable(from_here, status);
1831 ServiceWorkerMetrics::CountWriteDatabaseResult(status); 1838 ServiceWorkerMetrics::CountWriteDatabaseResult(status);
1832 } 1839 }
1833 1840
1834 bool ServiceWorkerDatabase::IsDatabaseInMemory() const { 1841 bool ServiceWorkerDatabase::IsDatabaseInMemory() const {
1835 return path_.empty(); 1842 return path_.empty();
1836 } 1843 }
1837 1844
1838 } // namespace content 1845 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698