| 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 |
| 5 #include "content/renderer/media/peer_connection_tracker.h" | 5 #include "content/renderer/media/peer_connection_tracker.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "base/values.h" |
| 16 #include "content/common/media/peer_connection_tracker_messages.h" | 18 #include "content/common/media/peer_connection_tracker_messages.h" |
| 17 #include "content/renderer/media/rtc_peer_connection_handler.h" | 19 #include "content/renderer/media/rtc_peer_connection_handler.h" |
| 18 #include "content/renderer/render_thread_impl.h" | 20 #include "content/renderer/render_thread_impl.h" |
| 19 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 21 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 20 #include "third_party/WebKit/public/platform/WebMediaStream.h" | 22 #include "third_party/WebKit/public/platform/WebMediaStream.h" |
| 21 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" | 23 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
| 22 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 24 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
| 23 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" | 25 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" |
| 24 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h" | 26 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h" |
| 25 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" | 27 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h" |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 GET_STRING_OF_STATE(ICEGatheringStateGathering) | 239 GET_STRING_OF_STATE(ICEGatheringStateGathering) |
| 238 GET_STRING_OF_STATE(ICEGatheringStateComplete) | 240 GET_STRING_OF_STATE(ICEGatheringStateComplete) |
| 239 default: | 241 default: |
| 240 NOTREACHED(); | 242 NOTREACHED(); |
| 241 break; | 243 break; |
| 242 } | 244 } |
| 243 return result; | 245 return result; |
| 244 } | 246 } |
| 245 | 247 |
| 246 // Builds a DictionaryValue from the StatsReport. | 248 // Builds a DictionaryValue from the StatsReport. |
| 247 // The caller takes the ownership of the returned value. | |
| 248 // Note: | 249 // Note: |
| 249 // The format must be consistent with what webrtc_internals.js expects. | 250 // The format must be consistent with what webrtc_internals.js expects. |
| 250 // If you change it here, you must change webrtc_internals.js as well. | 251 // If you change it here, you must change webrtc_internals.js as well. |
| 251 static base::DictionaryValue* GetDictValueStats(const StatsReport& report) { | 252 static std::unique_ptr<base::DictionaryValue> GetDictValueStats( |
| 253 const StatsReport& report) { |
| 252 if (report.values().empty()) | 254 if (report.values().empty()) |
| 253 return NULL; | 255 return NULL; |
| 254 | 256 |
| 255 base::DictionaryValue* dict = new base::DictionaryValue(); | 257 auto values = base::MakeUnique<base::ListValue>(); |
| 256 dict->SetDouble("timestamp", report.timestamp()); | |
| 257 | |
| 258 base::ListValue* values = new base::ListValue(); | |
| 259 dict->Set("values", values); | |
| 260 | 258 |
| 261 for (const auto& v : report.values()) { | 259 for (const auto& v : report.values()) { |
| 262 const StatsReport::ValuePtr& value = v.second; | 260 const StatsReport::ValuePtr& value = v.second; |
| 263 values->AppendString(value->display_name()); | 261 values->AppendString(value->display_name()); |
| 264 switch (value->type()) { | 262 switch (value->type()) { |
| 265 case StatsReport::Value::kInt: | 263 case StatsReport::Value::kInt: |
| 266 values->AppendInteger(value->int_val()); | 264 values->AppendInteger(value->int_val()); |
| 267 break; | 265 break; |
| 268 case StatsReport::Value::kFloat: | 266 case StatsReport::Value::kFloat: |
| 269 values->AppendDouble(value->float_val()); | 267 values->AppendDouble(value->float_val()); |
| 270 break; | 268 break; |
| 271 case StatsReport::Value::kString: | 269 case StatsReport::Value::kString: |
| 272 values->AppendString(value->string_val()); | 270 values->AppendString(value->string_val()); |
| 273 break; | 271 break; |
| 274 case StatsReport::Value::kStaticString: | 272 case StatsReport::Value::kStaticString: |
| 275 values->AppendString(value->static_string_val()); | 273 values->AppendString(value->static_string_val()); |
| 276 break; | 274 break; |
| 277 case StatsReport::Value::kBool: | 275 case StatsReport::Value::kBool: |
| 278 values->AppendBoolean(value->bool_val()); | 276 values->AppendBoolean(value->bool_val()); |
| 279 break; | 277 break; |
| 280 case StatsReport::Value::kInt64: // int64_t isn't supported, so use | 278 case StatsReport::Value::kInt64: // int64_t isn't supported, so use |
| 281 // string. | 279 // string. |
| 282 case StatsReport::Value::kId: | 280 case StatsReport::Value::kId: |
| 283 default: | 281 default: |
| 284 values->AppendString(value->ToString()); | 282 values->AppendString(value->ToString()); |
| 285 break; | 283 break; |
| 286 } | 284 } |
| 287 } | 285 } |
| 288 | 286 |
| 287 auto dict = base::MakeUnique<base::DictionaryValue>(); |
| 288 dict->SetDouble("timestamp", report.timestamp()); |
| 289 dict->Set("values", std::move(values)); |
| 290 |
| 289 return dict; | 291 return dict; |
| 290 } | 292 } |
| 291 | 293 |
| 292 // Builds a DictionaryValue from the StatsReport. | 294 // Builds a DictionaryValue from the StatsReport. |
| 293 // The caller takes the ownership of the returned value. | 295 // The caller takes the ownership of the returned value. |
| 294 static std::unique_ptr<base::DictionaryValue> GetDictValue( | 296 static std::unique_ptr<base::DictionaryValue> GetDictValue( |
| 295 const StatsReport& report) { | 297 const StatsReport& report) { |
| 296 std::unique_ptr<base::DictionaryValue> stats, result; | 298 std::unique_ptr<base::DictionaryValue> stats = GetDictValueStats(report); |
| 297 | |
| 298 stats.reset(GetDictValueStats(report)); | |
| 299 if (!stats) | 299 if (!stats) |
| 300 return NULL; | 300 return NULL; |
| 301 | 301 |
| 302 result.reset(new base::DictionaryValue()); | |
| 303 // Note: | 302 // Note: |
| 304 // The format must be consistent with what webrtc_internals.js expects. | 303 // The format must be consistent with what webrtc_internals.js expects. |
| 305 // If you change it here, you must change webrtc_internals.js as well. | 304 // If you change it here, you must change webrtc_internals.js as well. |
| 306 result->Set("stats", stats.release()); | 305 auto result = base::MakeUnique<base::DictionaryValue>(); |
| 306 result->Set("stats", std::move(stats)); |
| 307 result->SetString("id", report.id()->ToString()); | 307 result->SetString("id", report.id()->ToString()); |
| 308 result->SetString("type", report.TypeToString()); | 308 result->SetString("type", report.TypeToString()); |
| 309 | 309 |
| 310 return result; | 310 return result; |
| 311 } | 311 } |
| 312 | 312 |
| 313 class InternalStatsObserver : public webrtc::StatsObserver { | 313 class InternalStatsObserver : public webrtc::StatsObserver { |
| 314 public: | 314 public: |
| 315 InternalStatsObserver(int lid) | 315 InternalStatsObserver(int lid) |
| 316 : lid_(lid), main_thread_(base::ThreadTaskRunnerHandle::Get()) {} | 316 : lid_(lid), main_thread_(base::ThreadTaskRunnerHandle::Get()) {} |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 DCHECK(main_thread_.CalledOnValidThread()); | 743 DCHECK(main_thread_.CalledOnValidThread()); |
| 744 SendTarget()->Send(new PeerConnectionTrackerHost_UpdatePeerConnection( | 744 SendTarget()->Send(new PeerConnectionTrackerHost_UpdatePeerConnection( |
| 745 local_id, std::string(callback_type), value)); | 745 local_id, std::string(callback_type), value)); |
| 746 } | 746 } |
| 747 | 747 |
| 748 void PeerConnectionTracker::OverrideSendTargetForTesting(RenderThread* target) { | 748 void PeerConnectionTracker::OverrideSendTargetForTesting(RenderThread* target) { |
| 749 send_target_for_test_ = target; | 749 send_target_for_test_ = target; |
| 750 } | 750 } |
| 751 | 751 |
| 752 } // namespace content | 752 } // namespace content |
| OLD | NEW |