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

Side by Side Diff: third_party/WebKit/Source/core/frame/UseCounter.cpp

Issue 2796283005: Adding UseCounter specific for extensions (Closed)
Patch Set: bug fix Created 3 years, 8 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 /* 1 /*
2 * Copyright (C) 2012 Google, Inc. All rights reserved. 2 * Copyright (C) 2012 Google, Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 ASSERT_NOT_REACHED(); 1099 ASSERT_NOT_REACHED();
1100 return 0; 1100 return 0;
1101 } 1101 }
1102 1102
1103 ASSERT_NOT_REACHED(); 1103 ASSERT_NOT_REACHED();
1104 return 0; 1104 return 0;
1105 } 1105 }
1106 1106
1107 UseCounter::UseCounter(Context context) 1107 UseCounter::UseCounter(Context context)
1108 : mute_count_(0), 1108 : mute_count_(0),
1109 disable_reporting_(false),
1110 context_(context), 1109 context_(context),
1111 features_recorded_(kNumberOfFeatures), 1110 features_recorded_(kNumberOfFeatures),
1112 css_recorded_(numCSSPropertyIDs), 1111 css_recorded_(numCSSPropertyIDs),
1113 animated_css_recorded_(numCSSPropertyIDs) {} 1112 animated_css_recorded_(numCSSPropertyIDs) {}
1114 1113
1115 void UseCounter::MuteForInspector() { 1114 void UseCounter::MuteForInspector() {
1116 mute_count_++; 1115 mute_count_++;
1117 } 1116 }
1118 1117
1119 void UseCounter::UnmuteForInspector() { 1118 void UseCounter::UnmuteForInspector() {
1120 mute_count_--; 1119 mute_count_--;
1121 } 1120 }
1122 1121
1123 void UseCounter::RecordMeasurement(Feature feature) { 1122 void UseCounter::RecordMeasurement(Feature feature) {
1124 if (mute_count_) 1123 if (mute_count_)
1125 return; 1124 return;
1126 1125
1127 DCHECK(feature != kOBSOLETE_PageDestruction && 1126 DCHECK(feature != kOBSOLETE_PageDestruction &&
1128 feature != 1127 feature !=
1129 kPageVisits); // PageDestruction is reserved as a scaling factor. 1128 kPageVisits); // PageDestruction is reserved as a scaling factor.
1130 DCHECK(feature < kNumberOfFeatures); 1129 DCHECK(feature < kNumberOfFeatures);
1131 1130
1132 if (!features_recorded_.QuickGet(feature)) { 1131 if (!features_recorded_.QuickGet(feature)) {
1133 // Note that HTTPArchive tooling looks specifically for this event - see 1132 // Note that HTTPArchive tooling looks specifically for this event - see
1134 // https://github.com/HTTPArchive/httparchive/issues/59 1133 // https://github.com/HTTPArchive/httparchive/issues/59
1135 if (!disable_reporting_) { 1134 if (context_ != kDisabledContext) {
1136 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), 1135 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"),
1137 "FeatureFirstUsed", "feature", feature); 1136 "FeatureFirstUsed", "feature", feature);
1138 FeaturesHistogram().Count(feature); 1137 FeaturesHistogram().Count(feature);
1139 NotifyFeatureCounted(feature); 1138 NotifyFeatureCounted(feature);
1140 } 1139 }
1141 features_recorded_.QuickSet(feature); 1140 features_recorded_.QuickSet(feature);
1142 } 1141 }
1143 legacy_counter_.CountFeature(feature); 1142 legacy_counter_.CountFeature(feature);
1144 } 1143 }
1145 1144
(...skipping 10 matching lines...) Expand all
1156 } 1155 }
1157 1156
1158 DEFINE_TRACE(UseCounter) { 1157 DEFINE_TRACE(UseCounter) {
1159 visitor->Trace(observers_); 1158 visitor->Trace(observers_);
1160 } 1159 }
1161 1160
1162 void UseCounter::DidCommitLoad(KURL url) { 1161 void UseCounter::DidCommitLoad(KURL url) {
1163 legacy_counter_.UpdateMeasurements(); 1162 legacy_counter_.UpdateMeasurements();
1164 1163
1165 // Reset state from previous load. 1164 // Reset state from previous load.
1166 disable_reporting_ = false;
1167
1168 // Use the protocol of the document being loaded into the main frame to 1165 // Use the protocol of the document being loaded into the main frame to
1169 // decide whether this page is interesting from a metrics perspective. 1166 // decide whether this page is interesting from a metrics perspective.
1170 // Note that SVGImage cases always have an about:blank URL 1167 // Note that SVGImage cases always have an about:blank URL
1171 if (context_ == kDefaultContext && 1168 if (context_ != kSVGImageContext) {
1172 !SchemeRegistry::ShouldTrackUsageMetricsForScheme(url.Protocol())) { 1169 if (url.ProtocolIs("chrome-extension"))
1173 disable_reporting_ = true; 1170 context_ = kExtensionContext;
1171 else if (!SchemeRegistry::ShouldTrackUsageMetricsForScheme(url.Protocol()))
Rick Byers 2017/04/28 15:04:40 nit: avoid the double negative by removing the '!'
lunalu1 2017/05/01 15:37:52 Done
1172 context_ = kDisabledContext;
1173 else
1174 context_ = kDefaultContext;
1174 } 1175 }
1175 1176
1176 features_recorded_.ClearAll(); 1177 features_recorded_.ClearAll();
1177 css_recorded_.ClearAll(); 1178 css_recorded_.ClearAll();
1178 animated_css_recorded_.ClearAll(); 1179 animated_css_recorded_.ClearAll();
1179 if (!disable_reporting_ && !mute_count_) { 1180 if (context_ != kDisabledContext && !mute_count_) {
1180 FeaturesHistogram().Count(kPageVisits); 1181 FeaturesHistogram().Count(kPageVisits);
1181 CssHistogram().Count(totalPagesMeasuredCSSSampleId()); 1182 if (context_ != kExtensionContext) {
1182 AnimatedCSSHistogram().Count(totalPagesMeasuredCSSSampleId()); 1183 CssHistogram().Count(totalPagesMeasuredCSSSampleId());
1184 AnimatedCSSHistogram().Count(totalPagesMeasuredCSSSampleId());
1185 }
1183 } 1186 }
1184 } 1187 }
1185 1188
1186 void UseCounter::Count(const Frame* frame, Feature feature) { 1189 void UseCounter::Count(const Frame* frame, Feature feature) {
1187 if (!frame) 1190 if (!frame)
1188 return; 1191 return;
1189 Page* page = frame->GetPage(); 1192 Page* page = frame->GetPage();
1190 if (!page) 1193 if (!page)
1191 return; 1194 return;
1192 1195
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 void UseCounter::Count(CSSParserMode css_parser_mode, CSSPropertyID property) { 1248 void UseCounter::Count(CSSParserMode css_parser_mode, CSSPropertyID property) {
1246 DCHECK(isCSSPropertyIDWithName(property) || property == CSSPropertyVariable); 1249 DCHECK(isCSSPropertyIDWithName(property) || property == CSSPropertyVariable);
1247 1250
1248 if (!IsUseCounterEnabledForMode(css_parser_mode) || mute_count_) 1251 if (!IsUseCounterEnabledForMode(css_parser_mode) || mute_count_)
1249 return; 1252 return;
1250 1253
1251 if (!css_recorded_.QuickGet(property)) { 1254 if (!css_recorded_.QuickGet(property)) {
1252 // Note that HTTPArchive tooling looks specifically for this event - see 1255 // Note that HTTPArchive tooling looks specifically for this event - see
1253 // https://github.com/HTTPArchive/httparchive/issues/59 1256 // https://github.com/HTTPArchive/httparchive/issues/59
1254 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property); 1257 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property);
1255 if (!disable_reporting_) { 1258 if (context_ != kDisabledContext && context_ != kExtensionContext) {
1256 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), 1259 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"),
1257 "CSSFirstUsed", "feature", sample_id); 1260 "CSSFirstUsed", "feature", sample_id);
1258 CssHistogram().Count(sample_id); 1261 CssHistogram().Count(sample_id);
1259 } 1262 }
1260 css_recorded_.QuickSet(property); 1263 css_recorded_.QuickSet(property);
1261 } 1264 }
1262 legacy_counter_.CountCSS(property); 1265 legacy_counter_.CountCSS(property);
1263 } 1266 }
1264 1267
1265 void UseCounter::Count(Feature feature) { 1268 void UseCounter::Count(Feature feature) {
(...skipping 26 matching lines...) Expand all
1292 } 1295 }
1293 1296
1294 void UseCounter::CountAnimatedCSS(CSSPropertyID property) { 1297 void UseCounter::CountAnimatedCSS(CSSPropertyID property) {
1295 DCHECK(isCSSPropertyIDWithName(property) || property == CSSPropertyVariable); 1298 DCHECK(isCSSPropertyIDWithName(property) || property == CSSPropertyVariable);
1296 1299
1297 if (mute_count_) 1300 if (mute_count_)
1298 return; 1301 return;
1299 1302
1300 if (!animated_css_recorded_.QuickGet(property)) { 1303 if (!animated_css_recorded_.QuickGet(property)) {
1301 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property); 1304 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property);
1302 if (!disable_reporting_) { 1305 if (context_ != kDisabledContext && context_ != kExtensionContext) {
1303 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), 1306 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"),
1304 "AnimatedCSSFirstUsed", "feature", sample_id); 1307 "AnimatedCSSFirstUsed", "feature", sample_id);
1305 AnimatedCSSHistogram().Count(sample_id); 1308 AnimatedCSSHistogram().Count(sample_id);
1306 } 1309 }
1307 animated_css_recorded_.QuickSet(property); 1310 animated_css_recorded_.QuickSet(property);
1308 } 1311 }
1309 } 1312 }
1310 1313
1311 void UseCounter::NotifyFeatureCounted(Feature feature) { 1314 void UseCounter::NotifyFeatureCounted(Feature feature) {
1312 DCHECK(!mute_count_); 1315 DCHECK(!mute_count_);
1313 DCHECK(!disable_reporting_); 1316 DCHECK(context_ != kDisabledContext);
1314 HeapHashSet<Member<Observer>> to_be_removed; 1317 HeapHashSet<Member<Observer>> to_be_removed;
1315 for (auto observer : observers_) { 1318 for (auto observer : observers_) {
1316 if (observer->OnCountFeature(feature)) 1319 if (observer->OnCountFeature(feature))
1317 to_be_removed.insert(observer); 1320 to_be_removed.insert(observer);
1318 } 1321 }
1319 observers_.RemoveAll(to_be_removed); 1322 observers_.RemoveAll(to_be_removed);
1320 } 1323 }
1321 1324
1322 EnumerationHistogram& UseCounter::FeaturesHistogram() const { 1325 EnumerationHistogram& UseCounter::FeaturesHistogram() const {
1326 DCHECK_NE(kDisabledContext, context_);
1323 // Every SVGImage has it's own Page instance, and multiple web pages can 1327 // Every SVGImage has it's own Page instance, and multiple web pages can
1324 // share the usage of a single SVGImage. Ideally perhaps we'd delegate 1328 // share the usage of a single SVGImage. Ideally perhaps we'd delegate
1325 // metrics from an SVGImage to one of the Page's it's displayed in, but 1329 // metrics from an SVGImage to one of the Page's it's displayed in, but
1326 // that's tricky (SVGImage is intentionally isolated, and the Page that 1330 // that's tricky (SVGImage is intentionally isolated, and the Page that
1327 // created it may not even exist anymore). 1331 // created it may not even exist anymore).
1328 // So instead we just use a dedicated histogram for the SVG case. 1332 // So instead we just use a dedicated histogram for the SVG case.
1333 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, svg_histogram,
1334 ("Blink.UseCounter.SVGImage.Features",
1335 blink::UseCounter::kNumberOfFeatures));
1336 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, extension_histogram,
1337 ("Blink.UseCounter.Extensions.Features",
1338 blink::UseCounter::kNumberOfFeatures));
1329 DEFINE_STATIC_LOCAL( 1339 DEFINE_STATIC_LOCAL(
1330 blink::EnumerationHistogram, histogram, 1340 blink::EnumerationHistogram, histogram,
1331 ("Blink.UseCounter.Features", blink::UseCounter::kNumberOfFeatures)); 1341 ("Blink.UseCounter.Features", blink::UseCounter::kNumberOfFeatures));
1332 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, svg_histogram, 1342 switch (context_) {
1333 ("Blink.UseCounter.SVGImage.Features", 1343 case kSVGImageContext:
1334 blink::UseCounter::kNumberOfFeatures)); 1344 return svg_histogram;
1335 1345 case kExtensionContext:
1336 return context_ == kSVGImageContext ? svg_histogram : histogram; 1346 return extension_histogram;
1347 default:
1348 return histogram;
1349 }
1337 } 1350 }
1338 1351
1339 EnumerationHistogram& UseCounter::CssHistogram() const { 1352 EnumerationHistogram& UseCounter::CssHistogram() const {
1340 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, histogram, 1353 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, histogram,
Rick Byers 2017/04/28 15:04:40 Nit: Add DCHECKs to verify we don't have kExtensio
lunalu1 2017/05/01 15:37:52 Done.
1341 ("Blink.UseCounter.CSSProperties", kMaximumCSSSampleId)); 1354 ("Blink.UseCounter.CSSProperties", kMaximumCSSSampleId));
1342 DEFINE_STATIC_LOCAL( 1355 DEFINE_STATIC_LOCAL(
1343 blink::EnumerationHistogram, svg_histogram, 1356 blink::EnumerationHistogram, svg_histogram,
1344 ("Blink.UseCounter.SVGImage.CSSProperties", kMaximumCSSSampleId)); 1357 ("Blink.UseCounter.SVGImage.CSSProperties", kMaximumCSSSampleId));
1345 1358
1346 return context_ == kSVGImageContext ? svg_histogram : histogram; 1359 return context_ == kSVGImageContext ? svg_histogram : histogram;
1347 } 1360 }
1348 1361
1349 EnumerationHistogram& UseCounter::AnimatedCSSHistogram() const { 1362 EnumerationHistogram& UseCounter::AnimatedCSSHistogram() const {
1350 DEFINE_STATIC_LOCAL( 1363 DEFINE_STATIC_LOCAL(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1415 } 1428 }
1416 } 1429 }
1417 1430
1418 if (needs_pages_measured_update) 1431 if (needs_pages_measured_update)
1419 css_properties_histogram.Count(totalPagesMeasuredCSSSampleId()); 1432 css_properties_histogram.Count(totalPagesMeasuredCSSSampleId());
1420 1433
1421 css_bits_.ClearAll(); 1434 css_bits_.ClearAll();
1422 } 1435 }
1423 1436
1424 } // namespace blink 1437 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698