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

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

Issue 654823002: ServiceWorker: Convert ServiceWorkerDatabase::Status to string for logging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporate reviews and rebase 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_database.cc ('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"
11 #include "base/files/file_util.h" 11 #include "base/files/file_util.h"
12 #include "base/hash.h"
13 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
14 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
15 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
16 #include "base/task_runner_util.h" 15 #include "base/task_runner_util.h"
17 #include "content/browser/service_worker/service_worker_context_core.h" 16 #include "content/browser/service_worker/service_worker_context_core.h"
18 #include "content/browser/service_worker/service_worker_disk_cache.h" 17 #include "content/browser/service_worker/service_worker_disk_cache.h"
19 #include "content/browser/service_worker/service_worker_info.h" 18 #include "content/browser/service_worker/service_worker_info.h"
20 #include "content/browser/service_worker/service_worker_metrics.h" 19 #include "content/browser/service_worker/service_worker_metrics.h"
21 #include "content/browser/service_worker/service_worker_registration.h" 20 #include "content/browser/service_worker/service_worker_registration.h"
22 #include "content/browser/service_worker/service_worker_utils.h" 21 #include "content/browser/service_worker/service_worker_utils.h"
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 ServiceWorkerStatusCode status = installing_registration.get() ? 275 ServiceWorkerStatusCode status = installing_registration.get() ?
277 SERVICE_WORKER_OK : SERVICE_WORKER_ERROR_NOT_FOUND; 276 SERVICE_WORKER_OK : SERVICE_WORKER_ERROR_NOT_FOUND;
278 TRACE_EVENT_INSTANT2( 277 TRACE_EVENT_INSTANT2(
279 "ServiceWorker", 278 "ServiceWorker",
280 "ServiceWorkerStorage::FindRegistrationForDocument:CheckInstalling", 279 "ServiceWorkerStorage::FindRegistrationForDocument:CheckInstalling",
281 TRACE_EVENT_SCOPE_THREAD, 280 TRACE_EVENT_SCOPE_THREAD,
282 "URL", document_url.spec(), 281 "URL", document_url.spec(),
283 "Status", (status == SERVICE_WORKER_OK) ? "Found" : "Not Found"); 282 "Status", (status == SERVICE_WORKER_OK) ? "Found" : "Not Found");
nhiroki 2014/10/16 09:20:51 Can you use |ServiceWorkerStatusToString(status)|?
shimazu 2014/10/17 01:54:47 Done.
284 CompleteFindNow(installing_registration, 283 CompleteFindNow(installing_registration,
285 status, 284 status,
286 callback); 285 callback);
287 return; 286 return;
288 } 287 }
289 288
290 // To connect this TRACE_EVENT with the callback, TimeTicks is used for 289 // To connect this TRACE_EVENT with the callback, TimeTicks is used for
291 // callback id. 290 // callback id.
292 int64 callback_id = base::TimeTicks::Now().ToInternalValue(); 291 int64 callback_id = base::TimeTicks::Now().ToInternalValue();
293 TRACE_EVENT_ASYNC_BEGIN1( 292 TRACE_EVENT_ASYNC_BEGIN1(
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 DCHECK(data); 762 DCHECK(data);
764 DCHECK_EQ(INITIALIZING, state_); 763 DCHECK_EQ(INITIALIZING, state_);
765 764
766 if (status == ServiceWorkerDatabase::STATUS_OK) { 765 if (status == ServiceWorkerDatabase::STATUS_OK) {
767 next_registration_id_ = data->next_registration_id; 766 next_registration_id_ = data->next_registration_id;
768 next_version_id_ = data->next_version_id; 767 next_version_id_ = data->next_version_id;
769 next_resource_id_ = data->next_resource_id; 768 next_resource_id_ = data->next_resource_id;
770 registered_origins_.swap(data->origins); 769 registered_origins_.swap(data->origins);
771 state_ = INITIALIZED; 770 state_ = INITIALIZED;
772 } else { 771 } else {
773 // TODO(nhiroki): Stringify |status| using StatusToString() defined in 772 DVLOG(2) << "Failed to initialize: "
774 // service_worker_database.cc. 773 << ServiceWorkerDatabase::StatusToString(status);
775 DVLOG(2) << "Failed to initialize: " << status;
776 ScheduleDeleteAndStartOver(); 774 ScheduleDeleteAndStartOver();
777 } 775 }
778 776
779 for (std::vector<base::Closure>::const_iterator it = pending_tasks_.begin(); 777 for (std::vector<base::Closure>::const_iterator it = pending_tasks_.begin();
780 it != pending_tasks_.end(); ++it) { 778 it != pending_tasks_.end(); ++it) {
781 RunSoon(FROM_HERE, *it); 779 RunSoon(FROM_HERE, *it);
782 } 780 }
783 pending_tasks_.clear(); 781 pending_tasks_.clear();
784 } 782 }
785 783
786 void ServiceWorkerStorage::DidFindRegistrationForDocument( 784 void ServiceWorkerStorage::DidFindRegistrationForDocument(
787 const GURL& document_url, 785 const GURL& document_url,
788 const FindRegistrationCallback& callback, 786 const FindRegistrationCallback& callback,
789 int64 callback_id, 787 int64 callback_id,
790 const ServiceWorkerDatabase::RegistrationData& data, 788 const ServiceWorkerDatabase::RegistrationData& data,
791 const ResourceList& resources, 789 const ResourceList& resources,
792 ServiceWorkerDatabase::Status status) { 790 ServiceWorkerDatabase::Status status) {
793 if (status == ServiceWorkerDatabase::STATUS_OK) { 791 if (status == ServiceWorkerDatabase::STATUS_OK) {
794 ReturnFoundRegistration(callback, data, resources); 792 ReturnFoundRegistration(callback, data, resources);
795 TRACE_EVENT_ASYNC_END1( 793 TRACE_EVENT_ASYNC_END1(
796 "ServiceWorker", 794 "ServiceWorker",
797 "ServiceWorkerStorage::FindRegistrationForDocument", 795 "ServiceWorkerStorage::FindRegistrationForDocument",
798 callback_id, 796 callback_id,
799 "Status", "OK"); 797 "Status", ServiceWorkerDatabase::StatusToString(status));
800 return; 798 return;
801 } 799 }
802 800
803 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) { 801 if (status == ServiceWorkerDatabase::STATUS_ERROR_NOT_FOUND) {
804 // Look for something currently being installed. 802 // Look for something currently being installed.
805 scoped_refptr<ServiceWorkerRegistration> installing_registration = 803 scoped_refptr<ServiceWorkerRegistration> installing_registration =
806 FindInstallingRegistrationForDocument(document_url); 804 FindInstallingRegistrationForDocument(document_url);
807 callback.Run(installing_registration.get() ? SERVICE_WORKER_OK 805 ServiceWorkerStatusCode installing_status = installing_registration.get() ?
808 : SERVICE_WORKER_ERROR_NOT_FOUND, 806 SERVICE_WORKER_OK : SERVICE_WORKER_ERROR_NOT_FOUND;
809 installing_registration); 807 callback.Run(installing_status, installing_registration);
810 TRACE_EVENT_ASYNC_END1( 808 TRACE_EVENT_ASYNC_END2(
811 "ServiceWorker", 809 "ServiceWorker",
812 "ServiceWorkerStorage::FindRegistrationForDocument", 810 "ServiceWorkerStorage::FindRegistrationForDocument",
813 callback_id, 811 callback_id,
814 "Status", status); 812 "Status", ServiceWorkerDatabase::StatusToString(status),
813 "Info",
814 (installing_status == SERVICE_WORKER_OK) ?
815 "Found installing registration" : "Not found any registrations");
nhiroki 2014/10/16 09:20:51 nit: found -> find
shimazu 2014/10/17 01:54:46 Done.
815 return; 816 return;
816 } 817 }
817 818
818 ScheduleDeleteAndStartOver(); 819 ScheduleDeleteAndStartOver();
819 callback.Run(DatabaseStatusToStatusCode(status), 820 callback.Run(DatabaseStatusToStatusCode(status),
820 scoped_refptr<ServiceWorkerRegistration>()); 821 scoped_refptr<ServiceWorkerRegistration>());
821 TRACE_EVENT_ASYNC_END1( 822 TRACE_EVENT_ASYNC_END1(
822 "ServiceWorker", 823 "ServiceWorker",
823 "ServiceWorkerStorage::FindRegistrationForDocument", 824 "ServiceWorkerStorage::FindRegistrationForDocument",
824 callback_id, 825 callback_id,
825 "Status", status); 826 "Status", ServiceWorkerDatabase::StatusToString(status));
826 } 827 }
827 828
828 void ServiceWorkerStorage::DidFindRegistrationForPattern( 829 void ServiceWorkerStorage::DidFindRegistrationForPattern(
829 const GURL& scope, 830 const GURL& scope,
830 const FindRegistrationCallback& callback, 831 const FindRegistrationCallback& callback,
831 const ServiceWorkerDatabase::RegistrationData& data, 832 const ServiceWorkerDatabase::RegistrationData& data,
832 const ResourceList& resources, 833 const ResourceList& resources,
833 ServiceWorkerDatabase::Status status) { 834 ServiceWorkerDatabase::Status status) {
834 if (status == ServiceWorkerDatabase::STATUS_OK) { 835 if (status == ServiceWorkerDatabase::STATUS_OK) {
835 ReturnFoundRegistration(callback, data, resources); 836 ReturnFoundRegistration(callback, data, resources);
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 DVLOG(1) << "Schedule to delete the context and start over."; 1406 DVLOG(1) << "Schedule to delete the context and start over.";
1406 context_->ScheduleDeleteAndStartOver(); 1407 context_->ScheduleDeleteAndStartOver();
1407 } 1408 }
1408 1409
1409 void ServiceWorkerStorage::DidDeleteDatabase( 1410 void ServiceWorkerStorage::DidDeleteDatabase(
1410 const StatusCallback& callback, 1411 const StatusCallback& callback,
1411 ServiceWorkerDatabase::Status status) { 1412 ServiceWorkerDatabase::Status status) {
1412 DCHECK_EQ(DISABLED, state_); 1413 DCHECK_EQ(DISABLED, state_);
1413 if (status != ServiceWorkerDatabase::STATUS_OK) { 1414 if (status != ServiceWorkerDatabase::STATUS_OK) {
1414 // Give up the corruption recovery until the browser restarts. 1415 // Give up the corruption recovery until the browser restarts.
1415 LOG(ERROR) << "Failed to delete the database: " << status; 1416 LOG(ERROR) << "Failed to delete the database: "
1417 << ServiceWorkerDatabase::StatusToString(status);
1416 callback.Run(DatabaseStatusToStatusCode(status)); 1418 callback.Run(DatabaseStatusToStatusCode(status));
1417 return; 1419 return;
1418 } 1420 }
1419 DVLOG(1) << "Deleted ServiceWorkerDatabase successfully."; 1421 DVLOG(1) << "Deleted ServiceWorkerDatabase successfully.";
1420 1422
1421 // Delete the disk cache on the cache thread. 1423 // Delete the disk cache on the cache thread.
1422 // TODO(nhiroki): What if there is a bunch of files in the cache directory? 1424 // TODO(nhiroki): What if there is a bunch of files in the cache directory?
1423 // Deleting the directory could take a long time and restart could be delayed. 1425 // Deleting the directory could take a long time and restart could be delayed.
1424 // We should probably rename the directory and delete it later. 1426 // We should probably rename the directory and delete it later.
1425 PostTaskAndReplyWithResult( 1427 PostTaskAndReplyWithResult(
(...skipping 12 matching lines...) Expand all
1438 // Give up the corruption recovery until the browser restarts. 1440 // Give up the corruption recovery until the browser restarts.
1439 LOG(ERROR) << "Failed to delete the diskcache."; 1441 LOG(ERROR) << "Failed to delete the diskcache.";
1440 callback.Run(SERVICE_WORKER_ERROR_FAILED); 1442 callback.Run(SERVICE_WORKER_ERROR_FAILED);
1441 return; 1443 return;
1442 } 1444 }
1443 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully."; 1445 DVLOG(1) << "Deleted ServiceWorkerDiskCache successfully.";
1444 callback.Run(SERVICE_WORKER_OK); 1446 callback.Run(SERVICE_WORKER_OK);
1445 } 1447 }
1446 1448
1447 } // namespace content 1449 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/service_worker/service_worker_database.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698