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/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/hash.h" | |
11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
12 #include "base/sequenced_task_runner.h" | 14 #include "base/sequenced_task_runner.h" |
13 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
14 #include "base/task_runner_util.h" | 16 #include "base/task_runner_util.h" |
15 #include "content/browser/service_worker/service_worker_context_core.h" | 17 #include "content/browser/service_worker/service_worker_context_core.h" |
16 #include "content/browser/service_worker/service_worker_disk_cache.h" | 18 #include "content/browser/service_worker/service_worker_disk_cache.h" |
17 #include "content/browser/service_worker/service_worker_info.h" | 19 #include "content/browser/service_worker/service_worker_info.h" |
18 #include "content/browser/service_worker/service_worker_metrics.h" | 20 #include "content/browser/service_worker/service_worker_metrics.h" |
19 #include "content/browser/service_worker/service_worker_registration.h" | 21 #include "content/browser/service_worker/service_worker_registration.h" |
20 #include "content/browser/service_worker/service_worker_utils.h" | 22 #include "content/browser/service_worker/service_worker_utils.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
243 context, | 245 context, |
244 old_storage->database_task_runner_, | 246 old_storage->database_task_runner_, |
245 old_storage->disk_cache_thread_, | 247 old_storage->disk_cache_thread_, |
246 old_storage->quota_manager_proxy_.get())); | 248 old_storage->quota_manager_proxy_.get())); |
247 } | 249 } |
248 | 250 |
249 void ServiceWorkerStorage::FindRegistrationForDocument( | 251 void ServiceWorkerStorage::FindRegistrationForDocument( |
250 const GURL& document_url, | 252 const GURL& document_url, |
251 const FindRegistrationCallback& callback) { | 253 const FindRegistrationCallback& callback) { |
252 DCHECK(!document_url.has_ref()); | 254 DCHECK(!document_url.has_ref()); |
255 TRACE_EVENT_ASYNC_BEGIN1( | |
256 "ServiceWorker", | |
257 "ServiceWorkerStorage::FindRegistrationForDocument", | |
258 base::Hash(document_url.spec()), | |
horo
2014/09/05 11:02:32
I think we can use the pointer of callback as ID.
shimazu
2014/09/08 07:04:46
I think so, too.
But the pointer is different betw
| |
259 "URL", document_url.spec()); | |
253 if (!LazyInitialize(base::Bind( | 260 if (!LazyInitialize(base::Bind( |
254 &ServiceWorkerStorage::FindRegistrationForDocument, | 261 &ServiceWorkerStorage::FindRegistrationForDocument, |
255 weak_factory_.GetWeakPtr(), document_url, callback))) { | 262 weak_factory_.GetWeakPtr(), document_url, callback))) { |
256 if (state_ != INITIALIZING || !context_) { | 263 if (state_ != INITIALIZING || !context_) { |
257 CompleteFindNow(scoped_refptr<ServiceWorkerRegistration>(), | 264 CompleteFindNow(scoped_refptr<ServiceWorkerRegistration>(), |
258 SERVICE_WORKER_ERROR_FAILED, callback); | 265 SERVICE_WORKER_ERROR_FAILED, callback); |
259 } | 266 } |
260 return; | 267 return; |
261 } | 268 } |
262 DCHECK_EQ(INITIALIZED, state_); | 269 DCHECK_EQ(INITIALIZED, state_); |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
760 } | 767 } |
761 | 768 |
762 void ServiceWorkerStorage::DidFindRegistrationForDocument( | 769 void ServiceWorkerStorage::DidFindRegistrationForDocument( |
763 const GURL& document_url, | 770 const GURL& document_url, |
764 const FindRegistrationCallback& callback, | 771 const FindRegistrationCallback& callback, |
765 const ServiceWorkerDatabase::RegistrationData& data, | 772 const ServiceWorkerDatabase::RegistrationData& data, |
766 const ResourceList& resources, | 773 const ResourceList& resources, |
767 ServiceWorkerDatabase::Status status) { | 774 ServiceWorkerDatabase::Status status) { |
768 if (status == ServiceWorkerDatabase::STATUS_OK) { | 775 if (status == ServiceWorkerDatabase::STATUS_OK) { |
769 ReturnFoundRegistration(callback, data, resources); | 776 ReturnFoundRegistration(callback, data, resources); |
777 TRACE_EVENT_ASYNC_END1( | |
778 "ServiceWorker", | |
779 "ServiceWorkerStorage::FindRegistrationForDocument -> " | |
780 "ServiceWorkerStorage::DidFindRegistrationForDocument", | |
781 base::Hash(document_url.spec()), | |
782 "Status", "OK"); | |
770 return; | 783 return; |
771 } | 784 } |
772 | 785 |
773 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { | 786 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { |
774 // Look for something currently being installed. | 787 // Look for something currently being installed. |
775 scoped_refptr<ServiceWorkerRegistration> installing_registration = | 788 scoped_refptr<ServiceWorkerRegistration> installing_registration = |
776 FindInstallingRegistrationForDocument(document_url); | 789 FindInstallingRegistrationForDocument(document_url); |
777 callback.Run(installing_registration.get() ? SERVICE_WORKER_OK | 790 callback.Run(installing_registration.get() ? SERVICE_WORKER_OK |
778 : SERVICE_WORKER_ERROR_NOT_FOUND, | 791 : SERVICE_WORKER_ERROR_NOT_FOUND, |
779 installing_registration); | 792 installing_registration); |
793 TRACE_EVENT_ASYNC_END1( | |
794 "ServiceWorker", | |
795 "ServiceWorkerStorage::FindRegistrationForDocument -> " | |
796 "ServiceWorkerStorage::DidFindRegistrationForDocument", | |
797 base::Hash(document_url.spec()), | |
798 "Status", status); | |
780 return; | 799 return; |
781 } | 800 } |
782 | 801 |
783 ScheduleDeleteAndStartOver(); | 802 ScheduleDeleteAndStartOver(); |
784 callback.Run(DatabaseStatusToStatusCode(status), | 803 callback.Run(DatabaseStatusToStatusCode(status), |
785 scoped_refptr<ServiceWorkerRegistration>()); | 804 scoped_refptr<ServiceWorkerRegistration>()); |
805 TRACE_EVENT_ASYNC_END1( | |
806 "ServiceWorker", | |
807 "ServiceWorkerStorage::FindRegistrationForDocument -> " | |
808 "ServiceWorkerStorage::DidFindRegistrationForDocument", | |
809 base::Hash(document_url.spec()), | |
810 "Status", status); | |
786 } | 811 } |
787 | 812 |
788 void ServiceWorkerStorage::DidFindRegistrationForPattern( | 813 void ServiceWorkerStorage::DidFindRegistrationForPattern( |
789 const GURL& scope, | 814 const GURL& scope, |
790 const FindRegistrationCallback& callback, | 815 const FindRegistrationCallback& callback, |
791 const ServiceWorkerDatabase::RegistrationData& data, | 816 const ServiceWorkerDatabase::RegistrationData& data, |
792 const ResourceList& resources, | 817 const ResourceList& resources, |
793 ServiceWorkerDatabase::Status status) { | 818 ServiceWorkerDatabase::Status status) { |
794 if (status == ServiceWorkerDatabase::STATUS_OK) { | 819 if (status == ServiceWorkerDatabase::STATUS_OK) { |
795 ReturnFoundRegistration(callback, data, resources); | 820 ReturnFoundRegistration(callback, data, resources); |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1398 // Give up the corruption recovery until the browser restarts. | 1423 // Give up the corruption recovery until the browser restarts. |
1399 LOG(ERROR) << "Failed to delete the diskcache."; | 1424 LOG(ERROR) << "Failed to delete the diskcache."; |
1400 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1425 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
1401 return; | 1426 return; |
1402 } | 1427 } |
1403 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; | 1428 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; |
1404 callback.Run(SERVICE_WORKER_OK); | 1429 callback.Run(SERVICE_WORKER_OK); |
1405 } | 1430 } |
1406 | 1431 |
1407 } // namespace content | 1432 } // namespace content |
OLD | NEW |