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

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

Powered by Google App Engine
This is Rietveld 408576698