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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
747 DCHECK_EQ(INITIALIZING, state_); | 747 DCHECK_EQ(INITIALIZING, state_); |
748 | 748 |
749 if (status == ServiceWorkerDatabase::STATUS_OK) { | 749 if (status == ServiceWorkerDatabase::STATUS_OK) { |
750 next_registration_id_ = data->next_registration_id; | 750 next_registration_id_ = data->next_registration_id; |
751 next_version_id_ = data->next_version_id; | 751 next_version_id_ = data->next_version_id; |
752 next_resource_id_ = data->next_resource_id; | 752 next_resource_id_ = data->next_resource_id; |
753 registered_origins_.swap(data->origins); | 753 registered_origins_.swap(data->origins); |
754 state_ = INITIALIZED; | 754 state_ = INITIALIZED; |
755 } else { | 755 } else { |
756 // TODO(nhiroki): Stringify |status| using StatusToString() defined in | 756 // TODO(nhiroki): Stringify |status| using StatusToString() defined in |
757 // service_worker_database.cc. | 757 // service_worker_database.cc. |
nhiroki
2014/10/16 04:21:07
Can you address this TODO?
shimazu
2014/10/16 09:01:53
Done.
| |
758 DVLOG(2) << "Failed to initialize: " << status; | 758 DVLOG(2) << "Failed to initialize: " << status; |
759 ScheduleDeleteAndStartOver(); | 759 ScheduleDeleteAndStartOver(); |
760 } | 760 } |
761 | 761 |
762 for (std::vector<base::Closure>::const_iterator it = pending_tasks_.begin(); | 762 for (std::vector<base::Closure>::const_iterator it = pending_tasks_.begin(); |
763 it != pending_tasks_.end(); ++it) { | 763 it != pending_tasks_.end(); ++it) { |
764 RunSoon(FROM_HERE, *it); | 764 RunSoon(FROM_HERE, *it); |
765 } | 765 } |
766 pending_tasks_.clear(); | 766 pending_tasks_.clear(); |
767 } | 767 } |
768 | 768 |
769 void ServiceWorkerStorage::DidFindRegistrationForDocument( | 769 void ServiceWorkerStorage::DidFindRegistrationForDocument( |
770 const GURL& document_url, | 770 const GURL& document_url, |
771 const FindRegistrationCallback& callback, | 771 const FindRegistrationCallback& callback, |
772 const ServiceWorkerDatabase::RegistrationData& data, | 772 const ServiceWorkerDatabase::RegistrationData& data, |
773 const ResourceList& resources, | 773 const ResourceList& resources, |
774 ServiceWorkerDatabase::Status status) { | 774 ServiceWorkerDatabase::Status status) { |
775 if (status == ServiceWorkerDatabase::STATUS_OK) { | 775 if (status == ServiceWorkerDatabase::STATUS_OK) { |
776 ReturnFoundRegistration(callback, data, resources); | 776 ReturnFoundRegistration(callback, data, resources); |
777 TRACE_EVENT_ASYNC_END1( | 777 TRACE_EVENT_ASYNC_END1( |
778 "ServiceWorker", | 778 "ServiceWorker", |
779 "ServiceWorkerStorage::FindRegistrationForDocument", | 779 "ServiceWorkerStorage::FindRegistrationForDocument", |
780 base::Hash(document_url.spec()), | 780 base::Hash(document_url.spec()), |
781 "Status", "OK"); | 781 "Status", ServiceWorkerDatabase::StatusToString(status)); |
782 return; | 782 return; |
783 } | 783 } |
784 | 784 |
785 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { | 785 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { |
786 // Look for something currently being installed. | 786 // Look for something currently being installed. |
787 scoped_refptr<ServiceWorkerRegistration> installing_registration = | 787 scoped_refptr<ServiceWorkerRegistration> installing_registration = |
788 FindInstallingRegistrationForDocument(document_url); | 788 FindInstallingRegistrationForDocument(document_url); |
789 callback.Run(installing_registration.get() ? SERVICE_WORKER_OK | 789 ServiceWorkerStatusCode installing_status = installing_registration.get() ? |
790 : SERVICE_WORKER_ERROR_NOT_FOUND, | 790 SERVICE_WORKER_OK : SERVICE_WORKER_ERROR_NOT_FOUND; |
791 installing_registration); | 791 callback.Run(installing_status, installing_registration); |
792 TRACE_EVENT_ASYNC_END1( | 792 TRACE_EVENT_ASYNC_END2( |
793 "ServiceWorker", | 793 "ServiceWorker", |
794 "ServiceWorkerStorage::FindRegistrationForDocument", | 794 "ServiceWorkerStorage::FindRegistrationForDocument", |
795 base::Hash(document_url.spec()), | 795 base::Hash(document_url.spec()), |
796 "Status", status); | 796 "Status", ServiceWorkerDatabase::StatusToString(status), |
797 "Found installing registration", | |
798 installing_status == SERVICE_WORKER_OK); | |
nhiroki
2014/10/16 04:21:07
It seems more natural that "Status" value correspo
shimazu
2014/10/16 09:01:53
This looks good! I fixed it.
nhiroki
2014/10/16 09:20:51
Oops... sorry, I meant |ServiceWorkerStatusToStrin
shimazu
2014/10/17 01:54:46
I think "Found/Not Found" is better than |ServiceW
nhiroki
2014/10/17 03:24:02
(This comment is based on patchset 4)
Hmm... I gu
| |
797 return; | 799 return; |
798 } | 800 } |
799 | 801 |
800 ScheduleDeleteAndStartOver(); | 802 ScheduleDeleteAndStartOver(); |
801 callback.Run(DatabaseStatusToStatusCode(status), | 803 callback.Run(DatabaseStatusToStatusCode(status), |
802 scoped_refptr<ServiceWorkerRegistration>()); | 804 scoped_refptr<ServiceWorkerRegistration>()); |
803 TRACE_EVENT_ASYNC_END1( | 805 TRACE_EVENT_ASYNC_END1( |
804 "ServiceWorker", | 806 "ServiceWorker", |
805 "ServiceWorkerStorage::FindRegistrationForDocument", | 807 "ServiceWorkerStorage::FindRegistrationForDocument", |
806 base::Hash(document_url.spec()), | 808 base::Hash(document_url.spec()), |
807 "Status", status); | 809 "Status", ServiceWorkerDatabase::StatusToString(status)); |
808 } | 810 } |
809 | 811 |
810 void ServiceWorkerStorage::DidFindRegistrationForPattern( | 812 void ServiceWorkerStorage::DidFindRegistrationForPattern( |
811 const GURL& scope, | 813 const GURL& scope, |
812 const FindRegistrationCallback& callback, | 814 const FindRegistrationCallback& callback, |
813 const ServiceWorkerDatabase::RegistrationData& data, | 815 const ServiceWorkerDatabase::RegistrationData& data, |
814 const ResourceList& resources, | 816 const ResourceList& resources, |
815 ServiceWorkerDatabase::Status status) { | 817 ServiceWorkerDatabase::Status status) { |
816 if (status == ServiceWorkerDatabase::STATUS_OK) { | 818 if (status == ServiceWorkerDatabase::STATUS_OK) { |
817 ReturnFoundRegistration(callback, data, resources); | 819 ReturnFoundRegistration(callback, data, resources); |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1420 // Give up the corruption recovery until the browser restarts. | 1422 // Give up the corruption recovery until the browser restarts. |
1421 LOG(ERROR) << "Failed to delete the diskcache."; | 1423 LOG(ERROR) << "Failed to delete the diskcache."; |
1422 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1424 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
1423 return; | 1425 return; |
1424 } | 1426 } |
1425 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; | 1427 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; |
1426 callback.Run(SERVICE_WORKER_OK); | 1428 callback.Run(SERVICE_WORKER_OK); |
1427 } | 1429 } |
1428 | 1430 |
1429 } // namespace content | 1431 } // namespace content |
OLD | NEW |