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

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

Issue 2894063002: Expose UseCounter::Feature enum out of blink as WebFeature (Closed)
Patch Set: Rebase Created 3 years, 6 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 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 animated_css_recorded_(numCSSPropertyIDs) {} 1107 animated_css_recorded_(numCSSPropertyIDs) {}
1108 1108
1109 void UseCounter::MuteForInspector() { 1109 void UseCounter::MuteForInspector() {
1110 mute_count_++; 1110 mute_count_++;
1111 } 1111 }
1112 1112
1113 void UseCounter::UnmuteForInspector() { 1113 void UseCounter::UnmuteForInspector() {
1114 mute_count_--; 1114 mute_count_--;
1115 } 1115 }
1116 1116
1117 void UseCounter::RecordMeasurement(Feature feature) { 1117 void UseCounter::RecordMeasurement(WebFeature feature) {
1118 if (mute_count_) 1118 if (mute_count_)
1119 return; 1119 return;
1120 1120
1121 // PageDestruction is reserved as a scaling factor. 1121 // PageDestruction is reserved as a scaling factor.
1122 DCHECK_NE(kOBSOLETE_PageDestruction, feature); 1122 DCHECK_NE(WebFeature::kOBSOLETE_PageDestruction, feature);
1123 DCHECK_NE(kPageVisits, feature); 1123 DCHECK_NE(WebFeature::kPageVisits, feature);
1124 DCHECK_GE(kNumberOfFeatures, feature); 1124 DCHECK_GE(WebFeature::kNumberOfFeatures, feature);
1125 1125
1126 if (!features_recorded_.QuickGet(feature)) { 1126 int feature_id = static_cast<int>(feature);
1127 if (!features_recorded_.QuickGet(feature_id)) {
1127 // Note that HTTPArchive tooling looks specifically for this event - see 1128 // Note that HTTPArchive tooling looks specifically for this event - see
1128 // https://github.com/HTTPArchive/httparchive/issues/59 1129 // https://github.com/HTTPArchive/httparchive/issues/59
1129 if (context_ != kDisabledContext) { 1130 if (context_ != kDisabledContext) {
1130 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), 1131 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"),
1131 "FeatureFirstUsed", "feature", feature); 1132 "FeatureFirstUsed", "feature", feature_id);
1132 FeaturesHistogram().Count(feature); 1133 FeaturesHistogram().Count(feature_id);
1133 NotifyFeatureCounted(feature); 1134 NotifyFeatureCounted(feature);
1134 } 1135 }
1135 features_recorded_.QuickSet(feature); 1136 features_recorded_.QuickSet(feature_id);
1136 } 1137 }
1137 legacy_counter_.CountFeature(feature); 1138 legacy_counter_.CountFeature(feature);
1138 } 1139 }
1139 1140
1140 bool UseCounter::HasRecordedMeasurement(Feature feature) const { 1141 bool UseCounter::HasRecordedMeasurement(WebFeature feature) const {
1141 if (mute_count_) 1142 if (mute_count_)
1142 return false; 1143 return false;
1143 1144
1144 // PageDestruction is reserved as a scaling factor. 1145 // PageDestruction is reserved as a scaling factor.
1145 DCHECK_NE(kOBSOLETE_PageDestruction, feature); 1146 DCHECK_NE(WebFeature::kOBSOLETE_PageDestruction, feature);
1146 DCHECK_NE(kPageVisits, feature); 1147 DCHECK_NE(WebFeature::kPageVisits, feature);
1147 DCHECK_GE(kNumberOfFeatures, feature); 1148 DCHECK_GE(WebFeature::kNumberOfFeatures, feature);
1148 1149
1149 return features_recorded_.QuickGet(feature); 1150 return features_recorded_.QuickGet(static_cast<int>(feature));
1150 } 1151 }
1151 1152
1152 DEFINE_TRACE(UseCounter) { 1153 DEFINE_TRACE(UseCounter) {
1153 visitor->Trace(observers_); 1154 visitor->Trace(observers_);
1154 } 1155 }
1155 1156
1156 void UseCounter::DidCommitLoad(KURL url) { 1157 void UseCounter::DidCommitLoad(KURL url) {
1157 legacy_counter_.UpdateMeasurements(); 1158 legacy_counter_.UpdateMeasurements();
1158 1159
1159 // Reset state from previous load. 1160 // Reset state from previous load.
(...skipping 14 matching lines...) Expand all
1174 animated_css_recorded_.ClearAll(); 1175 animated_css_recorded_.ClearAll();
1175 if (context_ != kDisabledContext && !mute_count_) { 1176 if (context_ != kDisabledContext && !mute_count_) {
1176 FeaturesHistogram().Count(kPageVisits); 1177 FeaturesHistogram().Count(kPageVisits);
1177 if (context_ != kExtensionContext) { 1178 if (context_ != kExtensionContext) {
1178 CssHistogram().Count(totalPagesMeasuredCSSSampleId()); 1179 CssHistogram().Count(totalPagesMeasuredCSSSampleId());
1179 AnimatedCSSHistogram().Count(totalPagesMeasuredCSSSampleId()); 1180 AnimatedCSSHistogram().Count(totalPagesMeasuredCSSSampleId());
1180 } 1181 }
1181 } 1182 }
1182 } 1183 }
1183 1184
1184 void UseCounter::Count(const Frame* frame, Feature feature) { 1185 void UseCounter::Count(const Frame* frame, WebFeature feature) {
1185 if (!frame) 1186 if (!frame)
1186 return; 1187 return;
1187 Page* page = frame->GetPage(); 1188 Page* page = frame->GetPage();
1188 if (!page) 1189 if (!page)
1189 return; 1190 return;
1190 1191
1191 page->GetUseCounter().Count(feature); 1192 page->GetUseCounter().Count(feature);
1192 } 1193 }
1193 1194
1194 void UseCounter::Count(const Document& document, Feature feature) { 1195 void UseCounter::Count(const Document& document, WebFeature feature) {
1195 Count(document.GetFrame(), feature); 1196 Count(document.GetFrame(), feature);
1196 } 1197 }
1197 1198
1198 bool UseCounter::IsCounted(Document& document, Feature feature) { 1199 bool UseCounter::IsCounted(Document& document, Feature feature) {
1199 Page* page = document.GetPage(); 1200 Page* page = document.GetPage();
1200 if (!page) 1201 if (!page)
1201 return false; 1202 return false;
1202 return page->GetUseCounter().HasRecordedMeasurement(feature); 1203 return page->GetUseCounter().HasRecordedMeasurement(feature);
1203 } 1204 }
1204 1205
(...skipping 10 matching lines...) Expand all
1215 Page* page = document.GetPage(); 1216 Page* page = document.GetPage();
1216 if (!page) 1217 if (!page)
1217 return false; 1218 return false;
1218 1219
1219 CSSPropertyID unresolved_property = unresolvedCSSPropertyID(string); 1220 CSSPropertyID unresolved_property = unresolvedCSSPropertyID(string);
1220 if (unresolved_property == CSSPropertyInvalid) 1221 if (unresolved_property == CSSPropertyInvalid)
1221 return false; 1222 return false;
1222 return page->GetUseCounter().IsCounted(unresolved_property); 1223 return page->GetUseCounter().IsCounted(unresolved_property);
1223 } 1224 }
1224 1225
1225 void UseCounter::Count(ExecutionContext* context, Feature feature) { 1226 void UseCounter::Count(ExecutionContext* context, WebFeature feature) {
1226 if (!context) 1227 if (!context)
1227 return; 1228 return;
1228 if (context->IsDocument()) { 1229 if (context->IsDocument()) {
1229 Count(*ToDocument(context), feature); 1230 Count(*ToDocument(context), feature);
1230 return; 1231 return;
1231 } 1232 }
1232 if (context->IsWorkerOrWorkletGlobalScope()) 1233 if (context->IsWorkerOrWorkletGlobalScope()) {
1233 ToWorkerOrWorkletGlobalScope(context)->CountFeature(feature); 1234 ToWorkerOrWorkletGlobalScope(context)->CountFeature(
1235 static_cast<Feature>(feature));
1236 }
1234 } 1237 }
1235 1238
1236 void UseCounter::CountCrossOriginIframe(const Document& document, 1239 void UseCounter::CountCrossOriginIframe(const Document& document,
1237 Feature feature) { 1240 Feature feature) {
1238 LocalFrame* frame = document.GetFrame(); 1241 LocalFrame* frame = document.GetFrame();
1239 if (frame && frame->IsCrossOriginSubframe()) 1242 if (frame && frame->IsCrossOriginSubframe())
1240 Count(frame, feature); 1243 Count(frame, feature);
1241 } 1244 }
1242 1245
1243 void UseCounter::Count(CSSParserMode css_parser_mode, CSSPropertyID property) { 1246 void UseCounter::Count(CSSParserMode css_parser_mode, CSSPropertyID property) {
1244 DCHECK(isCSSPropertyIDWithName(property) || property == CSSPropertyVariable); 1247 DCHECK(isCSSPropertyIDWithName(property) || property == CSSPropertyVariable);
1245 1248
1246 if (!IsUseCounterEnabledForMode(css_parser_mode) || mute_count_) 1249 if (!IsUseCounterEnabledForMode(css_parser_mode) || mute_count_)
1247 return; 1250 return;
1248 1251
1249 if (!css_recorded_.QuickGet(property)) { 1252 if (!css_recorded_.QuickGet(property)) {
1250 // Note that HTTPArchive tooling looks specifically for this event - see 1253 // Note that HTTPArchive tooling looks specifically for this event - see
1251 // https://github.com/HTTPArchive/httparchive/issues/59 1254 // https://github.com/HTTPArchive/httparchive/issues/59
1252 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property); 1255 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property);
1253 if (context_ != kDisabledContext && context_ != kExtensionContext) { 1256 if (context_ != kDisabledContext && context_ != kExtensionContext) {
1254 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), 1257 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"),
1255 "CSSFirstUsed", "feature", sample_id); 1258 "CSSFirstUsed", "feature", sample_id);
1256 CssHistogram().Count(sample_id); 1259 CssHistogram().Count(sample_id);
1257 } 1260 }
1258 css_recorded_.QuickSet(property); 1261 css_recorded_.QuickSet(property);
1259 } 1262 }
1260 legacy_counter_.CountCSS(property); 1263 legacy_counter_.CountCSS(property);
1261 } 1264 }
1262 1265
1263 void UseCounter::Count(Feature feature) { 1266 void UseCounter::Count(WebFeature feature) {
1264 RecordMeasurement(feature); 1267 RecordMeasurement(feature);
1265 } 1268 }
1266 1269
1267 bool UseCounter::IsCountedAnimatedCSS(CSSPropertyID unresolved_property) { 1270 bool UseCounter::IsCountedAnimatedCSS(CSSPropertyID unresolved_property) {
1268 return animated_css_recorded_.QuickGet(unresolved_property); 1271 return animated_css_recorded_.QuickGet(unresolved_property);
1269 } 1272 }
1270 1273
1271 bool UseCounter::IsCountedAnimatedCSS(Document& document, 1274 bool UseCounter::IsCountedAnimatedCSS(Document& document,
1272 const String& string) { 1275 const String& string) {
1273 Page* page = document.GetPage(); 1276 Page* page = document.GetPage();
(...skipping 25 matching lines...) Expand all
1299 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property); 1302 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property);
1300 if (context_ != kDisabledContext && context_ != kExtensionContext) { 1303 if (context_ != kDisabledContext && context_ != kExtensionContext) {
1301 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), 1304 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"),
1302 "AnimatedCSSFirstUsed", "feature", sample_id); 1305 "AnimatedCSSFirstUsed", "feature", sample_id);
1303 AnimatedCSSHistogram().Count(sample_id); 1306 AnimatedCSSHistogram().Count(sample_id);
1304 } 1307 }
1305 animated_css_recorded_.QuickSet(property); 1308 animated_css_recorded_.QuickSet(property);
1306 } 1309 }
1307 } 1310 }
1308 1311
1309 void UseCounter::NotifyFeatureCounted(Feature feature) { 1312 void UseCounter::NotifyFeatureCounted(WebFeature feature) {
1310 DCHECK(!mute_count_); 1313 DCHECK(!mute_count_);
1311 DCHECK_NE(kDisabledContext, context_); 1314 DCHECK_NE(kDisabledContext, context_);
1312 HeapHashSet<Member<Observer>> to_be_removed; 1315 HeapHashSet<Member<Observer>> to_be_removed;
1313 for (auto observer : observers_) { 1316 for (auto observer : observers_) {
1314 if (observer->OnCountFeature(feature)) 1317 if (observer->OnCountFeature(feature))
1315 to_be_removed.insert(observer); 1318 to_be_removed.insert(observer);
1316 } 1319 }
1317 observers_.RemoveAll(to_be_removed); 1320 observers_.RemoveAll(to_be_removed);
1318 } 1321 }
1319 1322
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1386 UseCounter::LegacyCounter::LegacyCounter() 1389 UseCounter::LegacyCounter::LegacyCounter()
1387 : feature_bits_(kNumberOfFeatures), css_bits_(numCSSPropertyIDs) {} 1390 : feature_bits_(kNumberOfFeatures), css_bits_(numCSSPropertyIDs) {}
1388 1391
1389 UseCounter::LegacyCounter::~LegacyCounter() { 1392 UseCounter::LegacyCounter::~LegacyCounter() {
1390 // PageDestruction was intended to be used as a scale, but it's broken (due to 1393 // PageDestruction was intended to be used as a scale, but it's broken (due to
1391 // fast shutdown). See https://crbug.com/597963. 1394 // fast shutdown). See https://crbug.com/597963.
1392 FeatureObserverHistogram().Count(kOBSOLETE_PageDestruction); 1395 FeatureObserverHistogram().Count(kOBSOLETE_PageDestruction);
1393 UpdateMeasurements(); 1396 UpdateMeasurements();
1394 } 1397 }
1395 1398
1396 void UseCounter::LegacyCounter::CountFeature(Feature feature) { 1399 void UseCounter::LegacyCounter::CountFeature(WebFeature feature) {
1397 feature_bits_.QuickSet(feature); 1400 feature_bits_.QuickSet(static_cast<int>(feature));
1398 } 1401 }
1399 1402
1400 void UseCounter::LegacyCounter::CountCSS(CSSPropertyID property) { 1403 void UseCounter::LegacyCounter::CountCSS(CSSPropertyID property) {
1401 css_bits_.QuickSet(property); 1404 css_bits_.QuickSet(property);
1402 } 1405 }
1403 1406
1404 void UseCounter::LegacyCounter::UpdateMeasurements() { 1407 void UseCounter::LegacyCounter::UpdateMeasurements() {
1405 EnumerationHistogram& feature_histogram = FeatureObserverHistogram(); 1408 EnumerationHistogram& feature_histogram = FeatureObserverHistogram();
1406 feature_histogram.Count(kPageVisits); 1409 feature_histogram.Count(kPageVisits);
1407 for (size_t i = 0; i < kNumberOfFeatures; ++i) { 1410 for (size_t i = 0; i < kNumberOfFeatures; ++i) {
(...skipping 19 matching lines...) Expand all
1427 } 1430 }
1428 } 1431 }
1429 1432
1430 if (needs_pages_measured_update) 1433 if (needs_pages_measured_update)
1431 css_properties_histogram.Count(totalPagesMeasuredCSSSampleId()); 1434 css_properties_histogram.Count(totalPagesMeasuredCSSSampleId());
1432 1435
1433 css_bits_.ClearAll(); 1436 css_bits_.ClearAll();
1434 } 1437 }
1435 1438
1436 } // namespace blink 1439 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698