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(Document& document, Observer* observer) { | |
Rick Byers
2017/02/13 20:46:31
nit: IMHO this would make more sense as an instanc
nhiroki
2017/02/14 02:03:29
There is no special reason. I just aligned it with
| |
1202 Frame* frame = document.frame(); | |
1203 if (!frame) | |
1204 return; | |
1205 FrameHost* host = frame->host(); | |
1206 if (!host) | |
1207 return; | |
1208 host->useCounter().m_observers.insert(observer); | |
1209 } | |
1210 | |
1196 bool UseCounter::isCounted(Document& document, const String& string) { | 1211 bool UseCounter::isCounted(Document& document, const String& string) { |
1197 Frame* frame = document.frame(); | 1212 Frame* frame = document.frame(); |
1198 if (!frame) | 1213 if (!frame) |
1199 return false; | 1214 return false; |
1200 FrameHost* host = frame->host(); | 1215 FrameHost* host = frame->host(); |
1201 if (!host) | 1216 if (!host) |
1202 return false; | 1217 return false; |
1203 | 1218 |
1204 CSSPropertyID unresolvedProperty = unresolvedCSSPropertyID(string); | 1219 CSSPropertyID unresolvedProperty = unresolvedCSSPropertyID(string); |
1205 if (unresolvedProperty == CSSPropertyInvalid) | 1220 if (unresolvedProperty == CSSPropertyInvalid) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1242 } | 1257 } |
1243 m_CSSRecorded.quickSet(property); | 1258 m_CSSRecorded.quickSet(property); |
1244 } | 1259 } |
1245 m_legacyCounter.countCSS(property); | 1260 m_legacyCounter.countCSS(property); |
1246 } | 1261 } |
1247 | 1262 |
1248 void UseCounter::count(Feature feature) { | 1263 void UseCounter::count(Feature feature) { |
1249 recordMeasurement(feature); | 1264 recordMeasurement(feature); |
1250 } | 1265 } |
1251 | 1266 |
1267 void UseCounter::notifyFeatureCounted(Feature feature) { | |
1268 DCHECK(!m_muteCount); | |
1269 DCHECK(!m_disableReporting); | |
1270 HeapHashSet<Member<Observer>> toBeRemoved; | |
1271 for (auto observer : m_observers) { | |
1272 if (observer->onCountFeature(feature)) | |
1273 toBeRemoved.insert(observer); | |
1274 } | |
1275 m_observers.removeAll(toBeRemoved); | |
1276 } | |
1277 | |
1252 EnumerationHistogram& UseCounter::featuresHistogram() const { | 1278 EnumerationHistogram& UseCounter::featuresHistogram() const { |
1253 // Every SVGImage has it's own Page instance, and multiple web pages can | 1279 // 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 | 1280 // 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 | 1281 // 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 | 1282 // that's tricky (SVGImage is intentionally isolated, and the Page that |
1257 // created it may not even exist anymore). | 1283 // created it may not even exist anymore). |
1258 // So instead we just use a dedicated histogram for the SVG case. | 1284 // So instead we just use a dedicated histogram for the SVG case. |
1259 DEFINE_STATIC_LOCAL( | 1285 DEFINE_STATIC_LOCAL( |
1260 blink::EnumerationHistogram, histogram, | 1286 blink::EnumerationHistogram, histogram, |
1261 ("Blink.UseCounter.Features", blink::UseCounter::NumberOfFeatures)); | 1287 ("Blink.UseCounter.Features", blink::UseCounter::NumberOfFeatures)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1335 } | 1361 } |
1336 } | 1362 } |
1337 | 1363 |
1338 if (needsPagesMeasuredUpdate) | 1364 if (needsPagesMeasuredUpdate) |
1339 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); | 1365 cssPropertiesHistogram.count(totalPagesMeasuredCSSSampleId()); |
1340 | 1366 |
1341 m_CSSBits.clearAll(); | 1367 m_CSSBits.clearAll(); |
1342 } | 1368 } |
1343 | 1369 |
1344 } // namespace blink | 1370 } // namespace blink |
OLD | NEW |