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

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

Issue 2771823002: Implement updateViaCache flag and no-cache by default for main service worker scripts
Patch Set: fix IPC Created 3 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_storage.h" 5 #include "content/browser/service_worker/service_worker_storage.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_ABORT)); 383 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_ABORT));
384 return; 384 return;
385 } 385 }
386 386
387 DCHECK_NE(version->fetch_handler_existence(), 387 DCHECK_NE(version->fetch_handler_existence(),
388 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN); 388 ServiceWorkerVersion::FetchHandlerExistence::UNKNOWN);
389 389
390 ServiceWorkerDatabase::RegistrationData data; 390 ServiceWorkerDatabase::RegistrationData data;
391 data.registration_id = registration->id(); 391 data.registration_id = registration->id();
392 data.scope = registration->pattern(); 392 data.scope = registration->pattern();
393 data.update_via_cache = registration->update_via_cache();
393 data.script = version->script_url(); 394 data.script = version->script_url();
394 data.has_fetch_handler = version->fetch_handler_existence() == 395 data.has_fetch_handler = version->fetch_handler_existence() ==
395 ServiceWorkerVersion::FetchHandlerExistence::EXISTS; 396 ServiceWorkerVersion::FetchHandlerExistence::EXISTS;
396 data.version_id = version->version_id(); 397 data.version_id = version->version_id();
397 data.last_update_check = registration->last_update_check(); 398 data.last_update_check = registration->last_update_check();
398 data.is_active = (version == registration->active_version()); 399 data.is_active = (version == registration->active_version());
399 data.foreign_fetch_scopes = version->foreign_fetch_scopes(); 400 data.foreign_fetch_scopes = version->foreign_fetch_scopes();
400 data.foreign_fetch_origins = version->foreign_fetch_origins(); 401 data.foreign_fetch_origins = version->foreign_fetch_origins();
401 if (version->origin_trial_tokens()) 402 if (version->origin_trial_tokens())
402 data.origin_trial_tokens = *version->origin_trial_tokens(); 403 data.origin_trial_tokens = *version->origin_trial_tokens();
(...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 1141
1141 ServiceWorkerRegistration* registration = 1142 ServiceWorkerRegistration* registration =
1142 context_->GetLiveRegistration(registration_data.registration_id); 1143 context_->GetLiveRegistration(registration_data.registration_id);
1143 if (registration) { 1144 if (registration) {
1144 infos.push_back(registration->GetInfo()); 1145 infos.push_back(registration->GetInfo());
1145 continue; 1146 continue;
1146 } 1147 }
1147 1148
1148 ServiceWorkerRegistrationInfo info; 1149 ServiceWorkerRegistrationInfo info;
1149 info.pattern = registration_data.scope; 1150 info.pattern = registration_data.scope;
1151 info.update_via_cache = registration_data.update_via_cache;
1150 info.registration_id = registration_data.registration_id; 1152 info.registration_id = registration_data.registration_id;
1151 info.stored_version_size_bytes = 1153 info.stored_version_size_bytes =
1152 registration_data.resources_total_size_bytes; 1154 registration_data.resources_total_size_bytes;
1153 if (ServiceWorkerVersion* version = 1155 if (ServiceWorkerVersion* version =
1154 context_->GetLiveVersion(registration_data.version_id)) { 1156 context_->GetLiveVersion(registration_data.version_id)) {
1155 if (registration_data.is_active) 1157 if (registration_data.is_active)
1156 info.active_version = version->GetInfo(); 1158 info.active_version = version->GetInfo();
1157 else 1159 else
1158 info.waiting_version = version->GetInfo(); 1160 info.waiting_version = version->GetInfo();
1159 infos.push_back(info); 1161 infos.push_back(info);
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1330 scoped_refptr<ServiceWorkerRegistration> 1332 scoped_refptr<ServiceWorkerRegistration>
1331 ServiceWorkerStorage::GetOrCreateRegistration( 1333 ServiceWorkerStorage::GetOrCreateRegistration(
1332 const ServiceWorkerDatabase::RegistrationData& data, 1334 const ServiceWorkerDatabase::RegistrationData& data,
1333 const ResourceList& resources) { 1335 const ResourceList& resources) {
1334 scoped_refptr<ServiceWorkerRegistration> registration = 1336 scoped_refptr<ServiceWorkerRegistration> registration =
1335 context_->GetLiveRegistration(data.registration_id); 1337 context_->GetLiveRegistration(data.registration_id);
1336 if (registration) 1338 if (registration)
1337 return registration; 1339 return registration;
1338 1340
1339 registration = new ServiceWorkerRegistration( 1341 registration = new ServiceWorkerRegistration(
1340 ServiceWorkerRegistrationOptions(data.scope), data.registration_id, 1342 ServiceWorkerRegistrationOptions(data.scope, data.update_via_cache),
1341 context_); 1343 data.registration_id, context_);
1342 registration->set_resources_total_size_bytes(data.resources_total_size_bytes); 1344 registration->set_resources_total_size_bytes(data.resources_total_size_bytes);
1343 registration->set_last_update_check(data.last_update_check); 1345 registration->set_last_update_check(data.last_update_check);
1344 if (pending_deletions_.find(data.registration_id) != 1346 if (pending_deletions_.find(data.registration_id) !=
1345 pending_deletions_.end()) { 1347 pending_deletions_.end()) {
1346 registration->set_is_deleted(true); 1348 registration->set_is_deleted(true);
1347 } 1349 }
1348 scoped_refptr<ServiceWorkerVersion> version = 1350 scoped_refptr<ServiceWorkerVersion> version =
1349 context_->GetLiveVersion(data.version_id); 1351 context_->GetLiveVersion(data.version_id);
1350 if (!version) { 1352 if (!version) {
1351 version = new ServiceWorkerVersion( 1353 version = new ServiceWorkerVersion(
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 callback.Run(SERVICE_WORKER_ERROR_FAILED); 1918 callback.Run(SERVICE_WORKER_ERROR_FAILED);
1917 return; 1919 return;
1918 } 1920 }
1919 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; 1921 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully.";
1920 ServiceWorkerMetrics::RecordDeleteAndStartOverResult( 1922 ServiceWorkerMetrics::RecordDeleteAndStartOverResult(
1921 ServiceWorkerMetrics::DELETE_OK); 1923 ServiceWorkerMetrics::DELETE_OK);
1922 callback.Run(SERVICE_WORKER_OK); 1924 callback.Run(SERVICE_WORKER_OK);
1923 } 1925 }
1924 1926
1925 } // namespace content 1927 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698