1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/public/common/use_counter/use_counter_feature.h"
#include "services/network/public/mojom/permissions_policy/permissions_policy_feature.mojom-shared.h"
#include "third_party/blink/public/common/user_agent/user_agent_metadata.h"
#include "third_party/blink/public/mojom/use_counter/metrics/css_property_id.mojom-shared.h"
#include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom-shared.h"
#include "third_party/blink/public/mojom/use_counter/metrics/webdx_feature.mojom-shared.h"
namespace blink {
UseCounterFeature::UseCounterFeature(mojom::UseCounterFeatureType type,
EnumValue value)
: type_(type), value_(value) {
DCHECK(IsValid());
}
bool UseCounterFeature::SetTypeAndValue(mojom::UseCounterFeatureType type,
EnumValue value) {
type_ = type;
value_ = value;
return IsValid();
}
bool UseCounterFeature::IsValid() const {
switch (type_) {
case mojom::UseCounterFeatureType::kWebFeature:
return value_ <= static_cast<UseCounterFeature::EnumValue>(
mojom::WebFeature::kMaxValue);
case mojom::UseCounterFeatureType::kWebDXFeature:
return value_ <= static_cast<UseCounterFeature::EnumValue>(
mojom::WebDXFeature::kMaxValue);
case mojom::UseCounterFeatureType::kCssProperty:
case mojom::UseCounterFeatureType::kAnimatedCssProperty:
return value_ <= static_cast<UseCounterFeature::EnumValue>(
mojom::CSSSampleId::kMaxValue);
case mojom::UseCounterFeatureType::kPermissionsPolicyViolationEnforce:
case mojom::UseCounterFeatureType::kPermissionsPolicyHeader:
case mojom::UseCounterFeatureType::kPermissionsPolicyIframeAttribute:
case mojom::UseCounterFeatureType::
kPermissionsPolicyEnabledPrivacySensitive:
return value_ <= static_cast<UseCounterFeature::EnumValue>(
network::mojom::PermissionsPolicyFeature::kMaxValue);
}
}
bool UseCounterFeature::operator==(const UseCounterFeature& rhs) const {
return std::tie(type_, value_) == std::tie(rhs.type_, rhs.value_);
}
bool UseCounterFeature::operator<(const UseCounterFeature& rhs) const {
return std::tie(type_, value_) < std::tie(rhs.type_, rhs.value_);
}
} // namespace blink
|