Commit 66d2c586 authored by Taylor Brandstetter's avatar Taylor Brandstetter Committed by Commit Bot

Filter out any non-standard WebRTC stats members.

Instead of using a whitelist, which is how non-standard stats objects
are being filtered out, this uses an "is_standardized" method on
RTCStatsMemberInterface.

This will allow us to easily add non-standard stats to WebRTC (or mark
previously non-standardized stats as standardized) without needing to
update chromium as well every time.

Follow up to:
https://webrtc-review.googlesource.com/c/src/+/83743

Bug: webrtc:9410
Change-Id: Idd349fedf30aa15db7c6e101115a1171aef33b4f
Reviewed-on: https://chromium-review.googlesource.com/1121319Reviewed-by: default avatarHenrik Boström <hbos@chromium.org>
Commit-Queue: Henrik Boström <hbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571861}
parent e0e9e4b0
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "content/renderer/media/webrtc/rtc_stats.h" #include "content/renderer/media/webrtc/rtc_stats.h"
#include <algorithm>
#include <set> #include <set>
#include <string> #include <string>
...@@ -57,6 +58,22 @@ bool IsWhitelistedStats(const webrtc::RTCStats& stats) { ...@@ -57,6 +58,22 @@ bool IsWhitelistedStats(const webrtc::RTCStats& stats) {
return GetStatsWhitelist()->IsWhitelisted(stats); return GetStatsWhitelist()->IsWhitelisted(stats);
} }
// Filters out any unstandardized members; stats should only be surfaced to JS
// if they're standardized.
std::vector<const webrtc::RTCStatsMemberInterface*> StandardizedMembers(
std::vector<const webrtc::RTCStatsMemberInterface*> stats_members) {
// Note that using "is_standarized" avoids having to maintain a whitelist of
// every single standardized member, as we do at the "stats object" level
// with "RTCStatsWhitelist".
stats_members.erase(
std::remove_if(stats_members.begin(), stats_members.end(),
[](const webrtc::RTCStatsMemberInterface* member) {
return !member->is_standardized();
}),
stats_members.end());
return stats_members;
}
} // namespace } // namespace
RTCStatsReport::RTCStatsReport( RTCStatsReport::RTCStatsReport(
...@@ -105,7 +122,7 @@ RTCStats::RTCStats( ...@@ -105,7 +122,7 @@ RTCStats::RTCStats(
const webrtc::RTCStats* stats) const webrtc::RTCStats* stats)
: stats_owner_(stats_owner), : stats_owner_(stats_owner),
stats_(stats), stats_(stats),
stats_members_(stats->Members()) { stats_members_(StandardizedMembers(stats->Members())) {
DCHECK(stats_owner_); DCHECK(stats_owner_);
DCHECK(stats_); DCHECK(stats_);
DCHECK(stats_owner_->Get(stats_->id())); DCHECK(stats_owner_->Get(stats_->id()));
......
...@@ -15,6 +15,9 @@ ...@@ -15,6 +15,9 @@
namespace content { namespace content {
// Wrapper around a webrtc::RTCStatsReport that also filters out any stats
// objects that aren't whitelisted, and any members that aren't standardized
// (using RTCStatsMemberInterface::is_standardized).
class CONTENT_EXPORT RTCStatsReport : public blink::WebRTCStatsReport { class CONTENT_EXPORT RTCStatsReport : public blink::WebRTCStatsReport {
public: public:
RTCStatsReport( RTCStatsReport(
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// 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 <memory>
#include "content/renderer/media/webrtc/rtc_stats.h" #include "content/renderer/media/webrtc/rtc_stats.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -45,4 +47,47 @@ TEST(RTCStatsTest, OnlyIncludeWhitelistedStats_Iteration) { ...@@ -45,4 +47,47 @@ TEST(RTCStatsTest, OnlyIncludeWhitelistedStats_Iteration) {
EXPECT_FALSE(report.Next()); EXPECT_FALSE(report.Next());
} }
// Stats object with both a standard and non-standard member, used for the test
// below.
namespace {
class TestStats : public webrtc::RTCStats {
public:
WEBRTC_RTCSTATS_DECL();
TestStats(const std::string& id, int64_t timestamp_us);
~TestStats() override = default;
webrtc::RTCStatsMember<int32_t> standardized;
webrtc::RTCNonStandardStatsMember<int32_t> non_standardized;
};
WEBRTC_RTCSTATS_IMPL(TestStats,
webrtc::RTCStats,
"teststats",
&standardized,
&non_standardized);
TestStats::TestStats(const std::string& id, int64_t timestamp_us)
: RTCStats(id, timestamp_us),
standardized("standardized"),
non_standardized("non_standardized") {}
} // namespace
// Similar to how only whitelisted stats objects should be surfaced, only
// standardized members of the whitelisted objects should be surfaced.
TEST(RTCStatsTest, OnlyIncludeStandarizedMembers) {
rtc::scoped_refptr<webrtc::RTCStatsReport> webrtc_report =
webrtc::RTCStatsReport::Create(42);
WhitelistStatsForTesting(TestStats::kType);
webrtc_report->AddStats(std::make_unique<TestStats>("id", 0));
// TestStats has two members, but the non-standard member should be filtered
// out.
RTCStatsReport report(webrtc_report.get());
std::unique_ptr<blink::WebRTCStats> stats = report.Next();
ASSERT_NE(nullptr, stats);
ASSERT_EQ(1u, stats->MembersCount());
EXPECT_EQ("standardized", stats->GetMember(0)->GetName());
}
} // namespace content } // namespace content
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