Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(767)

Unified Diff: content/renderer/media/webrtc/rtc_stats.cc

Issue 2490183002: Filter webrtc::RTCStats by whitelist in surfacing them to Blink. (Closed)
Patch Set: git cl format: {\n} -> {} Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/media/webrtc/rtc_stats.h ('k') | content/renderer/media/webrtc/rtc_stats_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/media/webrtc/rtc_stats.cc
diff --git a/content/renderer/media/webrtc/rtc_stats.cc b/content/renderer/media/webrtc/rtc_stats.cc
index 06aa1c79362248290dde8f04fde6232e0f02dba8..be7c7f736439569c7c79ca5325d795f81d80d6d9 100644
--- a/content/renderer/media/webrtc/rtc_stats.cc
+++ b/content/renderer/media/webrtc/rtc_stats.cc
@@ -4,11 +4,56 @@
#include "content/renderer/media/webrtc/rtc_stats.h"
+#include <set>
+#include <string>
+
+#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/time/time.h"
+#include "third_party/webrtc/api/stats/rtcstats_objects.h"
namespace content {
+namespace {
+
+class RTCStatsWhitelist {
+ public:
+ RTCStatsWhitelist() {
+ whitelisted_stats_types_.insert(webrtc::RTCCertificateStats::kType);
+ whitelisted_stats_types_.insert(webrtc::RTCDataChannelStats::kType);
+ whitelisted_stats_types_.insert(webrtc::RTCIceCandidatePairStats::kType);
+ whitelisted_stats_types_.insert(webrtc::RTCIceCandidateStats::kType);
+ whitelisted_stats_types_.insert(webrtc::RTCLocalIceCandidateStats::kType);
+ whitelisted_stats_types_.insert(webrtc::RTCRemoteIceCandidateStats::kType);
+ whitelisted_stats_types_.insert(webrtc::RTCPeerConnectionStats::kType);
+ whitelisted_stats_types_.insert(webrtc::RTCRTPStreamStats::kType);
+ whitelisted_stats_types_.insert(webrtc::RTCInboundRTPStreamStats::kType);
+ whitelisted_stats_types_.insert(webrtc::RTCOutboundRTPStreamStats::kType);
+ whitelisted_stats_types_.insert(webrtc::RTCTransportStats::kType);
+ }
+
+ bool IsWhitelisted(const webrtc::RTCStats& stats) {
+ return whitelisted_stats_types_.find(stats.type()) !=
+ whitelisted_stats_types_.end();
+ }
+
+ void WhitelistStatsForTesting(const char* type) {
+ whitelisted_stats_types_.insert(type);
+ }
+
+ private:
+ std::set<std::string> whitelisted_stats_types_;
+};
+
+base::LazyInstance<RTCStatsWhitelist>::Leaky
+ g_whitelisted_stats = LAZY_INSTANCE_INITIALIZER;
+
+bool IsWhitelistedStats(const webrtc::RTCStats& stats) {
+ return g_whitelisted_stats.Get().IsWhitelisted(stats);
+}
+
+} // namespace
+
RTCStatsReport::RTCStatsReport(
const scoped_refptr<const webrtc::RTCStatsReport>& stats_report)
: stats_report_(stats_report),
@@ -28,19 +73,22 @@ std::unique_ptr<blink::WebRTCStatsReport> RTCStatsReport::copyHandle() const {
std::unique_ptr<blink::WebRTCStats> RTCStatsReport::getStats(
blink::WebString id) const {
const webrtc::RTCStats* stats = stats_report_->Get(id.utf8());
- if (!stats)
+ if (!stats || !IsWhitelistedStats(*stats))
return std::unique_ptr<blink::WebRTCStats>();
return std::unique_ptr<blink::WebRTCStats>(
new RTCStats(stats_report_, stats));
}
std::unique_ptr<blink::WebRTCStats> RTCStatsReport::next() {
- if (it_ == end_)
- return std::unique_ptr<blink::WebRTCStats>();
- const webrtc::RTCStats& next = *it_;
- ++it_;
- return std::unique_ptr<blink::WebRTCStats>(
- new RTCStats(stats_report_, &next));
+ while (it_ != end_) {
+ const webrtc::RTCStats& next = *it_;
+ ++it_;
+ if (IsWhitelistedStats(next)) {
+ return std::unique_ptr<blink::WebRTCStats>(
+ new RTCStats(stats_report_, &next));
+ }
+ }
+ return std::unique_ptr<blink::WebRTCStats>();
}
RTCStats::RTCStats(
@@ -224,4 +272,8 @@ blink::WebVector<blink::WebString> RTCStatsMember::valueSequenceString() const {
return web_sequence;
}
+void WhitelistStatsForTesting(const char* type) {
+ g_whitelisted_stats.Get().WhitelistStatsForTesting(type);
+}
+
} // namespace content
« no previous file with comments | « content/renderer/media/webrtc/rtc_stats.h ('k') | content/renderer/media/webrtc/rtc_stats_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698