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