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

Side by Side Diff: chrome/browser/media/webrtc/rtc_stats_dictionary.cc

Issue 2534633002: Preparation CL for WebRTC performance test using promise-based getStats (Closed)
Patch Set: Created 4 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media/webrtc/rtc_stats_dictionary.h"
6
7 namespace content {
8
9 RTCStatsReportDictionary::RTCStatsReportDictionary(
10 std::unique_ptr<base::DictionaryValue> report)
11 : report_(std::move(report)) {
12 DCHECK(report_);
13 }
14
15 RTCStatsReportDictionary::~RTCStatsReportDictionary() {
16 }
17
18 std::unique_ptr<RTCStatsDictionary> RTCStatsReportDictionary::Get(
19 const std::string id) {
20 const base::DictionaryValue* dictionary;
21 if (!report_->GetDictionary(id, &dictionary))
22 return nullptr;
23 return std::unique_ptr<RTCStatsDictionary>(
24 new RTCStatsDictionary(this, dictionary));
25 }
26
27 std::vector<RTCStatsDictionary> RTCStatsReportDictionary::Filter(
28 bool(*filter)(const RTCStatsDictionary& dictionary)) {
29 std::vector<RTCStatsDictionary> result;
30 for (base::DictionaryValue::Iterator it(*report_); !it.IsAtEnd();
31 it.Advance()) {
32 const base::DictionaryValue* it_value;
33 DCHECK(it.value().GetAsDictionary(&it_value));
34 RTCStatsDictionary stats(this, it_value);
35 if (filter(stats))
36 result.push_back(stats);
37 }
38 return result;
39 }
40
41 RTCStatsDictionary::RTCStatsDictionary(
42 RTCStatsReportDictionary* report, const base::DictionaryValue* stats)
43 : report_(report), stats_(stats) {
44 DCHECK(report_);
45 DCHECK(stats_);
46 }
47
48 RTCStatsDictionary::RTCStatsDictionary(
49 const RTCStatsDictionary& other) = default;
50
51 RTCStatsDictionary::~RTCStatsDictionary() {
52 }
53
54 bool RTCStatsDictionary::IsBoolean(const std::string& key) const {
55 bool value;
56 return GetBoolean(key, &value);
57 }
58
59 bool RTCStatsDictionary::GetBoolean(const std::string& key) const {
60 bool value;
61 DCHECK(GetBoolean(key, &value));
62 return value;
63 }
64
65 bool RTCStatsDictionary::IsNumber(const std::string& key) const {
66 double value;
67 return GetNumber(key, &value);
68 }
69
70 double RTCStatsDictionary::GetNumber(const std::string& key) const {
71 double value;
72 DCHECK(GetNumber(key, &value));
73 return value;
74 }
75
76 bool RTCStatsDictionary::IsString(const std::string& key) const {
77 std::string value;
78 return GetString(key, &value);
79 }
80
81 std::string RTCStatsDictionary::GetString(const std::string& key) const {
82 std::string value;
83 DCHECK(GetString(key, &value));
84 return value;
85 }
86
87 bool RTCStatsDictionary::IsSequenceBoolean(const std::string& key) const {
88 std::vector<bool> value;
89 return GetSequenceBoolean(key, &value);
90 }
91
92 std::vector<bool> RTCStatsDictionary::GetSequenceBoolean(
93 const std::string& key) const {
94 std::vector<bool> value;
95 DCHECK(GetSequenceBoolean(key, &value));
96 return value;
97 }
98
99 bool RTCStatsDictionary::IsSequenceNumber(const std::string& key) const {
100 std::vector<double> value;
101 return GetSequenceNumber(key, &value);
102 }
103
104 std::vector<double> RTCStatsDictionary::GetSequenceNumber(
105 const std::string& key) const {
106 std::vector<double> value;
107 DCHECK(GetSequenceNumber(key, &value));
108 return value;
109 }
110
111 bool RTCStatsDictionary::IsSequenceString(const std::string& key) const {
112 std::vector<std::string> value;
113 return GetSequenceString(key, &value);
114 }
115
116 std::vector<std::string> RTCStatsDictionary::GetSequenceString(
117 const std::string& key) const {
118 std::vector<std::string> value;
119 DCHECK(GetSequenceString(key, &value));
120 return value;
121 }
122
123 bool RTCStatsDictionary::GetBoolean(
124 const std::string& key, bool* out) const {
125 return stats_->GetBoolean(key, out);
126 }
127
128 bool RTCStatsDictionary::GetNumber(
129 const std::string& key, double* out) const {
130 return stats_->GetDouble(key, out);
131 }
132
133 bool RTCStatsDictionary::GetString(
134 const std::string& key, std::string* out) const {
135 return stats_->GetString(key, out);
136 }
137
138 bool RTCStatsDictionary::GetSequenceBoolean(
139 const std::string& key,
140 std::vector<bool>* out) const {
141 const base::ListValue* list;
142 if (!stats_->GetList(key, &list))
143 return false;
144 std::vector<bool> sequence;
145 bool element;
146 for (size_t i = 0; i < list->GetSize(); ++i) {
147 if (!list->GetBoolean(i, &element))
148 return false;
149 sequence.push_back(element);
150 }
151 *out = std::move(sequence);
152 return true;
153 }
154
155 bool RTCStatsDictionary::GetSequenceNumber(
156 const std::string& key,
157 std::vector<double>* out) const {
158 const base::ListValue* list;
159 if (!stats_->GetList(key, &list))
160 return false;
161 std::vector<double> sequence;
162 double element;
163 for (size_t i = 0; i < list->GetSize(); ++i) {
164 if (!list->GetDouble(i, &element))
165 return false;
166 sequence.push_back(element);
167 }
168 *out = std::move(sequence);
169 return true;
170 }
171
172 bool RTCStatsDictionary::GetSequenceString(
173 const std::string& key,
174 std::vector<std::string>* out) const {
175 const base::ListValue* list;
176 if (!stats_->GetList(key, &list))
177 return false;
178 std::vector<std::string> sequence;
179 std::string element;
180 for (size_t i = 0; i < list->GetSize(); ++i) {
181 if (!list->GetString(i, &element))
182 return false;
183 sequence.push_back(element);
184 }
185 *out = std::move(sequence);
186 return true;
187 }
188
189 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698