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