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/browser/webrtc/webrtc_internals.h" | 5 #include "content/browser/webrtc/webrtc_internals.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include <memory> |
| 10 #include <utility> |
| 11 |
9 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
10 #include "build/build_config.h" | 13 #include "build/build_config.h" |
11 #include "content/browser/renderer_host/render_process_host_impl.h" | 14 #include "content/browser/renderer_host/render_process_host_impl.h" |
12 #include "content/browser/web_contents/web_contents_view.h" | 15 #include "content/browser/web_contents/web_contents_view.h" |
13 #include "content/browser/webrtc/webrtc_internals_ui_observer.h" | 16 #include "content/browser/webrtc/webrtc_internals_ui_observer.h" |
14 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
15 #include "content/public/browser/content_browser_client.h" | 18 #include "content/public/browser/content_browser_client.h" |
16 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
17 #include "device/power_save_blocker/power_save_blocker.h" | 20 #include "device/power_save_blocker/power_save_blocker.h" |
18 #include "ipc/ipc_platform_file.h" | 21 #include "ipc/ipc_platform_file.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 113 } |
111 | 114 |
112 void WebRTCInternals::OnAddPeerConnection(int render_process_id, | 115 void WebRTCInternals::OnAddPeerConnection(int render_process_id, |
113 ProcessId pid, | 116 ProcessId pid, |
114 int lid, | 117 int lid, |
115 const string& url, | 118 const string& url, |
116 const string& rtc_configuration, | 119 const string& rtc_configuration, |
117 const string& constraints) { | 120 const string& constraints) { |
118 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 121 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
119 | 122 |
120 base::DictionaryValue* dict = new base::DictionaryValue(); | 123 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
121 dict->SetInteger("rid", render_process_id); | 124 dict->SetInteger("rid", render_process_id); |
122 dict->SetInteger("pid", static_cast<int>(pid)); | 125 dict->SetInteger("pid", static_cast<int>(pid)); |
123 dict->SetInteger("lid", lid); | 126 dict->SetInteger("lid", lid); |
124 dict->SetString("rtcConfiguration", rtc_configuration); | 127 dict->SetString("rtcConfiguration", rtc_configuration); |
125 dict->SetString("constraints", constraints); | 128 dict->SetString("constraints", constraints); |
126 dict->SetString("url", url); | 129 dict->SetString("url", url); |
127 peer_connection_data_.Append(dict); | 130 peer_connection_data_.Append(std::move(dict)); |
128 CreateOrReleasePowerSaveBlocker(); | 131 CreateOrReleasePowerSaveBlocker(); |
129 | 132 |
130 if (observers_.might_have_observers()) | 133 if (observers_.might_have_observers()) |
131 SendUpdate("addPeerConnection", dict->CreateDeepCopy()); | 134 SendUpdate("addPeerConnection", dict->CreateDeepCopy()); |
132 | 135 |
133 if (render_process_id_set_.insert(render_process_id).second) { | 136 if (render_process_id_set_.insert(render_process_id).second) { |
134 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); | 137 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); |
135 if (host) | 138 if (host) |
136 host->AddObserver(this); | 139 host->AddObserver(this); |
137 } | 140 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 record->GetInteger("lid", &this_lid); | 180 record->GetInteger("lid", &this_lid); |
178 | 181 |
179 if (this_pid != static_cast<int>(pid) || this_lid != lid) | 182 if (this_pid != static_cast<int>(pid) || this_lid != lid) |
180 continue; | 183 continue; |
181 | 184 |
182 // Append the update to the end of the log. | 185 // Append the update to the end of the log. |
183 base::ListValue* log = EnsureLogList(record); | 186 base::ListValue* log = EnsureLogList(record); |
184 if (!log) | 187 if (!log) |
185 return; | 188 return; |
186 | 189 |
187 base::DictionaryValue* log_entry = new base::DictionaryValue(); | 190 std::unique_ptr<base::DictionaryValue> log_entry( |
188 if (!log_entry) | 191 new base::DictionaryValue()); |
189 return; | |
190 | 192 |
191 double epoch_time = base::Time::Now().ToJsTime(); | 193 double epoch_time = base::Time::Now().ToJsTime(); |
192 string time = base::DoubleToString(epoch_time); | 194 string time = base::DoubleToString(epoch_time); |
193 log_entry->SetString("time", time); | 195 log_entry->SetString("time", time); |
194 log_entry->SetString("type", type); | 196 log_entry->SetString("type", type); |
195 log_entry->SetString("value", value); | 197 log_entry->SetString("value", value); |
196 log->Append(log_entry); | |
197 | 198 |
198 if (observers_.might_have_observers()) { | 199 if (observers_.might_have_observers()) { |
199 std::unique_ptr<base::DictionaryValue> update( | 200 std::unique_ptr<base::DictionaryValue> update( |
200 new base::DictionaryValue()); | 201 new base::DictionaryValue()); |
201 update->SetInteger("pid", static_cast<int>(pid)); | 202 update->SetInteger("pid", static_cast<int>(pid)); |
202 update->SetInteger("lid", lid); | 203 update->SetInteger("lid", lid); |
203 update->MergeDictionary(log_entry); | 204 update->MergeDictionary(log_entry.get()); |
204 | 205 |
205 SendUpdate("updatePeerConnection", std::move(update)); | 206 SendUpdate("updatePeerConnection", std::move(update)); |
206 } | 207 } |
| 208 |
| 209 log->Append(std::move(log_entry)); |
| 210 |
207 return; | 211 return; |
208 } | 212 } |
209 } | 213 } |
210 | 214 |
211 void WebRTCInternals::OnAddStats(base::ProcessId pid, int lid, | 215 void WebRTCInternals::OnAddStats(base::ProcessId pid, int lid, |
212 const base::ListValue& value) { | 216 const base::ListValue& value) { |
213 if (!observers_.might_have_observers()) | 217 if (!observers_.might_have_observers()) |
214 return; | 218 return; |
215 | 219 |
216 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 220 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
217 dict->SetInteger("pid", static_cast<int>(pid)); | 221 dict->SetInteger("pid", static_cast<int>(pid)); |
218 dict->SetInteger("lid", lid); | 222 dict->SetInteger("lid", lid); |
219 | 223 |
220 dict->Set("reports", value.CreateDeepCopy()); | 224 dict->Set("reports", value.CreateDeepCopy()); |
221 | 225 |
222 SendUpdate("addStats", std::move(dict)); | 226 SendUpdate("addStats", std::move(dict)); |
223 } | 227 } |
224 | 228 |
225 void WebRTCInternals::OnGetUserMedia(int rid, | 229 void WebRTCInternals::OnGetUserMedia(int rid, |
226 base::ProcessId pid, | 230 base::ProcessId pid, |
227 const std::string& origin, | 231 const std::string& origin, |
228 bool audio, | 232 bool audio, |
229 bool video, | 233 bool video, |
230 const std::string& audio_constraints, | 234 const std::string& audio_constraints, |
231 const std::string& video_constraints) { | 235 const std::string& video_constraints) { |
232 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 236 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
233 | 237 |
234 base::DictionaryValue* dict = new base::DictionaryValue(); | 238 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
235 dict->SetInteger("rid", rid); | 239 dict->SetInteger("rid", rid); |
236 dict->SetInteger("pid", static_cast<int>(pid)); | 240 dict->SetInteger("pid", static_cast<int>(pid)); |
237 dict->SetString("origin", origin); | 241 dict->SetString("origin", origin); |
238 if (audio) | 242 if (audio) |
239 dict->SetString("audio", audio_constraints); | 243 dict->SetString("audio", audio_constraints); |
240 if (video) | 244 if (video) |
241 dict->SetString("video", video_constraints); | 245 dict->SetString("video", video_constraints); |
242 | 246 |
243 get_user_media_requests_.Append(dict); | 247 get_user_media_requests_.Append(std::move(dict)); |
244 | 248 |
245 if (observers_.might_have_observers()) | 249 if (observers_.might_have_observers()) |
246 SendUpdate("addGetUserMedia", dict->CreateDeepCopy()); | 250 SendUpdate("addGetUserMedia", dict->CreateDeepCopy()); |
247 | 251 |
248 if (render_process_id_set_.insert(rid).second) { | 252 if (render_process_id_set_.insert(rid).second) { |
249 RenderProcessHost* host = RenderProcessHost::FromID(rid); | 253 RenderProcessHost* host = RenderProcessHost::FromID(rid); |
250 if (host) | 254 if (host) |
251 host->AddObserver(this); | 255 host->AddObserver(this); |
252 } | 256 } |
253 } | 257 } |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 while (!pending_updates_.empty()) { | 527 while (!pending_updates_.empty()) { |
524 const auto& update = pending_updates_.front(); | 528 const auto& update = pending_updates_.front(); |
525 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | 529 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
526 observers_, | 530 observers_, |
527 OnUpdate(update.command(), update.value())); | 531 OnUpdate(update.command(), update.value())); |
528 pending_updates_.pop(); | 532 pending_updates_.pop(); |
529 } | 533 } |
530 } | 534 } |
531 | 535 |
532 } // namespace content | 536 } // namespace content |
OLD | NEW |