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

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 update 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 LocalFrame* frame, Feature feature) { 1185 void UseCounter::Count(const LocalFrame* 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, frame); 1192 page->GetUseCounter().Count(feature, frame);
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, const LocalFrame* source_frame) { 1266 void UseCounter::Count(WebFeature feature, const LocalFrame* source_frame) {
1264 // TODO(rbyers): Report UseCounter to browser process along with page 1267 // TODO(rbyers): Report UseCounter to browser process along with page
1265 // load metrics for sourceFrame crbug.com/716565 1268 // load metrics for sourceFrame crbug.com/716565
1266 RecordMeasurement(feature); 1269 RecordMeasurement(feature);
1267 } 1270 }
1268 1271
1269 bool UseCounter::IsCountedAnimatedCSS(CSSPropertyID unresolved_property) { 1272 bool UseCounter::IsCountedAnimatedCSS(CSSPropertyID unresolved_property) {
1270 return animated_css_recorded_.QuickGet(unresolved_property); 1273 return animated_css_recorded_.QuickGet(unresolved_property);
1271 } 1274 }
1272 1275
1273 bool UseCounter::IsCountedAnimatedCSS(Document& document, 1276 bool UseCounter::IsCountedAnimatedCSS(Document& document,
(...skipping 27 matching lines...) Expand all
1301 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property); 1304 int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property);
1302 if (context_ != kDisabledContext && context_ != kExtensionContext) { 1305 if (context_ != kDisabledContext && context_ != kExtensionContext) {
1303 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), 1306 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"),
1304 "AnimatedCSSFirstUsed", "feature", sample_id); 1307 "AnimatedCSSFirstUsed", "feature", sample_id);
1305 AnimatedCSSHistogram().Count(sample_id); 1308 AnimatedCSSHistogram().Count(sample_id);
1306 } 1309 }
1307 animated_css_recorded_.QuickSet(property); 1310 animated_css_recorded_.QuickSet(property);
1308 } 1311 }
1309 } 1312 }
1310 1313
1311 void UseCounter::NotifyFeatureCounted(Feature feature) { 1314 void UseCounter::NotifyFeatureCounted(WebFeature feature) {
1312 DCHECK(!mute_count_); 1315 DCHECK(!mute_count_);
1313 DCHECK_NE(kDisabledContext, context_); 1316 DCHECK_NE(kDisabledContext, context_);
1314 HeapHashSet<Member<Observer>> to_be_removed; 1317 HeapHashSet<Member<Observer>> to_be_removed;
1315 for (auto observer : observers_) { 1318 for (auto observer : observers_) {
1316 if (observer->OnCountFeature(feature)) 1319 if (observer->OnCountFeature(feature))
1317 to_be_removed.insert(observer); 1320 to_be_removed.insert(observer);
1318 } 1321 }
1319 observers_.RemoveAll(to_be_removed); 1322 observers_.RemoveAll(to_be_removed);
1320 } 1323 }
1321 1324
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 UseCounter::LegacyCounter::LegacyCounter() 1391 UseCounter::LegacyCounter::LegacyCounter()
1389 : feature_bits_(kNumberOfFeatures), css_bits_(numCSSPropertyIDs) {} 1392 : feature_bits_(kNumberOfFeatures), css_bits_(numCSSPropertyIDs) {}
1390 1393
1391 UseCounter::LegacyCounter::~LegacyCounter() { 1394 UseCounter::LegacyCounter::~LegacyCounter() {
1392 // PageDestruction was intended to be used as a scale, but it's broken (due to 1395 // PageDestruction was intended to be used as a scale, but it's broken (due to
1393 // fast shutdown). See https://crbug.com/597963. 1396 // fast shutdown). See https://crbug.com/597963.
1394 FeatureObserverHistogram().Count(kOBSOLETE_PageDestruction); 1397 FeatureObserverHistogram().Count(kOBSOLETE_PageDestruction);
1395 UpdateMeasurements(); 1398 UpdateMeasurements();
1396 } 1399 }
1397 1400
1398 void UseCounter::LegacyCounter::CountFeature(Feature feature) { 1401 void UseCounter::LegacyCounter::CountFeature(WebFeature feature) {
1399 feature_bits_.QuickSet(feature); 1402 feature_bits_.QuickSet(static_cast<int>(feature));
1400 } 1403 }
1401 1404
1402 void UseCounter::LegacyCounter::CountCSS(CSSPropertyID property) { 1405 void UseCounter::LegacyCounter::CountCSS(CSSPropertyID property) {
1403 css_bits_.QuickSet(property); 1406 css_bits_.QuickSet(property);
1404 } 1407 }
1405 1408
1406 void UseCounter::LegacyCounter::UpdateMeasurements() { 1409 void UseCounter::LegacyCounter::UpdateMeasurements() {
1407 EnumerationHistogram& feature_histogram = FeatureObserverHistogram(); 1410 EnumerationHistogram& feature_histogram = FeatureObserverHistogram();
1408 feature_histogram.Count(kPageVisits); 1411 feature_histogram.Count(kPageVisits);
1409 for (size_t i = 0; i < kNumberOfFeatures; ++i) { 1412 for (size_t i = 0; i < kNumberOfFeatures; ++i) {
(...skipping 19 matching lines...) Expand all
1429 } 1432 }
1430 } 1433 }
1431 1434
1432 if (needs_pages_measured_update) 1435 if (needs_pages_measured_update)
1433 css_properties_histogram.Count(totalPagesMeasuredCSSSampleId()); 1436 css_properties_histogram.Count(totalPagesMeasuredCSSSampleId());
1434 1437
1435 css_bits_.ClearAll(); 1438 css_bits_.ClearAll();
1436 } 1439 }
1437 1440
1438 } // namespace blink 1441 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/frame/UseCounter.h ('k') | third_party/WebKit/Source/core/frame/UseCounterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698