1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/browser/service_worker/service_worker_metrics.h"
7 #include "base/metrics/histogram.h"
8 #include "base/metrics/user_metrics_action.h"
9 #include "content/public/browser/browser_thread.h"
10 #include "content/public/browser/content_browser_client.h"
11 #include "content/public/browser/user_metrics.h"
12 #include "content/public/common/content_client.h"
18 void RecordURLMetricOnUI(const GURL
& url
) {
19 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
20 GetContentClient()->browser()->RecordURLMetric(
21 "ServiceWorker.ControlledPageUrl", url
);
26 void ServiceWorkerMetrics::CountInitDiskCacheResult(bool result
) {
27 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.DiskCache.InitResult", result
);
30 void ServiceWorkerMetrics::CountReadResponseResult(
31 ServiceWorkerMetrics::ReadResponseResult result
) {
32 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.DiskCache.ReadResponseResult",
33 result
, NUM_READ_RESPONSE_RESULT_TYPES
);
36 void ServiceWorkerMetrics::CountWriteResponseResult(
37 ServiceWorkerMetrics::WriteResponseResult result
) {
38 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.DiskCache.WriteResponseResult",
39 result
, NUM_WRITE_RESPONSE_RESULT_TYPES
);
42 void ServiceWorkerMetrics::CountOpenDatabaseResult(
43 ServiceWorkerDatabase::Status status
) {
44 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.Database.OpenResult",
45 status
, ServiceWorkerDatabase::STATUS_ERROR_MAX
);
48 void ServiceWorkerMetrics::CountReadDatabaseResult(
49 ServiceWorkerDatabase::Status status
) {
50 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.Database.ReadResult",
51 status
, ServiceWorkerDatabase::STATUS_ERROR_MAX
);
54 void ServiceWorkerMetrics::CountWriteDatabaseResult(
55 ServiceWorkerDatabase::Status status
) {
56 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.Database.WriteResult",
57 status
, ServiceWorkerDatabase::STATUS_ERROR_MAX
);
60 void ServiceWorkerMetrics::RecordDestroyDatabaseResult(
61 ServiceWorkerDatabase::Status status
) {
62 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.Database.DestroyDatabase", status
,
63 ServiceWorkerDatabase::STATUS_ERROR_MAX
);
66 void ServiceWorkerMetrics::RecordDeleteAndStartOverResult(
67 DeleteAndStartOverResult result
) {
68 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.Storage.DeleteAndStartOverResult",
69 result
, NUM_DELETE_AND_START_OVER_RESULT_TYPES
);
72 void ServiceWorkerMetrics::CountControlledPageLoad(const GURL
& url
) {
73 RecordAction(base::UserMetricsAction("ServiceWorker.ControlledPageLoad"));
74 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
75 base::Bind(&RecordURLMetricOnUI
, url
));
78 } // namespace content