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/files/file_util.h" | 11 #include "base/files/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()), |
| 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 base::Hash(document_url.spec()), |
| 781 "Status", "OK"); |
770 return; | 782 return; |
771 } | 783 } |
772 | 784 |
773 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { | 785 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { |
774 // Look for something currently being installed. | 786 // Look for something currently being installed. |
775 scoped_refptr<ServiceWorkerRegistration> installing_registration = | 787 scoped_refptr<ServiceWorkerRegistration> installing_registration = |
776 FindInstallingRegistrationForDocument(document_url); | 788 FindInstallingRegistrationForDocument(document_url); |
777 callback.Run(installing_registration.get() ? SERVICE_WORKER_OK | 789 callback.Run(installing_registration.get() ? SERVICE_WORKER_OK |
778 : SERVICE_WORKER_ERROR_NOT_FOUND, | 790 : SERVICE_WORKER_ERROR_NOT_FOUND, |
779 installing_registration); | 791 installing_registration); |
| 792 TRACE_EVENT_ASYNC_END1( |
| 793 "ServiceWorker", |
| 794 "ServiceWorkerStorage::FindRegistrationForDocument", |
| 795 base::Hash(document_url.spec()), |
| 796 "Status", status); |
780 return; | 797 return; |
781 } | 798 } |
782 | 799 |
783 ScheduleDeleteAndStartOver(); | 800 ScheduleDeleteAndStartOver(); |
784 callback.Run(DatabaseStatusToStatusCode(status), | 801 callback.Run(DatabaseStatusToStatusCode(status), |
785 scoped_refptr<ServiceWorkerRegistration>()); | 802 scoped_refptr<ServiceWorkerRegistration>()); |
| 803 TRACE_EVENT_ASYNC_END1( |
| 804 "ServiceWorker", |
| 805 "ServiceWorkerStorage::FindRegistrationForDocument", |
| 806 base::Hash(document_url.spec()), |
| 807 "Status", status); |
786 } | 808 } |
787 | 809 |
788 void ServiceWorkerStorage::DidFindRegistrationForPattern( | 810 void ServiceWorkerStorage::DidFindRegistrationForPattern( |
789 const GURL& scope, | 811 const GURL& scope, |
790 const FindRegistrationCallback& callback, | 812 const FindRegistrationCallback& callback, |
791 const ServiceWorkerDatabase::RegistrationData& data, | 813 const ServiceWorkerDatabase::RegistrationData& data, |
792 const ResourceList& resources, | 814 const ResourceList& resources, |
793 ServiceWorkerDatabase::Status status) { | 815 ServiceWorkerDatabase::Status status) { |
794 if (status == ServiceWorkerDatabase::STATUS_OK) { | 816 if (status == ServiceWorkerDatabase::STATUS_OK) { |
795 ReturnFoundRegistration(callback, data, resources); | 817 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. | 1420 // Give up the corruption recovery until the browser restarts. |
1399 LOG(ERROR) << "Failed to delete the diskcache."; | 1421 LOG(ERROR) << "Failed to delete the diskcache."; |
1400 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1422 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
1401 return; | 1423 return; |
1402 } | 1424 } |
1403 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; | 1425 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; |
1404 callback.Run(SERVICE_WORKER_OK); | 1426 callback.Run(SERVICE_WORKER_OK); |
1405 } | 1427 } |
1406 | 1428 |
1407 } // namespace content | 1429 } // namespace content |
OLD | NEW |