OLD | NEW |
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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
420 | 420 |
421 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; | 421 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; |
422 if (IsDisabled() || !context_) { | 422 if (IsDisabled() || !context_) { |
423 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); | 423 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); |
424 return; | 424 return; |
425 } | 425 } |
426 | 426 |
427 ServiceWorkerDatabase::RegistrationData data; | 427 ServiceWorkerDatabase::RegistrationData data; |
428 data.registration_id = registration->id(); | 428 data.registration_id = registration->id(); |
429 data.scope = registration->pattern(); | 429 data.scope = registration->pattern(); |
430 data.script = registration->script_url(); | 430 data.script = version->script_url(); |
431 data.has_fetch_handler = true; | 431 data.has_fetch_handler = true; |
432 data.version_id = version->version_id(); | 432 data.version_id = version->version_id(); |
433 data.last_update_check = registration->last_update_check(); | 433 data.last_update_check = registration->last_update_check(); |
434 data.is_active = (version == registration->active_version()); | 434 data.is_active = (version == registration->active_version()); |
435 | 435 |
436 ResourceList resources; | 436 ResourceList resources; |
437 version->script_cache_map()->GetResources(&resources); | 437 version->script_cache_map()->GetResources(&resources); |
438 | 438 |
439 if (!has_checked_for_stale_resources_) | 439 if (!has_checked_for_stale_resources_) |
440 DeleteStaleResources(); | 440 DeleteStaleResources(); |
(...skipping 21 matching lines...) Expand all Loading... |
462 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); | 462 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); |
463 return; | 463 return; |
464 } | 464 } |
465 | 465 |
466 PostTaskAndReplyWithResult( | 466 PostTaskAndReplyWithResult( |
467 database_task_runner_.get(), | 467 database_task_runner_.get(), |
468 FROM_HERE, | 468 FROM_HERE, |
469 base::Bind(&ServiceWorkerDatabase::UpdateVersionToActive, | 469 base::Bind(&ServiceWorkerDatabase::UpdateVersionToActive, |
470 base::Unretained(database_.get()), | 470 base::Unretained(database_.get()), |
471 registration->id(), | 471 registration->id(), |
472 registration->script_url().GetOrigin()), | 472 registration->pattern().GetOrigin()), |
473 base::Bind(&ServiceWorkerStorage::DidUpdateToActiveState, | 473 base::Bind(&ServiceWorkerStorage::DidUpdateToActiveState, |
474 weak_factory_.GetWeakPtr(), | 474 weak_factory_.GetWeakPtr(), |
475 callback)); | 475 callback)); |
476 } | 476 } |
477 | 477 |
478 void ServiceWorkerStorage::UpdateLastUpdateCheckTime( | 478 void ServiceWorkerStorage::UpdateLastUpdateCheckTime( |
479 ServiceWorkerRegistration* registration) { | 479 ServiceWorkerRegistration* registration) { |
480 DCHECK(registration); | 480 DCHECK(registration); |
481 | 481 |
482 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; | 482 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; |
483 if (IsDisabled() || !context_) | 483 if (IsDisabled() || !context_) |
484 return; | 484 return; |
485 | 485 |
486 database_task_runner_->PostTask( | 486 database_task_runner_->PostTask( |
487 FROM_HERE, | 487 FROM_HERE, |
488 base::Bind( | 488 base::Bind( |
489 base::IgnoreResult(&ServiceWorkerDatabase::UpdateLastCheckTime), | 489 base::IgnoreResult(&ServiceWorkerDatabase::UpdateLastCheckTime), |
490 base::Unretained(database_.get()), | 490 base::Unretained(database_.get()), |
491 registration->id(), | 491 registration->id(), |
492 registration->script_url().GetOrigin(), | 492 registration->pattern().GetOrigin(), |
493 registration->last_update_check())); | 493 registration->last_update_check())); |
494 } | 494 } |
495 | 495 |
496 void ServiceWorkerStorage::DeleteRegistration( | 496 void ServiceWorkerStorage::DeleteRegistration( |
497 int64 registration_id, | 497 int64 registration_id, |
498 const GURL& origin, | 498 const GURL& origin, |
499 const StatusCallback& callback) { | 499 const StatusCallback& callback) { |
500 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; | 500 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; |
501 if (IsDisabled() || !context_) { | 501 if (IsDisabled() || !context_) { |
502 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); | 502 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 | 869 |
870 ServiceWorkerRegistration* registration = | 870 ServiceWorkerRegistration* registration = |
871 context_->GetLiveRegistration(it->registration_id); | 871 context_->GetLiveRegistration(it->registration_id); |
872 if (registration) { | 872 if (registration) { |
873 infos.push_back(registration->GetInfo()); | 873 infos.push_back(registration->GetInfo()); |
874 continue; | 874 continue; |
875 } | 875 } |
876 | 876 |
877 ServiceWorkerRegistrationInfo info; | 877 ServiceWorkerRegistrationInfo info; |
878 info.pattern = it->scope; | 878 info.pattern = it->scope; |
879 info.script_url = it->script; | |
880 info.registration_id = it->registration_id; | 879 info.registration_id = it->registration_id; |
881 if (ServiceWorkerVersion* version = | 880 if (ServiceWorkerVersion* version = |
882 context_->GetLiveVersion(it->version_id)) { | 881 context_->GetLiveVersion(it->version_id)) { |
883 if (it->is_active) | 882 if (it->is_active) |
884 info.active_version = version->GetInfo(); | 883 info.active_version = version->GetInfo(); |
885 else | 884 else |
886 info.waiting_version = version->GetInfo(); | 885 info.waiting_version = version->GetInfo(); |
887 infos.push_back(info); | 886 infos.push_back(info); |
888 continue; | 887 continue; |
889 } | 888 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
962 scoped_refptr<ServiceWorkerRegistration> | 961 scoped_refptr<ServiceWorkerRegistration> |
963 ServiceWorkerStorage::GetOrCreateRegistration( | 962 ServiceWorkerStorage::GetOrCreateRegistration( |
964 const ServiceWorkerDatabase::RegistrationData& data, | 963 const ServiceWorkerDatabase::RegistrationData& data, |
965 const ResourceList& resources) { | 964 const ResourceList& resources) { |
966 scoped_refptr<ServiceWorkerRegistration> registration = | 965 scoped_refptr<ServiceWorkerRegistration> registration = |
967 context_->GetLiveRegistration(data.registration_id); | 966 context_->GetLiveRegistration(data.registration_id); |
968 if (registration.get()) | 967 if (registration.get()) |
969 return registration; | 968 return registration; |
970 | 969 |
971 registration = new ServiceWorkerRegistration( | 970 registration = new ServiceWorkerRegistration( |
972 data.scope, data.script, data.registration_id, context_); | 971 data.scope, data.registration_id, context_); |
973 registration->set_last_update_check(data.last_update_check); | 972 registration->set_last_update_check(data.last_update_check); |
974 if (pending_deletions_.find(data.registration_id) != | 973 if (pending_deletions_.find(data.registration_id) != |
975 pending_deletions_.end()) { | 974 pending_deletions_.end()) { |
976 registration->set_is_deleted(true); | 975 registration->set_is_deleted(true); |
977 } | 976 } |
978 scoped_refptr<ServiceWorkerVersion> version = | 977 scoped_refptr<ServiceWorkerVersion> version = |
979 context_->GetLiveVersion(data.version_id); | 978 context_->GetLiveVersion(data.version_id); |
980 if (!version.get()) { | 979 if (!version.get()) { |
981 version = | 980 version = new ServiceWorkerVersion( |
982 new ServiceWorkerVersion(registration.get(), data.version_id, context_); | 981 registration.get(), data.script, data.version_id, context_); |
983 version->SetStatus(data.is_active ? | 982 version->SetStatus(data.is_active ? |
984 ServiceWorkerVersion::ACTIVATED : ServiceWorkerVersion::INSTALLED); | 983 ServiceWorkerVersion::ACTIVATED : ServiceWorkerVersion::INSTALLED); |
985 version->script_cache_map()->SetResources(resources); | 984 version->script_cache_map()->SetResources(resources); |
986 } | 985 } |
987 | 986 |
988 if (version->status() == ServiceWorkerVersion::ACTIVATED) | 987 if (version->status() == ServiceWorkerVersion::ACTIVATED) |
989 registration->SetActiveVersion(version.get()); | 988 registration->SetActiveVersion(version.get()); |
990 else if (version->status() == ServiceWorkerVersion::INSTALLED) | 989 else if (version->status() == ServiceWorkerVersion::INSTALLED) |
991 registration->SetWaitingVersion(version.get()); | 990 registration->SetWaitingVersion(version.get()); |
992 else | 991 else |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1399 // Give up the corruption recovery until the browser restarts. | 1398 // Give up the corruption recovery until the browser restarts. |
1400 LOG(ERROR) << "Failed to delete the diskcache."; | 1399 LOG(ERROR) << "Failed to delete the diskcache."; |
1401 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1400 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
1402 return; | 1401 return; |
1403 } | 1402 } |
1404 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; | 1403 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; |
1405 callback.Run(SERVICE_WORKER_OK); | 1404 callback.Run(SERVICE_WORKER_OK); |
1406 } | 1405 } |
1407 | 1406 |
1408 } // namespace content | 1407 } // namespace content |
OLD | NEW |