Chromium Code Reviews| 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/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 118 DCHECK(database); | 118 DCHECK(database); |
| 119 if (!database->DeleteRegistration(registration_id, origin)) { | 119 if (!database->DeleteRegistration(registration_id, origin)) { |
| 120 original_task_runner->PostTask( | 120 original_task_runner->PostTask( |
| 121 FROM_HERE, base::Bind(callback, false, SERVICE_WORKER_ERROR_FAILED)); | 121 FROM_HERE, base::Bind(callback, false, SERVICE_WORKER_ERROR_FAILED)); |
| 122 return; | 122 return; |
| 123 } | 123 } |
| 124 | 124 |
| 125 // TODO(nhiroki): Add convenient method to ServiceWorkerDatabase to check the | 125 // TODO(nhiroki): Add convenient method to ServiceWorkerDatabase to check the |
| 126 // unique origin list. | 126 // unique origin list. |
| 127 std::vector<ServiceWorkerDatabase::RegistrationData> registrations; | 127 std::vector<ServiceWorkerDatabase::RegistrationData> registrations; |
| 128 if (!database->GetRegistrationsForOrigin(origin, ®istrations)) { | 128 ServiceWorkerStatusCode status = |
| 129 database->GetRegistrationsForOrigin(origin, ®istrations); | |
| 130 if (status != SERVICE_WORKER_OK) { | |
| 129 original_task_runner->PostTask( | 131 original_task_runner->PostTask( |
| 130 FROM_HERE, base::Bind(callback, false, SERVICE_WORKER_ERROR_FAILED)); | 132 FROM_HERE, base::Bind(callback, false, status)); |
| 131 return; | 133 return; |
| 132 } | 134 } |
| 133 | 135 |
| 134 bool deletable = registrations.empty(); | 136 bool deletable = registrations.empty(); |
| 135 original_task_runner->PostTask( | 137 original_task_runner->PostTask( |
| 136 FROM_HERE, base::Bind(callback, deletable, SERVICE_WORKER_OK)); | 138 FROM_HERE, base::Bind(callback, deletable, SERVICE_WORKER_OK)); |
| 137 } | 139 } |
| 138 | 140 |
| 139 void UpdateToActiveStateInDB( | 141 void UpdateToActiveStateInDB( |
| 140 ServiceWorkerDatabase* database, | 142 ServiceWorkerDatabase* database, |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 521 it != pending_tasks_.end(); ++it) { | 523 it != pending_tasks_.end(); ++it) { |
| 522 RunSoon(FROM_HERE, *it); | 524 RunSoon(FROM_HERE, *it); |
| 523 } | 525 } |
| 524 pending_tasks_.clear(); | 526 pending_tasks_.clear(); |
| 525 } | 527 } |
| 526 | 528 |
| 527 void ServiceWorkerStorage::DidGetRegistrationsForPattern( | 529 void ServiceWorkerStorage::DidGetRegistrationsForPattern( |
| 528 const GURL& scope, | 530 const GURL& scope, |
| 529 const FindRegistrationCallback& callback, | 531 const FindRegistrationCallback& callback, |
| 530 RegistrationList* registrations, | 532 RegistrationList* registrations, |
| 531 bool success) { | 533 ServiceWorkerStatusCode status) { |
| 532 DCHECK(registrations); | 534 DCHECK(registrations); |
| 533 if (!success) { | 535 if (status != SERVICE_WORKER_OK) { |
| 536 // TODO(nhiroki): Handle database error (http://crbug.com/371675). | |
| 534 callback.Run(SERVICE_WORKER_ERROR_FAILED, | 537 callback.Run(SERVICE_WORKER_ERROR_FAILED, |
|
michaeln
2014/05/15 19:59:30
should |status| be passed in here?
nhiroki
2014/05/16 02:11:11
If we handle DB related errors like DB_CORRUPTED i
| |
| 535 scoped_refptr<ServiceWorkerRegistration>()); | 538 scoped_refptr<ServiceWorkerRegistration>()); |
| 536 return; | 539 return; |
| 537 } | 540 } |
| 538 | 541 |
| 539 // Find one with a matching scope. | 542 // Find one with a matching scope. |
| 540 for (RegistrationList::const_iterator it = registrations->begin(); | 543 for (RegistrationList::const_iterator it = registrations->begin(); |
| 541 it != registrations->end(); ++it) { | 544 it != registrations->end(); ++it) { |
| 542 if (scope == it->scope) { | 545 if (scope == it->scope) { |
| 543 scoped_refptr<ServiceWorkerRegistration> registration = | 546 scoped_refptr<ServiceWorkerRegistration> registration = |
| 544 context_->GetLiveRegistration(it->registration_id); | 547 context_->GetLiveRegistration(it->registration_id); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 558 } | 561 } |
| 559 | 562 |
| 560 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND, | 563 callback.Run(SERVICE_WORKER_ERROR_NOT_FOUND, |
| 561 scoped_refptr<ServiceWorkerRegistration>()); | 564 scoped_refptr<ServiceWorkerRegistration>()); |
| 562 } | 565 } |
| 563 | 566 |
| 564 void ServiceWorkerStorage::DidGetRegistrationsForDocument( | 567 void ServiceWorkerStorage::DidGetRegistrationsForDocument( |
| 565 const GURL& document_url, | 568 const GURL& document_url, |
| 566 const FindRegistrationCallback& callback, | 569 const FindRegistrationCallback& callback, |
| 567 RegistrationList* registrations, | 570 RegistrationList* registrations, |
| 568 bool success) { | 571 ServiceWorkerStatusCode status) { |
| 569 DCHECK(registrations); | 572 DCHECK(registrations); |
| 570 if (!success) { | 573 if (status != SERVICE_WORKER_OK) { |
| 574 // TODO(nhiroki): Handle database error (http://crbug.com/371675). | |
| 571 callback.Run(SERVICE_WORKER_ERROR_FAILED, | 575 callback.Run(SERVICE_WORKER_ERROR_FAILED, |
|
michaeln
2014/05/15 19:59:30
ditto |status|? dunno if it should just asking
| |
| 572 scoped_refptr<ServiceWorkerRegistration>()); | 576 scoped_refptr<ServiceWorkerRegistration>()); |
| 573 return; | 577 return; |
| 574 } | 578 } |
| 575 | 579 |
| 576 // Find one with a pattern match. | 580 // Find one with a pattern match. |
| 577 for (RegistrationList::const_iterator it = registrations->begin(); | 581 for (RegistrationList::const_iterator it = registrations->begin(); |
| 578 it != registrations->end(); ++it) { | 582 it != registrations->end(); ++it) { |
| 579 // TODO(michaeln): if there are multiple matches the one with | 583 // TODO(michaeln): if there are multiple matches the one with |
| 580 // the longest scope should win. | 584 // the longest scope should win. |
| 581 if (ServiceWorkerUtils::ScopeMatches(it->scope, document_url)) { | 585 if (ServiceWorkerUtils::ScopeMatches(it->scope, document_url)) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 return; | 631 return; |
| 628 } | 632 } |
| 629 | 633 |
| 630 callback.Run(status, scoped_refptr<ServiceWorkerRegistration>()); | 634 callback.Run(status, scoped_refptr<ServiceWorkerRegistration>()); |
| 631 return; | 635 return; |
| 632 } | 636 } |
| 633 | 637 |
| 634 void ServiceWorkerStorage::DidGetAllRegistrations( | 638 void ServiceWorkerStorage::DidGetAllRegistrations( |
| 635 const GetAllRegistrationInfosCallback& callback, | 639 const GetAllRegistrationInfosCallback& callback, |
| 636 RegistrationList* registrations, | 640 RegistrationList* registrations, |
| 637 bool success) { | 641 ServiceWorkerStatusCode status) { |
| 638 DCHECK(registrations); | 642 DCHECK(registrations); |
| 639 if (!success) { | 643 if (status != SERVICE_WORKER_OK) { |
| 644 // TODO(nhiroki): Handle database error (http://crbug.com/371675). | |
| 640 callback.Run(std::vector<ServiceWorkerRegistrationInfo>()); | 645 callback.Run(std::vector<ServiceWorkerRegistrationInfo>()); |
| 641 return; | 646 return; |
| 642 } | 647 } |
| 643 | 648 |
| 644 // Add all stored registrations. | 649 // Add all stored registrations. |
| 645 std::set<int64> pushed_registrations; | 650 std::set<int64> pushed_registrations; |
| 646 std::vector<ServiceWorkerRegistrationInfo> infos; | 651 std::vector<ServiceWorkerRegistrationInfo> infos; |
| 647 for (RegistrationList::const_iterator it = registrations->begin(); | 652 for (RegistrationList::const_iterator it = registrations->begin(); |
| 648 it != registrations->end(); ++it) { | 653 it != registrations->end(); ++it) { |
| 649 DCHECK(pushed_registrations.insert(it->registration_id).second); | 654 DCHECK(pushed_registrations.insert(it->registration_id).second); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 770 // TODO(michaeln): Store data on disk and do error checking. | 775 // TODO(michaeln): Store data on disk and do error checking. |
| 771 disk_cache_.reset(new ServiceWorkerDiskCache); | 776 disk_cache_.reset(new ServiceWorkerDiskCache); |
| 772 int rv = disk_cache_->InitWithMemBackend( | 777 int rv = disk_cache_->InitWithMemBackend( |
| 773 kMaxMemDiskCacheSize, | 778 kMaxMemDiskCacheSize, |
| 774 base::Bind(&EmptyCompletionCallback)); | 779 base::Bind(&EmptyCompletionCallback)); |
| 775 DCHECK_EQ(net::OK, rv); | 780 DCHECK_EQ(net::OK, rv); |
| 776 return disk_cache_.get(); | 781 return disk_cache_.get(); |
| 777 } | 782 } |
| 778 | 783 |
| 779 } // namespace content | 784 } // namespace content |
| OLD | NEW |