| 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) |
| 246 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 244 #if defined(OS_ANDROID) | 247 #if defined(OS_ANDROID) |
| 245 EnableAecDumpOnAllRenderProcessHosts(); | 248 EnableAudioDebugRecordingsOnAllRenderProcessHosts(); |
| 246 #else | 249 #else |
| 247 select_file_dialog_ = ui::SelectFileDialog::Create(this, NULL); | 250 select_file_dialog_ = ui::SelectFileDialog::Create(this, NULL); |
| 248 select_file_dialog_->SelectFile( | 251 select_file_dialog_->SelectFile( |
| 249 ui::SelectFileDialog::SELECT_SAVEAS_FILE, | 252 ui::SelectFileDialog::SELECT_SAVEAS_FILE, |
| 250 base::string16(), | 253 base::string16(), |
| 251 aec_dump_file_path_, | 254 audio_debug_recordings_file_path_, |
| 252 NULL, | 255 NULL, |
| 253 0, | 256 0, |
| 254 FILE_PATH_LITERAL(""), | 257 FILE_PATH_LITERAL(""), |
| 255 web_contents->GetTopLevelNativeWindow(), | 258 web_contents->GetTopLevelNativeWindow(), |
| 256 NULL); | 259 NULL); |
| 257 #endif | 260 #endif |
| 258 #endif | 261 #endif |
| 259 } | 262 } |
| 260 | 263 |
| 261 void WebRTCInternals::DisableAecDump() { | 264 void WebRTCInternals::DisableAudioDebugRecordings() { |
| 262 #if defined(ENABLE_WEBRTC) | 265 #if defined(ENABLE_WEBRTC) |
| 263 aec_dump_enabled_ = false; | 266 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 267 audio_debug_recordings_ = false; |
| 264 | 268 |
| 265 // Tear down the dialog since the user has unchecked the AEC dump box. | 269 // Tear down the dialog since the user has unchecked the audio debug |
| 270 // recordings box. |
| 266 select_file_dialog_ = NULL; | 271 select_file_dialog_ = NULL; |
| 267 | 272 |
| 268 for (RenderProcessHost::iterator i( | 273 for (RenderProcessHost::iterator i( |
| 269 content::RenderProcessHost::AllHostsIterator()); | 274 content::RenderProcessHost::AllHostsIterator()); |
| 270 !i.IsAtEnd(); i.Advance()) { | 275 !i.IsAtEnd(); i.Advance()) { |
| 271 i.GetCurrentValue()->DisableAecDump(); | 276 i.GetCurrentValue()->DisableAudioDebugRecordings(); |
| 272 } | 277 } |
| 273 #endif | 278 #endif |
| 274 } | 279 } |
| 275 | 280 |
| 281 bool WebRTCInternals::IsAudioDebugRecordingsEnabled() const { |
| 282 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 283 return audio_debug_recordings_; |
| 284 } |
| 285 |
| 286 const base::FilePath& WebRTCInternals::GetAudioDebugRecordingsFilePath() const { |
| 287 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 288 return audio_debug_recordings_file_path_; |
| 289 } |
| 290 |
| 276 void WebRTCInternals::ResetForTesting() { | 291 void WebRTCInternals::ResetForTesting() { |
| 277 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 292 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 278 observers_.Clear(); | 293 observers_.Clear(); |
| 279 peer_connection_data_.Clear(); | 294 peer_connection_data_.Clear(); |
| 280 CreateOrReleasePowerSaveBlocker(); | 295 CreateOrReleasePowerSaveBlocker(); |
| 281 get_user_media_requests_.Clear(); | 296 get_user_media_requests_.Clear(); |
| 282 aec_dump_enabled_ = false; | 297 audio_debug_recordings_ = false; |
| 283 } | 298 } |
| 284 | 299 |
| 285 void WebRTCInternals::SendUpdate(const string& command, base::Value* value) { | 300 void WebRTCInternals::SendUpdate(const string& command, base::Value* value) { |
| 286 DCHECK(observers_.might_have_observers()); | 301 DCHECK(observers_.might_have_observers()); |
| 287 | 302 |
| 288 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | 303 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
| 289 observers_, | 304 observers_, |
| 290 OnUpdate(command, value)); | 305 OnUpdate(command, value)); |
| 291 } | 306 } |
| 292 | 307 |
| 293 void WebRTCInternals::RenderProcessHostDestroyed(RenderProcessHost* host) { | 308 void WebRTCInternals::RenderProcessHostDestroyed(RenderProcessHost* host) { |
| 294 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 309 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 295 OnRendererExit(host->GetID()); | 310 OnRendererExit(host->GetID()); |
| 296 | 311 |
| 297 render_process_id_set_.erase(host->GetID()); | 312 render_process_id_set_.erase(host->GetID()); |
| 298 host->RemoveObserver(this); | 313 host->RemoveObserver(this); |
| 299 } | 314 } |
| 300 | 315 |
| 301 void WebRTCInternals::FileSelected(const base::FilePath& path, | 316 void WebRTCInternals::FileSelected(const base::FilePath& path, |
| 302 int /* unused_index */, | 317 int /* unused_index */, |
| 303 void* /*unused_params */) { | 318 void* /*unused_params */) { |
| 304 #if defined(ENABLE_WEBRTC) | 319 #if defined(ENABLE_WEBRTC) |
| 305 aec_dump_file_path_ = path; | 320 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 306 EnableAecDumpOnAllRenderProcessHosts(); | 321 audio_debug_recordings_file_path_ = path; |
| 322 EnableAudioDebugRecordingsOnAllRenderProcessHosts(); |
| 307 #endif | 323 #endif |
| 308 } | 324 } |
| 309 | 325 |
| 310 void WebRTCInternals::FileSelectionCanceled(void* params) { | 326 void WebRTCInternals::FileSelectionCanceled(void* params) { |
| 311 #if defined(ENABLE_WEBRTC) | 327 #if defined(ENABLE_WEBRTC) |
| 312 SendUpdate("aecRecordingFileSelectionCancelled", NULL); | 328 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 329 SendUpdate("audioDebugRecordingsFileSelectionCancelled", NULL); |
| 313 #endif | 330 #endif |
| 314 } | 331 } |
| 315 | 332 |
| 316 void WebRTCInternals::OnRendererExit(int render_process_id) { | 333 void WebRTCInternals::OnRendererExit(int render_process_id) { |
| 317 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 334 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 318 | 335 |
| 319 // Iterates from the end of the list to remove the PeerConnections created | 336 // Iterates from the end of the list to remove the PeerConnections created |
| 320 // by the exitting renderer. | 337 // by the exitting renderer. |
| 321 for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { | 338 for (int i = peer_connection_data_.GetSize() - 1; i >= 0; --i) { |
| 322 base::DictionaryValue* record = NULL; | 339 base::DictionaryValue* record = NULL; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 375 } |
| 359 | 376 |
| 360 if (found_any && observers_.might_have_observers()) { | 377 if (found_any && observers_.might_have_observers()) { |
| 361 base::DictionaryValue update; | 378 base::DictionaryValue update; |
| 362 update.SetInteger("rid", render_process_id); | 379 update.SetInteger("rid", render_process_id); |
| 363 SendUpdate("removeGetUserMediaForRenderer", &update); | 380 SendUpdate("removeGetUserMediaForRenderer", &update); |
| 364 } | 381 } |
| 365 } | 382 } |
| 366 | 383 |
| 367 #if defined(ENABLE_WEBRTC) | 384 #if defined(ENABLE_WEBRTC) |
| 368 void WebRTCInternals::EnableAecDumpOnAllRenderProcessHosts() { | 385 void WebRTCInternals::EnableAudioDebugRecordingsOnAllRenderProcessHosts() { |
| 369 aec_dump_enabled_ = true; | 386 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 387 |
| 388 audio_debug_recordings_ = true; |
| 370 for (RenderProcessHost::iterator i( | 389 for (RenderProcessHost::iterator i( |
| 371 content::RenderProcessHost::AllHostsIterator()); | 390 content::RenderProcessHost::AllHostsIterator()); |
| 372 !i.IsAtEnd(); i.Advance()) { | 391 !i.IsAtEnd(); i.Advance()) { |
| 373 i.GetCurrentValue()->EnableAecDump(aec_dump_file_path_); | 392 i.GetCurrentValue()->EnableAudioDebugRecordings( |
| 393 audio_debug_recordings_file_path_); |
| 374 } | 394 } |
| 375 } | 395 } |
| 376 #endif | 396 #endif |
| 377 | 397 |
| 378 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { | 398 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { |
| 379 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 399 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 380 | 400 |
| 381 if (peer_connection_data_.empty() && power_save_blocker_) { | 401 if (peer_connection_data_.empty() && power_save_blocker_) { |
| 382 DVLOG(1) << ("Releasing the block on application suspension since no " | 402 DVLOG(1) << ("Releasing the block on application suspension since no " |
| 383 "PeerConnections are active anymore."); | 403 "PeerConnections are active anymore."); |
| 384 power_save_blocker_.reset(); | 404 power_save_blocker_.reset(); |
| 385 } else if (!peer_connection_data_.empty() && !power_save_blocker_) { | 405 } else if (!peer_connection_data_.empty() && !power_save_blocker_) { |
| 386 DVLOG(1) << ("Preventing the application from being suspended while one or " | 406 DVLOG(1) << ("Preventing the application from being suspended while one or " |
| 387 "more PeerConnections are active."); | 407 "more PeerConnections are active."); |
| 388 power_save_blocker_ = | 408 power_save_blocker_ = |
| 389 content::PowerSaveBlocker::Create( | 409 content::PowerSaveBlocker::Create( |
| 390 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, | 410 PowerSaveBlocker::kPowerSaveBlockPreventAppSuspension, |
| 391 PowerSaveBlocker::kReasonOther, | 411 PowerSaveBlocker::kReasonOther, |
| 392 "WebRTC has active PeerConnections").Pass(); | 412 "WebRTC has active PeerConnections").Pass(); |
| 393 } | 413 } |
| 394 } | 414 } |
| 395 | 415 |
| 396 } // namespace content | 416 } // namespace content |
| OLD | NEW |