OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/webrtc/rtc_stats.h" | 5 #include "content/renderer/media/webrtc/rtc_stats.h" |
6 | 6 |
| 7 #include <set> |
| 8 #include <string> |
| 9 |
| 10 #include "base/lazy_instance.h" |
7 #include "base/logging.h" | 11 #include "base/logging.h" |
8 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "third_party/webrtc/api/stats/rtcstats_objects.h" |
9 | 14 |
10 namespace content { | 15 namespace content { |
11 | 16 |
| 17 namespace { |
| 18 |
| 19 class RTCStatsWhitelist { |
| 20 public: |
| 21 RTCStatsWhitelist() { |
| 22 whitelisted_stats_types_.insert(webrtc::RTCCertificateStats::kType); |
| 23 whitelisted_stats_types_.insert(webrtc::RTCDataChannelStats::kType); |
| 24 whitelisted_stats_types_.insert(webrtc::RTCIceCandidatePairStats::kType); |
| 25 whitelisted_stats_types_.insert(webrtc::RTCIceCandidateStats::kType); |
| 26 whitelisted_stats_types_.insert(webrtc::RTCLocalIceCandidateStats::kType); |
| 27 whitelisted_stats_types_.insert(webrtc::RTCRemoteIceCandidateStats::kType); |
| 28 whitelisted_stats_types_.insert(webrtc::RTCPeerConnectionStats::kType); |
| 29 whitelisted_stats_types_.insert(webrtc::RTCRTPStreamStats::kType); |
| 30 whitelisted_stats_types_.insert(webrtc::RTCInboundRTPStreamStats::kType); |
| 31 whitelisted_stats_types_.insert(webrtc::RTCOutboundRTPStreamStats::kType); |
| 32 whitelisted_stats_types_.insert(webrtc::RTCTransportStats::kType); |
| 33 } |
| 34 |
| 35 bool IsWhitelisted(const webrtc::RTCStats& stats) { |
| 36 return whitelisted_stats_types_.find(stats.type()) != |
| 37 whitelisted_stats_types_.end(); |
| 38 } |
| 39 |
| 40 void WhitelistStatsForTesting(const char* type) { |
| 41 whitelisted_stats_types_.insert(type); |
| 42 } |
| 43 |
| 44 private: |
| 45 std::set<std::string> whitelisted_stats_types_; |
| 46 }; |
| 47 |
| 48 base::LazyInstance<RTCStatsWhitelist>::Leaky |
| 49 g_whitelisted_stats = LAZY_INSTANCE_INITIALIZER; |
| 50 |
| 51 bool IsWhitelistedStats(const webrtc::RTCStats& stats) { |
| 52 return g_whitelisted_stats.Get().IsWhitelisted(stats); |
| 53 } |
| 54 |
| 55 } // namespace |
| 56 |
12 RTCStatsReport::RTCStatsReport( | 57 RTCStatsReport::RTCStatsReport( |
13 const scoped_refptr<const webrtc::RTCStatsReport>& stats_report) | 58 const scoped_refptr<const webrtc::RTCStatsReport>& stats_report) |
14 : stats_report_(stats_report), | 59 : stats_report_(stats_report), |
15 it_(stats_report_->begin()), | 60 it_(stats_report_->begin()), |
16 end_(stats_report_->end()) { | 61 end_(stats_report_->end()) { |
17 DCHECK(stats_report_); | 62 DCHECK(stats_report_); |
18 } | 63 } |
19 | 64 |
20 RTCStatsReport::~RTCStatsReport() { | 65 RTCStatsReport::~RTCStatsReport() { |
21 } | 66 } |
22 | 67 |
23 std::unique_ptr<blink::WebRTCStatsReport> RTCStatsReport::copyHandle() const { | 68 std::unique_ptr<blink::WebRTCStatsReport> RTCStatsReport::copyHandle() const { |
24 return std::unique_ptr<blink::WebRTCStatsReport>( | 69 return std::unique_ptr<blink::WebRTCStatsReport>( |
25 new RTCStatsReport(stats_report_)); | 70 new RTCStatsReport(stats_report_)); |
26 } | 71 } |
27 | 72 |
28 std::unique_ptr<blink::WebRTCStats> RTCStatsReport::getStats( | 73 std::unique_ptr<blink::WebRTCStats> RTCStatsReport::getStats( |
29 blink::WebString id) const { | 74 blink::WebString id) const { |
30 const webrtc::RTCStats* stats = stats_report_->Get(id.utf8()); | 75 const webrtc::RTCStats* stats = stats_report_->Get(id.utf8()); |
31 if (!stats) | 76 if (!stats || !IsWhitelistedStats(*stats)) |
32 return std::unique_ptr<blink::WebRTCStats>(); | 77 return std::unique_ptr<blink::WebRTCStats>(); |
33 return std::unique_ptr<blink::WebRTCStats>( | 78 return std::unique_ptr<blink::WebRTCStats>( |
34 new RTCStats(stats_report_, stats)); | 79 new RTCStats(stats_report_, stats)); |
35 } | 80 } |
36 | 81 |
37 std::unique_ptr<blink::WebRTCStats> RTCStatsReport::next() { | 82 std::unique_ptr<blink::WebRTCStats> RTCStatsReport::next() { |
38 if (it_ == end_) | 83 while (it_ != end_) { |
39 return std::unique_ptr<blink::WebRTCStats>(); | 84 const webrtc::RTCStats& next = *it_; |
40 const webrtc::RTCStats& next = *it_; | 85 ++it_; |
41 ++it_; | 86 if (IsWhitelistedStats(next)) { |
42 return std::unique_ptr<blink::WebRTCStats>( | 87 return std::unique_ptr<blink::WebRTCStats>( |
43 new RTCStats(stats_report_, &next)); | 88 new RTCStats(stats_report_, &next)); |
| 89 } |
| 90 } |
| 91 return std::unique_ptr<blink::WebRTCStats>(); |
44 } | 92 } |
45 | 93 |
46 RTCStats::RTCStats( | 94 RTCStats::RTCStats( |
47 const scoped_refptr<const webrtc::RTCStatsReport>& stats_owner, | 95 const scoped_refptr<const webrtc::RTCStatsReport>& stats_owner, |
48 const webrtc::RTCStats* stats) | 96 const webrtc::RTCStats* stats) |
49 : stats_owner_(stats_owner), | 97 : stats_owner_(stats_owner), |
50 stats_(stats), | 98 stats_(stats), |
51 stats_members_(stats->Members()) { | 99 stats_members_(stats->Members()) { |
52 DCHECK(stats_owner_); | 100 DCHECK(stats_owner_); |
53 DCHECK(stats_); | 101 DCHECK(stats_); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 blink::WebVector<blink::WebString> RTCStatsMember::valueSequenceString() const { | 265 blink::WebVector<blink::WebString> RTCStatsMember::valueSequenceString() const { |
218 DCHECK(isDefined()); | 266 DCHECK(isDefined()); |
219 const std::vector<std::string>& sequence = | 267 const std::vector<std::string>& sequence = |
220 *member_->cast_to<webrtc::RTCStatsMember<std::vector<std::string>>>(); | 268 *member_->cast_to<webrtc::RTCStatsMember<std::vector<std::string>>>(); |
221 blink::WebVector<blink::WebString> web_sequence(sequence.size()); | 269 blink::WebVector<blink::WebString> web_sequence(sequence.size()); |
222 for (size_t i = 0; i < sequence.size(); ++i) | 270 for (size_t i = 0; i < sequence.size(); ++i) |
223 web_sequence[i] = blink::WebString::fromUTF8(sequence[i]); | 271 web_sequence[i] = blink::WebString::fromUTF8(sequence[i]); |
224 return web_sequence; | 272 return web_sequence; |
225 } | 273 } |
226 | 274 |
| 275 void WhitelistStatsForTesting(const char* type) { |
| 276 g_whitelisted_stats.Get().WhitelistStatsForTesting(type); |
| 277 } |
| 278 |
227 } // namespace content | 279 } // namespace content |
OLD | NEW |