Implement RTCNonStandardStatsMember using StatExposureCriteria

Adds a new StatExposureCriteria for non-standard stats. This removes the
virtual call to is_standardized() which can simply use the
StatExposureCriteria.

Bug: webrtc:14546
Change-Id: If4174019ff8cc6559ab0dc9a04e0f8a6631b9842
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/279045
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@webrtc.org>
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39057}
This commit is contained in:
Evan Shrubsole 2022-10-31 11:05:33 +00:00 committed by WebRTC LUCI CQ
parent d7956891d0
commit 7ef0c1aff5

View File

@ -229,6 +229,8 @@ enum class StatExposureCriteria : uint8_t {
// to JavaScript. The requirements for exposure are written in the spec at
// https://w3c.github.io/webrtc-stats/#limiting-exposure-of-hardware-capabilities.
kHardwareCapability,
// The stat is non-standard so user agents should filter these.
kNonStandard,
};
// Interface for `RTCStats` members, which have a name and a value of a type
@ -268,7 +270,9 @@ class RTCStatsMemberInterface {
virtual bool is_defined() const = 0;
// Is this part of the stats spec? Used so that chromium can easily filter
// out anything unstandardized.
virtual bool is_standardized() const = 0;
bool is_standardized() const {
return exposure_criteria() != StatExposureCriteria::kNonStandard;
}
// Non-standard stats members can have group IDs in order to be exposed in
// JavaScript through experiments. Standardized stats have no group IDs.
virtual std::vector<NonStandardGroupId> group_ids() const { return {}; }
@ -330,7 +334,6 @@ class RTCStatsMember : public RTCStatsMemberInterface {
bool is_sequence() const override;
bool is_string() const override;
bool is_defined() const override { return value_.has_value(); }
bool is_standardized() const override { return true; }
std::string ValueToString() const override;
std::string ValueToJson() const override;
@ -500,35 +503,40 @@ extern template class RTC_EXPORT_TEMPLATE_DECLARE(RTC_EXPORT)
// Using inheritance just so that it's obvious from the member's declaration
// whether it's standardized or not.
template <typename T>
class RTCNonStandardStatsMember : public RTCStatsMember<T> {
class RTCNonStandardStatsMember
: public RTCRestrictedStatsMember<T, StatExposureCriteria::kNonStandard> {
public:
explicit RTCNonStandardStatsMember(const char* name)
: RTCStatsMember<T>(name) {}
: RTCRestrictedStatsBase(name) {}
RTCNonStandardStatsMember(const char* name,
std::initializer_list<NonStandardGroupId> group_ids)
: RTCStatsMember<T>(name), group_ids_(group_ids) {}
: RTCRestrictedStatsBase(name), group_ids_(group_ids) {}
RTCNonStandardStatsMember(const char* name, const T& value)
: RTCStatsMember<T>(name, value) {}
: RTCRestrictedStatsBase(name, value) {}
RTCNonStandardStatsMember(const char* name, T&& value)
: RTCStatsMember<T>(name, std::move(value)) {}
explicit RTCNonStandardStatsMember(const RTCNonStandardStatsMember<T>& other)
: RTCStatsMember<T>(other), group_ids_(other.group_ids_) {}
explicit RTCNonStandardStatsMember(RTCNonStandardStatsMember<T>&& other)
: RTCStatsMember<T>(std::move(other)),
: RTCRestrictedStatsBase(name, std::move(value)) {}
RTCNonStandardStatsMember(const RTCNonStandardStatsMember<T>& other)
: RTCRestrictedStatsBase(other), group_ids_(other.group_ids_) {}
RTCNonStandardStatsMember(RTCNonStandardStatsMember<T>&& other)
: RTCRestrictedStatsBase(std::move(other)),
group_ids_(std::move(other.group_ids_)) {}
bool is_standardized() const override { return false; }
std::vector<NonStandardGroupId> group_ids() const override {
return group_ids_;
}
T& operator=(const T& value) { return RTCStatsMember<T>::operator=(value); }
T& operator=(const T& value) {
return RTCRestrictedStatsMember<
T, StatExposureCriteria::kNonStandard>::operator=(value);
}
T& operator=(const T&& value) {
return RTCStatsMember<T>::operator=(std::move(value));
return RTCRestrictedStatsMember<
T, StatExposureCriteria::kNonStandard>::operator=(std::move(value));
}
private:
using RTCRestrictedStatsBase =
RTCRestrictedStatsMember<T, StatExposureCriteria::kNonStandard>;
std::vector<NonStandardGroupId> group_ids_;
};