Add ICU message format support
[chromium-blink-merge.git] / content / browser / service_worker / service_worker_metrics.h
blob0e0fe8e382a0df79a17f33e118715d88505d7891
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/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 ServiceWorkerDiskCache.
87 static void CountInitDiskCacheResult(bool result);
88 static void CountReadResponseResult(ReadResponseResult result);
89 static void CountWriteResponseResult(WriteResponseResult result);
91 // Used for ServiceWorkerDatabase.
92 static void CountOpenDatabaseResult(ServiceWorkerDatabase::Status status);
93 static void CountReadDatabaseResult(ServiceWorkerDatabase::Status status);
94 static void CountWriteDatabaseResult(ServiceWorkerDatabase::Status status);
95 static void RecordDestroyDatabaseResult(ServiceWorkerDatabase::Status status);
97 // Used for ServiceWorkerStorage.
98 static void RecordPurgeResourceResult(int net_error);
99 static void RecordDeleteAndStartOverResult(DeleteAndStartOverResult result);
100 static void RecordDiskCacheMigrationResult(DiskCacheMigrationResult result);
102 // Counts the number of page loads controlled by a Service Worker.
103 static void CountControlledPageLoad(const GURL& url);
105 // Records the result of trying to start a worker. |is_installed| indicates
106 // whether the version has been installed.
107 static void RecordStartWorkerStatus(ServiceWorkerStatusCode status,
108 bool is_installed);
110 // Records the time taken to successfully start a worker. |is_installed|
111 // indicates whether the version has been installed.
112 static void RecordStartWorkerTime(const base::TimeDelta& time,
113 bool is_installed);
115 // Records the result of trying to stop a worker.
116 static void RecordStopWorkerStatus(StopWorkerStatus status);
118 // Records the time taken to successfully stop a worker.
119 static void RecordStopWorkerTime(const base::TimeDelta& time);
121 static void RecordActivateEventStatus(ServiceWorkerStatusCode status);
122 static void RecordInstallEventStatus(ServiceWorkerStatusCode status);
124 // Records how much of dispatched events are handled while a Service
125 // Worker is awake (i.e. after it is woken up until it gets stopped).
126 static void RecordEventHandledRatio(const GURL& scope,
127 EventType event,
128 size_t handled_events,
129 size_t fired_events);
131 // Records the result of dispatching a fetch event to a service worker.
132 static void RecordFetchEventStatus(bool is_main_resource,
133 ServiceWorkerStatusCode status);
135 // Records the amount of time spent handling a fetch event with the given
136 // result.
137 static void RecordFetchEventTime(ServiceWorkerFetchEventResult result,
138 const base::TimeDelta& time);
140 // Records result of a ServiceWorkerURLRequestJob that was forwarded to
141 // the service worker.
142 static void RecordURLRequestJobResult(bool is_main_resource,
143 URLRequestJobResult result);
145 // Records the error code provided when the renderer returns a response with
146 // status zero to a fetch request.
147 static void RecordStatusZeroResponseError(
148 bool is_main_resource,
149 blink::WebServiceWorkerResponseError error);
151 // Records the mode of request that was fallbacked to the network.
152 static void RecordFallbackedRequestMode(FetchRequestMode mode);
154 private:
155 DISALLOW_IMPLICIT_CONSTRUCTORS(ServiceWorkerMetrics);
158 } // namespace content
160 #endif // CONTENT_BROWSER_SERVICE_WORKER_SERVICE_WORKER_METRICS_H_