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

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

Issue 457903002: After 24 hours, bust the browser cache when checking for ServiceWorker updates (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
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 <string> 7 #include <string>
8 8
9 #include "base/bind_helpers.h" 9 #include "base/bind_helpers.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); 410 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED));
411 return; 411 return;
412 } 412 }
413 413
414 ServiceWorkerDatabase::RegistrationData data; 414 ServiceWorkerDatabase::RegistrationData data;
415 data.registration_id = registration->id(); 415 data.registration_id = registration->id();
416 data.scope = registration->pattern(); 416 data.scope = registration->pattern();
417 data.script = registration->script_url(); 417 data.script = registration->script_url();
418 data.has_fetch_handler = true; 418 data.has_fetch_handler = true;
419 data.version_id = version->version_id(); 419 data.version_id = version->version_id();
420 data.last_update_check = base::Time::Now(); 420 data.last_update_check = registration->last_update_check();
421 data.is_active = false; // initially stored in the waiting state 421 data.is_active = false; // initially stored in the waiting state
422 422
423 ResourceList resources; 423 ResourceList resources;
424 version->script_cache_map()->GetResources(&resources); 424 version->script_cache_map()->GetResources(&resources);
425 425
426 if (!has_checked_for_stale_resources_) 426 if (!has_checked_for_stale_resources_)
427 DeleteStaleResources(); 427 DeleteStaleResources();
428 428
429 database_task_runner_->PostTask( 429 database_task_runner_->PostTask(
430 FROM_HERE, 430 FROM_HERE,
(...skipping 22 matching lines...) Expand all
453 FROM_HERE, 453 FROM_HERE,
454 base::Bind(&ServiceWorkerDatabase::UpdateVersionToActive, 454 base::Bind(&ServiceWorkerDatabase::UpdateVersionToActive,
455 base::Unretained(database_.get()), 455 base::Unretained(database_.get()),
456 registration->id(), 456 registration->id(),
457 registration->script_url().GetOrigin()), 457 registration->script_url().GetOrigin()),
458 base::Bind(&ServiceWorkerStorage::DidUpdateToActiveState, 458 base::Bind(&ServiceWorkerStorage::DidUpdateToActiveState,
459 weak_factory_.GetWeakPtr(), 459 weak_factory_.GetWeakPtr(),
460 callback)); 460 callback));
461 } 461 }
462 462
463 void ServiceWorkerStorage::UpdateLastUpdateCheckTime(
464 ServiceWorkerRegistration* registration) {
465 DCHECK(registration);
466
467 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_;
468 if (IsDisabled() || !context_)
469 return;
470
471 database_task_runner_->PostTask(
472 FROM_HERE,
473 base::Bind(
474 base::IgnoreResult(&ServiceWorkerDatabase::UpdateLastCheckTime),
475 base::Unretained(database_.get()),
476 registration->id(),
477 registration->script_url().GetOrigin(),
478 registration->last_update_check()));
479 }
480
463 void ServiceWorkerStorage::DeleteRegistration( 481 void ServiceWorkerStorage::DeleteRegistration(
464 int64 registration_id, 482 int64 registration_id,
465 const GURL& origin, 483 const GURL& origin,
466 const StatusCallback& callback) { 484 const StatusCallback& callback) {
467 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; 485 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_;
468 if (IsDisabled() || !context_) { 486 if (IsDisabled() || !context_) {
469 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); 487 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED));
470 return; 488 return;
471 } 489 }
472 490
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 ServiceWorkerStorage::GetOrCreateRegistration( 933 ServiceWorkerStorage::GetOrCreateRegistration(
916 const ServiceWorkerDatabase::RegistrationData& data, 934 const ServiceWorkerDatabase::RegistrationData& data,
917 const ResourceList& resources) { 935 const ResourceList& resources) {
918 scoped_refptr<ServiceWorkerRegistration> registration = 936 scoped_refptr<ServiceWorkerRegistration> registration =
919 context_->GetLiveRegistration(data.registration_id); 937 context_->GetLiveRegistration(data.registration_id);
920 if (registration) 938 if (registration)
921 return registration; 939 return registration;
922 940
923 registration = new ServiceWorkerRegistration( 941 registration = new ServiceWorkerRegistration(
924 data.scope, data.script, data.registration_id, context_); 942 data.scope, data.script, data.registration_id, context_);
943 registration->set_last_update_check(data.last_update_check);
925 if (pending_deletions_.find(data.registration_id) != 944 if (pending_deletions_.find(data.registration_id) !=
926 pending_deletions_.end()) { 945 pending_deletions_.end()) {
927 registration->set_is_deleted(); 946 registration->set_is_deleted();
928 } 947 }
929 scoped_refptr<ServiceWorkerVersion> version = 948 scoped_refptr<ServiceWorkerVersion> version =
930 context_->GetLiveVersion(data.version_id); 949 context_->GetLiveVersion(data.version_id);
931 if (!version) { 950 if (!version) {
932 version = new ServiceWorkerVersion(registration, data.version_id, context_); 951 version = new ServiceWorkerVersion(registration, data.version_id, context_);
933 version->SetStatus(data.is_active ? 952 version->SetStatus(data.is_active ?
934 ServiceWorkerVersion::ACTIVATED : ServiceWorkerVersion::INSTALLED); 953 ServiceWorkerVersion::ACTIVATED : ServiceWorkerVersion::INSTALLED);
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 // Give up the corruption recovery until the browser restarts. 1365 // Give up the corruption recovery until the browser restarts.
1347 LOG(ERROR) << "Failed to delete the diskcache."; 1366 LOG(ERROR) << "Failed to delete the diskcache.";
1348 callback.Run(SERVICE_WORKER_ERROR_FAILED); 1367 callback.Run(SERVICE_WORKER_ERROR_FAILED);
1349 return; 1368 return;
1350 } 1369 }
1351 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; 1370 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully.";
1352 callback.Run(SERVICE_WORKER_OK); 1371 callback.Run(SERVICE_WORKER_OK);
1353 } 1372 }
1354 1373
1355 } // namespace content 1374 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698