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/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/web_contents/web_contents_view.h" | 12 #include "content/browser/web_contents/web_contents_view.h" |
| 13 #include "content/common/media/peer_connection_tracker_messages.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/power_save_blocker.h" | 16 #include "content/public/browser/power_save_blocker.h" |
| 16 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
| 17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 19 #include "ipc/ipc_platform_file.h" | |
| 20 | |
| 21 #if defined(OS_WIN) | |
| 22 #define IntToStringType base::IntToString16 | |
| 23 #else | |
| 24 #define IntToStringType base::IntToString | |
|
dcheng
2016/04/04 21:44:57
Ugh.
Ivo-OOO until feb 6
2016/04/05 08:59:27
I copied this from render_process_host_impl.cc and
| |
| 25 #endif | |
| 18 | 26 |
| 19 using base::ProcessId; | 27 using base::ProcessId; |
| 20 using std::string; | 28 using std::string; |
| 21 | 29 |
| 22 namespace content { | 30 namespace content { |
| 23 | 31 |
| 24 namespace { | 32 namespace { |
| 25 | 33 |
| 26 static base::LazyInstance<WebRTCInternals>::Leaky g_webrtc_internals = | 34 static base::LazyInstance<WebRTCInternals>::Leaky g_webrtc_internals = |
| 27 LAZY_INSTANCE_INITIALIZER; | 35 LAZY_INSTANCE_INITIALIZER; |
| 28 | 36 |
| 29 // Makes sure that |dict| has a ListValue under path "log". | 37 // Makes sure that |dict| has a ListValue under path "log". |
| 30 static base::ListValue* EnsureLogList(base::DictionaryValue* dict) { | 38 static base::ListValue* EnsureLogList(base::DictionaryValue* dict) { |
| 31 base::ListValue* log = NULL; | 39 base::ListValue* log = NULL; |
| 32 if (!dict->GetList("log", &log)) { | 40 if (!dict->GetList("log", &log)) { |
| 33 log = new base::ListValue(); | 41 log = new base::ListValue(); |
| 34 if (log) | 42 if (log) |
| 35 dict->Set("log", log); | 43 dict->Set("log", log); |
| 36 } | 44 } |
| 37 return log; | 45 return log; |
| 38 } | 46 } |
| 39 | 47 |
| 48 #if defined(ENABLE_WEBRTC) | |
| 49 // Creates a file used for handing over to the renderer. | |
| 50 IPC::PlatformFileForTransit CreateFileForProcess(base::FilePath file_path, | |
|
dcheng
2016/04/04 21:44:57
const base::FilePath&
Ivo-OOO until feb 6
2016/04/05 08:59:27
Done.
| |
| 51 base::ProcessHandle process) { | |
| 52 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | |
| 53 base::File event_log_file( | |
| 54 file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_APPEND); | |
| 55 if (!event_log_file.IsValid()) { | |
| 56 VLOG(1) << "Could not open event log file, error=" | |
| 57 << event_log_file.error_details(); | |
| 58 return IPC::InvalidPlatformFileForTransit(); | |
| 59 } | |
| 60 return IPC::TakeFileHandleForProcess(std::move(event_log_file), process); | |
| 61 } | |
| 62 | |
| 63 void SendEventLogFileToRenderer(int rid, | |
| 64 int lid, | |
|
dcheng
2016/04/04 21:44:57
No abbreviations here.
Ivo-OOO until feb 6
2016/04/05 08:59:27
Done.
| |
| 65 IPC::PlatformFileForTransit file_for_transit) { | |
| 66 #if defined(OS_ANDROID) | |
| 67 const int64_t max_file_size = 10000000; | |
| 68 #else | |
| 69 const int64_t max_file_size = 30000000; | |
| 70 #endif | |
| 71 RenderProcessHost* rph = RenderProcessHost::FromID(rid); | |
| 72 if (rph) { | |
| 73 rph->Send(new PeerConnectionTracker_StartEventLog(lid, file_for_transit, | |
|
dcheng
2016/04/04 21:44:57
Does it make sense to send an invalid fd here?
Ivo-OOO until feb 6
2016/04/05 08:59:27
Good point, I guess that doesn't make sense. I wil
| |
| 74 max_file_size)); | |
| 75 } | |
| 76 } | |
| 77 #endif | |
| 40 } // namespace | 78 } // namespace |
| 41 | 79 |
| 42 WebRTCInternals::PendingUpdate::PendingUpdate( | 80 WebRTCInternals::PendingUpdate::PendingUpdate( |
| 43 const std::string& command, scoped_ptr<base::Value> value) | 81 const std::string& command, scoped_ptr<base::Value> value) |
| 44 : command_(command), value_(std::move(value)) {} | 82 : command_(command), value_(std::move(value)) {} |
| 45 | 83 |
| 46 WebRTCInternals::PendingUpdate::PendingUpdate(PendingUpdate&& other) | 84 WebRTCInternals::PendingUpdate::PendingUpdate(PendingUpdate&& other) |
| 47 : command_(std::move(other.command_)), | 85 : command_(std::move(other.command_)), |
| 48 value_(std::move(other.value_)) {} | 86 value_(std::move(other.value_)) {} |
| 49 | 87 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 60 DCHECK(thread_checker_.CalledOnValidThread()); | 98 DCHECK(thread_checker_.CalledOnValidThread()); |
| 61 return value_.get(); | 99 return value_.get(); |
| 62 } | 100 } |
| 63 | 101 |
| 64 WebRTCInternals::WebRTCInternals() : WebRTCInternals(500) {} | 102 WebRTCInternals::WebRTCInternals() : WebRTCInternals(500) {} |
| 65 | 103 |
| 66 WebRTCInternals::WebRTCInternals(int aggregate_updates_ms) | 104 WebRTCInternals::WebRTCInternals(int aggregate_updates_ms) |
| 67 : audio_debug_recordings_(false), | 105 : audio_debug_recordings_(false), |
| 68 event_log_recordings_(false), | 106 event_log_recordings_(false), |
| 69 selecting_event_log_(false), | 107 selecting_event_log_(false), |
| 108 nr_event_log_files_(0), | |
| 70 aggregate_updates_ms_(aggregate_updates_ms), | 109 aggregate_updates_ms_(aggregate_updates_ms), |
| 71 weak_factory_(this) { | 110 weak_factory_(this) { |
| 72 // TODO(grunell): Shouldn't all the webrtc_internals* files be excluded from the | 111 // TODO(grunell): Shouldn't all the webrtc_internals* files be excluded from the |
| 73 // build if WebRTC is disabled? | 112 // build if WebRTC is disabled? |
| 74 #if defined(ENABLE_WEBRTC) | 113 #if defined(ENABLE_WEBRTC) |
| 75 audio_debug_recordings_file_path_ = | 114 audio_debug_recordings_file_path_ = |
| 76 GetContentClient()->browser()->GetDefaultDownloadDirectory(); | 115 GetContentClient()->browser()->GetDefaultDownloadDirectory(); |
| 77 event_log_recordings_file_path_ = audio_debug_recordings_file_path_; | 116 event_log_recordings_file_path_ = audio_debug_recordings_file_path_; |
| 78 | 117 |
| 79 if (audio_debug_recordings_file_path_.empty()) { | 118 if (audio_debug_recordings_file_path_.empty()) { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 110 base::DictionaryValue* dict = new base::DictionaryValue(); | 149 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 111 dict->SetInteger("rid", render_process_id); | 150 dict->SetInteger("rid", render_process_id); |
| 112 dict->SetInteger("pid", static_cast<int>(pid)); | 151 dict->SetInteger("pid", static_cast<int>(pid)); |
| 113 dict->SetInteger("lid", lid); | 152 dict->SetInteger("lid", lid); |
| 114 dict->SetString("rtcConfiguration", rtc_configuration); | 153 dict->SetString("rtcConfiguration", rtc_configuration); |
| 115 dict->SetString("constraints", constraints); | 154 dict->SetString("constraints", constraints); |
| 116 dict->SetString("url", url); | 155 dict->SetString("url", url); |
| 117 peer_connection_data_.Append(dict); | 156 peer_connection_data_.Append(dict); |
| 118 CreateOrReleasePowerSaveBlocker(); | 157 CreateOrReleasePowerSaveBlocker(); |
| 119 | 158 |
| 159 if (event_log_recordings_ && nr_event_log_files_ > 0) { | |
| 160 nr_event_log_files_--; | |
| 161 base::FilePath file_path = event_log_recordings_file_path_; | |
| 162 file_path = file_path.AddExtension(IntToStringType(render_process_id)); | |
| 163 file_path = file_path.AddExtension(IntToStringType(lid)); | |
| 164 | |
| 165 BrowserThread::PostTaskAndReplyWithResult( | |
| 166 BrowserThread::FILE, FROM_HERE, | |
| 167 base::Bind(&CreateFileForProcess, file_path, | |
| 168 base::GetCurrentProcessHandle()), | |
| 169 base::Bind(&SendEventLogFileToRenderer, render_process_id, lid)); | |
| 170 } | |
| 171 | |
| 120 if (observers_.might_have_observers()) | 172 if (observers_.might_have_observers()) |
| 121 SendUpdate("addPeerConnection", dict->CreateDeepCopy()); | 173 SendUpdate("addPeerConnection", dict->CreateDeepCopy()); |
| 122 | 174 |
| 123 if (render_process_id_set_.insert(render_process_id).second) { | 175 if (render_process_id_set_.insert(render_process_id).second) { |
| 124 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); | 176 RenderProcessHost* host = RenderProcessHost::FromID(render_process_id); |
| 125 if (host) | 177 if (host) |
| 126 host->AddObserver(this); | 178 host->AddObserver(this); |
| 127 } | 179 } |
| 128 } | 180 } |
| 129 | 181 |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 DCHECK(select_file_dialog_ == nullptr); | 383 DCHECK(select_file_dialog_ == nullptr); |
| 332 selecting_event_log_ = true; | 384 selecting_event_log_ = true; |
| 333 select_file_dialog_ = ui::SelectFileDialog::Create(this, nullptr); | 385 select_file_dialog_ = ui::SelectFileDialog::Create(this, nullptr); |
| 334 select_file_dialog_->SelectFile( | 386 select_file_dialog_->SelectFile( |
| 335 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), | 387 ui::SelectFileDialog::SELECT_SAVEAS_FILE, base::string16(), |
| 336 event_log_recordings_file_path_, nullptr, 0, FILE_PATH_LITERAL(""), | 388 event_log_recordings_file_path_, nullptr, 0, FILE_PATH_LITERAL(""), |
| 337 web_contents->GetTopLevelNativeWindow(), nullptr); | 389 web_contents->GetTopLevelNativeWindow(), nullptr); |
| 338 #endif | 390 #endif |
| 339 } else { | 391 } else { |
| 340 event_log_recordings_ = false; | 392 event_log_recordings_ = false; |
| 393 nr_event_log_files_ = 0; | |
| 341 // Tear down the dialog since the user has unchecked the audio debug | 394 // Tear down the dialog since the user has unchecked the audio debug |
| 342 // recordings box. | 395 // recordings box. |
| 396 DCHECK(select_file_dialog_->HasOneRef()); | |
| 343 select_file_dialog_ = nullptr; | 397 select_file_dialog_ = nullptr; |
| 344 DCHECK(select_file_dialog_->HasOneRef()); | |
| 345 | 398 |
| 346 for (RenderProcessHost::iterator i( | 399 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { |
| 347 content::RenderProcessHost::AllHostsIterator()); | 400 base::DictionaryValue* record = NULL; |
| 348 !i.IsAtEnd(); i.Advance()) { | 401 peer_connection_data_.GetDictionary(i, &record); |
| 349 i.GetCurrentValue()->DisableEventLogRecordings(); | 402 |
| 403 int rid, lid; | |
| 404 record->GetInteger("rid", &rid); | |
| 405 record->GetInteger("lid", &lid); | |
| 406 auto rph = RenderProcessHost::FromID(rid); | |
| 407 if (rph) { | |
| 408 rph->Send(new PeerConnectionTracker_StopEventLog(lid)); | |
| 409 } | |
| 350 } | 410 } |
| 351 } | 411 } |
| 352 #endif | 412 #endif |
| 353 } | 413 } |
| 354 | 414 |
| 355 bool WebRTCInternals::IsEventLogRecordingsEnabled() const { | 415 bool WebRTCInternals::IsEventLogRecordingsEnabled() const { |
| 356 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 416 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 357 return event_log_recordings_; | 417 return event_log_recordings_; |
| 358 } | 418 } |
| 359 | 419 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 scoped_ptr<base::DictionaryValue> update(new base::DictionaryValue()); | 520 scoped_ptr<base::DictionaryValue> update(new base::DictionaryValue()); |
| 461 update->SetInteger("rid", render_process_id); | 521 update->SetInteger("rid", render_process_id); |
| 462 SendUpdate("removeGetUserMediaForRenderer", std::move(update)); | 522 SendUpdate("removeGetUserMediaForRenderer", std::move(update)); |
| 463 } | 523 } |
| 464 } | 524 } |
| 465 | 525 |
| 466 #if defined(ENABLE_WEBRTC) | 526 #if defined(ENABLE_WEBRTC) |
| 467 void WebRTCInternals::EnableAudioDebugRecordingsOnAllRenderProcessHosts() { | 527 void WebRTCInternals::EnableAudioDebugRecordingsOnAllRenderProcessHosts() { |
| 468 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 528 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 469 | 529 |
| 530 #if defined(OS_ANDROID) | |
| 531 nr_event_log_files_ = 3; | |
| 532 #else | |
| 533 nr_event_log_files_ = 10; | |
| 534 #endif | |
| 470 audio_debug_recordings_ = true; | 535 audio_debug_recordings_ = true; |
| 471 for (RenderProcessHost::iterator i( | 536 for (RenderProcessHost::iterator i( |
| 472 content::RenderProcessHost::AllHostsIterator()); | 537 content::RenderProcessHost::AllHostsIterator()); |
| 473 !i.IsAtEnd(); i.Advance()) { | 538 !i.IsAtEnd(); i.Advance()) { |
| 474 i.GetCurrentValue()->EnableAudioDebugRecordings( | 539 i.GetCurrentValue()->EnableAudioDebugRecordings( |
| 475 audio_debug_recordings_file_path_); | 540 audio_debug_recordings_file_path_); |
| 476 } | 541 } |
| 477 } | 542 } |
| 478 | 543 |
| 479 void WebRTCInternals::EnableEventLogRecordingsOnAllRenderProcessHosts() { | 544 void WebRTCInternals::EnableEventLogRecordingsOnAllRenderProcessHosts() { |
| 480 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 545 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 481 | 546 |
| 482 event_log_recordings_ = true; | 547 event_log_recordings_ = true; |
| 483 for (RenderProcessHost::iterator i( | 548 for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) { |
| 484 content::RenderProcessHost::AllHostsIterator()); | 549 if (nr_event_log_files_ <= 0) { |
| 485 !i.IsAtEnd(); i.Advance()) { | 550 VLOG(1) << "Maximum number of WebRTC event log files reached."; |
| 486 i.GetCurrentValue()->EnableEventLogRecordings( | 551 break; |
| 487 event_log_recordings_file_path_); | 552 } |
| 553 nr_event_log_files_--; | |
| 554 base::DictionaryValue* record = NULL; | |
| 555 peer_connection_data_.GetDictionary(i, &record); | |
| 556 | |
| 557 int rid, lid; | |
| 558 record->GetInteger("rid", &rid); | |
| 559 record->GetInteger("lid", &lid); | |
| 560 base::FilePath file_path = event_log_recordings_file_path_; | |
| 561 file_path = file_path.AddExtension(IntToStringType(rid)); | |
| 562 file_path = file_path.AddExtension(IntToStringType(lid)); | |
| 563 | |
| 564 BrowserThread::PostTaskAndReplyWithResult( | |
| 565 BrowserThread::FILE, FROM_HERE, | |
| 566 base::Bind(&CreateFileForProcess, file_path, | |
| 567 base::GetCurrentProcessHandle()), | |
| 568 base::Bind(&SendEventLogFileToRenderer, rid, lid)); | |
| 488 } | 569 } |
| 489 } | 570 } |
| 490 #endif | 571 #endif |
| 491 | 572 |
| 492 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { | 573 void WebRTCInternals::CreateOrReleasePowerSaveBlocker() { |
| 493 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 574 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 494 | 575 |
| 495 if (peer_connection_data_.empty() && power_save_blocker_) { | 576 if (peer_connection_data_.empty() && power_save_blocker_) { |
| 496 DVLOG(1) << ("Releasing the block on application suspension since no " | 577 DVLOG(1) << ("Releasing the block on application suspension since no " |
| 497 "PeerConnections are active anymore."); | 578 "PeerConnections are active anymore."); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 510 while (!pending_updates_.empty()) { | 591 while (!pending_updates_.empty()) { |
| 511 const auto& update = pending_updates_.front(); | 592 const auto& update = pending_updates_.front(); |
| 512 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, | 593 FOR_EACH_OBSERVER(WebRTCInternalsUIObserver, |
| 513 observers_, | 594 observers_, |
| 514 OnUpdate(update.command(), update.value())); | 595 OnUpdate(update.command(), update.value())); |
| 515 pending_updates_.pop(); | 596 pending_updates_.pop(); |
| 516 } | 597 } |
| 517 } | 598 } |
| 518 | 599 |
| 519 } // namespace content | 600 } // namespace content |
| OLD | NEW |