OLD | NEW |
---|---|
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 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1094 NOTREACHED(); | 1094 NOTREACHED(); |
1095 return 0; | 1095 return 0; |
1096 } | 1096 } |
1097 | 1097 |
1098 NOTREACHED(); | 1098 NOTREACHED(); |
1099 return 0; | 1099 return 0; |
1100 } | 1100 } |
1101 | 1101 |
1102 UseCounter::UseCounter(Context context) | 1102 UseCounter::UseCounter(Context context) |
1103 : mute_count_(0), | 1103 : mute_count_(0), |
1104 disable_reporting_(false), | |
1105 context_(context), | 1104 context_(context), |
1106 features_recorded_(kNumberOfFeatures), | 1105 features_recorded_(kNumberOfFeatures), |
1107 css_recorded_(numCSSPropertyIDs), | 1106 css_recorded_(numCSSPropertyIDs), |
1108 animated_css_recorded_(numCSSPropertyIDs) {} | 1107 animated_css_recorded_(numCSSPropertyIDs) {} |
1109 | 1108 |
1110 void UseCounter::MuteForInspector() { | 1109 void UseCounter::MuteForInspector() { |
1111 mute_count_++; | 1110 mute_count_++; |
1112 } | 1111 } |
1113 | 1112 |
1114 void UseCounter::UnmuteForInspector() { | 1113 void UseCounter::UnmuteForInspector() { |
1115 mute_count_--; | 1114 mute_count_--; |
1116 } | 1115 } |
1117 | 1116 |
1118 void UseCounter::RecordMeasurement(Feature feature) { | 1117 void UseCounter::RecordMeasurement(Feature feature) { |
1119 if (mute_count_) | 1118 if (mute_count_) |
1120 return; | 1119 return; |
1121 | 1120 |
1122 DCHECK(feature != kOBSOLETE_PageDestruction && | 1121 DCHECK(feature != kOBSOLETE_PageDestruction && |
1123 feature != | 1122 feature != |
1124 kPageVisits); // PageDestruction is reserved as a scaling factor. | 1123 kPageVisits); // PageDestruction is reserved as a scaling factor. |
1125 DCHECK(feature < kNumberOfFeatures); | 1124 DCHECK(feature < kNumberOfFeatures); |
1126 | 1125 |
1127 if (!features_recorded_.QuickGet(feature)) { | 1126 if (!features_recorded_.QuickGet(feature)) { |
1128 // Note that HTTPArchive tooling looks specifically for this event - see | 1127 // Note that HTTPArchive tooling looks specifically for this event - see |
1129 // https://github.com/HTTPArchive/httparchive/issues/59 | 1128 // https://github.com/HTTPArchive/httparchive/issues/59 |
1130 if (!disable_reporting_) { | 1129 if (context_ != kDisabledContext) { |
1131 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), | 1130 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), |
1132 "FeatureFirstUsed", "feature", feature); | 1131 "FeatureFirstUsed", "feature", feature); |
1133 FeaturesHistogram().Count(feature); | 1132 FeaturesHistogram().Count(feature); |
1134 NotifyFeatureCounted(feature); | 1133 NotifyFeatureCounted(feature); |
1135 } | 1134 } |
1136 features_recorded_.QuickSet(feature); | 1135 features_recorded_.QuickSet(feature); |
1137 } | 1136 } |
1138 legacy_counter_.CountFeature(feature); | 1137 legacy_counter_.CountFeature(feature); |
1139 } | 1138 } |
1140 | 1139 |
(...skipping 10 matching lines...) Expand all Loading... | |
1151 } | 1150 } |
1152 | 1151 |
1153 DEFINE_TRACE(UseCounter) { | 1152 DEFINE_TRACE(UseCounter) { |
1154 visitor->Trace(observers_); | 1153 visitor->Trace(observers_); |
1155 } | 1154 } |
1156 | 1155 |
1157 void UseCounter::DidCommitLoad(KURL url) { | 1156 void UseCounter::DidCommitLoad(KURL url) { |
1158 legacy_counter_.UpdateMeasurements(); | 1157 legacy_counter_.UpdateMeasurements(); |
1159 | 1158 |
1160 // Reset state from previous load. | 1159 // Reset state from previous load. |
1161 disable_reporting_ = false; | |
1162 | |
1163 // Use the protocol of the document being loaded into the main frame to | 1160 // Use the protocol of the document being loaded into the main frame to |
1164 // decide whether this page is interesting from a metrics perspective. | 1161 // decide whether this page is interesting from a metrics perspective. |
1165 // Note that SVGImage cases always have an about:blank URL | 1162 // Note that SVGImage cases always have an about:blank URL |
1166 if (context_ == kDefaultContext && | 1163 if (context_ != kSVGImageContext) { |
1167 !SchemeRegistry::ShouldTrackUsageMetricsForScheme(url.Protocol())) { | 1164 if (url.ProtocolIs("chrome-extension")) |
1168 disable_reporting_ = true; | 1165 context_ = kExtensionContext; |
1166 else if (SchemeRegistry::ShouldTrackUsageMetricsForScheme(url.Protocol())) | |
1167 context_ = kDefaultContext; | |
1168 else | |
1169 context_ = kDisabledContext; | |
1169 } | 1170 } |
1170 | 1171 |
1171 features_recorded_.ClearAll(); | 1172 features_recorded_.ClearAll(); |
1172 css_recorded_.ClearAll(); | 1173 css_recorded_.ClearAll(); |
1173 animated_css_recorded_.ClearAll(); | 1174 animated_css_recorded_.ClearAll(); |
1174 if (!disable_reporting_ && !mute_count_) { | 1175 if (context_ != kDisabledContext && !mute_count_) { |
1175 FeaturesHistogram().Count(kPageVisits); | 1176 FeaturesHistogram().Count(kPageVisits); |
1176 CssHistogram().Count(totalPagesMeasuredCSSSampleId()); | 1177 if (context_ != kExtensionContext) { |
1177 AnimatedCSSHistogram().Count(totalPagesMeasuredCSSSampleId()); | 1178 CssHistogram().Count(totalPagesMeasuredCSSSampleId()); |
1179 AnimatedCSSHistogram().Count(totalPagesMeasuredCSSSampleId()); | |
1180 } | |
1178 } | 1181 } |
1179 } | 1182 } |
1180 | 1183 |
1181 void UseCounter::Count(const Frame* frame, Feature feature) { | 1184 void UseCounter::Count(const Frame* frame, Feature feature) { |
1182 if (!frame) | 1185 if (!frame) |
1183 return; | 1186 return; |
1184 Page* page = frame->GetPage(); | 1187 Page* page = frame->GetPage(); |
1185 if (!page) | 1188 if (!page) |
1186 return; | 1189 return; |
1187 | 1190 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1240 void UseCounter::Count(CSSParserMode css_parser_mode, CSSPropertyID property) { | 1243 void UseCounter::Count(CSSParserMode css_parser_mode, CSSPropertyID property) { |
1241 DCHECK(isCSSPropertyIDWithName(property) || property == CSSPropertyVariable); | 1244 DCHECK(isCSSPropertyIDWithName(property) || property == CSSPropertyVariable); |
1242 | 1245 |
1243 if (!IsUseCounterEnabledForMode(css_parser_mode) || mute_count_) | 1246 if (!IsUseCounterEnabledForMode(css_parser_mode) || mute_count_) |
1244 return; | 1247 return; |
1245 | 1248 |
1246 if (!css_recorded_.QuickGet(property)) { | 1249 if (!css_recorded_.QuickGet(property)) { |
1247 // Note that HTTPArchive tooling looks specifically for this event - see | 1250 // Note that HTTPArchive tooling looks specifically for this event - see |
1248 // https://github.com/HTTPArchive/httparchive/issues/59 | 1251 // https://github.com/HTTPArchive/httparchive/issues/59 |
1249 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property); | 1252 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property); |
1250 if (!disable_reporting_) { | 1253 if (context_ != kDisabledContext && context_ != kExtensionContext) { |
1251 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), | 1254 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), |
1252 "CSSFirstUsed", "feature", sample_id); | 1255 "CSSFirstUsed", "feature", sample_id); |
1253 CssHistogram().Count(sample_id); | 1256 CssHistogram().Count(sample_id); |
1254 } | 1257 } |
1255 css_recorded_.QuickSet(property); | 1258 css_recorded_.QuickSet(property); |
1256 } | 1259 } |
1257 legacy_counter_.CountCSS(property); | 1260 legacy_counter_.CountCSS(property); |
1258 } | 1261 } |
1259 | 1262 |
1260 void UseCounter::Count(Feature feature) { | 1263 void UseCounter::Count(Feature feature) { |
(...skipping 26 matching lines...) Expand all Loading... | |
1287 } | 1290 } |
1288 | 1291 |
1289 void UseCounter::CountAnimatedCSS(CSSPropertyID property) { | 1292 void UseCounter::CountAnimatedCSS(CSSPropertyID property) { |
1290 DCHECK(isCSSPropertyIDWithName(property) || property == CSSPropertyVariable); | 1293 DCHECK(isCSSPropertyIDWithName(property) || property == CSSPropertyVariable); |
1291 | 1294 |
1292 if (mute_count_) | 1295 if (mute_count_) |
1293 return; | 1296 return; |
1294 | 1297 |
1295 if (!animated_css_recorded_.QuickGet(property)) { | 1298 if (!animated_css_recorded_.QuickGet(property)) { |
1296 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property); | 1299 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property); |
1297 if (!disable_reporting_) { | 1300 if (context_ != kDisabledContext && context_ != kExtensionContext) { |
1298 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), | 1301 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), |
1299 "AnimatedCSSFirstUsed", "feature", sample_id); | 1302 "AnimatedCSSFirstUsed", "feature", sample_id); |
1300 AnimatedCSSHistogram().Count(sample_id); | 1303 AnimatedCSSHistogram().Count(sample_id); |
1301 } | 1304 } |
1302 animated_css_recorded_.QuickSet(property); | 1305 animated_css_recorded_.QuickSet(property); |
1303 } | 1306 } |
1304 } | 1307 } |
1305 | 1308 |
1306 void UseCounter::NotifyFeatureCounted(Feature feature) { | 1309 void UseCounter::NotifyFeatureCounted(Feature feature) { |
1307 DCHECK(!mute_count_); | 1310 DCHECK(!mute_count_); |
1308 DCHECK(!disable_reporting_); | 1311 DCHECK(context_ != kDisabledContext); |
Alexei Svitkine (slow)
2017/05/10 15:17:30
DCHECK_NE
lunalu1
2017/05/10 19:39:38
Done. Updated a few other DCHECK's too.
| |
1309 HeapHashSet<Member<Observer>> to_be_removed; | 1312 HeapHashSet<Member<Observer>> to_be_removed; |
1310 for (auto observer : observers_) { | 1313 for (auto observer : observers_) { |
1311 if (observer->OnCountFeature(feature)) | 1314 if (observer->OnCountFeature(feature)) |
1312 to_be_removed.insert(observer); | 1315 to_be_removed.insert(observer); |
1313 } | 1316 } |
1314 observers_.RemoveAll(to_be_removed); | 1317 observers_.RemoveAll(to_be_removed); |
1315 } | 1318 } |
1316 | 1319 |
1317 EnumerationHistogram& UseCounter::FeaturesHistogram() const { | 1320 EnumerationHistogram& UseCounter::FeaturesHistogram() const { |
1321 DCHECK_NE(kDisabledContext, context_); | |
1318 // Every SVGImage has it's own Page instance, and multiple web pages can | 1322 // Every SVGImage has it's own Page instance, and multiple web pages can |
1319 // share the usage of a single SVGImage. Ideally perhaps we'd delegate | 1323 // share the usage of a single SVGImage. Ideally perhaps we'd delegate |
1320 // metrics from an SVGImage to one of the Page's it's displayed in, but | 1324 // metrics from an SVGImage to one of the Page's it's displayed in, but |
1321 // that's tricky (SVGImage is intentionally isolated, and the Page that | 1325 // that's tricky (SVGImage is intentionally isolated, and the Page that |
1322 // created it may not even exist anymore). | 1326 // created it may not even exist anymore). |
1323 // So instead we just use a dedicated histogram for the SVG case. | 1327 // So instead we just use a dedicated histogram for the SVG case. |
1328 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, svg_histogram, | |
1329 ("Blink.UseCounter.SVGImage.Features", | |
1330 blink::UseCounter::kNumberOfFeatures)); | |
1331 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, extension_histogram, | |
1332 ("Blink.UseCounter.Extensions.Features", | |
1333 blink::UseCounter::kNumberOfFeatures)); | |
1324 DEFINE_STATIC_LOCAL( | 1334 DEFINE_STATIC_LOCAL( |
1325 blink::EnumerationHistogram, histogram, | 1335 blink::EnumerationHistogram, histogram, |
1326 ("Blink.UseCounter.Features", blink::UseCounter::kNumberOfFeatures)); | 1336 ("Blink.UseCounter.Features", blink::UseCounter::kNumberOfFeatures)); |
1327 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, svg_histogram, | 1337 switch (context_) { |
1328 ("Blink.UseCounter.SVGImage.Features", | 1338 case kSVGImageContext: |
1329 blink::UseCounter::kNumberOfFeatures)); | 1339 return svg_histogram; |
1330 | 1340 case kExtensionContext: |
1331 return context_ == kSVGImageContext ? svg_histogram : histogram; | 1341 return extension_histogram; |
1342 default: | |
Alexei Svitkine (slow)
2017/05/10 15:17:30
Nit: Suggest not having a default clause and expli
lunalu1
2017/05/10 19:39:38
Done.
| |
1343 return histogram; | |
1344 } | |
1332 } | 1345 } |
1333 | 1346 |
1334 EnumerationHistogram& UseCounter::CssHistogram() const { | 1347 EnumerationHistogram& UseCounter::CssHistogram() const { |
1348 DCHECK_NE(kExtensionContext, context_); | |
1349 DCHECK_NE(kDisabledContext, context_); | |
1335 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, histogram, | 1350 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, histogram, |
1336 ("Blink.UseCounter.CSSProperties", kMaximumCSSSampleId)); | 1351 ("Blink.UseCounter.CSSProperties", kMaximumCSSSampleId)); |
1337 DEFINE_STATIC_LOCAL( | 1352 DEFINE_STATIC_LOCAL( |
1338 blink::EnumerationHistogram, svg_histogram, | 1353 blink::EnumerationHistogram, svg_histogram, |
1339 ("Blink.UseCounter.SVGImage.CSSProperties", kMaximumCSSSampleId)); | 1354 ("Blink.UseCounter.SVGImage.CSSProperties", kMaximumCSSSampleId)); |
1340 | 1355 |
1341 return context_ == kSVGImageContext ? svg_histogram : histogram; | 1356 return context_ == kSVGImageContext ? svg_histogram : histogram; |
1342 } | 1357 } |
1343 | 1358 |
1344 EnumerationHistogram& UseCounter::AnimatedCSSHistogram() const { | 1359 EnumerationHistogram& UseCounter::AnimatedCSSHistogram() const { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1410 } | 1425 } |
1411 } | 1426 } |
1412 | 1427 |
1413 if (needs_pages_measured_update) | 1428 if (needs_pages_measured_update) |
1414 css_properties_histogram.Count(totalPagesMeasuredCSSSampleId()); | 1429 css_properties_histogram.Count(totalPagesMeasuredCSSSampleId()); |
1415 | 1430 |
1416 css_bits_.ClearAll(); | 1431 css_bits_.ClearAll(); |
1417 } | 1432 } |
1418 | 1433 |
1419 } // namespace blink | 1434 } // namespace blink |
OLD | NEW |