| 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> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "content/browser/renderer_host/render_process_host_impl.h" | 14 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 15 #include "content/browser/web_contents/web_contents_view.h" | 15 #include "content/browser/web_contents/web_contents_view.h" |
| 16 #include "content/browser/webrtc/webrtc_internals_ui_observer.h" | 16 #include "content/browser/webrtc/webrtc_internals_ui_observer.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/content_browser_client.h" | 18 #include "content/public/browser/content_browser_client.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "device/power_save_blocker/power_save_blocker.h" | 20 #include "device/power_save_blocker/power_save_blocker.h" |
| 21 #include "ipc/ipc_platform_file.h" | 21 #include "ipc/ipc_platform_file.h" |
| 22 #include "media/media_features.h" |
| 22 | 23 |
| 23 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 24 #define IntToStringType base::IntToString16 | 25 #define IntToStringType base::IntToString16 |
| 25 #else | 26 #else |
| 26 #define IntToStringType base::IntToString | 27 #define IntToStringType base::IntToString |
| 27 #endif | 28 #endif |
| 28 | 29 |
| 29 using base::ProcessId; | 30 using base::ProcessId; |
| 30 using std::string; | 31 using std::string; |
| 31 | 32 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 bool should_block_power_saving) | 79 bool should_block_power_saving) |
| 79 : audio_debug_recordings_(false), | 80 : audio_debug_recordings_(false), |
| 80 event_log_recordings_(false), | 81 event_log_recordings_(false), |
| 81 selecting_event_log_(false), | 82 selecting_event_log_(false), |
| 82 num_open_connections_(0), | 83 num_open_connections_(0), |
| 83 should_block_power_saving_(should_block_power_saving), | 84 should_block_power_saving_(should_block_power_saving), |
| 84 aggregate_updates_ms_(aggregate_updates_ms), | 85 aggregate_updates_ms_(aggregate_updates_ms), |
| 85 weak_factory_(this) { | 86 weak_factory_(this) { |
| 86 // TODO(grunell): Shouldn't all the webrtc_internals* files be excluded from the | 87 // TODO(grunell): Shouldn't all the webrtc_internals* files be excluded from the |
| 87 // build if WebRTC is disabled? | 88 // build if WebRTC is disabled? |
| 88 #if defined(ENABLE_WEBRTC) | 89 #if BUILDFLAG(ENABLE_WEBRTC) |
| 89 audio_debug_recordings_file_path_ = | 90 audio_debug_recordings_file_path_ = |
| 90 GetContentClient()->browser()->GetDefaultDownloadDirectory(); | 91 GetContentClient()->browser()->GetDefaultDownloadDirectory(); |
| 91 event_log_recordings_file_path_ = audio_debug_recordings_file_path_; | 92 event_log_recordings_file_path_ = audio_debug_recordings_file_path_; |
| 92 | 93 |
| 93 if (audio_debug_recordings_file_path_.empty()) { | 94 if (audio_debug_recordings_file_path_.empty()) { |
| 94 // In this case the default path (|audio_debug_recordings_file_path_|) will | 95 // In this case the default path (|audio_debug_recordings_file_path_|) will |
| 95 // be empty and the platform default path will be used in the file dialog | 96 // be empty and the platform default path will be used in the file dialog |
| 96 // (with no default file name). See SelectFileDialog::SelectFile. On Android | 97 // (with no default file name). See SelectFileDialog::SelectFile. On Android |
| 97 // where there's no dialog we'll fail to open the file. | 98 // where there's no dialog we'll fail to open the file. |
| 98 VLOG(1) << "Could not get the download directory."; | 99 VLOG(1) << "Could not get the download directory."; |
| 99 } else { | 100 } else { |
| 100 audio_debug_recordings_file_path_ = | 101 audio_debug_recordings_file_path_ = |
| 101 audio_debug_recordings_file_path_.Append( | 102 audio_debug_recordings_file_path_.Append( |
| 102 FILE_PATH_LITERAL("audio_debug")); | 103 FILE_PATH_LITERAL("audio_debug")); |
| 103 event_log_recordings_file_path_ = | 104 event_log_recordings_file_path_ = |
| 104 event_log_recordings_file_path_.Append(FILE_PATH_LITERAL("event_log")); | 105 event_log_recordings_file_path_.Append(FILE_PATH_LITERAL("event_log")); |
| 105 } | 106 } |
| 106 #endif // defined(ENABLE_WEBRTC) | 107 #endif // BUILDFLAG(ENABLE_WEBRTC) |
| 107 } | 108 } |
| 108 | 109 |
| 109 WebRTCInternals::~WebRTCInternals() { | 110 WebRTCInternals::~WebRTCInternals() { |
| 110 } | 111 } |
| 111 | 112 |
| 112 WebRTCInternals* WebRTCInternals::GetInstance() { | 113 WebRTCInternals* WebRTCInternals::GetInstance() { |
| 113 return g_webrtc_internals.Pointer(); | 114 return g_webrtc_internals.Pointer(); |
| 114 } | 115 } |
| 115 | 116 |
| 116 void WebRTCInternals::OnAddPeerConnection(int render_process_id, | 117 void WebRTCInternals::OnAddPeerConnection(int render_process_id, |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 observer->OnUpdate("updateAllPeerConnections", &peer_connection_data_); | 289 observer->OnUpdate("updateAllPeerConnections", &peer_connection_data_); |
| 289 | 290 |
| 290 for (const auto& request : get_user_media_requests_) { | 291 for (const auto& request : get_user_media_requests_) { |
| 291 observer->OnUpdate("addGetUserMedia", request.get()); | 292 observer->OnUpdate("addGetUserMedia", request.get()); |
| 292 } | 293 } |
| 293 } | 294 } |
| 294 | 295 |
| 295 void WebRTCInternals::EnableAudioDebugRecordings( | 296 void WebRTCInternals::EnableAudioDebugRecordings( |
| 296 content::WebContents* web_contents) { | 297 content::WebContents* web_contents) { |
| 297 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 298 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 298 #if defined(ENABLE_WEBRTC) | 299 #if BUILDFLAG(ENABLE_WEBRTC) |
| 299 #if defined(OS_ANDROID) | 300 #if defined(OS_ANDROID) |
| 300 EnableAudioDebugRecordingsOnAllRenderProcessHosts(); | 301 EnableAudioDebugRecordingsOnAllRenderProcessHosts(); |
| 301 #else | 302 #else |
| 302 selecting_event_log_ = false; | 303 selecting_event_log_ = false; |
| 303 DCHECK(!select_file_dialog_); | 304 DCHECK(!select_file_dialog_); |
| 304 select_file_dialog_ = ui::SelectFileDialog::Create(this, NULL); | 305 select_file_dialog_ = ui::SelectFileDialog::Create(this, NULL); |
| 305 select_file_dialog_->SelectFile( | 306 select_file_dialog_->SelectFile( |
| 306 ui::SelectFileDialog::SELECT_SAVEAS_FILE, | 307 ui::SelectFileDialog::SELECT_SAVEAS_FILE, |
| 307 base::string16(), | 308 base::string16(), |
| 308 audio_debug_recordings_file_path_, | 309 audio_debug_recordings_file_path_, |
| 309 NULL, | 310 NULL, |
| 310 0, | 311 0, |
| 311 FILE_PATH_LITERAL(""), | 312 FILE_PATH_LITERAL(""), |
| 312 web_contents->GetTopLevelNativeWindow(), | 313 web_contents->GetTopLevelNativeWindow(), |
| 313 NULL); | 314 NULL); |
| 314 #endif | 315 #endif |
| 315 #endif | 316 #endif |
| 316 } | 317 } |
| 317 | 318 |
| 318 void WebRTCInternals::DisableAudioDebugRecordings() { | 319 void WebRTCInternals::DisableAudioDebugRecordings() { |
| 319 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 320 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 320 #if defined(ENABLE_WEBRTC) | 321 #if BUILDFLAG(ENABLE_WEBRTC) |
| 321 audio_debug_recordings_ = false; | 322 audio_debug_recordings_ = false; |
| 322 | 323 |
| 323 // Tear down the dialog since the user has unchecked the audio debug | 324 // Tear down the dialog since the user has unchecked the audio debug |
| 324 // recordings box. | 325 // recordings box. |
| 325 select_file_dialog_ = NULL; | 326 select_file_dialog_ = NULL; |
| 326 | 327 |
| 327 for (RenderProcessHost::iterator i( | 328 for (RenderProcessHost::iterator i( |
| 328 content::RenderProcessHost::AllHostsIterator()); | 329 content::RenderProcessHost::AllHostsIterator()); |
| 329 !i.IsAtEnd(); i.Advance()) { | 330 !i.IsAtEnd(); i.Advance()) { |
| 330 i.GetCurrentValue()->DisableAudioDebugRecordings(); | 331 i.GetCurrentValue()->DisableAudioDebugRecordings(); |
| 331 } | 332 } |
| 332 #endif | 333 #endif |
| 333 } | 334 } |
| 334 | 335 |
| 335 bool WebRTCInternals::IsAudioDebugRecordingsEnabled() const { | 336 bool WebRTCInternals::IsAudioDebugRecordingsEnabled() const { |
| 336 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 337 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 337 return audio_debug_recordings_; | 338 return audio_debug_recordings_; |
| 338 } | 339 } |
| 339 | 340 |
| 340 const base::FilePath& WebRTCInternals::GetAudioDebugRecordingsFilePath() const { | 341 const base::FilePath& WebRTCInternals::GetAudioDebugRecordingsFilePath() const { |
| 341 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 342 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 342 return audio_debug_recordings_file_path_; | 343 return audio_debug_recordings_file_path_; |
| 343 } | 344 } |
| 344 | 345 |
| 345 void WebRTCInternals::EnableEventLogRecordings( | 346 void WebRTCInternals::EnableEventLogRecordings( |
| 346 content::WebContents* web_contents) { | 347 content::WebContents* web_contents) { |
| 347 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 348 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 348 #if defined(ENABLE_WEBRTC) | 349 #if BUILDFLAG(ENABLE_WEBRTC) |
| 349 #if defined(OS_ANDROID) | 350 #if defined(OS_ANDROID) |
| 350 EnableEventLogRecordingsOnAllRenderProcessHosts(); | 351 EnableEventLogRecordingsOnAllRenderProcessHosts(); |
| 351 #else | 352 #else |
| 352 DCHECK(web_contents); | 353 DCHECK(web_contents); |
| 353 DCHECK(!select_file_dialog_); | 354 DCHECK(!select_file_dialog_); |
| 354 selecting_event_log_ = true; | 355 selecting_event_log_ = true; |
| 355 select_file_dialog_ = ui::SelectFileDialog::Create(this, nullptr); | 356 select_file_dialog_ = ui::SelectFileDialog::Create(this, nullptr); |
| 356 select_file_dialog_->SelectFile( | 357 select_file_dialog_->SelectFile( |
| 357 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), | 358 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), |
| 358 event_log_recordings_file_path_, nullptr, 0, FILE_PATH_LITERAL(""), | 359 event_log_recordings_file_path_, nullptr, 0, FILE_PATH_LITERAL(""), |
| 359 web_contents->GetTopLevelNativeWindow(), nullptr); | 360 web_contents->GetTopLevelNativeWindow(), nullptr); |
| 360 #endif | 361 #endif |
| 361 #endif | 362 #endif |
| 362 } | 363 } |
| 363 | 364 |
| 364 void WebRTCInternals::DisableEventLogRecordings() { | 365 void WebRTCInternals::DisableEventLogRecordings() { |
| 365 #if defined(ENABLE_WEBRTC) | 366 #if BUILDFLAG(ENABLE_WEBRTC) |
| 366 event_log_recordings_ = false; | 367 event_log_recordings_ = false; |
| 367 // Tear down the dialog since the user has unchecked the event log checkbox. | 368 // Tear down the dialog since the user has unchecked the event log checkbox. |
| 368 select_file_dialog_ = nullptr; | 369 select_file_dialog_ = nullptr; |
| 369 for (RenderProcessHost::iterator i( | 370 for (RenderProcessHost::iterator i( |
| 370 content::RenderProcessHost::AllHostsIterator()); | 371 content::RenderProcessHost::AllHostsIterator()); |
| 371 !i.IsAtEnd(); i.Advance()) | 372 !i.IsAtEnd(); i.Advance()) |
| 372 i.GetCurrentValue()->StopWebRTCEventLog(); | 373 i.GetCurrentValue()->StopWebRTCEventLog(); |
| 373 #endif | 374 #endif |
| 374 } | 375 } |
| 375 | 376 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 403 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 404 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 404 OnRendererExit(host->GetID()); | 405 OnRendererExit(host->GetID()); |
| 405 | 406 |
| 406 render_process_id_set_.erase(host->GetID()); | 407 render_process_id_set_.erase(host->GetID()); |
| 407 host->RemoveObserver(this); | 408 host->RemoveObserver(this); |
| 408 } | 409 } |
| 409 | 410 |
| 410 void WebRTCInternals::FileSelected(const base::FilePath& path, | 411 void WebRTCInternals::FileSelected(const base::FilePath& path, |
| 411 int /* unused_index */, | 412 int /* unused_index */, |
| 412 void* /*unused_params */) { | 413 void* /*unused_params */) { |
| 413 #if defined(ENABLE_WEBRTC) | 414 #if BUILDFLAG(ENABLE_WEBRTC) |
| 414 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 415 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 415 if (selecting_event_log_) { | 416 if (selecting_event_log_) { |
| 416 event_log_recordings_file_path_ = path; | 417 event_log_recordings_file_path_ = path; |
| 417 EnableEventLogRecordingsOnAllRenderProcessHosts(); | 418 EnableEventLogRecordingsOnAllRenderProcessHosts(); |
| 418 } else { | 419 } else { |
| 419 audio_debug_recordings_file_path_ = path; | 420 audio_debug_recordings_file_path_ = path; |
| 420 EnableAudioDebugRecordingsOnAllRenderProcessHosts(); | 421 EnableAudioDebugRecordingsOnAllRenderProcessHosts(); |
| 421 } | 422 } |
| 422 #endif | 423 #endif |
| 423 } | 424 } |
| 424 | 425 |
| 425 void WebRTCInternals::FileSelectionCanceled(void* params) { | 426 void WebRTCInternals::FileSelectionCanceled(void* params) { |
| 426 #if defined(ENABLE_WEBRTC) | 427 #if BUILDFLAG(ENABLE_WEBRTC) |
| 427 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 428 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 428 if (selecting_event_log_) { | 429 if (selecting_event_log_) { |
| 429 SendUpdate("eventLogRecordingsFileSelectionCancelled", nullptr); | 430 SendUpdate("eventLogRecordingsFileSelectionCancelled", nullptr); |
| 430 } else { | 431 } else { |
| 431 SendUpdate("audioDebugRecordingsFileSelectionCancelled", nullptr); | 432 SendUpdate("audioDebugRecordingsFileSelectionCancelled", nullptr); |
| 432 } | 433 } |
| 433 #endif | 434 #endif |
| 434 } | 435 } |
| 435 | 436 |
| 436 void WebRTCInternals::OnRendererExit(int render_process_id) { | 437 void WebRTCInternals::OnRendererExit(int render_process_id) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 } | 479 } |
| 479 } | 480 } |
| 480 | 481 |
| 481 if (found_any && observers_.might_have_observers()) { | 482 if (found_any && observers_.might_have_observers()) { |
| 482 std::unique_ptr<base::DictionaryValue> update(new base::DictionaryValue()); | 483 std::unique_ptr<base::DictionaryValue> update(new base::DictionaryValue()); |
| 483 update->SetInteger("rid", render_process_id); | 484 update->SetInteger("rid", render_process_id); |
| 484 SendUpdate("removeGetUserMediaForRenderer", std::move(update)); | 485 SendUpdate("removeGetUserMediaForRenderer", std::move(update)); |
| 485 } | 486 } |
| 486 } | 487 } |
| 487 | 488 |
| 488 #if defined(ENABLE_WEBRTC) | 489 #if BUILDFLAG(ENABLE_WEBRTC) |
| 489 void WebRTCInternals::EnableAudioDebugRecordingsOnAllRenderProcessHosts() { | 490 void WebRTCInternals::EnableAudioDebugRecordingsOnAllRenderProcessHosts() { |
| 490 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 491 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 491 | 492 |
| 492 audio_debug_recordings_ = true; | 493 audio_debug_recordings_ = true; |
| 493 for (RenderProcessHost::iterator i( | 494 for (RenderProcessHost::iterator i( |
| 494 content::RenderProcessHost::AllHostsIterator()); | 495 content::RenderProcessHost::AllHostsIterator()); |
| 495 !i.IsAtEnd(); i.Advance()) { | 496 !i.IsAtEnd(); i.Advance()) { |
| 496 i.GetCurrentValue()->EnableAudioDebugRecordings( | 497 i.GetCurrentValue()->EnableAudioDebugRecordings( |
| 497 audio_debug_recordings_file_path_); | 498 audio_debug_recordings_file_path_); |
| 498 } | 499 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 548 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 548 while (!pending_updates_.empty()) { | 549 while (!pending_updates_.empty()) { |
| 549 const auto& update = pending_updates_.front(); | 550 const auto& update = pending_updates_.front(); |
| 550 for (auto& observer : observers_) | 551 for (auto& observer : observers_) |
| 551 observer.OnUpdate(update.command(), update.value()); | 552 observer.OnUpdate(update.command(), update.value()); |
| 552 pending_updates_.pop(); | 553 pending_updates_.pop(); |
| 553 } | 554 } |
| 554 } | 555 } |
| 555 | 556 |
| 556 } // namespace content | 557 } // namespace content |
| OLD | NEW |