Commit e9ba4b39 authored by Yutaka Hirano's avatar Yutaka Hirano Committed by Commit Bot

Move UseCounterHelper to its own file

Bug: 963306
Change-Id: If948bfa3c49f819d8c908b3f4d179882c441427a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1640919
Commit-Queue: Yutaka Hirano <yhirano@chromium.org>
Commit-Queue: Kentaro Hara <haraken@chromium.org>
Auto-Submit: Yutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665537}
parent 55300212
...@@ -1847,7 +1847,7 @@ jumbo_source_set("unit_tests") { ...@@ -1847,7 +1847,7 @@ jumbo_source_set("unit_tests") {
"frame/performance_monitor_test.cc", "frame/performance_monitor_test.cc",
"frame/root_frame_viewport_test.cc", "frame/root_frame_viewport_test.cc",
"frame/rotation_viewport_anchor_test.cc", "frame/rotation_viewport_anchor_test.cc",
"frame/use_counter_test.cc", "frame/use_counter_helper_test.cc",
"frame/visual_viewport_test.cc", "frame/visual_viewport_test.cc",
"fullscreen/scoped_allow_fullscreen_test.cc", "fullscreen/scoped_allow_fullscreen_test.cc",
"geometry/dom_matrix_test.cc", "geometry/dom_matrix_test.cc",
......
...@@ -66,7 +66,7 @@ ...@@ -66,7 +66,7 @@
#include "third_party/blink/renderer/core/execution_context/security_context.h" #include "third_party/blink/renderer/core/execution_context/security_context.h"
#include "third_party/blink/renderer/core/frame/dom_timer_coordinator.h" #include "third_party/blink/renderer/core/frame/dom_timer_coordinator.h"
#include "third_party/blink/renderer/core/frame/hosts_using_features.h" #include "third_party/blink/renderer/core/frame/hosts_using_features.h"
#include "third_party/blink/renderer/core/frame/use_counter.h" #include "third_party/blink/renderer/core/frame/use_counter_helper.h"
#include "third_party/blink/renderer/core/html/custom/v0_custom_element.h" #include "third_party/blink/renderer/core/html/custom/v0_custom_element.h"
#include "third_party/blink/renderer/core/html/parser/parser_synchronization_policy.h" #include "third_party/blink/renderer/core/html/parser/parser_synchronization_policy.h"
#include "third_party/blink/renderer/core/scroll/scroll_types.h" #include "third_party/blink/renderer/core/scroll/scroll_types.h"
......
...@@ -171,8 +171,9 @@ blink_core_sources("frame") { ...@@ -171,8 +171,9 @@ blink_core_sources("frame") {
"smart_clip.cc", "smart_clip.cc",
"smart_clip.h", "smart_clip.h",
"test_report_body.h", "test_report_body.h",
"use_counter.cc",
"use_counter.h", "use_counter.h",
"use_counter_helper.cc",
"use_counter_helper.h",
"user_activation.cc", "user_activation.cc",
"user_activation.h", "user_activation.h",
"viewport_data.cc", "viewport_data.cc",
......
...@@ -26,151 +26,6 @@ ...@@ -26,151 +26,6 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_USE_COUNTER_H_ #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_USE_COUNTER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_USE_COUNTER_H_ #define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_USE_COUNTER_H_
#include <bitset>
#include "base/macros.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/css_property_names.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_mode.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h" #include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink {
class DocumentLoader;
class Element;
class EnumerationHistogram;
class LocalFrame;
class StyleSheetContents;
// Utility class for muting UseCounter, for instance ignoring attributes
// constructed in user-agent shadow DOM. Once constructed, all UseCounting
// is muted, until the object is destroyed again. It is the callees
// responsibility to make sure this happens.
class UseCounterMuteScope {
STACK_ALLOCATED();
public:
UseCounterMuteScope(const Element& element);
~UseCounterMuteScope();
private:
Member<DocumentLoader> loader_;
};
// This class provides an implementation of UseCounter - see the class comment
// of blink::UseCounter for the feature.
// Changes on UseCounterHelper are observable by UseCounterHelper::Observer.
class CORE_EXPORT UseCounterHelper final {
DISALLOW_NEW();
public:
// The context determines whether a feature is reported to UMA histograms. For
// example, when the context is set to kDisabledContext, no features will be
// reported to UMA, but features may still be marked as seen to avoid multiple
// console warnings for deprecation.
enum Context {
kDefaultContext,
// Counters for extensions.
kExtensionContext,
// Context for file:// URLs.
kFileContext,
// Context when counters should be disabled (eg, internal pages such as
// about, devtools, etc).
kDisabledContext
};
enum CommitState { kPreCommit, kCommited };
// CSS properties for animation are separately counted. This enum is used to
// distinguish them.
enum class CSSPropertyType { kDefault, kAnimation };
explicit UseCounterHelper(Context = kDefaultContext,
CommitState = kPreCommit);
// An interface to observe UseCounterHelper changes. Note that this is never
// notified when the counter is disabled by |m_muteCount| or when |m_context|
// is kDisabledContext.
class Observer : public GarbageCollected<Observer> {
public:
// Notified when a feature is counted for the first time. This should return
// true if it no longer needs to observe changes so that the counter can
// remove a reference to the observer and stop notifications.
virtual bool OnCountFeature(WebFeature) = 0;
virtual void Trace(blink::Visitor* visitor) {}
};
// Repeated calls are ignored.
void Count(CSSPropertyID, CSSPropertyType, const LocalFrame*);
// Repeated calls are ignored.
void Count(WebFeature, const LocalFrame*);
bool IsCounted(CSSPropertyID unresolved_property, CSSPropertyType) const;
// Retains a reference to the observer to notify of UseCounterHelper changes.
void AddObserver(Observer*);
// Invoked when a new document is loaded into the main frame of the page.
void DidCommitLoad(const LocalFrame*);
// When muted, all calls to "count" functions are ignoed. May be nested.
void MuteForInspector();
void UnmuteForInspector();
void RecordMeasurement(WebFeature, const LocalFrame&);
void ReportAndTraceMeasurementByFeatureId(int, const LocalFrame&);
void ReportAndTraceMeasurementByCSSSampleId(int,
const LocalFrame*,
bool /*is_animated*/);
// Return whether the feature has been seen since the last page load
// (except when muted). Does include features seen in documents which have
// reporting disabled.
bool HasRecordedMeasurement(WebFeature) const;
void ClearMeasurementForTesting(WebFeature);
void Trace(blink::Visitor*);
private:
// Notifies that a feature is newly counted to |m_observers|. This shouldn't
// be called when the counter is disabled by |m_muteCount| or when |m_context|
// if kDisabledContext.
void NotifyFeatureCounted(WebFeature);
EnumerationHistogram& FeaturesHistogram() const;
EnumerationHistogram& CssHistogram() const;
EnumerationHistogram& AnimatedCSSHistogram() const;
static int MapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyID);
// If non-zero, ignore all 'count' calls completely.
unsigned mute_count_;
// The scope represented by this UseCounterHelper instance, which must be
// fixed for the duration of a page but can change when a new page is loaded.
Context context_;
// CommitState tracks whether navigation has commited. Prior to commit,
// UseCounters are logged locally and delivered to the browser only once the
// document has been commited (eg. to ensure never logging a feature that has
// no corresponding PageVisits).
CommitState commit_state_;
// Track what features/properties have been recorded.
std::bitset<static_cast<size_t>(WebFeature::kNumberOfFeatures)>
features_recorded_;
std::bitset<numCSSPropertyIDs> css_recorded_;
std::bitset<numCSSPropertyIDs> animated_css_recorded_;
HeapHashSet<Member<Observer>> observers_;
DISALLOW_COPY_AND_ASSIGN(UseCounterHelper);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_USE_COUNTER_H_ #endif // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_USE_COUNTER_H_
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "third_party/blink/renderer/core/frame/use_counter.h" #include "third_party/blink/renderer/core/frame/use_counter_helper.h"
#include "third_party/blink/public/mojom/use_counter/css_property_id.mojom-blink.h" #include "third_party/blink/public/mojom/use_counter/css_property_id.mojom-blink.h"
#include "third_party/blink/renderer/core/css/css_style_sheet.h" #include "third_party/blink/renderer/core/css/css_style_sheet.h"
......
/*
* Copyright (C) 2012 Google, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_USE_COUNTER_HELPER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_USE_COUNTER_HELPER_H_
#include <bitset>
#include "base/macros.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/css/css_property_names.h"
#include "third_party/blink/renderer/core/css/parser/css_parser_mode.h"
#include "third_party/blink/renderer/core/frame/web_feature.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/instrumentation/use_counter.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace blink {
class DocumentLoader;
class Element;
class EnumerationHistogram;
class LocalFrame;
// Utility class for muting UseCounter, for instance ignoring attributes
// constructed in user-agent shadow DOM. Once constructed, all UseCounting
// is muted, until the object is destroyed again. It is the callees
// responsibility to make sure this happens.
class UseCounterMuteScope {
STACK_ALLOCATED();
public:
UseCounterMuteScope(const Element& element);
~UseCounterMuteScope();
private:
Member<DocumentLoader> loader_;
};
// This class provides an implementation of UseCounter - see the class comment
// of blink::UseCounter for the feature.
// Changes on UseCounterHelper are observable by UseCounterHelper::Observer.
class CORE_EXPORT UseCounterHelper final {
DISALLOW_NEW();
public:
// The context determines whether a feature is reported to UMA histograms. For
// example, when the context is set to kDisabledContext, no features will be
// reported to UMA, but features may still be marked as seen to avoid multiple
// console warnings for deprecation.
enum Context {
kDefaultContext,
// Counters for extensions.
kExtensionContext,
// Context for file:// URLs.
kFileContext,
// Context when counters should be disabled (eg, internal pages such as
// about, devtools, etc).
kDisabledContext
};
enum CommitState { kPreCommit, kCommited };
// CSS properties for animation are separately counted. This enum is used to
// distinguish them.
enum class CSSPropertyType { kDefault, kAnimation };
explicit UseCounterHelper(Context = kDefaultContext,
CommitState = kPreCommit);
// An interface to observe UseCounterHelper changes. Note that this is never
// notified when the counter is disabled by |m_muteCount| or when |m_context|
// is kDisabledContext.
class Observer : public GarbageCollected<Observer> {
public:
// Notified when a feature is counted for the first time. This should return
// true if it no longer needs to observe changes so that the counter can
// remove a reference to the observer and stop notifications.
virtual bool OnCountFeature(WebFeature) = 0;
virtual void Trace(blink::Visitor* visitor) {}
};
// Repeated calls are ignored.
void Count(CSSPropertyID, CSSPropertyType, const LocalFrame*);
// Repeated calls are ignored.
void Count(WebFeature, const LocalFrame*);
bool IsCounted(CSSPropertyID unresolved_property, CSSPropertyType) const;
// Retains a reference to the observer to notify of UseCounterHelper changes.
void AddObserver(Observer*);
// Invoked when a new document is loaded into the main frame of the page.
void DidCommitLoad(const LocalFrame*);
// When muted, all calls to "count" functions are ignoed. May be nested.
void MuteForInspector();
void UnmuteForInspector();
void RecordMeasurement(WebFeature, const LocalFrame&);
void ReportAndTraceMeasurementByFeatureId(int, const LocalFrame&);
void ReportAndTraceMeasurementByCSSSampleId(int,
const LocalFrame*,
bool /*is_animated*/);
// Return whether the feature has been seen since the last page load
// (except when muted). Does include features seen in documents which have
// reporting disabled.
bool HasRecordedMeasurement(WebFeature) const;
void ClearMeasurementForTesting(WebFeature);
void Trace(blink::Visitor*);
private:
// Notifies that a feature is newly counted to |m_observers|. This shouldn't
// be called when the counter is disabled by |m_muteCount| or when |m_context|
// if kDisabledContext.
void NotifyFeatureCounted(WebFeature);
EnumerationHistogram& FeaturesHistogram() const;
EnumerationHistogram& CssHistogram() const;
EnumerationHistogram& AnimatedCSSHistogram() const;
static int MapCSSPropertyIdToCSSSampleIdForHistogram(CSSPropertyID);
// If non-zero, ignore all 'count' calls completely.
unsigned mute_count_;
// The scope represented by this UseCounterHelper instance, which must be
// fixed for the duration of a page but can change when a new page is loaded.
Context context_;
// CommitState tracks whether navigation has commited. Prior to commit,
// UseCounters are logged locally and delivered to the browser only once the
// document has been commited (eg. to ensure never logging a feature that has
// no corresponding PageVisits).
CommitState commit_state_;
// Track what features/properties have been recorded.
std::bitset<static_cast<size_t>(WebFeature::kNumberOfFeatures)>
features_recorded_;
std::bitset<numCSSPropertyIDs> css_recorded_;
std::bitset<numCSSPropertyIDs> animated_css_recorded_;
HeapHashSet<Member<Observer>> observers_;
DISALLOW_COPY_AND_ASSIGN(UseCounterHelper);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_USE_COUNTER_HELPER_H_
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "third_party/blink/renderer/core/frame/use_counter.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/mojom/use_counter/css_property_id.mojom-blink.h" #include "third_party/blink/public/mojom/use_counter/css_property_id.mojom-blink.h"
#include "third_party/blink/renderer/core/dom/shadow_root.h" #include "third_party/blink/renderer/core/dom/shadow_root.h"
#include "third_party/blink/renderer/core/frame/deprecation.h" #include "third_party/blink/renderer/core/frame/deprecation.h"
#include "third_party/blink/renderer/core/frame/use_counter.h"
#include "third_party/blink/renderer/core/html/html_html_element.h" #include "third_party/blink/renderer/core/html/html_html_element.h"
#include "third_party/blink/renderer/core/loader/document_loader.h" #include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/page/page.h"
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "third_party/blink/renderer/core/frame/dactyloscoper.h" #include "third_party/blink/renderer/core/frame/dactyloscoper.h"
#include "third_party/blink/renderer/core/frame/frame_types.h" #include "third_party/blink/renderer/core/frame/frame_types.h"
#include "third_party/blink/renderer/core/frame/use_counter.h" #include "third_party/blink/renderer/core/frame/use_counter.h"
#include "third_party/blink/renderer/core/frame/use_counter_helper.h"
#include "third_party/blink/renderer/core/html/parser/parser_synchronization_policy.h" #include "third_party/blink/renderer/core/html/parser/parser_synchronization_policy.h"
#include "third_party/blink/renderer/core/loader/document_load_timing.h" #include "third_party/blink/renderer/core/loader/document_load_timing.h"
#include "third_party/blink/renderer/core/loader/frame_loader_types.h" #include "third_party/blink/renderer/core/loader/frame_loader_types.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment