Commit 108c8869 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Replace uses of WebRTCStats by RTCStats

The replacement is now possible that all users are in Blink.
Essentially, the former is a pure interface for the later.

As a follow up step the use of WebString will be replace by
WTF::String.

BUG=787254, 919392
R=guidou@chromium.org, haraken@chromium.org

Change-Id: I921d2351533f54f00c3dd1b19d20a1b6f7a2a3f9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1902445
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713841}
parent f4b5512c
......@@ -18,7 +18,6 @@ class SingleThreadTaskRunner;
}
namespace webrtc {
class RTCStats;
class RTCStatsCollectorCallback;
class RTCStatsMemberInterface;
class RTCStatsReport;
......@@ -27,28 +26,9 @@ enum class NonStandardGroupId;
namespace blink {
class WebRTCStats;
class WebRTCStatsMember;
class RTCStatsReportPlatform;
class BLINK_PLATFORM_EXPORT WebRTCStats {
public:
virtual ~WebRTCStats();
virtual WebString Id() const = 0;
virtual WebString GetType() const = 0;
virtual double Timestamp() const = 0;
virtual size_t MembersCount() const = 0;
virtual std::unique_ptr<WebRTCStatsMember> GetMember(size_t) const = 0;
};
BLINK_PLATFORM_EXPORT
std::unique_ptr<WebRTCStats> CreateRTCStats(
const scoped_refptr<const webrtc::RTCStatsReport>& stats_owner,
const webrtc::RTCStats* stats,
const WebVector<webrtc::NonStandardGroupId>& exposed_group_ids);
class BLINK_PLATFORM_EXPORT WebRTCStatsMember {
public:
virtual ~WebRTCStatsMember();
......
......@@ -928,7 +928,7 @@ TEST_F(RTCPeerConnectionHandlerTest, GetRTCStats) {
int undefined_stats_count = 0;
int defined_stats_count = 0;
for (std::unique_ptr<blink::WebRTCStats> stats = result->Next(); stats;
for (std::unique_ptr<RTCStats> stats = result->Next(); stats;
stats.reset(result->Next().release())) {
EXPECT_EQ(stats->GetType().Utf8(), webrtc::RTCTestStats::kType);
if (stats->Id().Utf8() == "RTCUndefinedStats") {
......
......@@ -15,8 +15,8 @@ namespace blink {
namespace {
v8::Local<v8::Value> WebRTCStatsToValue(ScriptState* script_state,
const WebRTCStats* stats) {
v8::Local<v8::Value> RTCStatsToValue(ScriptState* script_state,
const RTCStats* stats) {
V8ObjectBuilder builder(script_state);
builder.AddString("id", stats->Id());
......@@ -105,11 +105,11 @@ class RTCStatsReportIterationSource final
String& key,
v8::Local<v8::Value>& value,
ExceptionState& exception_state) override {
std::unique_ptr<WebRTCStats> stats = report_->Next();
std::unique_ptr<RTCStats> stats = report_->Next();
if (!stats)
return false;
key = stats->Id();
value = WebRTCStatsToValue(script_state, stats.get());
value = RTCStatsToValue(script_state, stats.get());
return true;
}
......@@ -153,10 +153,10 @@ bool RTCStatsReport::GetMapEntry(ScriptState* script_state,
const String& key,
v8::Local<v8::Value>& value,
ExceptionState&) {
std::unique_ptr<WebRTCStats> stats = report_->GetStats(key);
std::unique_ptr<RTCStats> stats = report_->GetStats(key);
if (!stats)
return false;
value = WebRTCStatsToValue(script_state, stats.get());
value = RTCStatsToValue(script_state, stats.get());
return true;
}
......
......@@ -6,8 +6,6 @@
namespace blink {
WebRTCStats::~WebRTCStats() = default;
WebRTCStatsMember::~WebRTCStatsMember() = default;
} // namespace blink
......@@ -137,36 +137,30 @@ std::unique_ptr<RTCStatsReportPlatform> RTCStatsReportPlatform::CopyHandle()
exposed_group_ids_);
}
std::unique_ptr<blink::WebRTCStats> RTCStatsReportPlatform::GetStats(
std::unique_ptr<RTCStats> RTCStatsReportPlatform::GetStats(
blink::WebString id) const {
const webrtc::RTCStats* stats = stats_report_->Get(id.Utf8());
if (!stats || !IsWhitelistedStats(*stats))
return std::unique_ptr<blink::WebRTCStats>();
return CreateRTCStats(stats_report_, stats, exposed_group_ids_);
return std::unique_ptr<RTCStats>();
return std::make_unique<RTCStats>(stats_report_, stats, exposed_group_ids_);
}
std::unique_ptr<blink::WebRTCStats> RTCStatsReportPlatform::Next() {
std::unique_ptr<RTCStats> RTCStatsReportPlatform::Next() {
while (it_ != end_) {
const webrtc::RTCStats& next = *it_;
++it_;
if (IsWhitelistedStats(next))
return CreateRTCStats(stats_report_, &next, exposed_group_ids_);
if (IsWhitelistedStats(next)) {
return std::make_unique<RTCStats>(stats_report_, &next,
exposed_group_ids_);
}
}
return std::unique_ptr<blink::WebRTCStats>();
return std::unique_ptr<RTCStats>();
}
size_t RTCStatsReportPlatform::Size() const {
return size_;
}
std::unique_ptr<blink::WebRTCStats> CreateRTCStats(
const scoped_refptr<const webrtc::RTCStatsReport>& stats_owner,
const webrtc::RTCStats* stats,
const blink::WebVector<webrtc::NonStandardGroupId>& exposed_group_ids) {
return std::make_unique<RTCStats>(std::move(stats_owner), stats,
exposed_group_ids);
}
RTCStats::RTCStats(
const scoped_refptr<const webrtc::RTCStatsReport>& stats_owner,
const webrtc::RTCStats* stats,
......
......@@ -15,6 +15,8 @@
namespace blink {
class RTCStats;
// Wrapper around a webrtc::RTCStatsReport. Filters out any stats objects that
// aren't whitelisted. |filter| controls whether to include only standard
// members (RTCStatsMemberInterface::is_standardized return true) or not
......@@ -38,10 +40,10 @@ class PLATFORM_EXPORT RTCStatsReportPlatform {
std::unique_ptr<RTCStatsReportPlatform> CopyHandle() const;
// Gets stats object by |id|, or null if no stats with that |id| exists.
std::unique_ptr<blink::WebRTCStats> GetStats(blink::WebString id) const;
std::unique_ptr<RTCStats> GetStats(blink::WebString id) const;
// The next stats object, or null if the end has been reached.
std::unique_ptr<blink::WebRTCStats> Next();
std::unique_ptr<RTCStats> Next();
// The number of stats objects.
size_t Size() const;
......@@ -55,20 +57,20 @@ class PLATFORM_EXPORT RTCStatsReportPlatform {
const size_t size_;
};
class PLATFORM_EXPORT RTCStats : public blink::WebRTCStats {
class PLATFORM_EXPORT RTCStats {
public:
RTCStats(
const scoped_refptr<const webrtc::RTCStatsReport>& stats_owner,
const webrtc::RTCStats* stats,
const blink::WebVector<webrtc::NonStandardGroupId>& exposed_group_ids);
~RTCStats() override;
virtual ~RTCStats();
blink::WebString Id() const override;
blink::WebString GetType() const override;
double Timestamp() const override;
blink::WebString Id() const;
blink::WebString GetType() const;
double Timestamp() const;
size_t MembersCount() const override;
std::unique_ptr<blink::WebRTCStatsMember> GetMember(size_t i) const override;
size_t MembersCount() const;
std::unique_ptr<blink::WebRTCStatsMember> GetMember(size_t i) const;
private:
// Reference to keep the report that owns |stats_| alive.
......
......@@ -45,7 +45,7 @@ TEST(RTCStatsTest, OnlyIncludeWhitelistedStats_Iteration) {
// Only whitelisted stats are counted.
EXPECT_EQ(report.Size(), 1u);
std::unique_ptr<blink::WebRTCStats> stats = report.Next();
std::unique_ptr<RTCStats> stats = report.Next();
EXPECT_TRUE(stats);
EXPECT_EQ(stats->Id(), whitelisted_id);
EXPECT_FALSE(report.Next());
......@@ -89,7 +89,7 @@ TEST(RTCStatsTest, OnlyIncludeStandarizedMembers) {
// TestStats has two members, but the non-standard member should be filtered
// out.
RTCStatsReportPlatform report(webrtc_report.get(), {});
std::unique_ptr<blink::WebRTCStats> stats = report.Next();
std::unique_ptr<RTCStats> stats = report.Next();
ASSERT_NE(nullptr, stats);
ASSERT_EQ(1u, stats->MembersCount());
EXPECT_EQ("standardized", stats->GetMember(0)->GetName());
......@@ -105,7 +105,7 @@ TEST(RTCStatsTest, IncludeAllMembers) {
RTCStatsReportPlatform report(
webrtc_report.get(), std::vector<webrtc::NonStandardGroupId>{
webrtc::NonStandardGroupId::kGroupIdForTesting});
std::unique_ptr<blink::WebRTCStats> stats = report.GetStats("id");
std::unique_ptr<RTCStats> stats = report.GetStats("id");
ASSERT_NE(nullptr, stats);
ASSERT_EQ(2u, stats->MembersCount());
EXPECT_EQ("standardized", stats->GetMember(0)->GetName());
......
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