Update broken references to image assets
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_metrics.h
blob3c68438d1239ed84797359dac1c467a1f29fc21d
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 #ifndef CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_METRICS_H_
6 #define CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_METRICS_H_
8 #include "base/macros.h"
9 #include "content/browser/service_worker/service_worker_database.h"
10 #include "content/common/service_worker/service_worker_types.h"
11 #include "third_party/WebKit/public/platform/modules/serviceworker/WebServiceWorkerResponseError.h"
13 class GURL;
15 namespace content {
17 class ServiceWorkerMetrics {
18 public:
19 enum ReadResponseResult {
20 READ_OK,
21 READ_HEADERS_ERROR,
22 READ_DATA_ERROR,
23 NUM_READ_RESPONSE_RESULT_TYPES,
26 enum WriteResponseResult {
27 WRITE_OK,
28 WRITE_HEADERS_ERROR,
29 WRITE_DATA_ERROR,
30 NUM_WRITE_RESPONSE_RESULT_TYPES,
33 enum DiskCacheMigrationResult {
34 MIGRATION_OK,
35 MIGRATION_NOT_NECESSARY,
36 MIGRATION_ERROR_MIGRATION_FAILED,
37 MIGRATION_ERROR_UPDATE_DATABASE,
38 NUM_MIGRATION_RESULT_TYPES,
41 enum DeleteAndStartOverResult {
42 DELETE_OK,
43 DELETE_DATABASE_ERROR,
44 DELETE_DISK_CACHE_ERROR,
45 NUM_DELETE_AND_START_OVER_RESULT_TYPES,
48 enum URLRequestJobResult {
49 REQUEST_JOB_FALLBACK_RESPONSE,
50 REQUEST_JOB_FALLBACK_FOR_CORS,
51 REQUEST_JOB_HEADERS_ONLY_RESPONSE,
52 REQUEST_JOB_STREAM_RESPONSE,
53 REQUEST_JOB_BLOB_RESPONSE,
54 REQUEST_JOB_ERROR_RESPONSE_STATUS_ZERO,
55 REQUEST_JOB_ERROR_BAD_BLOB,
56 REQUEST_JOB_ERROR_NO_PROVIDER_HOST,
57 REQUEST_JOB_ERROR_NO_ACTIVE_VERSION,
58 REQUEST_JOB_ERROR_NO_REQUEST,
59 REQUEST_JOB_ERROR_FETCH_EVENT_DISPATCH,
60 REQUEST_JOB_ERROR_BLOB_READ,
61 REQUEST_JOB_ERROR_STREAM_ABORTED,
62 REQUEST_JOB_ERROR_KILLED,
63 REQUEST_JOB_ERROR_KILLED_WITH_BLOB,
64 REQUEST_JOB_ERROR_KILLED_WITH_STREAM,
65 REQUEST_JOB_ERROR_DESTROYED,
66 REQUEST_JOB_ERROR_DESTROYED_WITH_BLOB,
67 REQUEST_JOB_ERROR_DESTROYED_WITH_STREAM,
68 NUM_REQUEST_JOB_RESULT_TYPES,
71 enum StopWorkerStatus {
72 STOP_STATUS_STOPPING,
73 STOP_STATUS_STOPPED,
74 STOP_STATUS_STALLED,
75 STOP_STATUS_STALLED_THEN_STOPPED,
76 NUM_STOP_STATUS_TYPES
79 enum EventType {
80 EVENT_TYPE_FETCH,
81 // Add new events to record here.
83 NUM_EVENT_TYPES
86 // Used for UMA. Append only.
87 enum class Site { OTHER, NEW_TAB_PAGE, NUM_TYPES };
89 // Excludes NTP scope from UMA for now as it tends to dominate the stats and
90 // makes the results largely skewed. Some metrics don't follow this policy
91 // and hence don't call this function.
92 static bool ShouldExcludeSiteFromHistogram(Site site);
93 static bool ShouldExcludeURLFromHistogram(const GURL& url);
95 // Used for ServiceWorkerDiskCache.
96 static void CountInitDiskCacheResult(bool result);
97 static void CountReadResponseResult(ReadResponseResult result);
98 static void CountWriteResponseResult(WriteResponseResult result);
100 // Used for ServiceWorkerDatabase.
101 static void CountOpenDatabaseResult(ServiceWorkerDatabase::Status status);
102 static void CountReadDatabaseResult(ServiceWorkerDatabase::Status status);
103 static void CountWriteDatabaseResult(ServiceWorkerDatabase::Status status);
104 static void RecordDestroyDatabaseResult(ServiceWorkerDatabase::Status status);
106 // Used for ServiceWorkerStorage.
107 static void RecordPurgeResourceResult(int net_error);
108 static void RecordDeleteAndStartOverResult(DeleteAndStartOverResult result);
109 static void RecordDiskCacheMigrationResult(DiskCacheMigrationResult result);
111 // Counts the number of page loads controlled by a Service Worker.
112 static void CountControlledPageLoad(const GURL& url);
114 // Records the result of trying to start a worker. |is_installed| indicates
115 // whether the version has been installed.
116 static void RecordStartWorkerStatus(ServiceWorkerStatusCode status,
117 bool is_installed);
119 // Records the time taken to successfully start a worker. |is_installed|
120 // indicates whether the version has been installed.
121 static void RecordStartWorkerTime(const base::TimeDelta& time,
122 bool is_installed);
124 // Records the result of trying to stop a worker.
125 static void RecordStopWorkerStatus(StopWorkerStatus status);
127 // Records the time taken to successfully stop a worker.
128 static void RecordStopWorkerTime(const base::TimeDelta& time);
130 static void RecordActivateEventStatus(ServiceWorkerStatusCode status);
131 static void RecordInstallEventStatus(ServiceWorkerStatusCode status);
133 // Records how much of dispatched events are handled while a Service
134 // Worker is awake (i.e. after it is woken up until it gets stopped).
135 static void RecordEventHandledRatio(EventType event,
136 size_t handled_events,
137 size_t fired_events);
139 // Records the result of dispatching a fetch event to a service worker.
140 static void RecordFetchEventStatus(bool is_main_resource,
141 ServiceWorkerStatusCode status);
143 // Records the amount of time spent handling a fetch event with the given
144 // result.
145 static void RecordFetchEventTime(ServiceWorkerFetchEventResult result,
146 const base::TimeDelta& time);
148 // Records result of a ServiceWorkerURLRequestJob that was forwarded to
149 // the service worker.
150 static void RecordURLRequestJobResult(bool is_main_resource,
151 URLRequestJobResult result);
153 // Records the error code provided when the renderer returns a response with
154 // status zero to a fetch request.
155 static void RecordStatusZeroResponseError(
156 bool is_main_resource,
157 blink::WebServiceWorkerResponseError error);
159 // Records the mode of request that was fallbacked to the network.
160 static void RecordFallbackedRequestMode(FetchRequestMode mode);
162 // Called at the beginning of each ServiceWorkerVersion::Dispatch*Event
163 // function. Records the time elapsed since idle (generally the time since the
164 // previous event ended).
165 static void RecordTimeBetweenEvents(const base::TimeDelta& time);
167 private:
168 DISALLOW_IMPLICIT_CONSTRUCTORS(ServiceWorkerMetrics);
171 } // namespace content
173 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_METRICS_H_