OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "content/renderer/media/peer_connection_tracker.h" | 4 #include "content/renderer/media/peer_connection_tracker.h" |
5 | 5 |
6 #include "base/strings/string_number_conversions.h" | 6 #include "base/strings/string_number_conversions.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
9 #include "content/common/media/peer_connection_tracker_messages.h" | 9 #include "content/common/media/peer_connection_tracker_messages.h" |
10 #include "content/renderer/media/rtc_media_constraints.h" | 10 #include "content/renderer/media/rtc_media_constraints.h" |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 const webrtc::StatsReport& report) { | 208 const webrtc::StatsReport& report) { |
209 if (report.values.empty()) | 209 if (report.values.empty()) |
210 return NULL; | 210 return NULL; |
211 | 211 |
212 base::DictionaryValue* dict = new base::DictionaryValue(); | 212 base::DictionaryValue* dict = new base::DictionaryValue(); |
213 dict->SetDouble("timestamp", report.timestamp); | 213 dict->SetDouble("timestamp", report.timestamp); |
214 | 214 |
215 base::ListValue* values = new base::ListValue(); | 215 base::ListValue* values = new base::ListValue(); |
216 dict->Set("values", values); | 216 dict->Set("values", values); |
217 | 217 |
218 for (size_t i = 0; i < report.values.size(); ++i) { | 218 for (const auto& v : report.values) { |
219 values->AppendString(report.values[i].display_name()); | 219 values->AppendString(v.display_name()); |
220 values->AppendString(report.values[i].value); | 220 values->AppendString(v.value); |
221 } | 221 } |
| 222 |
222 return dict; | 223 return dict; |
223 } | 224 } |
224 | 225 |
225 // Builds a DictionaryValue from the StatsReport. | 226 // Builds a DictionaryValue from the StatsReport. |
226 // The caller takes the ownership of the returned value. | 227 // The caller takes the ownership of the returned value. |
227 static base::DictionaryValue* GetDictValue(const webrtc::StatsReport& report) { | 228 static base::DictionaryValue* GetDictValue(const webrtc::StatsReport& report) { |
228 scoped_ptr<base::DictionaryValue> stats, result; | 229 scoped_ptr<base::DictionaryValue> stats, result; |
229 | 230 |
230 stats.reset(GetDictValueStats(report)); | 231 stats.reset(GetDictValueStats(report)); |
231 if (!stats) | 232 if (!stats) |
232 return NULL; | 233 return NULL; |
233 | 234 |
234 result.reset(new base::DictionaryValue()); | 235 result.reset(new base::DictionaryValue()); |
235 // Note: | 236 // Note: |
236 // The format must be consistent with what webrtc_internals.js expects. | 237 // The format must be consistent with what webrtc_internals.js expects. |
237 // If you change it here, you must change webrtc_internals.js as well. | 238 // If you change it here, you must change webrtc_internals.js as well. |
238 result->Set("stats", stats.release()); | 239 result->Set("stats", stats.release()); |
239 result->SetString("id", report.id); | 240 result->SetString("id", report.id); |
240 result->SetString("type", report.type); | 241 result->SetString("type", report.type); |
241 | 242 |
242 return result.release(); | 243 return result.release(); |
243 } | 244 } |
244 | 245 |
245 class InternalStatsObserver : public webrtc::StatsObserver { | 246 class InternalStatsObserver : public webrtc::StatsObserver { |
246 public: | 247 public: |
247 InternalStatsObserver(int lid) | 248 InternalStatsObserver(int lid) |
248 : lid_(lid), main_thread_(base::ThreadTaskRunnerHandle::Get()) {} | 249 : lid_(lid), main_thread_(base::ThreadTaskRunnerHandle::Get()) {} |
249 | 250 |
250 void OnComplete(const std::vector<webrtc::StatsReport>& reports) override { | 251 void OnComplete(const webrtc::StatsReports& reports) override { |
251 scoped_ptr<base::ListValue> list(new base::ListValue()); | 252 scoped_ptr<base::ListValue> list(new base::ListValue()); |
252 | 253 |
253 for (size_t i = 0; i < reports.size(); ++i) { | 254 for (const auto* r : reports) { |
254 base::DictionaryValue* report = GetDictValue(reports[i]); | 255 base::DictionaryValue* report = GetDictValue(*r); |
255 if (report) | 256 if (report) |
256 list->Append(report); | 257 list->Append(report); |
257 } | 258 } |
258 | 259 |
259 if (!list->empty()) { | 260 if (!list->empty()) { |
260 main_thread_->PostTask(FROM_HERE, | 261 main_thread_->PostTask(FROM_HERE, |
261 base::Bind(&InternalStatsObserver::OnCompleteImpl, | 262 base::Bind(&InternalStatsObserver::OnCompleteImpl, |
262 base::Passed(&list), lid_)); | 263 base::Passed(&list), lid_)); |
263 } | 264 } |
264 } | 265 } |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 DCHECK(main_thread_.CalledOnValidThread()); | 574 DCHECK(main_thread_.CalledOnValidThread()); |
574 if (peer_connection_id_map_.find(pc_handler) == peer_connection_id_map_.end()) | 575 if (peer_connection_id_map_.find(pc_handler) == peer_connection_id_map_.end()) |
575 return; | 576 return; |
576 | 577 |
577 RenderThreadImpl::current()->Send( | 578 RenderThreadImpl::current()->Send( |
578 new PeerConnectionTrackerHost_UpdatePeerConnection( | 579 new PeerConnectionTrackerHost_UpdatePeerConnection( |
579 peer_connection_id_map_[pc_handler], type, value)); | 580 peer_connection_id_map_[pc_handler], type, value)); |
580 } | 581 } |
581 | 582 |
582 } // namespace content | 583 } // namespace content |
OLD | NEW |