| 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 |
| 4 #include "content/renderer/media/peer_connection_tracker.h" | 5 #include "content/renderer/media/peer_connection_tracker.h" |
| 5 | 6 |
| 6 #include <stddef.h> | 7 #include <stddef.h> |
| 7 #include <stdint.h> | 8 #include <stdint.h> |
| 8 | 9 |
| 10 #include <memory> |
| 11 #include <utility> |
| 12 |
| 9 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "content/common/media/peer_connection_tracker_messages.h" | 16 #include "content/common/media/peer_connection_tracker_messages.h" |
| 13 #include "content/renderer/media/rtc_peer_connection_handler.h" | 17 #include "content/renderer/media/rtc_peer_connection_handler.h" |
| 14 #include "content/renderer/render_thread_impl.h" | 18 #include "content/renderer/render_thread_impl.h" |
| 15 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 16 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 20 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 17 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 21 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 22 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 values->AppendString(value->ToString()); | 268 values->AppendString(value->ToString()); |
| 265 break; | 269 break; |
| 266 } | 270 } |
| 267 } | 271 } |
| 268 | 272 |
| 269 return dict; | 273 return dict; |
| 270 } | 274 } |
| 271 | 275 |
| 272 // Builds a DictionaryValue from the StatsReport. | 276 // Builds a DictionaryValue from the StatsReport. |
| 273 // The caller takes the ownership of the returned value. | 277 // The caller takes the ownership of the returned value. |
| 274 static base::DictionaryValue* GetDictValue(const StatsReport& report) { | 278 static std::unique_ptr<base::DictionaryValue> GetDictValue( |
| 279 const StatsReport& report) { |
| 275 std::unique_ptr<base::DictionaryValue> stats, result; | 280 std::unique_ptr<base::DictionaryValue> stats, result; |
| 276 | 281 |
| 277 stats.reset(GetDictValueStats(report)); | 282 stats.reset(GetDictValueStats(report)); |
| 278 if (!stats) | 283 if (!stats) |
| 279 return NULL; | 284 return NULL; |
| 280 | 285 |
| 281 result.reset(new base::DictionaryValue()); | 286 result.reset(new base::DictionaryValue()); |
| 282 // Note: | 287 // Note: |
| 283 // The format must be consistent with what webrtc_internals.js expects. | 288 // The format must be consistent with what webrtc_internals.js expects. |
| 284 // If you change it here, you must change webrtc_internals.js as well. | 289 // If you change it here, you must change webrtc_internals.js as well. |
| 285 result->Set("stats", stats.release()); | 290 result->Set("stats", stats.release()); |
| 286 result->SetString("id", report.id()->ToString()); | 291 result->SetString("id", report.id()->ToString()); |
| 287 result->SetString("type", report.TypeToString()); | 292 result->SetString("type", report.TypeToString()); |
| 288 | 293 |
| 289 return result.release(); | 294 return result; |
| 290 } | 295 } |
| 291 | 296 |
| 292 class InternalStatsObserver : public webrtc::StatsObserver { | 297 class InternalStatsObserver : public webrtc::StatsObserver { |
| 293 public: | 298 public: |
| 294 InternalStatsObserver(int lid) | 299 InternalStatsObserver(int lid) |
| 295 : lid_(lid), main_thread_(base::ThreadTaskRunnerHandle::Get()) {} | 300 : lid_(lid), main_thread_(base::ThreadTaskRunnerHandle::Get()) {} |
| 296 | 301 |
| 297 void OnComplete(const StatsReports& reports) override { | 302 void OnComplete(const StatsReports& reports) override { |
| 298 std::unique_ptr<base::ListValue> list(new base::ListValue()); | 303 std::unique_ptr<base::ListValue> list(new base::ListValue()); |
| 299 | 304 |
| 300 for (const auto* r : reports) { | 305 for (const auto* r : reports) { |
| 301 base::DictionaryValue* report = GetDictValue(*r); | 306 std::unique_ptr<base::DictionaryValue> report = GetDictValue(*r); |
| 302 if (report) | 307 if (report) |
| 303 list->Append(report); | 308 list->Append(std::move(report)); |
| 304 } | 309 } |
| 305 | 310 |
| 306 if (!list->empty()) { | 311 if (!list->empty()) { |
| 307 main_thread_->PostTask(FROM_HERE, | 312 main_thread_->PostTask(FROM_HERE, |
| 308 base::Bind(&InternalStatsObserver::OnCompleteImpl, | 313 base::Bind(&InternalStatsObserver::OnCompleteImpl, |
| 309 base::Passed(&list), lid_)); | 314 base::Passed(&list), lid_)); |
| 310 } | 315 } |
| 311 } | 316 } |
| 312 | 317 |
| 313 protected: | 318 protected: |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 738 DCHECK(main_thread_.CalledOnValidThread()); | 743 DCHECK(main_thread_.CalledOnValidThread()); |
| 739 SendTarget()->Send(new PeerConnectionTrackerHost_UpdatePeerConnection( | 744 SendTarget()->Send(new PeerConnectionTrackerHost_UpdatePeerConnection( |
| 740 local_id, std::string(callback_type), value)); | 745 local_id, std::string(callback_type), value)); |
| 741 } | 746 } |
| 742 | 747 |
| 743 void PeerConnectionTracker::OverrideSendTargetForTesting(RenderThread* target) { | 748 void PeerConnectionTracker::OverrideSendTargetForTesting(RenderThread* target) { |
| 744 send_target_for_test_ = target; | 749 send_target_for_test_ = target; |
| 745 } | 750 } |
| 746 | 751 |
| 747 } // namespace content | 752 } // namespace content |
| OLD | NEW |