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); | |
128 CreateOrReleasePowerSaveBlocker(); | |
129 | 130 |
130 if (observers_.might_have_observers()) | 131 if (observers_.might_have_observers()) |
131 SendUpdate("addPeerConnection", dict->CreateDeepCopy()); | 132 SendUpdate("addPeerConnection", dict->CreateDeepCopy()); |
132 | 133 |
| 134 peer_connection_data_.Append(std::move(dict)); |
| 135 CreateOrReleasePowerSaveBlocker(); |
| 136 |
133 if (render_process_id_set_.insert(render_process_id).second) { | 137 if (render_process_id_set_.insert(render_process_id).second) { |
134 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); | 138 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); |
135 if (host) | 139 if (host) |
136 host->AddObserver(this); | 140 host->AddObserver(this); |
137 } | 141 } |
138 } | 142 } |
139 | 143 |
140 void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) { | 144 void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) { |
141 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 145 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
142 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { | 146 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 record->GetInteger("lid", &this_lid); | 181 record->GetInteger("lid", &this_lid); |
178 | 182 |
179 if (this_pid != static_cast<int>(pid) || this_lid != lid) | 183 if (this_pid != static_cast<int>(pid) || this_lid != lid) |
180 continue; | 184 continue; |
181 | 185 |
182 // Append the update to the end of the log. | 186 // Append the update to the end of the log. |
183 base::ListValue* log = EnsureLogList(record); | 187 base::ListValue* log = EnsureLogList(record); |
184 if (!log) | 188 if (!log) |
185 return; | 189 return; |
186 | 190 |
187 base::DictionaryValue* log_entry = new base::DictionaryValue(); | 191 std::unique_ptr<base::DictionaryValue> log_entry( |
188 if (!log_entry) | 192 new base::DictionaryValue()); |
189 return; | |
190 | 193 |
191 double epoch_time = base::Time::Now().ToJsTime(); | 194 double epoch_time = base::Time::Now().ToJsTime(); |
192 string time = base::DoubleToString(epoch_time); | 195 string time = base::DoubleToString(epoch_time); |
193 log_entry->SetString("time", time); | 196 log_entry->SetString("time", time); |
194 log_entry->SetString("type", type); | 197 log_entry->SetString("type", type); |
195 log_entry->SetString("value", value); | 198 log_entry->SetString("value", value); |
196 log->Append(log_entry); | |
197 | 199 |
198 if (observers_.might_have_observers()) { | 200 if (observers_.might_have_observers()) { |
199 std::unique_ptr<base::DictionaryValue> update( | 201 std::unique_ptr<base::DictionaryValue> update( |
200 new base::DictionaryValue()); | 202 new base::DictionaryValue()); |
201 update->SetInteger("pid", static_cast<int>(pid)); | 203 update->SetInteger("pid", static_cast<int>(pid)); |
202 update->SetInteger("lid", lid); | 204 update->SetInteger("lid", lid); |
203 update->MergeDictionary(log_entry); | 205 update->MergeDictionary(log_entry.get()); |
204 | 206 |
205 SendUpdate("updatePeerConnection", std::move(update)); | 207 SendUpdate("updatePeerConnection", std::move(update)); |
206 } | 208 } |
| 209 |
| 210 log->Append(std::move(log_entry)); |
| 211 |
207 return; | 212 return; |
208 } | 213 } |
209 } | 214 } |
210 | 215 |
211 void WebRTCInternals::OnAddStats(base::ProcessId pid, int lid, | 216 void WebRTCInternals::OnAddStats(base::ProcessId pid, int lid, |
212 const base::ListValue& value) { | 217 const base::ListValue& value) { |
213 if (!observers_.might_have_observers()) | 218 if (!observers_.might_have_observers()) |
214 return; | 219 return; |
215 | 220 |
216 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 221 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
217 dict->SetInteger("pid", static_cast<int>(pid)); | 222 dict->SetInteger("pid", static_cast<int>(pid)); |
218 dict->SetInteger("lid", lid); | 223 dict->SetInteger("lid", lid); |
219 | 224 |
220 dict->Set("reports", value.CreateDeepCopy()); | 225 dict->Set("reports", value.CreateDeepCopy()); |
221 | 226 |
222 SendUpdate("addStats", std::move(dict)); | 227 SendUpdate("addStats", std::move(dict)); |
223 } | 228 } |
224 | 229 |
225 void WebRTCInternals::OnGetUserMedia(int rid, | 230 void WebRTCInternals::OnGetUserMedia(int rid, |
226 base::ProcessId pid, | 231 base::ProcessId pid, |
227 const std::string& origin, | 232 const std::string& origin, |
228 bool audio, | 233 bool audio, |
229 bool video, | 234 bool video, |
230 const std::string& audio_constraints, | 235 const std::string& audio_constraints, |
231 const std::string& video_constraints) { | 236 const std::string& video_constraints) { |
232 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 237 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
233 | 238 |
234 base::DictionaryValue* dict = new base::DictionaryValue(); | 239 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
235 dict->SetInteger("rid", rid); | 240 dict->SetInteger("rid", rid); |
236 dict->SetInteger("pid", static_cast<int>(pid)); | 241 dict->SetInteger("pid", static_cast<int>(pid)); |
237 dict->SetString("origin", origin); | 242 dict->SetString("origin", origin); |
238 if (audio) | 243 if (audio) |
239 dict->SetString("audio", audio_constraints); | 244 dict->SetString("audio", audio_constraints); |
240 if (video) | 245 if (video) |
241 dict->SetString("video", video_constraints); | 246 dict->SetString("video", video_constraints); |
242 | 247 |
243 get_user_media_requests_.Append(dict); | |
244 | |
245 if (observers_.might_have_observers()) | 248 if (observers_.might_have_observers()) |
246 SendUpdate("addGetUserMedia", dict->CreateDeepCopy()); | 249 SendUpdate("addGetUserMedia", dict->CreateDeepCopy()); |
247 | 250 |
| 251 get_user_media_requests_.Append(std::move(dict)); |
| 252 |
248 if (render_process_id_set_.insert(rid).second) { | 253 if (render_process_id_set_.insert(rid).second) { |
249 RenderProcessHost* host = RenderProcessHost::FromID(rid); | 254 RenderProcessHost* host = RenderProcessHost::FromID(rid); |
250 if (host) | 255 if (host) |
251 host->AddObserver(this); | 256 host->AddObserver(this); |
252 } | 257 } |
253 } | 258 } |
254 | 259 |
255 void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver* observer) { | 260 void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver* observer) { |
256 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 261 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
257 observers_.AddObserver(observer); | 262 observers_.AddObserver(observer); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 while (!pending_updates_.empty()) { | 528 while (!pending_updates_.empty()) { |
524 const auto& update = pending_updates_.front(); | 529 const auto& update = pending_updates_.front(); |
525 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | 530 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
526 observers_, | 531 observers_, |
527 OnUpdate(update.command(), update.value())); | 532 OnUpdate(update.command(), update.value())); |
528 pending_updates_.pop(); | 533 pending_updates_.pop(); |
529 } | 534 } |
530 } | 535 } |
531 | 536 |
532 } // namespace content | 537 } // namespace content |
OLD | NEW |