| 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/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "content/common/media/peer_connection_tracker_messages.h" | 7 #include "content/common/media/peer_connection_tracker_messages.h" |
| 8 #include "content/renderer/media/rtc_media_constraints.h" | 8 #include "content/renderer/media/rtc_media_constraints.h" |
| 9 #include "content/renderer/media/rtc_peer_connection_handler.h" | 9 #include "content/renderer/media/rtc_peer_connection_handler.h" |
| 10 #include "content/renderer/render_thread_impl.h" | 10 #include "content/renderer/render_thread_impl.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // The caller takes the ownership of the returned value. | 154 // The caller takes the ownership of the returned value. |
| 155 // Note: | 155 // Note: |
| 156 // The format must be consistent with what webrtc_internals.js expects. | 156 // The format must be consistent with what webrtc_internals.js expects. |
| 157 // If you change it here, you must change webrtc_internals.js as well. | 157 // If you change it here, you must change webrtc_internals.js as well. |
| 158 static base::DictionaryValue* GetDictValueStats( | 158 static base::DictionaryValue* GetDictValueStats( |
| 159 const webrtc::StatsReport& report) { | 159 const webrtc::StatsReport& report) { |
| 160 if (report.values.empty()) | 160 if (report.values.empty()) |
| 161 return NULL; | 161 return NULL; |
| 162 | 162 |
| 163 DictionaryValue* dict = new base::DictionaryValue(); | 163 DictionaryValue* dict = new base::DictionaryValue(); |
| 164 if (!dict) | |
| 165 return NULL; | |
| 166 dict->SetDouble("timestamp", report.timestamp); | 164 dict->SetDouble("timestamp", report.timestamp); |
| 167 | 165 |
| 168 base::ListValue* values = new base::ListValue(); | 166 base::ListValue* values = new base::ListValue(); |
| 169 if (!values) { | |
| 170 delete dict; | |
| 171 return NULL; | |
| 172 } | |
| 173 dict->Set("values", values); | 167 dict->Set("values", values); |
| 174 | 168 |
| 175 for (size_t i = 0; i < report.values.size(); ++i) { | 169 for (size_t i = 0; i < report.values.size(); ++i) { |
| 176 values->AppendString(report.values[i].name); | 170 values->AppendString(report.values[i].name); |
| 177 values->AppendString(report.values[i].value); | 171 values->AppendString(report.values[i].value); |
| 178 } | 172 } |
| 179 return dict; | 173 return dict; |
| 180 } | 174 } |
| 181 | 175 |
| 182 // Builds a DictionaryValue from the StatsReport. | 176 // Builds a DictionaryValue from the StatsReport. |
| 183 // The caller takes the ownership of the returned value. | 177 // The caller takes the ownership of the returned value. |
| 184 static base::DictionaryValue* GetDictValue(const webrtc::StatsReport& report) { | 178 static base::DictionaryValue* GetDictValue(const webrtc::StatsReport& report) { |
| 185 scoped_ptr<base::DictionaryValue> stats, result; | 179 scoped_ptr<base::DictionaryValue> stats, result; |
| 186 | 180 |
| 187 stats.reset(GetDictValueStats(report)); | 181 stats.reset(GetDictValueStats(report)); |
| 188 if (!stats) | 182 if (!stats) |
| 189 return NULL; | 183 return NULL; |
| 190 | 184 |
| 191 result.reset(new base::DictionaryValue()); | 185 result.reset(new base::DictionaryValue()); |
| 192 if (!result) | |
| 193 return NULL; | |
| 194 | |
| 195 // Note: | 186 // Note: |
| 196 // The format must be consistent with what webrtc_internals.js expects. | 187 // The format must be consistent with what webrtc_internals.js expects. |
| 197 // If you change it here, you must change webrtc_internals.js as well. | 188 // If you change it here, you must change webrtc_internals.js as well. |
| 198 if (stats) | 189 result->Set("stats", stats.release()); |
| 199 result->Set("stats", stats.release()); | |
| 200 result->SetString("id", report.id); | 190 result->SetString("id", report.id); |
| 201 result->SetString("type", report.type); | 191 result->SetString("type", report.type); |
| 202 | 192 |
| 203 return result.release(); | 193 return result.release(); |
| 204 } | 194 } |
| 205 | 195 |
| 206 class InternalStatsObserver : public webrtc::StatsObserver { | 196 class InternalStatsObserver : public webrtc::StatsObserver { |
| 207 public: | 197 public: |
| 208 InternalStatsObserver(int lid) | 198 InternalStatsObserver(int lid) |
| 209 : lid_(lid){} | 199 : lid_(lid){} |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 const std::string& value) { | 444 const std::string& value) { |
| 455 if (peer_connection_id_map_.find(pc_handler) == peer_connection_id_map_.end()) | 445 if (peer_connection_id_map_.find(pc_handler) == peer_connection_id_map_.end()) |
| 456 return; | 446 return; |
| 457 | 447 |
| 458 RenderThreadImpl::current()->Send( | 448 RenderThreadImpl::current()->Send( |
| 459 new PeerConnectionTrackerHost_UpdatePeerConnection( | 449 new PeerConnectionTrackerHost_UpdatePeerConnection( |
| 460 peer_connection_id_map_[pc_handler], type, value)); | 450 peer_connection_id_map_[pc_handler], type, value)); |
| 461 } | 451 } |
| 462 | 452 |
| 463 } // namespace content | 453 } // namespace content |
| OLD | NEW |