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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 FROM_HERE, | 313 FROM_HERE, |
314 base::Bind( | 314 base::Bind( |
315 &FindForPatternInDB, | 315 &FindForPatternInDB, |
316 database_.get(), | 316 database_.get(), |
317 base::MessageLoopProxy::current(), | 317 base::MessageLoopProxy::current(), |
318 scope, | 318 scope, |
319 base::Bind(&ServiceWorkerStorage::DidFindRegistrationForPattern, | 319 base::Bind(&ServiceWorkerStorage::DidFindRegistrationForPattern, |
320 weak_factory_.GetWeakPtr(), scope, callback))); | 320 weak_factory_.GetWeakPtr(), scope, callback))); |
321 } | 321 } |
322 | 322 |
| 323 scoped_refptr<ServiceWorkerRegistration> |
| 324 ServiceWorkerStorage::GetUninstallingRegistration(const GURL& scope) { |
| 325 if (state_ != INITIALIZED || !context_) |
| 326 return NULL; |
| 327 for (RegistrationRefsById::const_iterator it = |
| 328 uninstalling_registrations_.begin(); |
| 329 it != uninstalling_registrations_.end(); |
| 330 ++it) { |
| 331 if (it->second->pattern() == scope) { |
| 332 DCHECK(it->second->is_uninstalling()); |
| 333 return it->second; |
| 334 } |
| 335 } |
| 336 return NULL; |
| 337 } |
| 338 |
323 void ServiceWorkerStorage::FindRegistrationForId( | 339 void ServiceWorkerStorage::FindRegistrationForId( |
324 int64 registration_id, | 340 int64 registration_id, |
325 const GURL& origin, | 341 const GURL& origin, |
326 const FindRegistrationCallback& callback) { | 342 const FindRegistrationCallback& callback) { |
327 if (!LazyInitialize(base::Bind( | 343 if (!LazyInitialize(base::Bind( |
328 &ServiceWorkerStorage::FindRegistrationForId, | 344 &ServiceWorkerStorage::FindRegistrationForId, |
329 weak_factory_.GetWeakPtr(), registration_id, origin, callback))) { | 345 weak_factory_.GetWeakPtr(), registration_id, origin, callback))) { |
330 if (state_ != INITIALIZING || !context_) { | 346 if (state_ != INITIALIZING || !context_) { |
331 CompleteFindNow(scoped_refptr<ServiceWorkerRegistration>(), | 347 CompleteFindNow(scoped_refptr<ServiceWorkerRegistration>(), |
332 SERVICE_WORKER_ERROR_FAILED, callback); | 348 SERVICE_WORKER_ERROR_FAILED, callback); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 return; | 420 return; |
405 } | 421 } |
406 | 422 |
407 ServiceWorkerDatabase::RegistrationData data; | 423 ServiceWorkerDatabase::RegistrationData data; |
408 data.registration_id = registration->id(); | 424 data.registration_id = registration->id(); |
409 data.scope = registration->pattern(); | 425 data.scope = registration->pattern(); |
410 data.script = registration->script_url(); | 426 data.script = registration->script_url(); |
411 data.has_fetch_handler = true; | 427 data.has_fetch_handler = true; |
412 data.version_id = version->version_id(); | 428 data.version_id = version->version_id(); |
413 data.last_update_check = base::Time::Now(); | 429 data.last_update_check = base::Time::Now(); |
414 data.is_active = false; // initially stored in the waiting state | 430 data.is_active = (version == registration->active_version()); |
415 | 431 |
416 ResourceList resources; | 432 ResourceList resources; |
417 version->script_cache_map()->GetResources(&resources); | 433 version->script_cache_map()->GetResources(&resources); |
418 | 434 |
419 if (!has_checked_for_stale_resources_) | 435 if (!has_checked_for_stale_resources_) |
420 DeleteStaleResources(); | 436 DeleteStaleResources(); |
421 | 437 |
422 database_task_runner_->PostTask( | 438 database_task_runner_->PostTask( |
423 FROM_HERE, | 439 FROM_HERE, |
424 base::Bind(&WriteRegistrationInDB, | 440 base::Bind(&WriteRegistrationInDB, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 | 601 |
586 database_task_runner_->PostTask( | 602 database_task_runner_->PostTask( |
587 FROM_HERE, | 603 FROM_HERE, |
588 base::Bind(base::IgnoreResult( | 604 base::Bind(base::IgnoreResult( |
589 &ServiceWorkerDatabase::PurgeUncommittedResourceIds), | 605 &ServiceWorkerDatabase::PurgeUncommittedResourceIds), |
590 base::Unretained(database_.get()), | 606 base::Unretained(database_.get()), |
591 ids)); | 607 ids)); |
592 } | 608 } |
593 } | 609 } |
594 | 610 |
| 611 void ServiceWorkerStorage::NotifyUninstallingRegistration( |
| 612 ServiceWorkerRegistration* registration) { |
| 613 uninstalling_registrations_[registration->id()] = registration; |
| 614 } |
| 615 |
| 616 void ServiceWorkerStorage::NotifyDoneUninstallingRegistration( |
| 617 ServiceWorkerRegistration* registration) { |
| 618 uninstalling_registrations_.erase(registration->id()); |
| 619 } |
| 620 |
595 void ServiceWorkerStorage::Disable() { | 621 void ServiceWorkerStorage::Disable() { |
596 state_ = DISABLED; | 622 state_ = DISABLED; |
597 if (disk_cache_) | 623 if (disk_cache_) |
598 disk_cache_->Disable(); | 624 disk_cache_->Disable(); |
599 } | 625 } |
600 | 626 |
601 bool ServiceWorkerStorage::IsDisabled() const { | 627 bool ServiceWorkerStorage::IsDisabled() const { |
602 return state_ == DISABLED; | 628 return state_ == DISABLED; |
603 } | 629 } |
604 | 630 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
751 const ServiceWorkerDatabase::RegistrationData& data, | 777 const ServiceWorkerDatabase::RegistrationData& data, |
752 const ResourceList& resources, | 778 const ResourceList& resources, |
753 ServiceWorkerDatabase::Status status) { | 779 ServiceWorkerDatabase::Status status) { |
754 if (status == ServiceWorkerDatabase::STATUS_OK) { | 780 if (status == ServiceWorkerDatabase::STATUS_OK) { |
755 callback.Run(SERVICE_WORKER_OK, | 781 callback.Run(SERVICE_WORKER_OK, |
756 GetOrCreateRegistration(data, resources)); | 782 GetOrCreateRegistration(data, resources)); |
757 return; | 783 return; |
758 } | 784 } |
759 | 785 |
760 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { | 786 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { |
761 // TODO(nhiroki): Find a registration in |installing_registrations_|. | 787 // TODO(nhiroki): Find a registration in |installing_registrations|. |
762 callback.Run(DatabaseStatusToStatusCode(status), | 788 callback.Run(DatabaseStatusToStatusCode(status), |
763 scoped_refptr<ServiceWorkerRegistration>()); | 789 scoped_refptr<ServiceWorkerRegistration>()); |
764 return; | 790 return; |
765 } | 791 } |
766 | 792 |
767 ScheduleDeleteAndStartOver(); | 793 ScheduleDeleteAndStartOver(); |
768 callback.Run(DatabaseStatusToStatusCode(status), | 794 callback.Run(DatabaseStatusToStatusCode(status), |
769 scoped_refptr<ServiceWorkerRegistration>()); | 795 scoped_refptr<ServiceWorkerRegistration>()); |
770 } | 796 } |
771 | 797 |
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1317 // Give up the corruption recovery until the browser restarts. | 1343 // Give up the corruption recovery until the browser restarts. |
1318 LOG(ERROR) << "Failed to delete the diskcache."; | 1344 LOG(ERROR) << "Failed to delete the diskcache."; |
1319 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1345 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
1320 return; | 1346 return; |
1321 } | 1347 } |
1322 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; | 1348 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; |
1323 callback.Run(SERVICE_WORKER_OK); | 1349 callback.Run(SERVICE_WORKER_OK); |
1324 } | 1350 } |
1325 | 1351 |
1326 } // namespace content | 1352 } // namespace content |
OLD | NEW |