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/webrtc_internals.h" | 5 #include "content/browser/media/webrtc/webrtc_internals.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "content/browser/media/webrtc/webrtc_internals_ui_observer.h" | 11 #include "content/browser/media/webrtc/webrtc_internals_ui_observer.h" |
| 12 #include "content/browser/renderer_host/render_process_host_impl.h" |
12 #include "content/browser/web_contents/web_contents_view.h" | 13 #include "content/browser/web_contents/web_contents_view.h" |
13 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
14 #include "content/public/browser/content_browser_client.h" | 15 #include "content/public/browser/content_browser_client.h" |
15 #include "content/public/browser/render_process_host.h" | |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "device/power_save_blocker/power_save_blocker.h" | 17 #include "device/power_save_blocker/power_save_blocker.h" |
| 18 #include "ipc/ipc_platform_file.h" |
| 19 |
| 20 #if defined(OS_WIN) |
| 21 #define IntToStringType base::IntToString16 |
| 22 #else |
| 23 #define IntToStringType base::IntToString |
| 24 #endif |
18 | 25 |
19 using base::ProcessId; | 26 using base::ProcessId; |
20 using std::string; | 27 using std::string; |
21 | 28 |
22 namespace content { | 29 namespace content { |
23 | 30 |
24 namespace { | 31 namespace { |
25 | 32 |
26 static base::LazyInstance<WebRTCInternals>::Leaky g_webrtc_internals = | 33 static base::LazyInstance<WebRTCInternals>::Leaky g_webrtc_internals = |
27 LAZY_INSTANCE_INITIALIZER; | 34 LAZY_INSTANCE_INITIALIZER; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 252 |
246 void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver* observer) { | 253 void WebRTCInternals::AddObserver(WebRTCInternalsUIObserver* observer) { |
247 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 254 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
248 observers_.AddObserver(observer); | 255 observers_.AddObserver(observer); |
249 } | 256 } |
250 | 257 |
251 void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver* observer) { | 258 void WebRTCInternals::RemoveObserver(WebRTCInternalsUIObserver* observer) { |
252 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 259 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
253 observers_.RemoveObserver(observer); | 260 observers_.RemoveObserver(observer); |
254 | 261 |
255 // Disables audio debug recordings if it is enabled and the last | 262 // Disables event log and audio debug recordings if enabled and the last |
256 // webrtc-internals page is going away. | 263 // webrtc-internals page is going away. |
257 if (audio_debug_recordings_ && !observers_.might_have_observers()) | 264 if (!observers_.might_have_observers()) { |
258 DisableAudioDebugRecordings(); | 265 if (audio_debug_recordings_) |
| 266 DisableAudioDebugRecordings(); |
| 267 DisableEventLogRecordings(); |
| 268 } |
259 } | 269 } |
260 | 270 |
261 void WebRTCInternals::UpdateObserver(WebRTCInternalsUIObserver* observer) { | 271 void WebRTCInternals::UpdateObserver(WebRTCInternalsUIObserver* observer) { |
262 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 272 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
263 if (peer_connection_data_.GetSize() > 0) | 273 if (peer_connection_data_.GetSize() > 0) |
264 observer->OnUpdate("updateAllPeerConnections", &peer_connection_data_); | 274 observer->OnUpdate("updateAllPeerConnections", &peer_connection_data_); |
265 | 275 |
266 for (const auto& request : get_user_media_requests_) { | 276 for (const auto& request : get_user_media_requests_) { |
267 observer->OnUpdate("addGetUserMedia", request.get()); | 277 observer->OnUpdate("addGetUserMedia", request.get()); |
268 } | 278 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 bool WebRTCInternals::IsAudioDebugRecordingsEnabled() const { | 321 bool WebRTCInternals::IsAudioDebugRecordingsEnabled() const { |
312 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 322 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
313 return audio_debug_recordings_; | 323 return audio_debug_recordings_; |
314 } | 324 } |
315 | 325 |
316 const base::FilePath& WebRTCInternals::GetAudioDebugRecordingsFilePath() const { | 326 const base::FilePath& WebRTCInternals::GetAudioDebugRecordingsFilePath() const { |
317 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 327 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
318 return audio_debug_recordings_file_path_; | 328 return audio_debug_recordings_file_path_; |
319 } | 329 } |
320 | 330 |
321 void WebRTCInternals::SetEventLogRecordings( | 331 void WebRTCInternals::EnableEventLogRecordings( |
322 bool enable, | |
323 content::WebContents* web_contents) { | 332 content::WebContents* web_contents) { |
324 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 333 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
325 #if defined(ENABLE_WEBRTC) | 334 #if defined(ENABLE_WEBRTC) |
326 if (enable) { | |
327 #if defined(OS_ANDROID) | 335 #if defined(OS_ANDROID) |
328 EnableEventLogRecordingsOnAllRenderProcessHosts(); | 336 EnableEventLogRecordingsOnAllRenderProcessHosts(); |
329 #else | 337 #else |
330 DCHECK(web_contents); | 338 DCHECK(web_contents); |
331 DCHECK(!select_file_dialog_); | 339 DCHECK(!select_file_dialog_); |
332 selecting_event_log_ = true; | 340 selecting_event_log_ = true; |
333 select_file_dialog_ = ui::SelectFileDialog::Create(this, nullptr); | 341 select_file_dialog_ = ui::SelectFileDialog::Create(this, nullptr); |
334 select_file_dialog_->SelectFile( | 342 select_file_dialog_->SelectFile( |
335 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), | 343 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), |
336 event_log_recordings_file_path_, nullptr, 0, FILE_PATH_LITERAL(""), | 344 event_log_recordings_file_path_, nullptr, 0, FILE_PATH_LITERAL(""), |
337 web_contents->GetTopLevelNativeWindow(), nullptr); | 345 web_contents->GetTopLevelNativeWindow(), nullptr); |
338 #endif | 346 #endif |
339 } else { | |
340 event_log_recordings_ = false; | |
341 // Tear down the dialog since the user has unchecked the audio debug | |
342 // recordings box. | |
343 select_file_dialog_ = nullptr; | |
344 DCHECK(select_file_dialog_->HasOneRef()); | |
345 | |
346 for (RenderProcessHost::iterator i( | |
347 content::RenderProcessHost::AllHostsIterator()); | |
348 !i.IsAtEnd(); i.Advance()) { | |
349 i.GetCurrentValue()->DisableEventLogRecordings(); | |
350 } | |
351 } | |
352 #endif | 347 #endif |
353 } | 348 } |
354 | 349 |
| 350 void WebRTCInternals::DisableEventLogRecordings() { |
| 351 #if defined(ENABLE_WEBRTC) |
| 352 event_log_recordings_ = false; |
| 353 // Tear down the dialog since the user has unchecked the event log checkbox. |
| 354 select_file_dialog_ = nullptr; |
| 355 for (RenderProcessHost::iterator i( |
| 356 content::RenderProcessHost::AllHostsIterator()); |
| 357 !i.IsAtEnd(); i.Advance()) |
| 358 i.GetCurrentValue()->StopWebRTCEventLog(); |
| 359 #endif |
| 360 } |
| 361 |
355 bool WebRTCInternals::IsEventLogRecordingsEnabled() const { | 362 bool WebRTCInternals::IsEventLogRecordingsEnabled() const { |
356 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 363 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
357 return event_log_recordings_; | 364 return event_log_recordings_; |
358 } | 365 } |
359 | 366 |
360 const base::FilePath& WebRTCInternals::GetEventLogRecordingsFilePath() const { | 367 const base::FilePath& WebRTCInternals::GetEventLogFilePath() const { |
361 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 368 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
362 return event_log_recordings_file_path_; | 369 return event_log_recordings_file_path_; |
363 } | 370 } |
364 | 371 |
365 void WebRTCInternals::SendUpdate(const string& command, | 372 void WebRTCInternals::SendUpdate(const string& command, |
366 std::unique_ptr<base::Value> value) { | 373 std::unique_ptr<base::Value> value) { |
367 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 374 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
368 DCHECK(observers_.might_have_observers()); | 375 DCHECK(observers_.might_have_observers()); |
369 | 376 |
370 bool queue_was_empty = pending_updates_.empty(); | 377 bool queue_was_empty = pending_updates_.empty(); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 audio_debug_recordings_file_path_); | 483 audio_debug_recordings_file_path_); |
477 } | 484 } |
478 } | 485 } |
479 | 486 |
480 void WebRTCInternals::EnableEventLogRecordingsOnAllRenderProcessHosts() { | 487 void WebRTCInternals::EnableEventLogRecordingsOnAllRenderProcessHosts() { |
481 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 488 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
482 | 489 |
483 event_log_recordings_ = true; | 490 event_log_recordings_ = true; |
484 for (RenderProcessHost::iterator i( | 491 for (RenderProcessHost::iterator i( |
485 content::RenderProcessHost::AllHostsIterator()); | 492 content::RenderProcessHost::AllHostsIterator()); |
486 !i.IsAtEnd(); i.Advance()) { | 493 !i.IsAtEnd(); i.Advance()) |
487 i.GetCurrentValue()->EnableEventLogRecordings( | 494 i.GetCurrentValue()->StartWebRTCEventLog(event_log_recordings_file_path_); |
488 event_log_recordings_file_path_); | |
489 } | |
490 } | 495 } |
491 #endif | 496 #endif |
492 | 497 |
493 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { | 498 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { |
494 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 499 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
495 | 500 |
496 if (peer_connection_data_.empty() && power_save_blocker_) { | 501 if (peer_connection_data_.empty() && power_save_blocker_) { |
497 DVLOG(1) << ("Releasing the block on application suspension since no " | 502 DVLOG(1) << ("Releasing the block on application suspension since no " |
498 "PeerConnections are active anymore."); | 503 "PeerConnections are active anymore."); |
499 power_save_blocker_.reset(); | 504 power_save_blocker_.reset(); |
(...skipping 14 matching lines...) Expand all Loading... |
514 while (!pending_updates_.empty()) { | 519 while (!pending_updates_.empty()) { |
515 const auto& update = pending_updates_.front(); | 520 const auto& update = pending_updates_.front(); |
516 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | 521 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
517 observers_, | 522 observers_, |
518 OnUpdate(update.command(), update.value())); | 523 OnUpdate(update.command(), update.value())); |
519 pending_updates_.pop(); | 524 pending_updates_.pop(); |
520 } | 525 } |
521 } | 526 } |
522 | 527 |
523 } // namespace content | 528 } // namespace content |
OLD | NEW |