| 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 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1118 PageVisits); // PageDestruction is reserved as a scaling factor. | 1118 PageVisits); // PageDestruction is reserved as a scaling factor. |
| 1119 DCHECK(feature < NumberOfFeatures); | 1119 DCHECK(feature < NumberOfFeatures); |
| 1120 | 1120 |
| 1121 if (!m_featuresRecorded.quickGet(feature)) { | 1121 if (!m_featuresRecorded.quickGet(feature)) { |
| 1122 // Note that HTTPArchive tooling looks specifically for this event - see | 1122 // Note that HTTPArchive tooling looks specifically for this event - see |
| 1123 // https://github.com/HTTPArchive/httparchive/issues/59 | 1123 // https://github.com/HTTPArchive/httparchive/issues/59 |
| 1124 if (!m_disableReporting) { | 1124 if (!m_disableReporting) { |
| 1125 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), | 1125 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), |
| 1126 "FeatureFirstUsed", "feature", feature); | 1126 "FeatureFirstUsed", "feature", feature); |
| 1127 featuresHistogram().count(feature); | 1127 featuresHistogram().count(feature); |
| 1128 notifyFeatureCounted(feature); |
| 1128 } | 1129 } |
| 1129 m_featuresRecorded.quickSet(feature); | 1130 m_featuresRecorded.quickSet(feature); |
| 1130 } | 1131 } |
| 1131 m_legacyCounter.countFeature(feature); | 1132 m_legacyCounter.countFeature(feature); |
| 1132 } | 1133 } |
| 1133 | 1134 |
| 1134 bool UseCounter::hasRecordedMeasurement(Feature feature) const { | 1135 bool UseCounter::hasRecordedMeasurement(Feature feature) const { |
| 1135 if (m_muteCount) | 1136 if (m_muteCount) |
| 1136 return false; | 1137 return false; |
| 1137 | 1138 |
| 1138 DCHECK(feature != OBSOLETE_PageDestruction && | 1139 DCHECK(feature != OBSOLETE_PageDestruction && |
| 1139 feature != | 1140 feature != |
| 1140 PageVisits); // PageDestruction is reserved as a scaling factor. | 1141 PageVisits); // PageDestruction is reserved as a scaling factor. |
| 1141 DCHECK(feature < NumberOfFeatures); | 1142 DCHECK(feature < NumberOfFeatures); |
| 1142 | 1143 |
| 1143 return m_featuresRecorded.quickGet(feature); | 1144 return m_featuresRecorded.quickGet(feature); |
| 1144 } | 1145 } |
| 1145 | 1146 |
| 1147 DEFINE_TRACE(UseCounter) { |
| 1148 visitor->trace(m_observers); |
| 1149 } |
| 1150 |
| 1146 void UseCounter::didCommitLoad(KURL url) { | 1151 void UseCounter::didCommitLoad(KURL url) { |
| 1147 m_legacyCounter.updateMeasurements(); | 1152 m_legacyCounter.updateMeasurements(); |
| 1148 | 1153 |
| 1149 // Reset state from previous load. | 1154 // Reset state from previous load. |
| 1150 m_disableReporting = false; | 1155 m_disableReporting = false; |
| 1151 | 1156 |
| 1152 // Use the protocol of the document being loaded into the main frame to | 1157 // Use the protocol of the document being loaded into the main frame to |
| 1153 // decide whether this page is interesting from a metrics perspective. | 1158 // decide whether this page is interesting from a metrics perspective. |
| 1154 // Note that SVGImage cases always have an about:blank URL | 1159 // Note that SVGImage cases always have an about:blank URL |
| 1155 if (m_context == DefaultContext && | 1160 if (m_context == DefaultContext && |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1186 FrameHost* host = frame->host(); | 1191 FrameHost* host = frame->host(); |
| 1187 if (!host) | 1192 if (!host) |
| 1188 return false; | 1193 return false; |
| 1189 return host->useCounter().hasRecordedMeasurement(feature); | 1194 return host->useCounter().hasRecordedMeasurement(feature); |
| 1190 } | 1195 } |
| 1191 | 1196 |
| 1192 bool UseCounter::isCounted(CSSPropertyID unresolvedProperty) { | 1197 bool UseCounter::isCounted(CSSPropertyID unresolvedProperty) { |
| 1193 return m_CSSRecorded.quickGet(unresolvedProperty); | 1198 return m_CSSRecorded.quickGet(unresolvedProperty); |
| 1194 } | 1199 } |
| 1195 | 1200 |
| 1201 void UseCounter::addObserver(Observer* observer) { |
| 1202 DCHECK(!m_observers.contains(observer)); |
| 1203 m_observers.insert(observer); |
| 1204 } |
| 1205 |
| 1196 bool UseCounter::isCounted(Document& document, const String& string) { | 1206 bool UseCounter::isCounted(Document& document, const String& string) { |
| 1197 Frame* frame = document.frame(); | 1207 Frame* frame = document.frame(); |
| 1198 if (!frame) | 1208 if (!frame) |
| 1199 return false; | 1209 return false; |
| 1200 FrameHost* host = frame->host(); | 1210 FrameHost* host = frame->host(); |
| 1201 if (!host) | 1211 if (!host) |
| 1202 return false; | 1212 return false; |
| 1203 | 1213 |
| 1204 CSSPropertyID unresolvedProperty = unresolvedCSSPropertyID(string); | 1214 CSSPropertyID unresolvedProperty = unresolvedCSSPropertyID(string); |
| 1205 if (unresolvedProperty == CSSPropertyInvalid) | 1215 if (unresolvedProperty == CSSPropertyInvalid) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1242 } | 1252 } |
| 1243 m_CSSRecorded.quickSet(property); | 1253 m_CSSRecorded.quickSet(property); |
| 1244 } | 1254 } |
| 1245 m_legacyCounter.countCSS(property); | 1255 m_legacyCounter.countCSS(property); |
| 1246 } | 1256 } |
| 1247 | 1257 |
| 1248 void UseCounter::count(Feature feature) { | 1258 void UseCounter::count(Feature feature) { |
| 1249 recordMeasurement(feature); | 1259 recordMeasurement(feature); |
| 1250 } | 1260 } |
| 1251 | 1261 |
| 1262 void UseCounter::notifyFeatureCounted(Feature feature) { |
| 1263 DCHECK(!m_muteCount); |
| 1264 DCHECK(!m_disableReporting); |
| 1265 HeapHashSet<Member<Observer>> toBeRemoved; |
| 1266 for (auto observer : m_observers) { |
| 1267 if (observer->onCountFeature(feature)) |
| 1268 toBeRemoved.insert(observer); |
| 1269 } |
| 1270 m_observers.removeAll(toBeRemoved); |
| 1271 } |
| 1272 |
| 1252 EnumerationHistogram& UseCounter::featuresHistogram() const { | 1273 EnumerationHistogram& UseCounter::featuresHistogram() const { |
| 1253 // Every SVGImage has it's own Page instance, and multiple web pages can | 1274 // Every SVGImage has it's own Page instance, and multiple web pages can |
| 1254 // share the usage of a single SVGImage. Ideally perhaps we'd delegate | 1275 // share the usage of a single SVGImage. Ideally perhaps we'd delegate |
| 1255 // metrics from an SVGImage to one of the Page's it's displayed in, but | 1276 // metrics from an SVGImage to one of the Page's it's displayed in, but |
| 1256 // that's tricky (SVGImage is intentionally isolated, and the Page that | 1277 // that's tricky (SVGImage is intentionally isolated, and the Page that |
| 1257 // created it may not even exist anymore). | 1278 // created it may not even exist anymore). |
| 1258 // So instead we just use a dedicated histogram for the SVG case. | 1279 // So instead we just use a dedicated histogram for the SVG case. |
| 1259 DEFINE_STATIC_LOCAL( | 1280 DEFINE_STATIC_LOCAL( |
| 1260 blink::EnumerationHistogram, histogram, | 1281 blink::EnumerationHistogram, histogram, |
| 1261 ("Blink.UseCounter.Features", blink::UseCounter::NumberOfFeatures)); | 1282 ("Blink.UseCounter.Features", blink::UseCounter::NumberOfFeatures)); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1335 } | 1356 } |
| 1336 } | 1357 } |
| 1337 | 1358 |
| 1338 if (needsPagesMeasuredUpdate) | 1359 if (needsPagesMeasuredUpdate) |
| 1339 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); | 1360 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); |
| 1340 | 1361 |
| 1341 m_CSSBits.clearAll(); | 1362 m_CSSBits.clearAll(); |
| 1342 } | 1363 } |
| 1343 | 1364 |
| 1344 } // namespace blink | 1365 } // namespace blink |
| OLD | NEW |