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/media/webrtc_internals.h" | 5 #include "content/browser/media/webrtc_internals.h" |
6 | 6 |
7 #include "base/strings/string_number_conversions.h" | 7 #include "base/strings/string_number_conversions.h" |
8 #include "content/browser/media/webrtc_internals_ui_observer.h" | 8 #include "content/browser/media/webrtc_internals_ui_observer.h" |
9 #include "content/browser/web_contents/web_contents_view.h" | 9 #include "content/browser/web_contents/web_contents_view.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 WebRTCInternals* WebRTCInternals::GetInstance() { | 66 WebRTCInternals* WebRTCInternals::GetInstance() { |
67 return g_webrtc_internals.Pointer(); | 67 return g_webrtc_internals.Pointer(); |
68 } | 68 } |
69 | 69 |
70 void WebRTCInternals::OnAddPeerConnection(int render_process_id, | 70 void WebRTCInternals::OnAddPeerConnection(int render_process_id, |
71 ProcessId pid, | 71 ProcessId pid, |
72 int lid, | 72 int lid, |
73 const string& url, | 73 const string& url, |
74 const string& rtc_configuration, | 74 const string& rtc_configuration, |
75 const string& constraints) { | 75 const string& constraints) { |
76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 76 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
77 | 77 |
78 base::DictionaryValue* dict = new base::DictionaryValue(); | 78 base::DictionaryValue* dict = new base::DictionaryValue(); |
79 if (!dict) | 79 if (!dict) |
80 return; | 80 return; |
81 | 81 |
82 dict->SetInteger("rid", render_process_id); | 82 dict->SetInteger("rid", render_process_id); |
83 dict->SetInteger("pid", static_cast<int>(pid)); | 83 dict->SetInteger("pid", static_cast<int>(pid)); |
84 dict->SetInteger("lid", lid); | 84 dict->SetInteger("lid", lid); |
85 dict->SetString("rtcConfiguration", rtc_configuration); | 85 dict->SetString("rtcConfiguration", rtc_configuration); |
86 dict->SetString("constraints", constraints); | 86 dict->SetString("constraints", constraints); |
87 dict->SetString("url", url); | 87 dict->SetString("url", url); |
88 peer_connection_data_.Append(dict); | 88 peer_connection_data_.Append(dict); |
89 CreateOrReleasePowerSaveBlocker(); | 89 CreateOrReleasePowerSaveBlocker(); |
90 | 90 |
91 if (observers_.might_have_observers()) | 91 if (observers_.might_have_observers()) |
92 SendUpdate("addPeerConnection", dict); | 92 SendUpdate("addPeerConnection", dict); |
93 } | 93 } |
94 | 94 |
95 void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) { | 95 void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) { |
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 96 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
97 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { | 97 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { |
98 base::DictionaryValue* dict = NULL; | 98 base::DictionaryValue* dict = NULL; |
99 peer_connection_data_.GetDictionary(i, &dict); | 99 peer_connection_data_.GetDictionary(i, &dict); |
100 | 100 |
101 int this_pid = 0; | 101 int this_pid = 0; |
102 int this_lid = 0; | 102 int this_lid = 0; |
103 dict->GetInteger("pid", &this_pid); | 103 dict->GetInteger("pid", &this_pid); |
104 dict->GetInteger("lid", &this_lid); | 104 dict->GetInteger("lid", &this_lid); |
105 | 105 |
106 if (this_pid != static_cast<int>(pid) || this_lid != lid) | 106 if (this_pid != static_cast<int>(pid) || this_lid != lid) |
107 continue; | 107 continue; |
108 | 108 |
109 peer_connection_data_.Remove(i, NULL); | 109 peer_connection_data_.Remove(i, NULL); |
110 CreateOrReleasePowerSaveBlocker(); | 110 CreateOrReleasePowerSaveBlocker(); |
111 | 111 |
112 if (observers_.might_have_observers()) { | 112 if (observers_.might_have_observers()) { |
113 base::DictionaryValue id; | 113 base::DictionaryValue id; |
114 id.SetInteger("pid", static_cast<int>(pid)); | 114 id.SetInteger("pid", static_cast<int>(pid)); |
115 id.SetInteger("lid", lid); | 115 id.SetInteger("lid", lid); |
116 SendUpdate("removePeerConnection", &id); | 116 SendUpdate("removePeerConnection", &id); |
117 } | 117 } |
118 break; | 118 break; |
119 } | 119 } |
120 } | 120 } |
121 | 121 |
122 void WebRTCInternals::OnUpdatePeerConnection( | 122 void WebRTCInternals::OnUpdatePeerConnection( |
123 ProcessId pid, int lid, const string& type, const string& value) { | 123 ProcessId pid, int lid, const string& type, const string& value) { |
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 124 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
125 | 125 |
126 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { | 126 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { |
127 base::DictionaryValue* record = NULL; | 127 base::DictionaryValue* record = NULL; |
128 peer_connection_data_.GetDictionary(i, &record); | 128 peer_connection_data_.GetDictionary(i, &record); |
129 | 129 |
130 int this_pid = 0, this_lid = 0; | 130 int this_pid = 0, this_lid = 0; |
131 record->GetInteger("pid", &this_pid); | 131 record->GetInteger("pid", &this_pid); |
132 record->GetInteger("lid", &this_lid); | 132 record->GetInteger("lid", &this_lid); |
133 | 133 |
134 if (this_pid != static_cast<int>(pid) || this_lid != lid) | 134 if (this_pid != static_cast<int>(pid) || this_lid != lid) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 SendUpdate("addStats", &dict); | 180 SendUpdate("addStats", &dict); |
181 } | 181 } |
182 | 182 |
183 void WebRTCInternals::OnGetUserMedia(int rid, | 183 void WebRTCInternals::OnGetUserMedia(int rid, |
184 base::ProcessId pid, | 184 base::ProcessId pid, |
185 const std::string& origin, | 185 const std::string& origin, |
186 bool audio, | 186 bool audio, |
187 bool video, | 187 bool video, |
188 const std::string& audio_constraints, | 188 const std::string& audio_constraints, |
189 const std::string& video_constraints) { | 189 const std::string& video_constraints) { |
190 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 190 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
191 | 191 |
192 base::DictionaryValue* dict = new base::DictionaryValue(); | 192 base::DictionaryValue* dict = new base::DictionaryValue(); |
193 dict->SetInteger("rid", rid); | 193 dict->SetInteger("rid", rid); |
194 dict->SetInteger("pid", static_cast<int>(pid)); | 194 dict->SetInteger("pid", static_cast<int>(pid)); |
195 dict->SetString("origin", origin); | 195 dict->SetString("origin", origin); |
196 if (audio) | 196 if (audio) |
197 dict->SetString("audio", audio_constraints); | 197 dict->SetString("audio", audio_constraints); |
198 if (video) | 198 if (video) |
199 dict->SetString("video", video_constraints); | 199 dict->SetString("video", video_constraints); |
200 | 200 |
201 get_user_media_requests_.Append(dict); | 201 get_user_media_requests_.Append(dict); |
202 | 202 |
203 if (observers_.might_have_observers()) | 203 if (observers_.might_have_observers()) |
204 SendUpdate("addGetUserMedia", dict); | 204 SendUpdate("addGetUserMedia", dict); |
205 } | 205 } |
206 | 206 |
207 void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver *observer) { | 207 void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver *observer) { |
208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 208 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
209 observers_.AddObserver(observer); | 209 observers_.AddObserver(observer); |
210 } | 210 } |
211 | 211 |
212 void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver *observer) { | 212 void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver *observer) { |
213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 213 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
214 observers_.RemoveObserver(observer); | 214 observers_.RemoveObserver(observer); |
215 | 215 |
216 // Disables the AEC recording if it is enabled and the last webrtc-internals | 216 // Disables the AEC recording if it is enabled and the last webrtc-internals |
217 // page is going away. | 217 // page is going away. |
218 if (aec_dump_enabled_ && !observers_.might_have_observers()) | 218 if (aec_dump_enabled_ && !observers_.might_have_observers()) |
219 DisableAecDump(); | 219 DisableAecDump(); |
220 } | 220 } |
221 | 221 |
222 void WebRTCInternals::UpdateObserver(WebRTCInternalsUIObserver* observer) { | 222 void WebRTCInternals::UpdateObserver(WebRTCInternalsUIObserver* observer) { |
223 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 223 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
224 if (peer_connection_data_.GetSize() > 0) | 224 if (peer_connection_data_.GetSize() > 0) |
225 observer->OnUpdate("updateAllPeerConnections", &peer_connection_data_); | 225 observer->OnUpdate("updateAllPeerConnections", &peer_connection_data_); |
226 | 226 |
227 for (base::ListValue::iterator it = get_user_media_requests_.begin(); | 227 for (base::ListValue::iterator it = get_user_media_requests_.begin(); |
228 it != get_user_media_requests_.end(); | 228 it != get_user_media_requests_.end(); |
229 ++it) { | 229 ++it) { |
230 observer->OnUpdate("addGetUserMedia", *it); | 230 observer->OnUpdate("addGetUserMedia", *it); |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
(...skipping 25 matching lines...) Expand all Loading... |
259 | 259 |
260 for (RenderProcessHost::iterator i( | 260 for (RenderProcessHost::iterator i( |
261 content::RenderProcessHost::AllHostsIterator()); | 261 content::RenderProcessHost::AllHostsIterator()); |
262 !i.IsAtEnd(); i.Advance()) { | 262 !i.IsAtEnd(); i.Advance()) { |
263 i.GetCurrentValue()->DisableAecDump(); | 263 i.GetCurrentValue()->DisableAecDump(); |
264 } | 264 } |
265 #endif | 265 #endif |
266 } | 266 } |
267 | 267 |
268 void WebRTCInternals::ResetForTesting() { | 268 void WebRTCInternals::ResetForTesting() { |
269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 269 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
270 observers_.Clear(); | 270 observers_.Clear(); |
271 peer_connection_data_.Clear(); | 271 peer_connection_data_.Clear(); |
272 CreateOrReleasePowerSaveBlocker(); | 272 CreateOrReleasePowerSaveBlocker(); |
273 get_user_media_requests_.Clear(); | 273 get_user_media_requests_.Clear(); |
274 aec_dump_enabled_ = false; | 274 aec_dump_enabled_ = false; |
275 } | 275 } |
276 | 276 |
277 void WebRTCInternals::SendUpdate(const string& command, base::Value* value) { | 277 void WebRTCInternals::SendUpdate(const string& command, base::Value* value) { |
278 DCHECK(observers_.might_have_observers()); | 278 DCHECK(observers_.might_have_observers()); |
279 | 279 |
280 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | 280 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
281 observers_, | 281 observers_, |
282 OnUpdate(command, value)); | 282 OnUpdate(command, value)); |
283 } | 283 } |
284 | 284 |
285 void WebRTCInternals::Observe(int type, | 285 void WebRTCInternals::Observe(int type, |
286 const NotificationSource& source, | 286 const NotificationSource& source, |
287 const NotificationDetails& details) { | 287 const NotificationDetails& details) { |
288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 288 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
289 DCHECK_EQ(type, NOTIFICATION_RENDERER_PROCESS_TERMINATED); | 289 DCHECK_EQ(type, NOTIFICATION_RENDERER_PROCESS_TERMINATED); |
290 OnRendererExit(Source<RenderProcessHost>(source)->GetID()); | 290 OnRendererExit(Source<RenderProcessHost>(source)->GetID()); |
291 } | 291 } |
292 | 292 |
293 void WebRTCInternals::FileSelected(const base::FilePath& path, | 293 void WebRTCInternals::FileSelected(const base::FilePath& path, |
294 int /* unused_index */, | 294 int /* unused_index */, |
295 void* /*unused_params */) { | 295 void* /*unused_params */) { |
296 #if defined(ENABLE_WEBRTC) | 296 #if defined(ENABLE_WEBRTC) |
297 aec_dump_file_path_ = path; | 297 aec_dump_file_path_ = path; |
298 EnableAecDumpOnAllRenderProcessHosts(); | 298 EnableAecDumpOnAllRenderProcessHosts(); |
299 #endif | 299 #endif |
300 } | 300 } |
301 | 301 |
302 void WebRTCInternals::FileSelectionCanceled(void* params) { | 302 void WebRTCInternals::FileSelectionCanceled(void* params) { |
303 #if defined(ENABLE_WEBRTC) | 303 #if defined(ENABLE_WEBRTC) |
304 SendUpdate("aecRecordingFileSelectionCancelled", NULL); | 304 SendUpdate("aecRecordingFileSelectionCancelled", NULL); |
305 #endif | 305 #endif |
306 } | 306 } |
307 | 307 |
308 void WebRTCInternals::OnRendererExit(int render_process_id) { | 308 void WebRTCInternals::OnRendererExit(int render_process_id) { |
309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 309 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
310 | 310 |
311 // Iterates from the end of the list to remove the PeerConnections created | 311 // Iterates from the end of the list to remove the PeerConnections created |
312 // by the exitting renderer. | 312 // by the exitting renderer. |
313 for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { | 313 for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { |
314 base::DictionaryValue* record = NULL; | 314 base::DictionaryValue* record = NULL; |
315 peer_connection_data_.GetDictionary(i, &record); | 315 peer_connection_data_.GetDictionary(i, &record); |
316 | 316 |
317 int this_rid = 0; | 317 int this_rid = 0; |
318 record->GetInteger("rid", &this_rid); | 318 record->GetInteger("rid", &this_rid); |
319 | 319 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 aec_dump_enabled_ = true; | 361 aec_dump_enabled_ = true; |
362 for (RenderProcessHost::iterator i( | 362 for (RenderProcessHost::iterator i( |
363 content::RenderProcessHost::AllHostsIterator()); | 363 content::RenderProcessHost::AllHostsIterator()); |
364 !i.IsAtEnd(); i.Advance()) { | 364 !i.IsAtEnd(); i.Advance()) { |
365 i.GetCurrentValue()->EnableAecDump(aec_dump_file_path_); | 365 i.GetCurrentValue()->EnableAecDump(aec_dump_file_path_); |
366 } | 366 } |
367 } | 367 } |
368 #endif | 368 #endif |
369 | 369 |
370 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { | 370 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { |
371 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 371 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
372 | 372 |
373 if (peer_connection_data_.empty() && power_save_blocker_) { | 373 if (peer_connection_data_.empty() && power_save_blocker_) { |
374 DVLOG(1) << ("Releasing the block on application suspension since no " | 374 DVLOG(1) << ("Releasing the block on application suspension since no " |
375 "PeerConnections are active anymore."); | 375 "PeerConnections are active anymore."); |
376 power_save_blocker_.reset(); | 376 power_save_blocker_.reset(); |
377 } else if (!peer_connection_data_.empty() && !power_save_blocker_) { | 377 } else if (!peer_connection_data_.empty() && !power_save_blocker_) { |
378 DVLOG(1) << ("Preventing the application from being suspended while one or " | 378 DVLOG(1) << ("Preventing the application from being suspended while one or " |
379 "more PeerConnections are active."); | 379 "more PeerConnections are active."); |
380 power_save_blocker_ = | 380 power_save_blocker_ = |
381 content::PowerSaveBlocker::Create( | 381 content::PowerSaveBlocker::Create( |
382 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 382 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
383 PowerSaveBlocker::kReasonOther, | 383 PowerSaveBlocker::kReasonOther, |
384 "WebRTC has active PeerConnections").Pass(); | 384 "WebRTC has active PeerConnections").Pass(); |
385 } | 385 } |
386 } | 386 } |
387 | 387 |
388 } // namespace content | 388 } // namespace content |
OLD | NEW |