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 | 1094 |
1095 ASSERT_NOT_REACHED(); | 1095 ASSERT_NOT_REACHED(); |
1096 return 0; | 1096 return 0; |
1097 } | 1097 } |
1098 | 1098 |
1099 UseCounter::UseCounter(Context context) | 1099 UseCounter::UseCounter(Context context) |
1100 : m_muteCount(0), | 1100 : m_muteCount(0), |
1101 m_disableReporting(false), | 1101 m_disableReporting(false), |
1102 m_context(context), | 1102 m_context(context), |
1103 m_featuresRecorded(NumberOfFeatures), | 1103 m_featuresRecorded(NumberOfFeatures), |
1104 m_CSSRecorded(numCSSPropertyIDs) {} | 1104 m_CSSRecorded(numCSSPropertyIDs), |
| 1105 m_animatedCSSRecorded(numCSSPropertyIDs) {} |
1105 | 1106 |
1106 void UseCounter::muteForInspector() { | 1107 void UseCounter::muteForInspector() { |
1107 m_muteCount++; | 1108 m_muteCount++; |
1108 } | 1109 } |
1109 | 1110 |
1110 void UseCounter::unmuteForInspector() { | 1111 void UseCounter::unmuteForInspector() { |
1111 m_muteCount--; | 1112 m_muteCount--; |
1112 } | 1113 } |
1113 | 1114 |
1114 void UseCounter::recordMeasurement(Feature feature) { | 1115 void UseCounter::recordMeasurement(Feature feature) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1159 // 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 |
1160 // decide whether this page is interesting from a metrics perspective. | 1161 // decide whether this page is interesting from a metrics perspective. |
1161 // Note that SVGImage cases always have an about:blank URL | 1162 // Note that SVGImage cases always have an about:blank URL |
1162 if (m_context == DefaultContext && | 1163 if (m_context == DefaultContext && |
1163 !SchemeRegistry::shouldTrackUsageMetricsForScheme(url.protocol())) { | 1164 !SchemeRegistry::shouldTrackUsageMetricsForScheme(url.protocol())) { |
1164 m_disableReporting = true; | 1165 m_disableReporting = true; |
1165 } | 1166 } |
1166 | 1167 |
1167 m_featuresRecorded.clearAll(); | 1168 m_featuresRecorded.clearAll(); |
1168 m_CSSRecorded.clearAll(); | 1169 m_CSSRecorded.clearAll(); |
| 1170 m_animatedCSSRecorded.clearAll(); |
1169 if (!m_disableReporting && !m_muteCount) { | 1171 if (!m_disableReporting && !m_muteCount) { |
1170 featuresHistogram().count(PageVisits); | 1172 featuresHistogram().count(PageVisits); |
1171 cssHistogram().count(totalPagesMeasuredCSSSampleId()); | 1173 cssHistogram().count(totalPagesMeasuredCSSSampleId()); |
| 1174 animatedCSSHistogram().count(totalPagesMeasuredCSSSampleId()); |
1172 } | 1175 } |
1173 } | 1176 } |
1174 | 1177 |
1175 void UseCounter::count(const Frame* frame, Feature feature) { | 1178 void UseCounter::count(const Frame* frame, Feature feature) { |
1176 if (!frame) | 1179 if (!frame) |
1177 return; | 1180 return; |
1178 Page* page = frame->page(); | 1181 Page* page = frame->page(); |
1179 if (!page) | 1182 if (!page) |
1180 return; | 1183 return; |
1181 | 1184 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1225 } | 1228 } |
1226 | 1229 |
1227 void UseCounter::countCrossOriginIframe(const Document& document, | 1230 void UseCounter::countCrossOriginIframe(const Document& document, |
1228 Feature feature) { | 1231 Feature feature) { |
1229 LocalFrame* frame = document.frame(); | 1232 LocalFrame* frame = document.frame(); |
1230 if (frame && frame->isCrossOriginSubframe()) | 1233 if (frame && frame->isCrossOriginSubframe()) |
1231 count(frame, feature); | 1234 count(frame, feature); |
1232 } | 1235 } |
1233 | 1236 |
1234 void UseCounter::count(CSSParserMode cssParserMode, CSSPropertyID property) { | 1237 void UseCounter::count(CSSParserMode cssParserMode, CSSPropertyID property) { |
| 1238 // FIXME(suzyh): Count custom properties as well as named properties |
1235 DCHECK(isCSSPropertyIDWithName(property)); | 1239 DCHECK(isCSSPropertyIDWithName(property)); |
1236 | 1240 |
1237 if (!isUseCounterEnabledForMode(cssParserMode) || m_muteCount) | 1241 if (!isUseCounterEnabledForMode(cssParserMode) || m_muteCount) |
1238 return; | 1242 return; |
1239 | 1243 |
1240 if (!m_CSSRecorded.quickGet(property)) { | 1244 if (!m_CSSRecorded.quickGet(property)) { |
1241 // Note that HTTPArchive tooling looks specifically for this event - see | 1245 // Note that HTTPArchive tooling looks specifically for this event - see |
1242 // https://github.com/HTTPArchive/httparchive/issues/59 | 1246 // https://github.com/HTTPArchive/httparchive/issues/59 |
1243 int sampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(property); | 1247 int sampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(property); |
1244 if (!m_disableReporting) { | 1248 if (!m_disableReporting) { |
1245 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), | 1249 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), |
1246 "CSSFirstUsed", "feature", sampleId); | 1250 "CSSFirstUsed", "feature", sampleId); |
1247 cssHistogram().count(sampleId); | 1251 cssHistogram().count(sampleId); |
1248 } | 1252 } |
1249 m_CSSRecorded.quickSet(property); | 1253 m_CSSRecorded.quickSet(property); |
1250 } | 1254 } |
1251 m_legacyCounter.countCSS(property); | 1255 m_legacyCounter.countCSS(property); |
1252 } | 1256 } |
1253 | 1257 |
1254 void UseCounter::count(Feature feature) { | 1258 void UseCounter::count(Feature feature) { |
1255 recordMeasurement(feature); | 1259 recordMeasurement(feature); |
1256 } | 1260 } |
1257 | 1261 |
| 1262 bool UseCounter::isCountedAnimatedCSS(CSSPropertyID unresolvedProperty) { |
| 1263 return m_animatedCSSRecorded.quickGet(unresolvedProperty); |
| 1264 } |
| 1265 |
| 1266 bool UseCounter::isCountedAnimatedCSS(Document& document, |
| 1267 const String& string) { |
| 1268 Page* page = document.page(); |
| 1269 if (!page) |
| 1270 return false; |
| 1271 |
| 1272 CSSPropertyID unresolvedProperty = unresolvedCSSPropertyID(string); |
| 1273 if (unresolvedProperty == CSSPropertyInvalid) |
| 1274 return false; |
| 1275 return page->useCounter().isCountedAnimatedCSS(unresolvedProperty); |
| 1276 } |
| 1277 |
| 1278 void UseCounter::countAnimatedCSS(const Document& document, |
| 1279 CSSPropertyID property) { |
| 1280 Page* page = document.page(); |
| 1281 if (!page) |
| 1282 return; |
| 1283 |
| 1284 page->useCounter().countAnimatedCSS(property); |
| 1285 } |
| 1286 |
| 1287 void UseCounter::countAnimatedCSS(CSSPropertyID property) { |
| 1288 DCHECK(isCSSPropertyIDWithName(property) || property == CSSPropertyVariable); |
| 1289 |
| 1290 if (m_muteCount) |
| 1291 return; |
| 1292 |
| 1293 if (!m_animatedCSSRecorded.quickGet(property)) { |
| 1294 int sampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(property); |
| 1295 if (!m_disableReporting) { |
| 1296 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), |
| 1297 "AnimatedCSSFirstUsed", "feature", sampleId); |
| 1298 animatedCSSHistogram().count(sampleId); |
| 1299 } |
| 1300 m_animatedCSSRecorded.quickSet(property); |
| 1301 } |
| 1302 } |
| 1303 |
1258 void UseCounter::notifyFeatureCounted(Feature feature) { | 1304 void UseCounter::notifyFeatureCounted(Feature feature) { |
1259 DCHECK(!m_muteCount); | 1305 DCHECK(!m_muteCount); |
1260 DCHECK(!m_disableReporting); | 1306 DCHECK(!m_disableReporting); |
1261 HeapHashSet<Member<Observer>> toBeRemoved; | 1307 HeapHashSet<Member<Observer>> toBeRemoved; |
1262 for (auto observer : m_observers) { | 1308 for (auto observer : m_observers) { |
1263 if (observer->onCountFeature(feature)) | 1309 if (observer->onCountFeature(feature)) |
1264 toBeRemoved.insert(observer); | 1310 toBeRemoved.insert(observer); |
1265 } | 1311 } |
1266 m_observers.removeAll(toBeRemoved); | 1312 m_observers.removeAll(toBeRemoved); |
1267 } | 1313 } |
(...skipping 18 matching lines...) Expand all Loading... |
1286 EnumerationHistogram& UseCounter::cssHistogram() const { | 1332 EnumerationHistogram& UseCounter::cssHistogram() const { |
1287 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, histogram, | 1333 DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, histogram, |
1288 ("Blink.UseCounter.CSSProperties", kMaximumCSSSampleId)); | 1334 ("Blink.UseCounter.CSSProperties", kMaximumCSSSampleId)); |
1289 DEFINE_STATIC_LOCAL( | 1335 DEFINE_STATIC_LOCAL( |
1290 blink::EnumerationHistogram, svgHistogram, | 1336 blink::EnumerationHistogram, svgHistogram, |
1291 ("Blink.UseCounter.SVGImage.CSSProperties", kMaximumCSSSampleId)); | 1337 ("Blink.UseCounter.SVGImage.CSSProperties", kMaximumCSSSampleId)); |
1292 | 1338 |
1293 return m_context == SVGImageContext ? svgHistogram : histogram; | 1339 return m_context == SVGImageContext ? svgHistogram : histogram; |
1294 } | 1340 } |
1295 | 1341 |
| 1342 EnumerationHistogram& UseCounter::animatedCSSHistogram() const { |
| 1343 DEFINE_STATIC_LOCAL( |
| 1344 blink::EnumerationHistogram, histogram, |
| 1345 ("Blink.UseCounter.AnimatedCSSProperties", kMaximumCSSSampleId)); |
| 1346 DEFINE_STATIC_LOCAL( |
| 1347 blink::EnumerationHistogram, svgHistogram, |
| 1348 ("Blink.UseCounter.SVGImage.AnimatedCSSProperties", kMaximumCSSSampleId)); |
| 1349 |
| 1350 return m_context == SVGImageContext ? svgHistogram : histogram; |
| 1351 } |
| 1352 |
1296 /* | 1353 /* |
1297 * | 1354 * |
1298 * LEGACY metrics support - WebCore.FeatureObserver is to be superceded by | 1355 * LEGACY metrics support - WebCore.FeatureObserver is to be superceded by |
1299 * WebCore.UseCounter | 1356 * WebCore.UseCounter |
1300 * | 1357 * |
1301 */ | 1358 */ |
1302 | 1359 |
1303 static EnumerationHistogram& featureObserverHistogram() { | 1360 static EnumerationHistogram& featureObserverHistogram() { |
1304 DEFINE_STATIC_LOCAL( | 1361 DEFINE_STATIC_LOCAL( |
1305 EnumerationHistogram, histogram, | 1362 EnumerationHistogram, histogram, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1351 } | 1408 } |
1352 } | 1409 } |
1353 | 1410 |
1354 if (needsPagesMeasuredUpdate) | 1411 if (needsPagesMeasuredUpdate) |
1355 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); | 1412 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); |
1356 | 1413 |
1357 m_CSSBits.clearAll(); | 1414 m_CSSBits.clearAll(); |
1358 } | 1415 } |
1359 | 1416 |
1360 } // namespace blink | 1417 } // namespace blink |
OLD | NEW |