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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 FROM_HERE, | 322 FROM_HERE, |
323 base::Bind( | 323 base::Bind( |
324 &FindForPatternInDB, | 324 &FindForPatternInDB, |
325 database_.get(), | 325 database_.get(), |
326 base::MessageLoopProxy::current(), | 326 base::MessageLoopProxy::current(), |
327 scope, | 327 scope, |
328 base::Bind(&ServiceWorkerStorage::DidFindRegistrationForPattern, | 328 base::Bind(&ServiceWorkerStorage::DidFindRegistrationForPattern, |
329 weak_factory_.GetWeakPtr(), scope, callback))); | 329 weak_factory_.GetWeakPtr(), scope, callback))); |
330 } | 330 } |
331 | 331 |
| 332 scoped_refptr<ServiceWorkerRegistration> |
| 333 ServiceWorkerStorage::GetUninstallingRegistration(const GURL& scope) { |
| 334 if (state_ != INITIALIZED || !context_) |
| 335 return NULL; |
| 336 for (RegistrationRefsById::const_iterator it = |
| 337 uninstalling_registrations_.begin(); |
| 338 it != uninstalling_registrations_.end(); |
| 339 ++it) { |
| 340 if (it->second->pattern() == scope) { |
| 341 DCHECK(it->second->is_uninstalling()); |
| 342 return it->second; |
| 343 } |
| 344 } |
| 345 return NULL; |
| 346 } |
| 347 |
332 void ServiceWorkerStorage::FindRegistrationForId( | 348 void ServiceWorkerStorage::FindRegistrationForId( |
333 int64 registration_id, | 349 int64 registration_id, |
334 const GURL& origin, | 350 const GURL& origin, |
335 const FindRegistrationCallback& callback) { | 351 const FindRegistrationCallback& callback) { |
336 if (!LazyInitialize(base::Bind( | 352 if (!LazyInitialize(base::Bind( |
337 &ServiceWorkerStorage::FindRegistrationForId, | 353 &ServiceWorkerStorage::FindRegistrationForId, |
338 weak_factory_.GetWeakPtr(), registration_id, origin, callback))) { | 354 weak_factory_.GetWeakPtr(), registration_id, origin, callback))) { |
339 if (state_ != INITIALIZING || !context_) { | 355 if (state_ != INITIALIZING || !context_) { |
340 CompleteFindNow(scoped_refptr<ServiceWorkerRegistration>(), | 356 CompleteFindNow(scoped_refptr<ServiceWorkerRegistration>(), |
341 SERVICE_WORKER_ERROR_FAILED, callback); | 357 SERVICE_WORKER_ERROR_FAILED, callback); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 return; | 429 return; |
414 } | 430 } |
415 | 431 |
416 ServiceWorkerDatabase::RegistrationData data; | 432 ServiceWorkerDatabase::RegistrationData data; |
417 data.registration_id = registration->id(); | 433 data.registration_id = registration->id(); |
418 data.scope = registration->pattern(); | 434 data.scope = registration->pattern(); |
419 data.script = registration->script_url(); | 435 data.script = registration->script_url(); |
420 data.has_fetch_handler = true; | 436 data.has_fetch_handler = true; |
421 data.version_id = version->version_id(); | 437 data.version_id = version->version_id(); |
422 data.last_update_check = base::Time::Now(); | 438 data.last_update_check = base::Time::Now(); |
423 data.is_active = false; // initially stored in the waiting state | 439 data.is_active = (version == registration->active_version()); |
424 | 440 |
425 ResourceList resources; | 441 ResourceList resources; |
426 version->script_cache_map()->GetResources(&resources); | 442 version->script_cache_map()->GetResources(&resources); |
427 | 443 |
428 if (!has_checked_for_stale_resources_) | 444 if (!has_checked_for_stale_resources_) |
429 DeleteStaleResources(); | 445 DeleteStaleResources(); |
430 | 446 |
431 database_task_runner_->PostTask( | 447 database_task_runner_->PostTask( |
432 FROM_HERE, | 448 FROM_HERE, |
433 base::Bind(&WriteRegistrationInDB, | 449 base::Bind(&WriteRegistrationInDB, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 | 617 |
602 database_task_runner_->PostTask( | 618 database_task_runner_->PostTask( |
603 FROM_HERE, | 619 FROM_HERE, |
604 base::Bind(base::IgnoreResult( | 620 base::Bind(base::IgnoreResult( |
605 &ServiceWorkerDatabase::PurgeUncommittedResourceIds), | 621 &ServiceWorkerDatabase::PurgeUncommittedResourceIds), |
606 base::Unretained(database_.get()), | 622 base::Unretained(database_.get()), |
607 ids)); | 623 ids)); |
608 } | 624 } |
609 } | 625 } |
610 | 626 |
| 627 void ServiceWorkerStorage::NotifyUninstallingRegistration( |
| 628 ServiceWorkerRegistration* registration) { |
| 629 uninstalling_registrations_[registration->id()] = registration; |
| 630 } |
| 631 |
| 632 void ServiceWorkerStorage::NotifyDoneUninstallingRegistration( |
| 633 ServiceWorkerRegistration* registration) { |
| 634 uninstalling_registrations_.erase(registration->id()); |
| 635 } |
| 636 |
611 void ServiceWorkerStorage::Disable() { | 637 void ServiceWorkerStorage::Disable() { |
612 state_ = DISABLED; | 638 state_ = DISABLED; |
613 if (disk_cache_) | 639 if (disk_cache_) |
614 disk_cache_->Disable(); | 640 disk_cache_->Disable(); |
615 } | 641 } |
616 | 642 |
617 bool ServiceWorkerStorage::IsDisabled() const { | 643 bool ServiceWorkerStorage::IsDisabled() const { |
618 return state_ == DISABLED; | 644 return state_ == DISABLED; |
619 } | 645 } |
620 | 646 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 const FindRegistrationCallback& callback, | 792 const FindRegistrationCallback& callback, |
767 const ServiceWorkerDatabase::RegistrationData& data, | 793 const ServiceWorkerDatabase::RegistrationData& data, |
768 const ResourceList& resources, | 794 const ResourceList& resources, |
769 ServiceWorkerDatabase::Status status) { | 795 ServiceWorkerDatabase::Status status) { |
770 if (status == ServiceWorkerDatabase::STATUS_OK) { | 796 if (status == ServiceWorkerDatabase::STATUS_OK) { |
771 ReturnFoundRegistration(callback, data, resources); | 797 ReturnFoundRegistration(callback, data, resources); |
772 return; | 798 return; |
773 } | 799 } |
774 | 800 |
775 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { | 801 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { |
776 // TODO(nhiroki): Find a registration in |installing_registrations_|. | 802 // TODO(nhiroki): Find a registration in |installing_registrations|. |
777 callback.Run(DatabaseStatusToStatusCode(status), | 803 callback.Run(DatabaseStatusToStatusCode(status), |
778 scoped_refptr<ServiceWorkerRegistration>()); | 804 scoped_refptr<ServiceWorkerRegistration>()); |
779 return; | 805 return; |
780 } | 806 } |
781 | 807 |
782 ScheduleDeleteAndStartOver(); | 808 ScheduleDeleteAndStartOver(); |
783 callback.Run(DatabaseStatusToStatusCode(status), | 809 callback.Run(DatabaseStatusToStatusCode(status), |
784 scoped_refptr<ServiceWorkerRegistration>()); | 810 scoped_refptr<ServiceWorkerRegistration>()); |
785 } | 811 } |
786 | 812 |
(...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1346 // Give up the corruption recovery until the browser restarts. | 1372 // Give up the corruption recovery until the browser restarts. |
1347 LOG(ERROR) << "Failed to delete the diskcache."; | 1373 LOG(ERROR) << "Failed to delete the diskcache."; |
1348 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1374 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
1349 return; | 1375 return; |
1350 } | 1376 } |
1351 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; | 1377 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; |
1352 callback.Run(SERVICE_WORKER_OK); | 1378 callback.Run(SERVICE_WORKER_OK); |
1353 } | 1379 } |
1354 | 1380 |
1355 } // namespace content | 1381 } // namespace content |
OLD | NEW |