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
);
27 void ServiceWorkerMetrics::CountInitDiskCacheResult(bool result
) {
28 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.DiskCache.InitResult", result
);
32 void ServiceWorkerMetrics::CountReadResponseResult(
33 ServiceWorkerMetrics::ReadResponseResult result
) {
34 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.DiskCache.ReadResponseResult",
35 result
, NUM_READ_RESPONSE_RESULT_TYPES
);
39 void ServiceWorkerMetrics::CountWriteResponseResult(
40 ServiceWorkerMetrics::WriteResponseResult result
) {
41 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.DiskCache.WriteResponseResult",
42 result
, NUM_WRITE_RESPONSE_RESULT_TYPES
);
46 void ServiceWorkerMetrics::CountOpenDatabaseResult(
47 ServiceWorkerDatabase::Status status
) {
48 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.Database.OpenResult",
49 status
, ServiceWorkerDatabase::STATUS_ERROR_MAX
);
53 void ServiceWorkerMetrics::CountReadDatabaseResult(
54 ServiceWorkerDatabase::Status status
) {
55 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.Database.ReadResult",
56 status
, ServiceWorkerDatabase::STATUS_ERROR_MAX
);
60 void ServiceWorkerMetrics::CountWriteDatabaseResult(
61 ServiceWorkerDatabase::Status status
) {
62 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.Database.WriteResult",
63 status
, ServiceWorkerDatabase::STATUS_ERROR_MAX
);
67 void ServiceWorkerMetrics::CountControlledPageLoad(const GURL
& url
) {
68 RecordAction(base::UserMetricsAction("ServiceWorker.ControlledPageLoad"));
69 BrowserThread::PostTask(BrowserThread::UI
, FROM_HERE
,
70 base::Bind(&RecordURLMetricOnUI
, url
));
73 } // namespace content