| 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 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 = registration->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 = base::Time::Now(); | 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(); |
| 444 | 444 |
| 445 database_task_runner_->PostTask( | 445 database_task_runner_->PostTask( |
| 446 FROM_HERE, | 446 FROM_HERE, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 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->script_url().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( |
| 482 ServiceWorkerRegistration* registration) { |
| 483 DCHECK(registration); |
| 484 |
| 485 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; |
| 486 if (IsDisabled() || !context_) |
| 487 return; |
| 488 |
| 489 database_task_runner_->PostTask( |
| 490 FROM_HERE, |
| 491 base::Bind( |
| 492 base::IgnoreResult(&ServiceWorkerDatabase::UpdateLastCheckTime), |
| 493 base::Unretained(database_.get()), |
| 494 registration->id(), |
| 495 registration->script_url().GetOrigin(), |
| 496 registration->last_update_check())); |
| 497 } |
| 498 |
| 481 void ServiceWorkerStorage::DeleteRegistration( | 499 void ServiceWorkerStorage::DeleteRegistration( |
| 482 int64 registration_id, | 500 int64 registration_id, |
| 483 const GURL& origin, | 501 const GURL& origin, |
| 484 const StatusCallback& callback) { | 502 const StatusCallback& callback) { |
| 485 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; | 503 DCHECK(state_ == INITIALIZED || state_ == DISABLED) << state_; |
| 486 if (IsDisabled() || !context_) { | 504 if (IsDisabled() || !context_) { |
| 487 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); | 505 RunSoon(FROM_HERE, base::Bind(callback, SERVICE_WORKER_ERROR_FAILED)); |
| 488 return; | 506 return; |
| 489 } | 507 } |
| 490 | 508 |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 ServiceWorkerStorage::GetOrCreateRegistration( | 965 ServiceWorkerStorage::GetOrCreateRegistration( |
| 948 const ServiceWorkerDatabase::RegistrationData& data, | 966 const ServiceWorkerDatabase::RegistrationData& data, |
| 949 const ResourceList& resources) { | 967 const ResourceList& resources) { |
| 950 scoped_refptr<ServiceWorkerRegistration> registration = | 968 scoped_refptr<ServiceWorkerRegistration> registration = |
| 951 context_->GetLiveRegistration(data.registration_id); | 969 context_->GetLiveRegistration(data.registration_id); |
| 952 if (registration) | 970 if (registration) |
| 953 return registration; | 971 return registration; |
| 954 | 972 |
| 955 registration = new ServiceWorkerRegistration( | 973 registration = new ServiceWorkerRegistration( |
| 956 data.scope, data.script, data.registration_id, context_); | 974 data.scope, data.script, data.registration_id, context_); |
| 975 registration->set_last_update_check(data.last_update_check); |
| 957 if (pending_deletions_.find(data.registration_id) != | 976 if (pending_deletions_.find(data.registration_id) != |
| 958 pending_deletions_.end()) { | 977 pending_deletions_.end()) { |
| 959 registration->set_is_deleted(true); | 978 registration->set_is_deleted(true); |
| 960 } | 979 } |
| 961 scoped_refptr<ServiceWorkerVersion> version = | 980 scoped_refptr<ServiceWorkerVersion> version = |
| 962 context_->GetLiveVersion(data.version_id); | 981 context_->GetLiveVersion(data.version_id); |
| 963 if (!version) { | 982 if (!version) { |
| 964 version = new ServiceWorkerVersion(registration, data.version_id, context_); | 983 version = new ServiceWorkerVersion(registration, data.version_id, context_); |
| 965 version->SetStatus(data.is_active ? | 984 version->SetStatus(data.is_active ? |
| 966 ServiceWorkerVersion::ACTIVATED : ServiceWorkerVersion::INSTALLED); | 985 ServiceWorkerVersion::ACTIVATED : ServiceWorkerVersion::INSTALLED); |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1378 // Give up the corruption recovery until the browser restarts. | 1397 // Give up the corruption recovery until the browser restarts. |
| 1379 LOG(ERROR) << "Failed to delete the diskcache."; | 1398 LOG(ERROR) << "Failed to delete the diskcache."; |
| 1380 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1399 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
| 1381 return; | 1400 return; |
| 1382 } | 1401 } |
| 1383 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; | 1402 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; |
| 1384 callback.Run(SERVICE_WORKER_OK); | 1403 callback.Run(SERVICE_WORKER_OK); |
| 1385 } | 1404 } |
| 1386 | 1405 |
| 1387 } // namespace content | 1406 } // namespace content |
| OLD | NEW |