Chromium Code Reviews| Index: third_party/WebKit/Source/core/frame/UseCounter.cpp |
| diff --git a/third_party/WebKit/Source/core/frame/UseCounter.cpp b/third_party/WebKit/Source/core/frame/UseCounter.cpp |
| index 8a46a3b502c6bd5784820e808b1940f650c8e4c1..62a241d49e06746aa1bb614fd8ce8a18243ec929 100644 |
| --- a/third_party/WebKit/Source/core/frame/UseCounter.cpp |
| +++ b/third_party/WebKit/Source/core/frame/UseCounter.cpp |
| @@ -1106,7 +1106,6 @@ int UseCounter::MapCSSPropertyIdToCSSSampleIdForHistogram( |
| UseCounter::UseCounter(Context context) |
| : mute_count_(0), |
| - disable_reporting_(false), |
| context_(context), |
| features_recorded_(kNumberOfFeatures), |
| css_recorded_(numCSSPropertyIDs), |
| @@ -1132,7 +1131,7 @@ void UseCounter::RecordMeasurement(Feature feature) { |
| if (!features_recorded_.QuickGet(feature)) { |
| // Note that HTTPArchive tooling looks specifically for this event - see |
| // https://github.com/HTTPArchive/httparchive/issues/59 |
| - if (!disable_reporting_) { |
| + if (context_ != kDisabledContext) { |
| TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), |
| "FeatureFirstUsed", "feature", feature); |
| FeaturesHistogram().Count(feature); |
| @@ -1163,23 +1162,27 @@ void UseCounter::DidCommitLoad(KURL url) { |
| legacy_counter_.UpdateMeasurements(); |
| // Reset state from previous load. |
| - disable_reporting_ = false; |
| - |
| // Use the protocol of the document being loaded into the main frame to |
| // decide whether this page is interesting from a metrics perspective. |
| // Note that SVGImage cases always have an about:blank URL |
| - if (context_ == kDefaultContext && |
| - !SchemeRegistry::ShouldTrackUsageMetricsForScheme(url.Protocol())) { |
| - disable_reporting_ = true; |
| + if (context_ != kSVGImageContext) { |
| + if (url.ProtocolIs("chrome-extension")) |
| + context_ = kExtensionContext; |
| + else if (!SchemeRegistry::ShouldTrackUsageMetricsForScheme(url.Protocol())) |
|
Rick Byers
2017/04/28 15:04:40
nit: avoid the double negative by removing the '!'
lunalu1
2017/05/01 15:37:52
Done
|
| + context_ = kDisabledContext; |
| + else |
| + context_ = kDefaultContext; |
| } |
| features_recorded_.ClearAll(); |
| css_recorded_.ClearAll(); |
| animated_css_recorded_.ClearAll(); |
| - if (!disable_reporting_ && !mute_count_) { |
| + if (context_ != kDisabledContext && !mute_count_) { |
| FeaturesHistogram().Count(kPageVisits); |
| - CssHistogram().Count(totalPagesMeasuredCSSSampleId()); |
| - AnimatedCSSHistogram().Count(totalPagesMeasuredCSSSampleId()); |
| + if (context_ != kExtensionContext) { |
| + CssHistogram().Count(totalPagesMeasuredCSSSampleId()); |
| + AnimatedCSSHistogram().Count(totalPagesMeasuredCSSSampleId()); |
| + } |
| } |
| } |
| @@ -1252,7 +1255,7 @@ void UseCounter::Count(CSSParserMode css_parser_mode, CSSPropertyID property) { |
| // Note that HTTPArchive tooling looks specifically for this event - see |
| // https://github.com/HTTPArchive/httparchive/issues/59 |
| int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property); |
| - if (!disable_reporting_) { |
| + if (context_ != kDisabledContext && context_ != kExtensionContext) { |
| TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), |
| "CSSFirstUsed", "feature", sample_id); |
| CssHistogram().Count(sample_id); |
| @@ -1299,7 +1302,7 @@ void UseCounter::CountAnimatedCSS(CSSPropertyID property) { |
| if (!animated_css_recorded_.QuickGet(property)) { |
| int sample_id = MapCSSPropertyIdToCSSSampleIdForHistogram(property); |
| - if (!disable_reporting_) { |
| + if (context_ != kDisabledContext && context_ != kExtensionContext) { |
| TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("blink.feature_usage"), |
| "AnimatedCSSFirstUsed", "feature", sample_id); |
| AnimatedCSSHistogram().Count(sample_id); |
| @@ -1310,7 +1313,7 @@ void UseCounter::CountAnimatedCSS(CSSPropertyID property) { |
| void UseCounter::NotifyFeatureCounted(Feature feature) { |
| DCHECK(!mute_count_); |
| - DCHECK(!disable_reporting_); |
| + DCHECK(context_ != kDisabledContext); |
| HeapHashSet<Member<Observer>> to_be_removed; |
| for (auto observer : observers_) { |
| if (observer->OnCountFeature(feature)) |
| @@ -1320,20 +1323,30 @@ void UseCounter::NotifyFeatureCounted(Feature feature) { |
| } |
| EnumerationHistogram& UseCounter::FeaturesHistogram() const { |
| + DCHECK_NE(kDisabledContext, context_); |
| // Every SVGImage has it's own Page instance, and multiple web pages can |
| // share the usage of a single SVGImage. Ideally perhaps we'd delegate |
| // metrics from an SVGImage to one of the Page's it's displayed in, but |
| // that's tricky (SVGImage is intentionally isolated, and the Page that |
| // created it may not even exist anymore). |
| // So instead we just use a dedicated histogram for the SVG case. |
| - DEFINE_STATIC_LOCAL( |
| - blink::EnumerationHistogram, histogram, |
| - ("Blink.UseCounter.Features", blink::UseCounter::kNumberOfFeatures)); |
| DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, svg_histogram, |
| ("Blink.UseCounter.SVGImage.Features", |
| blink::UseCounter::kNumberOfFeatures)); |
| - |
| - return context_ == kSVGImageContext ? svg_histogram : histogram; |
| + DEFINE_STATIC_LOCAL(blink::EnumerationHistogram, extension_histogram, |
| + ("Blink.UseCounter.Extensions.Features", |
| + blink::UseCounter::kNumberOfFeatures)); |
| + DEFINE_STATIC_LOCAL( |
| + blink::EnumerationHistogram, histogram, |
| + ("Blink.UseCounter.Features", blink::UseCounter::kNumberOfFeatures)); |
| + switch (context_) { |
| + case kSVGImageContext: |
| + return svg_histogram; |
| + case kExtensionContext: |
| + return extension_histogram; |
| + default: |
| + return histogram; |
| + } |
| } |
| EnumerationHistogram& UseCounter::CssHistogram() const { |