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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 context, | 245 context, |
| 246 old_storage->database_task_runner_, | 246 old_storage->database_task_runner_, |
| 247 old_storage->disk_cache_thread_, | 247 old_storage->disk_cache_thread_, |
| 248 old_storage->quota_manager_proxy_.get())); | 248 old_storage->quota_manager_proxy_.get())); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void ServiceWorkerStorage::FindRegistrationForDocument( | 251 void ServiceWorkerStorage::FindRegistrationForDocument( |
| 252 const GURL& document_url, | 252 const GURL& document_url, |
| 253 const FindRegistrationCallback& callback) { | 253 const FindRegistrationCallback& callback) { |
| 254 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()); | |
| 260 if (!LazyInitialize(base::Bind( | 255 if (!LazyInitialize(base::Bind( |
| 261 &ServiceWorkerStorage::FindRegistrationForDocument, | 256 &ServiceWorkerStorage::FindRegistrationForDocument, |
| 262 weak_factory_.GetWeakPtr(), document_url, callback))) { | 257 weak_factory_.GetWeakPtr(), document_url, callback))) { |
| 263 if (state_ != INITIALIZING || !context_) { | 258 if (state_ != INITIALIZING || !context_) { |
| 264 CompleteFindNow(scoped_refptr<ServiceWorkerRegistration>(), | 259 CompleteFindNow(scoped_refptr<ServiceWorkerRegistration>(), |
| 265 SERVICE_WORKER_ERROR_FAILED, callback); | 260 SERVICE_WORKER_ERROR_FAILED, callback); |
| 266 } | 261 } |
| 262 TRACE_EVENT1( | |
| 263 "ServiceWorker", | |
| 264 "ServiceWorkerStorage::FindRegistrationForDocument:LazyInitialize", | |
| 265 "URL", document_url.spec()); | |
|
nhiroki
2014/10/14 02:03:26
Why don't you add TRACE_EVENT_ASYNC_XXX in LazyIni
shimazu
2014/10/14 04:10:47
I think LazyInitialize have to be tracked in order
nhiroki
2014/10/14 05:01:13
I see. If you'd like to track it, how about doing
nhiroki
2014/10/14 06:09:50
Or, if you'd like to record it as a single event (
shimazu
2014/10/14 09:07:02
Done.
| |
| 267 return; | 266 return; |
| 268 } | 267 } |
| 269 DCHECK_EQ(INITIALIZED, state_); | 268 DCHECK_EQ(INITIALIZED, state_); |
| 270 | 269 |
| 271 // See if there are any stored registrations for the origin. | 270 // See if there are any stored registrations for the origin. |
| 272 if (!ContainsKey(registered_origins_, document_url.GetOrigin())) { | 271 if (!ContainsKey(registered_origins_, document_url.GetOrigin())) { |
| 273 // Look for something currently being installed. | 272 // Look for something currently being installed. |
| 274 scoped_refptr<ServiceWorkerRegistration> installing_registration = | 273 scoped_refptr<ServiceWorkerRegistration> installing_registration = |
| 275 FindInstallingRegistrationForDocument(document_url); | 274 FindInstallingRegistrationForDocument(document_url); |
| 276 CompleteFindNow(installing_registration, | 275 CompleteFindNow(installing_registration, |
| 277 installing_registration.get() | 276 installing_registration.get() |
| 278 ? SERVICE_WORKER_OK | 277 ? SERVICE_WORKER_OK |
| 279 : SERVICE_WORKER_ERROR_NOT_FOUND, | 278 : SERVICE_WORKER_ERROR_NOT_FOUND, |
| 280 callback); | 279 callback); |
| 280 TRACE_EVENT1( | |
| 281 "ServiceWorker", | |
| 282 "ServiceWorkerStorage::FindRegistrationForDocument:NotContainsKey", | |
|
nhiroki
2014/10/14 02:03:26
nit: s/Contains/Contain
I think this wouldn't hel
shimazu
2014/10/14 04:10:47
I think there is no meaning in terms of performanc
nhiroki
2014/10/14 05:01:13
Please see the previous comment.
shimazu
2014/10/14 09:07:02
Done.
| |
| 283 "URL", document_url.spec()); | |
| 281 return; | 284 return; |
| 282 } | 285 } |
| 283 | 286 |
| 287 // To connect this TRACE_EVENT with the callback, TimeTicks is used for | |
| 288 // callback id. | |
| 289 int callback_id = base::TimeTicks::Now().ToInternalValue(); | |
|
nhiroki
2014/10/14 02:03:26
|callback_id| should be int64 because ToInternalVa
shimazu
2014/10/14 04:10:47
Done.
| |
| 290 TRACE_EVENT_ASYNC_BEGIN1( | |
| 291 "ServiceWorker", | |
| 292 "ServiceWorkerStorage::FindRegistrationForDocument", | |
| 293 callback_id, | |
| 294 "URL", document_url.spec()); | |
| 284 database_task_runner_->PostTask( | 295 database_task_runner_->PostTask( |
| 285 FROM_HERE, | 296 FROM_HERE, |
| 286 base::Bind( | 297 base::Bind( |
| 287 &FindForDocumentInDB, | 298 &FindForDocumentInDB, |
| 288 database_.get(), | 299 database_.get(), |
| 289 base::MessageLoopProxy::current(), | 300 base::MessageLoopProxy::current(), |
| 290 document_url, | 301 document_url, |
| 291 base::Bind(&ServiceWorkerStorage::DidFindRegistrationForDocument, | 302 base::Bind(&ServiceWorkerStorage::DidFindRegistrationForDocument, |
| 292 weak_factory_.GetWeakPtr(), document_url, callback))); | 303 weak_factory_.GetWeakPtr(), |
| 304 document_url, | |
| 305 callback, | |
| 306 callback_id))); | |
| 293 } | 307 } |
| 294 | 308 |
| 295 void ServiceWorkerStorage::FindRegistrationForPattern( | 309 void ServiceWorkerStorage::FindRegistrationForPattern( |
| 296 const GURL& scope, | 310 const GURL& scope, |
| 297 const FindRegistrationCallback& callback) { | 311 const FindRegistrationCallback& callback) { |
| 298 if (!LazyInitialize(base::Bind( | 312 if (!LazyInitialize(base::Bind( |
| 299 &ServiceWorkerStorage::FindRegistrationForPattern, | 313 &ServiceWorkerStorage::FindRegistrationForPattern, |
| 300 weak_factory_.GetWeakPtr(), scope, callback))) { | 314 weak_factory_.GetWeakPtr(), scope, callback))) { |
| 301 if (state_ != INITIALIZING || !context_) { | 315 if (state_ != INITIALIZING || !context_) { |
| 302 CompleteFindSoon(FROM_HERE, scoped_refptr<ServiceWorkerRegistration>(), | 316 CompleteFindSoon(FROM_HERE, scoped_refptr<ServiceWorkerRegistration>(), |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 for (std::vector<base::Closure>::const_iterator it = pending_tasks_.begin(); | 776 for (std::vector<base::Closure>::const_iterator it = pending_tasks_.begin(); |
| 763 it != pending_tasks_.end(); ++it) { | 777 it != pending_tasks_.end(); ++it) { |
| 764 RunSoon(FROM_HERE, *it); | 778 RunSoon(FROM_HERE, *it); |
| 765 } | 779 } |
| 766 pending_tasks_.clear(); | 780 pending_tasks_.clear(); |
| 767 } | 781 } |
| 768 | 782 |
| 769 void ServiceWorkerStorage::DidFindRegistrationForDocument( | 783 void ServiceWorkerStorage::DidFindRegistrationForDocument( |
| 770 const GURL& document_url, | 784 const GURL& document_url, |
| 771 const FindRegistrationCallback& callback, | 785 const FindRegistrationCallback& callback, |
| 786 int callback_id, | |
|
nhiroki
2014/10/14 02:03:26
ditto.
shimazu
2014/10/14 04:10:47
Done.
| |
| 772 const ServiceWorkerDatabase::RegistrationData& data, | 787 const ServiceWorkerDatabase::RegistrationData& data, |
| 773 const ResourceList& resources, | 788 const ResourceList& resources, |
| 774 ServiceWorkerDatabase::Status status) { | 789 ServiceWorkerDatabase::Status status) { |
| 775 if (status == ServiceWorkerDatabase::STATUS_OK) { | 790 if (status == ServiceWorkerDatabase::STATUS_OK) { |
| 776 ReturnFoundRegistration(callback, data, resources); | 791 ReturnFoundRegistration(callback, data, resources); |
| 777 TRACE_EVENT_ASYNC_END1( | 792 TRACE_EVENT_ASYNC_END1( |
| 778 "ServiceWorker", | 793 "ServiceWorker", |
| 779 "ServiceWorkerStorage::FindRegistrationForDocument", | 794 "ServiceWorkerStorage::FindRegistrationForDocument", |
| 780 base::Hash(document_url.spec()), | 795 callback_id, |
| 781 "Status", "OK"); | 796 "Status", "OK"); |
| 782 return; | 797 return; |
| 783 } | 798 } |
| 784 | 799 |
| 785 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { | 800 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { |
| 786 // Look for something currently being installed. | 801 // Look for something currently being installed. |
| 787 scoped_refptr<ServiceWorkerRegistration> installing_registration = | 802 scoped_refptr<ServiceWorkerRegistration> installing_registration = |
| 788 FindInstallingRegistrationForDocument(document_url); | 803 FindInstallingRegistrationForDocument(document_url); |
| 789 callback.Run(installing_registration.get() ? SERVICE_WORKER_OK | 804 callback.Run(installing_registration.get() ? SERVICE_WORKER_OK |
| 790 : SERVICE_WORKER_ERROR_NOT_FOUND, | 805 : SERVICE_WORKER_ERROR_NOT_FOUND, |
| 791 installing_registration); | 806 installing_registration); |
| 792 TRACE_EVENT_ASYNC_END1( | 807 TRACE_EVENT_ASYNC_END1( |
| 793 "ServiceWorker", | 808 "ServiceWorker", |
| 794 "ServiceWorkerStorage::FindRegistrationForDocument", | 809 "ServiceWorkerStorage::FindRegistrationForDocument", |
| 795 base::Hash(document_url.spec()), | 810 callback_id, |
| 796 "Status", status); | 811 "Status", status); |
|
nhiroki
2014/10/14 05:01:13
(Not related to this CL, but we are here...)
1.)
shimazu
2014/10/14 09:07:02
I'll create a different patch about this.
| |
| 797 return; | 812 return; |
| 798 } | 813 } |
| 799 | 814 |
| 800 ScheduleDeleteAndStartOver(); | 815 ScheduleDeleteAndStartOver(); |
| 801 callback.Run(DatabaseStatusToStatusCode(status), | 816 callback.Run(DatabaseStatusToStatusCode(status), |
| 802 scoped_refptr<ServiceWorkerRegistration>()); | 817 scoped_refptr<ServiceWorkerRegistration>()); |
| 803 TRACE_EVENT_ASYNC_END1( | 818 TRACE_EVENT_ASYNC_END1( |
| 804 "ServiceWorker", | 819 "ServiceWorker", |
| 805 "ServiceWorkerStorage::FindRegistrationForDocument", | 820 "ServiceWorkerStorage::FindRegistrationForDocument", |
| 806 base::Hash(document_url.spec()), | 821 callback_id, |
| 807 "Status", status); | 822 "Status", status); |
| 808 } | 823 } |
| 809 | 824 |
| 810 void ServiceWorkerStorage::DidFindRegistrationForPattern( | 825 void ServiceWorkerStorage::DidFindRegistrationForPattern( |
| 811 const GURL& scope, | 826 const GURL& scope, |
| 812 const FindRegistrationCallback& callback, | 827 const FindRegistrationCallback& callback, |
| 813 const ServiceWorkerDatabase::RegistrationData& data, | 828 const ServiceWorkerDatabase::RegistrationData& data, |
| 814 const ResourceList& resources, | 829 const ResourceList& resources, |
| 815 ServiceWorkerDatabase::Status status) { | 830 ServiceWorkerDatabase::Status status) { |
| 816 if (status == ServiceWorkerDatabase::STATUS_OK) { | 831 if (status == ServiceWorkerDatabase::STATUS_OK) { |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1420 // Give up the corruption recovery until the browser restarts. | 1435 // Give up the corruption recovery until the browser restarts. |
| 1421 LOG(ERROR) << "Failed to delete the diskcache."; | 1436 LOG(ERROR) << "Failed to delete the diskcache."; |
| 1422 callback.Run(SERVICE_WORKER_ERROR_FAILED); | 1437 callback.Run(SERVICE_WORKER_ERROR_FAILED); |
| 1423 return; | 1438 return; |
| 1424 } | 1439 } |
| 1425 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; | 1440 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; |
| 1426 callback.Run(SERVICE_WORKER_OK); | 1441 callback.Run(SERVICE_WORKER_OK); |
| 1427 } | 1442 } |
| 1428 | 1443 |
| 1429 } // namespace content | 1444 } // namespace content |
| OLD | NEW |