Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: content/browser/service_worker/service_worker_storage.cc

Issue 636253004: ServiceWorker: Move TRACE_EVENT to avoid early return and mismatching (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporate a review Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/service_worker/service_worker_storage.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_EVENT_INSTANT1(
263 "ServiceWorker",
264 "ServiceWorkerStorage::FindRegistrationForDocument:LazyInitialize",
nhiroki 2014/10/14 09:31:53 just suggestion: ":" looks a separator of namespac
265 TRACE_EVENT_SCOPE_THREAD,
266 "URL", document_url.spec());
267 return; 267 return;
268 } 268 }
269 DCHECK_EQ(INITIALIZED, state_); 269 DCHECK_EQ(INITIALIZED, state_);
270 270
271 // See if there are any stored registrations for the origin. 271 // See if there are any stored registrations for the origin.
272 if (!ContainsKey(registered_origins_, document_url.GetOrigin())) { 272 if (!ContainsKey(registered_origins_, document_url.GetOrigin())) {
273 // Look for something currently being installed. 273 // Look for something currently being installed.
274 scoped_refptr<ServiceWorkerRegistration> installing_registration = 274 scoped_refptr<ServiceWorkerRegistration> installing_registration =
275 FindInstallingRegistrationForDocument(document_url); 275 FindInstallingRegistrationForDocument(document_url);
276 ServiceWorkerStatusCode status = installing_registration.get() ?
277 SERVICE_WORKER_OK : SERVICE_WORKER_ERROR_NOT_FOUND;
278 TRACE_EVENT_INSTANT2(
279 "ServiceWorker",
280 "ServiceWorkerStorage::FindRegistrationForDocument:CheckInstalling",
nhiroki 2014/10/14 09:31:53 ditto.
281 TRACE_EVENT_SCOPE_THREAD,
282 "URL", document_url.spec(),
283 "Status", (status == SERVICE_WORKER_OK) ? "Found" : "Not Found");
nhiroki 2014/10/14 09:31:53 nit: "OK" is used for SERVICE_WORKER_OK at line 79
276 CompleteFindNow(installing_registration, 284 CompleteFindNow(installing_registration,
277 installing_registration.get() 285 status,
278 ? SERVICE_WORKER_OK
279 : SERVICE_WORKER_ERROR_NOT_FOUND,
280 callback); 286 callback);
281 return; 287 return;
282 } 288 }
283 289
290 // To connect this TRACE_EVENT with the callback, TimeTicks is used for
291 // callback id.
292 int64 callback_id = base::TimeTicks::Now().ToInternalValue();
293 TRACE_EVENT_ASYNC_BEGIN1(
294 "ServiceWorker",
295 "ServiceWorkerStorage::FindRegistrationForDocument",
296 callback_id,
297 "URL", document_url.spec());
284 database_task_runner_->PostTask( 298 database_task_runner_->PostTask(
285 FROM_HERE, 299 FROM_HERE,
286 base::Bind( 300 base::Bind(
287 &FindForDocumentInDB, 301 &FindForDocumentInDB,
288 database_.get(), 302 database_.get(),
289 base::MessageLoopProxy::current(), 303 base::MessageLoopProxy::current(),
290 document_url, 304 document_url,
291 base::Bind(&ServiceWorkerStorage::DidFindRegistrationForDocument, 305 base::Bind(&ServiceWorkerStorage::DidFindRegistrationForDocument,
292 weak_factory_.GetWeakPtr(), document_url, callback))); 306 weak_factory_.GetWeakPtr(),
307 document_url,
308 callback,
309 callback_id)));
293 } 310 }
294 311
295 void ServiceWorkerStorage::FindRegistrationForPattern( 312 void ServiceWorkerStorage::FindRegistrationForPattern(
296 const GURL& scope, 313 const GURL& scope,
297 const FindRegistrationCallback& callback) { 314 const FindRegistrationCallback& callback) {
298 if (!LazyInitialize(base::Bind( 315 if (!LazyInitialize(base::Bind(
299 &ServiceWorkerStorage::FindRegistrationForPattern, 316 &ServiceWorkerStorage::FindRegistrationForPattern,
300 weak_factory_.GetWeakPtr(), scope, callback))) { 317 weak_factory_.GetWeakPtr(), scope, callback))) {
301 if (state_ != INITIALIZING || !context_) { 318 if (state_ != INITIALIZING || !context_) {
302 CompleteFindSoon(FROM_HERE, scoped_refptr<ServiceWorkerRegistration>(), 319 CompleteFindSoon(FROM_HERE, scoped_refptr<ServiceWorkerRegistration>(),
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 for (std::vector<base::Closure>::const_iterator it = pending_tasks_.begin(); 779 for (std::vector<base::Closure>::const_iterator it = pending_tasks_.begin();
763 it != pending_tasks_.end(); ++it) { 780 it != pending_tasks_.end(); ++it) {
764 RunSoon(FROM_HERE, *it); 781 RunSoon(FROM_HERE, *it);
765 } 782 }
766 pending_tasks_.clear(); 783 pending_tasks_.clear();
767 } 784 }
768 785
769 void ServiceWorkerStorage::DidFindRegistrationForDocument( 786 void ServiceWorkerStorage::DidFindRegistrationForDocument(
770 const GURL& document_url, 787 const GURL& document_url,
771 const FindRegistrationCallback& callback, 788 const FindRegistrationCallback& callback,
789 int64 callback_id,
772 const ServiceWorkerDatabase::RegistrationData& data, 790 const ServiceWorkerDatabase::RegistrationData& data,
773 const ResourceList& resources, 791 const ResourceList& resources,
774 ServiceWorkerDatabase::Status status) { 792 ServiceWorkerDatabase::Status status) {
775 if (status == ServiceWorkerDatabase::STATUS_OK) { 793 if (status == ServiceWorkerDatabase::STATUS_OK) {
776 ReturnFoundRegistration(callback, data, resources); 794 ReturnFoundRegistration(callback, data, resources);
777 TRACE_EVENT_ASYNC_END1( 795 TRACE_EVENT_ASYNC_END1(
778 "ServiceWorker", 796 "ServiceWorker",
779 "ServiceWorkerStorage::FindRegistrationForDocument", 797 "ServiceWorkerStorage::FindRegistrationForDocument",
780 base::Hash(document_url.spec()), 798 callback_id,
781 "Status", "OK"); 799 "Status", "OK");
782 return; 800 return;
783 } 801 }
784 802
785 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { 803 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) {
786 // Look for something currently being installed. 804 // Look for something currently being installed.
787 scoped_refptr<ServiceWorkerRegistration> installing_registration = 805 scoped_refptr<ServiceWorkerRegistration> installing_registration =
788 FindInstallingRegistrationForDocument(document_url); 806 FindInstallingRegistrationForDocument(document_url);
789 callback.Run(installing_registration.get() ? SERVICE_WORKER_OK 807 callback.Run(installing_registration.get() ? SERVICE_WORKER_OK
790 : SERVICE_WORKER_ERROR_NOT_FOUND, 808 : SERVICE_WORKER_ERROR_NOT_FOUND,
791 installing_registration); 809 installing_registration);
792 TRACE_EVENT_ASYNC_END1( 810 TRACE_EVENT_ASYNC_END1(
793 "ServiceWorker", 811 "ServiceWorker",
794 "ServiceWorkerStorage::FindRegistrationForDocument", 812 "ServiceWorkerStorage::FindRegistrationForDocument",
795 base::Hash(document_url.spec()), 813 callback_id,
796 "Status", status); 814 "Status", status);
797 return; 815 return;
798 } 816 }
799 817
800 ScheduleDeleteAndStartOver(); 818 ScheduleDeleteAndStartOver();
801 callback.Run(DatabaseStatusToStatusCode(status), 819 callback.Run(DatabaseStatusToStatusCode(status),
802 scoped_refptr<ServiceWorkerRegistration>()); 820 scoped_refptr<ServiceWorkerRegistration>());
803 TRACE_EVENT_ASYNC_END1( 821 TRACE_EVENT_ASYNC_END1(
804 "ServiceWorker", 822 "ServiceWorker",
805 "ServiceWorkerStorage::FindRegistrationForDocument", 823 "ServiceWorkerStorage::FindRegistrationForDocument",
806 base::Hash(document_url.spec()), 824 callback_id,
807 "Status", status); 825 "Status", status);
808 } 826 }
809 827
810 void ServiceWorkerStorage::DidFindRegistrationForPattern( 828 void ServiceWorkerStorage::DidFindRegistrationForPattern(
811 const GURL& scope, 829 const GURL& scope,
812 const FindRegistrationCallback& callback, 830 const FindRegistrationCallback& callback,
813 const ServiceWorkerDatabase::RegistrationData& data, 831 const ServiceWorkerDatabase::RegistrationData& data,
814 const ResourceList& resources, 832 const ResourceList& resources,
815 ServiceWorkerDatabase::Status status) { 833 ServiceWorkerDatabase::Status status) {
816 if (status == ServiceWorkerDatabase::STATUS_OK) { 834 if (status == ServiceWorkerDatabase::STATUS_OK) {
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 // Give up the corruption recovery until the browser restarts. 1438 // Give up the corruption recovery until the browser restarts.
1421 LOG(ERROR) << "Failed to delete the diskcache."; 1439 LOG(ERROR) << "Failed to delete the diskcache.";
1422 callback.Run(SERVICE_WORKER_ERROR_FAILED); 1440 callback.Run(SERVICE_WORKER_ERROR_FAILED);
1423 return; 1441 return;
1424 } 1442 }
1425 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; 1443 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully.";
1426 callback.Run(SERVICE_WORKER_OK); 1444 callback.Run(SERVICE_WORKER_OK);
1427 } 1445 }
1428 1446
1429 } // namespace content 1447 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_storage.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698