Chromium Code Reviews| 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 19 matching lines...) Expand all Loading... | |
| 30 log = new base::ListValue(); | 30 log = new base::ListValue(); |
| 31 if (log) | 31 if (log) |
| 32 dict->Set("log", log); | 32 dict->Set("log", log); |
| 33 } | 33 } |
| 34 return log; | 34 return log; |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 WebRTCInternals::WebRTCInternals() | 39 WebRTCInternals::WebRTCInternals() |
| 40 : aec_dump_enabled_(false) { | 40 : audio_debug_recordings_(false) { |
| 41 // TODO(grunell): Shouldn't all the webrtc_internals* files be excluded from the | 41 // TODO(grunell): Shouldn't all the webrtc_internals* files be excluded from the |
| 42 // build if WebRTC is disabled? | 42 // build if WebRTC is disabled? |
| 43 #if defined(ENABLE_WEBRTC) | 43 #if defined(ENABLE_WEBRTC) |
| 44 aec_dump_file_path_ = | 44 audio_debug_recordings_file_path_ = |
| 45 GetContentClient()->browser()->GetDefaultDownloadDirectory(); | 45 GetContentClient()->browser()->GetDefaultDownloadDirectory(); |
| 46 if (aec_dump_file_path_.empty()) { | 46 if (audio_debug_recordings_file_path_.empty()) { |
| 47 // In this case the default path (|aec_dump_file_path_|) will be empty and | 47 // In this case the default path (|audio_debug_recordings_file_path_|) will |
| 48 // the platform default path will be used in the file dialog (with no | 48 // be empty and the platform default path will be used in the file dialog |
| 49 // default file name). See SelectFileDialog::SelectFile. On Android where | 49 // (with no default file name). See SelectFileDialog::SelectFile. On Android |
| 50 // there's no dialog we'll fail to open the file. | 50 // where there's no dialog we'll fail to open the file. |
| 51 VLOG(1) << "Could not get the download directory."; | 51 VLOG(1) << "Could not get the download directory."; |
| 52 } else { | 52 } else { |
| 53 aec_dump_file_path_ = | 53 audio_debug_recordings_file_path_ = |
| 54 aec_dump_file_path_.Append(FILE_PATH_LITERAL("audio.aecdump")); | 54 audio_debug_recordings_file_path_.Append( |
| 55 FILE_PATH_LITERAL("audio_debug")); | |
| 55 } | 56 } |
| 56 #endif // defined(ENABLE_WEBRTC) | 57 #endif // defined(ENABLE_WEBRTC) |
| 57 } | 58 } |
| 58 | 59 |
| 59 WebRTCInternals::~WebRTCInternals() { | 60 WebRTCInternals::~WebRTCInternals() { |
| 60 } | 61 } |
| 61 | 62 |
| 62 WebRTCInternals* WebRTCInternals::GetInstance() { | 63 WebRTCInternals* WebRTCInternals::GetInstance() { |
| 63 return g_webrtc_internals.Pointer(); | 64 return g_webrtc_internals.Pointer(); |
| 64 } | 65 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 | 215 |
| 215 void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver *observer) { | 216 void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver *observer) { |
| 216 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 217 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 217 observers_.AddObserver(observer); | 218 observers_.AddObserver(observer); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver *observer) { | 221 void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver *observer) { |
| 221 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 222 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 222 observers_.RemoveObserver(observer); | 223 observers_.RemoveObserver(observer); |
| 223 | 224 |
| 224 // Disables the AEC recording if it is enabled and the last webrtc-internals | 225 // Disables audio debug recordings if it is enabled and the last |
| 225 // page is going away. | 226 // webrtc-internals page is going away. |
| 226 if (aec_dump_enabled_ && !observers_.might_have_observers()) | 227 if (audio_debug_recordings_ && !observers_.might_have_observers()) |
| 227 DisableAecDump(); | 228 DisableAudioDebugRecordings(); |
| 228 } | 229 } |
| 229 | 230 |
| 230 void WebRTCInternals::UpdateObserver(WebRTCInternalsUIObserver* observer) { | 231 void WebRTCInternals::UpdateObserver(WebRTCInternalsUIObserver* observer) { |
| 231 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 232 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 232 if (peer_connection_data_.GetSize() > 0) | 233 if (peer_connection_data_.GetSize() > 0) |
| 233 observer->OnUpdate("updateAllPeerConnections", &peer_connection_data_); | 234 observer->OnUpdate("updateAllPeerConnections", &peer_connection_data_); |
| 234 | 235 |
| 235 for (base::ListValue::iterator it = get_user_media_requests_.begin(); | 236 for (base::ListValue::iterator it = get_user_media_requests_.begin(); |
| 236 it != get_user_media_requests_.end(); | 237 it != get_user_media_requests_.end(); |
| 237 ++it) { | 238 ++it) { |
| 238 observer->OnUpdate("addGetUserMedia", *it); | 239 observer->OnUpdate("addGetUserMedia", *it); |
| 239 } | 240 } |
| 240 } | 241 } |
| 241 | 242 |
| 242 void WebRTCInternals::EnableAecDump(content::WebContents* web_contents) { | 243 void WebRTCInternals::EnableAudioDebugRecordings( |
| 244 content::WebContents* web_contents) { | |
| 243 #if defined(ENABLE_WEBRTC) | 245 #if defined(ENABLE_WEBRTC) |
| 244 #if defined(OS_ANDROID) | 246 #if defined(OS_ANDROID) |
| 245 EnableAecDumpOnAllRenderProcessHosts(); | 247 EnableAudioDebugRecordingsOnAllRenderProcessHosts(); |
| 246 #else | 248 #else |
| 247 select_file_dialog_ = ui::SelectFileDialog::Create(this, NULL); | 249 select_file_dialog_ = ui::SelectFileDialog::Create(this, NULL); |
| 248 select_file_dialog_->SelectFile( | 250 select_file_dialog_->SelectFile( |
| 249 ui::SelectFileDialog::SELECT_SAVEAS_FILE, | 251 ui::SelectFileDialog::SELECT_SAVEAS_FILE, |
| 250 base::string16(), | 252 base::string16(), |
| 251 aec_dump_file_path_, | 253 audio_debug_recordings_file_path_, |
| 252 NULL, | 254 NULL, |
| 253 0, | 255 0, |
| 254 FILE_PATH_LITERAL(""), | 256 FILE_PATH_LITERAL(""), |
| 255 web_contents->GetTopLevelNativeWindow(), | 257 web_contents->GetTopLevelNativeWindow(), |
| 256 NULL); | 258 NULL); |
| 257 #endif | 259 #endif |
| 258 #endif | 260 #endif |
| 259 } | 261 } |
| 260 | 262 |
| 261 void WebRTCInternals::DisableAecDump() { | 263 void WebRTCInternals::DisableAudioDebugRecordings() { |
| 262 #if defined(ENABLE_WEBRTC) | 264 #if defined(ENABLE_WEBRTC) |
| 263 aec_dump_enabled_ = false; | 265 audio_debug_recordings_ = false; |
|
tommi (sloooow) - chröme
2015/08/07 12:09:50
add thread check here and elsewhere for these memb
Henrik Grunell
2015/08/17 15:05:16
Done.
| |
| 264 | 266 |
| 265 // Tear down the dialog since the user has unchecked the AEC dump box. | 267 // Tear down the dialog since the user has unchecked the audio debug |
| 268 // recordings box. | |
| 266 select_file_dialog_ = NULL; | 269 select_file_dialog_ = NULL; |
| 267 | 270 |
| 268 for (RenderProcessHost::iterator i( | 271 for (RenderProcessHost::iterator i( |
| 269 content::RenderProcessHost::AllHostsIterator()); | 272 content::RenderProcessHost::AllHostsIterator()); |
| 270 !i.IsAtEnd(); i.Advance()) { | 273 !i.IsAtEnd(); i.Advance()) { |
| 271 i.GetCurrentValue()->DisableAecDump(); | 274 i.GetCurrentValue()->DisableAudioDebugRecordings(); |
| 272 } | 275 } |
| 273 #endif | 276 #endif |
| 274 } | 277 } |
| 275 | 278 |
| 276 void WebRTCInternals::ResetForTesting() { | 279 void WebRTCInternals::ResetForTesting() { |
| 277 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 280 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 278 observers_.Clear(); | 281 observers_.Clear(); |
| 279 peer_connection_data_.Clear(); | 282 peer_connection_data_.Clear(); |
| 280 CreateOrReleasePowerSaveBlocker(); | 283 CreateOrReleasePowerSaveBlocker(); |
| 281 get_user_media_requests_.Clear(); | 284 get_user_media_requests_.Clear(); |
| 282 aec_dump_enabled_ = false; | 285 audio_debug_recordings_ = false; |
| 283 } | 286 } |
| 284 | 287 |
| 285 void WebRTCInternals::SendUpdate(const string& command, base::Value* value) { | 288 void WebRTCInternals::SendUpdate(const string& command, base::Value* value) { |
| 286 DCHECK(observers_.might_have_observers()); | 289 DCHECK(observers_.might_have_observers()); |
| 287 | 290 |
| 288 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | 291 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
| 289 observers_, | 292 observers_, |
| 290 OnUpdate(command, value)); | 293 OnUpdate(command, value)); |
| 291 } | 294 } |
| 292 | 295 |
| 293 void WebRTCInternals::RenderProcessHostDestroyed(RenderProcessHost* host) { | 296 void WebRTCInternals::RenderProcessHostDestroyed(RenderProcessHost* host) { |
| 294 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 297 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 295 OnRendererExit(host->GetID()); | 298 OnRendererExit(host->GetID()); |
| 296 | 299 |
| 297 render_process_id_set_.erase(host->GetID()); | 300 render_process_id_set_.erase(host->GetID()); |
| 298 host->RemoveObserver(this); | 301 host->RemoveObserver(this); |
| 299 } | 302 } |
| 300 | 303 |
| 301 void WebRTCInternals::FileSelected(const base::FilePath& path, | 304 void WebRTCInternals::FileSelected(const base::FilePath& path, |
| 302 int /* unused_index */, | 305 int /* unused_index */, |
| 303 void* /*unused_params */) { | 306 void* /*unused_params */) { |
| 304 #if defined(ENABLE_WEBRTC) | 307 #if defined(ENABLE_WEBRTC) |
| 305 aec_dump_file_path_ = path; | 308 audio_debug_recordings_file_path_ = path; |
| 306 EnableAecDumpOnAllRenderProcessHosts(); | 309 EnableAudioDebugRecordingsOnAllRenderProcessHosts(); |
| 307 #endif | 310 #endif |
| 308 } | 311 } |
| 309 | 312 |
| 310 void WebRTCInternals::FileSelectionCanceled(void* params) { | 313 void WebRTCInternals::FileSelectionCanceled(void* params) { |
| 311 #if defined(ENABLE_WEBRTC) | 314 #if defined(ENABLE_WEBRTC) |
| 312 SendUpdate("aecRecordingFileSelectionCancelled", NULL); | 315 SendUpdate("audioDebugRecordingsFileSelectionCancelled", NULL); |
| 313 #endif | 316 #endif |
| 314 } | 317 } |
| 315 | 318 |
| 316 void WebRTCInternals::OnRendererExit(int render_process_id) { | 319 void WebRTCInternals::OnRendererExit(int render_process_id) { |
| 317 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 320 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 318 | 321 |
| 319 // Iterates from the end of the list to remove the PeerConnections created | 322 // Iterates from the end of the list to remove the PeerConnections created |
| 320 // by the exitting renderer. | 323 // by the exitting renderer. |
| 321 for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { | 324 for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { |
| 322 base::DictionaryValue* record = NULL; | 325 base::DictionaryValue* record = NULL; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 } | 361 } |
| 359 | 362 |
| 360 if (found_any && observers_.might_have_observers()) { | 363 if (found_any && observers_.might_have_observers()) { |
| 361 base::DictionaryValue update; | 364 base::DictionaryValue update; |
| 362 update.SetInteger("rid", render_process_id); | 365 update.SetInteger("rid", render_process_id); |
| 363 SendUpdate("removeGetUserMediaForRenderer", &update); | 366 SendUpdate("removeGetUserMediaForRenderer", &update); |
| 364 } | 367 } |
| 365 } | 368 } |
| 366 | 369 |
| 367 #if defined(ENABLE_WEBRTC) | 370 #if defined(ENABLE_WEBRTC) |
| 368 void WebRTCInternals::EnableAecDumpOnAllRenderProcessHosts() { | 371 void WebRTCInternals::EnableAudioDebugRecordingsOnAllRenderProcessHosts() { |
| 369 aec_dump_enabled_ = true; | 372 audio_debug_recordings_ = true; |
| 370 for (RenderProcessHost::iterator i( | 373 for (RenderProcessHost::iterator i( |
| 371 content::RenderProcessHost::AllHostsIterator()); | 374 content::RenderProcessHost::AllHostsIterator()); |
| 372 !i.IsAtEnd(); i.Advance()) { | 375 !i.IsAtEnd(); i.Advance()) { |
| 373 i.GetCurrentValue()->EnableAecDump(aec_dump_file_path_); | 376 i.GetCurrentValue()->EnableAudioDebugRecordings( |
| 377 audio_debug_recordings_file_path_); | |
| 374 } | 378 } |
| 375 } | 379 } |
| 376 #endif | 380 #endif |
| 377 | 381 |
| 378 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { | 382 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { |
| 379 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 383 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 380 | 384 |
| 381 if (peer_connection_data_.empty() && power_save_blocker_) { | 385 if (peer_connection_data_.empty() && power_save_blocker_) { |
| 382 DVLOG(1) << ("Releasing the block on application suspension since no " | 386 DVLOG(1) << ("Releasing the block on application suspension since no " |
| 383 "PeerConnections are active anymore."); | 387 "PeerConnections are active anymore."); |
| 384 power_save_blocker_.reset(); | 388 power_save_blocker_.reset(); |
| 385 } else if (!peer_connection_data_.empty() && !power_save_blocker_) { | 389 } else if (!peer_connection_data_.empty() && !power_save_blocker_) { |
| 386 DVLOG(1) << ("Preventing the application from being suspended while one or " | 390 DVLOG(1) << ("Preventing the application from being suspended while one or " |
| 387 "more PeerConnections are active."); | 391 "more PeerConnections are active."); |
| 388 power_save_blocker_ = | 392 power_save_blocker_ = |
| 389 content::PowerSaveBlocker::Create( | 393 content::PowerSaveBlocker::Create( |
| 390 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 394 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 391 PowerSaveBlocker::kReasonOther, | 395 PowerSaveBlocker::kReasonOther, |
| 392 "WebRTC has active PeerConnections").Pass(); | 396 "WebRTC has active PeerConnections").Pass(); |
| 393 } | 397 } |
| 394 } | 398 } |
| 395 | 399 |
| 396 } // namespace content | 400 } // namespace content |
| OLD | NEW |