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

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

Issue 2250623003: Keep ServiceWorkerMetrics::Site in ServiceWorkerVersion (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: diff from https://codereview.chromium.org/2251633002/#ps40001 Created 4 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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_metrics.h" 5 #include "content/browser/service_worker/service_worker_metrics.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <string> 8 #include <string>
9 9
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 base::HistogramBase::kUmaTargetedHistogramFlag); 137 base::HistogramBase::kUmaTargetedHistogramFlag);
138 histogram_pointer->Add(status); 138 histogram_pointer->Add(status);
139 } 139 }
140 140
141 void RecordURLMetricOnUI(const GURL& url) { 141 void RecordURLMetricOnUI(const GURL& url) {
142 DCHECK_CURRENTLY_ON(BrowserThread::UI); 142 DCHECK_CURRENTLY_ON(BrowserThread::UI);
143 GetContentClient()->browser()->RecordURLMetric( 143 GetContentClient()->browser()->RecordURLMetric(
144 "ServiceWorker.ControlledPageUrl", url); 144 "ServiceWorker.ControlledPageUrl", url);
145 } 145 }
146 146
147 ServiceWorkerMetrics::Site SiteFromURL(const GURL& gurl) {
148 // UIThreadSearchTermsData::GoogleBaseURLValue() returns the google base
149 // URL, but not available in content layer.
150 static const char google_like_scope_prefix[] = "https://www.google.";
151 static const char ntp_scope_path[] = "/_/chrome/";
152 if (base::StartsWith(gurl.spec(), google_like_scope_prefix,
153 base::CompareCase::INSENSITIVE_ASCII) &&
154 base::StartsWith(gurl.path(), ntp_scope_path,
155 base::CompareCase::SENSITIVE)) {
156 return ServiceWorkerMetrics::Site::NEW_TAB_PAGE;
157 }
158
159 return ServiceWorkerMetrics::Site::OTHER;
160 }
161
162 enum EventHandledRatioType { 147 enum EventHandledRatioType {
163 EVENT_HANDLED_NONE, 148 EVENT_HANDLED_NONE,
164 EVENT_HANDLED_SOME, 149 EVENT_HANDLED_SOME,
165 EVENT_HANDLED_ALL, 150 EVENT_HANDLED_ALL,
166 NUM_EVENT_HANDLED_RATIO_TYPE, 151 NUM_EVENT_HANDLED_RATIO_TYPE,
167 }; 152 };
168 153
169 } // namespace 154 } // namespace
170 155
171 const char* ServiceWorkerMetrics::EventTypeToString(EventType event_type) { 156 const char* ServiceWorkerMetrics::EventTypeToString(EventType event_type) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 return "Navigation Hint Link Tap Unconfirmed"; 191 return "Navigation Hint Link Tap Unconfirmed";
207 case EventType::NAVIGATION_HINT_LINK_TAP_DOWN: 192 case EventType::NAVIGATION_HINT_LINK_TAP_DOWN:
208 return "Navigation Hint Link Tap Down"; 193 return "Navigation Hint Link Tap Down";
209 case EventType::NUM_TYPES: 194 case EventType::NUM_TYPES:
210 break; 195 break;
211 } 196 }
212 NOTREACHED() << "Got unexpected event type: " << static_cast<int>(event_type); 197 NOTREACHED() << "Got unexpected event type: " << static_cast<int>(event_type);
213 return "error"; 198 return "error";
214 } 199 }
215 200
201 ServiceWorkerMetrics::Site ServiceWorkerMetrics::SiteFromURL(
202 const GURL& url,
203 base::Optional<bool> has_fetch_handler) {
204 // UIThreadSearchTermsData::GoogleBaseURLValue() returns the google base
205 // URL, but not available in content layer.
206 static const char google_like_scope_prefix[] = "https://www.google.";
207 static const char ntp_scope_path[] = "/_/chrome/";
208 if (base::StartsWith(url.spec(), google_like_scope_prefix,
209 base::CompareCase::INSENSITIVE_ASCII) &&
210 base::StartsWith(url.path(), ntp_scope_path,
211 base::CompareCase::SENSITIVE)) {
212 return ServiceWorkerMetrics::Site::NEW_TAB_PAGE;
213 }
214
215 if (!has_fetch_handler)
216 return ServiceWorkerMetrics::Site::OTHER;
217 if (has_fetch_handler.value())
218 return ServiceWorkerMetrics::Site::WITH_FETCH_HANDLER;
219 return ServiceWorkerMetrics::Site::WITHOUT_FETCH_HANDLER;
220 }
221
216 bool ServiceWorkerMetrics::IsNavigationHintEvent(EventType event_type) { 222 bool ServiceWorkerMetrics::IsNavigationHintEvent(EventType event_type) {
217 return event_type == EventType::NAVIGATION_HINT_LINK_MOUSE_DOWN || 223 return event_type == EventType::NAVIGATION_HINT_LINK_MOUSE_DOWN ||
218 event_type == EventType::NAVIGATION_HINT_LINK_TAP_UNCONFIRMED || 224 event_type == EventType::NAVIGATION_HINT_LINK_TAP_UNCONFIRMED ||
219 event_type == EventType::NAVIGATION_HINT_LINK_TAP_DOWN; 225 event_type == EventType::NAVIGATION_HINT_LINK_TAP_DOWN;
220 } 226 }
221 227
222 bool ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(Site site) { 228 bool ServiceWorkerMetrics::ShouldExcludeSiteFromHistogram(Site site) {
223 return site == ServiceWorkerMetrics::Site::NEW_TAB_PAGE; 229 return site == ServiceWorkerMetrics::Site::NEW_TAB_PAGE;
224 } 230 }
225 231
226 bool ServiceWorkerMetrics::ShouldExcludeURLFromHistogram(const GURL& url) {
227 return ShouldExcludeSiteFromHistogram(SiteFromURL(url));
228 }
229
230 void ServiceWorkerMetrics::CountInitDiskCacheResult(bool result) { 232 void ServiceWorkerMetrics::CountInitDiskCacheResult(bool result) {
231 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.DiskCache.InitResult", result); 233 UMA_HISTOGRAM_BOOLEAN("ServiceWorker.DiskCache.InitResult", result);
232 } 234 }
233 235
234 void ServiceWorkerMetrics::CountReadResponseResult( 236 void ServiceWorkerMetrics::CountReadResponseResult(
235 ServiceWorkerMetrics::ReadResponseResult result) { 237 ServiceWorkerMetrics::ReadResponseResult result) {
236 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.DiskCache.ReadResponseResult", 238 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.DiskCache.ReadResponseResult",
237 result, NUM_READ_RESPONSE_RESULT_TYPES); 239 result, NUM_READ_RESPONSE_RESULT_TYPES);
238 } 240 }
239 241
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 UMA_HISTOGRAM_SPARSE_SLOWLY("ServiceWorker.Storage.PurgeResourceResult", 273 UMA_HISTOGRAM_SPARSE_SLOWLY("ServiceWorker.Storage.PurgeResourceResult",
272 std::abs(net_error)); 274 std::abs(net_error));
273 } 275 }
274 276
275 void ServiceWorkerMetrics::RecordDeleteAndStartOverResult( 277 void ServiceWorkerMetrics::RecordDeleteAndStartOverResult(
276 DeleteAndStartOverResult result) { 278 DeleteAndStartOverResult result) {
277 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.Storage.DeleteAndStartOverResult", 279 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.Storage.DeleteAndStartOverResult",
278 result, NUM_DELETE_AND_START_OVER_RESULT_TYPES); 280 result, NUM_DELETE_AND_START_OVER_RESULT_TYPES);
279 } 281 }
280 282
281 void ServiceWorkerMetrics::CountControlledPageLoad(const GURL& url, 283 void ServiceWorkerMetrics::CountControlledPageLoad(Site site,
282 bool has_fetch_handler, 284 const GURL& url,
283 bool is_main_frame_load) { 285 bool is_main_frame_load) {
284 Site site = SiteFromURL(url); 286 DCHECK_NE(site, Site::OTHER);
285 if (site == Site::OTHER) {
286 site = (has_fetch_handler) ? Site::WITH_FETCH_HANDLER
287 : Site::WITHOUT_FETCH_HANDLER;
288 }
289 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.PageLoad", static_cast<int>(site), 287 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.PageLoad", static_cast<int>(site),
290 static_cast<int>(Site::NUM_TYPES)); 288 static_cast<int>(Site::NUM_TYPES));
291 if (is_main_frame_load) { 289 if (is_main_frame_load) {
292 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.MainFramePageLoad", 290 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.MainFramePageLoad",
293 static_cast<int>(site), 291 static_cast<int>(site),
294 static_cast<int>(Site::NUM_TYPES)); 292 static_cast<int>(Site::NUM_TYPES));
295 } 293 }
296 294
297 if (ShouldExcludeSiteFromHistogram(site)) 295 if (ShouldExcludeSiteFromHistogram(site))
298 return; 296 return;
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 } else if (failure_count == 2) { 673 } else if (failure_count == 2) {
676 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.AfterFailureStreak_2", 674 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.AfterFailureStreak_2",
677 status, SERVICE_WORKER_ERROR_MAX_VALUE); 675 status, SERVICE_WORKER_ERROR_MAX_VALUE);
678 } else if (failure_count == 3) { 676 } else if (failure_count == 3) {
679 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.AfterFailureStreak_3", 677 UMA_HISTOGRAM_ENUMERATION("ServiceWorker.StartWorker.AfterFailureStreak_3",
680 status, SERVICE_WORKER_ERROR_MAX_VALUE); 678 status, SERVICE_WORKER_ERROR_MAX_VALUE);
681 } 679 }
682 } 680 }
683 681
684 } // namespace content 682 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698