| 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/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "content/browser/media/webrtc_internals_ui_observer.h" | 9 #include "content/browser/media/webrtc_internals_ui_observer.h" |
| 10 #include "content/browser/web_contents/web_contents_view.h" | 10 #include "content/browser/web_contents/web_contents_view.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/content_browser_client.h" | 12 #include "content/public/browser/content_browser_client.h" |
| 13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 #include "content/public/browser/notification_types.h" | 14 #include "content/public/browser/notification_types.h" |
| 15 #include "content/public/browser/power_save_blocker.h" |
| 15 #include "content/public/browser/render_process_host.h" | 16 #include "content/public/browser/render_process_host.h" |
| 16 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
| 17 | 18 |
| 18 using base::ProcessId; | 19 using base::ProcessId; |
| 19 using std::string; | 20 using std::string; |
| 20 | 21 |
| 21 namespace content { | 22 namespace content { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 // Makes sure that |dict| has a ListValue under path "log". | 25 // Makes sure that |dict| has a ListValue under path "log". |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 if (!dict) | 76 if (!dict) |
| 76 return; | 77 return; |
| 77 | 78 |
| 78 dict->SetInteger("rid", render_process_id); | 79 dict->SetInteger("rid", render_process_id); |
| 79 dict->SetInteger("pid", static_cast<int>(pid)); | 80 dict->SetInteger("pid", static_cast<int>(pid)); |
| 80 dict->SetInteger("lid", lid); | 81 dict->SetInteger("lid", lid); |
| 81 dict->SetString("rtcConfiguration", rtc_configuration); | 82 dict->SetString("rtcConfiguration", rtc_configuration); |
| 82 dict->SetString("constraints", constraints); | 83 dict->SetString("constraints", constraints); |
| 83 dict->SetString("url", url); | 84 dict->SetString("url", url); |
| 84 peer_connection_data_.Append(dict); | 85 peer_connection_data_.Append(dict); |
| 86 CreateOrReleasePowerSaveBlocker(); |
| 85 | 87 |
| 86 if (observers_.might_have_observers()) | 88 if (observers_.might_have_observers()) |
| 87 SendUpdate("addPeerConnection", dict); | 89 SendUpdate("addPeerConnection", dict); |
| 88 } | 90 } |
| 89 | 91 |
| 90 void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) { | 92 void WebRTCInternals::OnRemovePeerConnection(ProcessId pid, int lid) { |
| 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 92 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { | 94 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { |
| 93 base::DictionaryValue* dict = NULL; | 95 base::DictionaryValue* dict = NULL; |
| 94 peer_connection_data_.GetDictionary(i, &dict); | 96 peer_connection_data_.GetDictionary(i, &dict); |
| 95 | 97 |
| 96 int this_pid = 0; | 98 int this_pid = 0; |
| 97 int this_lid = 0; | 99 int this_lid = 0; |
| 98 dict->GetInteger("pid", &this_pid); | 100 dict->GetInteger("pid", &this_pid); |
| 99 dict->GetInteger("lid", &this_lid); | 101 dict->GetInteger("lid", &this_lid); |
| 100 | 102 |
| 101 if (this_pid != static_cast<int>(pid) || this_lid != lid) | 103 if (this_pid != static_cast<int>(pid) || this_lid != lid) |
| 102 continue; | 104 continue; |
| 103 | 105 |
| 104 peer_connection_data_.Remove(i, NULL); | 106 peer_connection_data_.Remove(i, NULL); |
| 107 CreateOrReleasePowerSaveBlocker(); |
| 105 | 108 |
| 106 if (observers_.might_have_observers()) { | 109 if (observers_.might_have_observers()) { |
| 107 base::DictionaryValue id; | 110 base::DictionaryValue id; |
| 108 id.SetInteger("pid", static_cast<int>(pid)); | 111 id.SetInteger("pid", static_cast<int>(pid)); |
| 109 id.SetInteger("lid", lid); | 112 id.SetInteger("lid", lid); |
| 110 SendUpdate("removePeerConnection", &id); | 113 SendUpdate("removePeerConnection", &id); |
| 111 } | 114 } |
| 112 break; | 115 break; |
| 113 } | 116 } |
| 114 } | 117 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 !i.IsAtEnd(); i.Advance()) { | 259 !i.IsAtEnd(); i.Advance()) { |
| 257 i.GetCurrentValue()->DisableAecDump(); | 260 i.GetCurrentValue()->DisableAecDump(); |
| 258 } | 261 } |
| 259 #endif | 262 #endif |
| 260 } | 263 } |
| 261 | 264 |
| 262 void WebRTCInternals::ResetForTesting() { | 265 void WebRTCInternals::ResetForTesting() { |
| 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 264 observers_.Clear(); | 267 observers_.Clear(); |
| 265 peer_connection_data_.Clear(); | 268 peer_connection_data_.Clear(); |
| 269 CreateOrReleasePowerSaveBlocker(); |
| 266 get_user_media_requests_.Clear(); | 270 get_user_media_requests_.Clear(); |
| 267 aec_dump_enabled_ = false; | 271 aec_dump_enabled_ = false; |
| 268 } | 272 } |
| 269 | 273 |
| 270 void WebRTCInternals::SendUpdate(const string& command, base::Value* value) { | 274 void WebRTCInternals::SendUpdate(const string& command, base::Value* value) { |
| 271 DCHECK(observers_.might_have_observers()); | 275 DCHECK(observers_.might_have_observers()); |
| 272 | 276 |
| 273 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | 277 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
| 274 observers_, | 278 observers_, |
| 275 OnUpdate(command, value)); | 279 OnUpdate(command, value)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 292 #endif | 296 #endif |
| 293 } | 297 } |
| 294 | 298 |
| 295 void WebRTCInternals::FileSelectionCanceled(void* params) { | 299 void WebRTCInternals::FileSelectionCanceled(void* params) { |
| 296 #if defined(ENABLE_WEBRTC) | 300 #if defined(ENABLE_WEBRTC) |
| 297 SendUpdate("aecRecordingFileSelectionCancelled", NULL); | 301 SendUpdate("aecRecordingFileSelectionCancelled", NULL); |
| 298 #endif | 302 #endif |
| 299 } | 303 } |
| 300 | 304 |
| 301 void WebRTCInternals::OnRendererExit(int render_process_id) { | 305 void WebRTCInternals::OnRendererExit(int render_process_id) { |
| 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 307 |
| 302 // Iterates from the end of the list to remove the PeerConnections created | 308 // Iterates from the end of the list to remove the PeerConnections created |
| 303 // by the exitting renderer. | 309 // by the exitting renderer. |
| 304 for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { | 310 for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { |
| 305 base::DictionaryValue* record = NULL; | 311 base::DictionaryValue* record = NULL; |
| 306 peer_connection_data_.GetDictionary(i, &record); | 312 peer_connection_data_.GetDictionary(i, &record); |
| 307 | 313 |
| 308 int this_rid = 0; | 314 int this_rid = 0; |
| 309 record->GetInteger("rid", &this_rid); | 315 record->GetInteger("rid", &this_rid); |
| 310 | 316 |
| 311 if (this_rid == render_process_id) { | 317 if (this_rid == render_process_id) { |
| 312 if (observers_.might_have_observers()) { | 318 if (observers_.might_have_observers()) { |
| 313 int lid = 0, pid = 0; | 319 int lid = 0, pid = 0; |
| 314 record->GetInteger("lid", &lid); | 320 record->GetInteger("lid", &lid); |
| 315 record->GetInteger("pid", &pid); | 321 record->GetInteger("pid", &pid); |
| 316 | 322 |
| 317 base::DictionaryValue update; | 323 base::DictionaryValue update; |
| 318 update.SetInteger("lid", lid); | 324 update.SetInteger("lid", lid); |
| 319 update.SetInteger("pid", pid); | 325 update.SetInteger("pid", pid); |
| 320 SendUpdate("removePeerConnection", &update); | 326 SendUpdate("removePeerConnection", &update); |
| 321 } | 327 } |
| 322 peer_connection_data_.Remove(i, NULL); | 328 peer_connection_data_.Remove(i, NULL); |
| 323 } | 329 } |
| 324 } | 330 } |
| 331 CreateOrReleasePowerSaveBlocker(); |
| 325 | 332 |
| 326 bool found_any = false; | 333 bool found_any = false; |
| 327 // Iterates from the end of the list to remove the getUserMedia requests | 334 // Iterates from the end of the list to remove the getUserMedia requests |
| 328 // created by the exiting renderer. | 335 // created by the exiting renderer. |
| 329 for (int i = get_user_media_requests_.GetSize() - 1; i >= 0; --i) { | 336 for (int i = get_user_media_requests_.GetSize() - 1; i >= 0; --i) { |
| 330 base::DictionaryValue* record = NULL; | 337 base::DictionaryValue* record = NULL; |
| 331 get_user_media_requests_.GetDictionary(i, &record); | 338 get_user_media_requests_.GetDictionary(i, &record); |
| 332 | 339 |
| 333 int this_rid = 0; | 340 int this_rid = 0; |
| 334 record->GetInteger("rid", &this_rid); | 341 record->GetInteger("rid", &this_rid); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 350 void WebRTCInternals::EnableAecDumpOnAllRenderProcessHosts() { | 357 void WebRTCInternals::EnableAecDumpOnAllRenderProcessHosts() { |
| 351 aec_dump_enabled_ = true; | 358 aec_dump_enabled_ = true; |
| 352 for (RenderProcessHost::iterator i( | 359 for (RenderProcessHost::iterator i( |
| 353 content::RenderProcessHost::AllHostsIterator()); | 360 content::RenderProcessHost::AllHostsIterator()); |
| 354 !i.IsAtEnd(); i.Advance()) { | 361 !i.IsAtEnd(); i.Advance()) { |
| 355 i.GetCurrentValue()->EnableAecDump(aec_dump_file_path_); | 362 i.GetCurrentValue()->EnableAecDump(aec_dump_file_path_); |
| 356 } | 363 } |
| 357 } | 364 } |
| 358 #endif | 365 #endif |
| 359 | 366 |
| 367 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { |
| 368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 369 |
| 370 if (peer_connection_data_.empty() && power_save_blocker_) { |
| 371 DVLOG(1) << ("Releasing the block on application suspension since no " |
| 372 "PeerConnections are active anymore."); |
| 373 power_save_blocker_.reset(); |
| 374 } else if (!peer_connection_data_.empty() && !power_save_blocker_) { |
| 375 DVLOG(1) << ("Preventing the application from being suspended while one or " |
| 376 "more PeerConnections are active."); |
| 377 power_save_blocker_ = content::PowerSaveBlocker::Create( |
| 378 content::PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 379 "WebRTC has active PeerConnections.").Pass(); |
| 380 } |
| 381 } |
| 382 |
| 360 } // namespace content | 383 } // namespace content |
| OLD | NEW |