Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1958)

Unified Diff: content/browser/media/webrtc/webrtc_internals.cc

Issue 1855193002: Move the call to enable the WebRTC event log from PeerConnectionFactory to PeerConnection. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments by dcheng. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/media/webrtc/webrtc_internals.cc
diff --git a/content/browser/media/webrtc/webrtc_internals.cc b/content/browser/media/webrtc/webrtc_internals.cc
index aa10c5e40bb406c3fb2d3e26453e8148eb85b094..f9652352dd0e3f06b685e8fb2089d94358103482 100644
--- a/content/browser/media/webrtc/webrtc_internals.cc
+++ b/content/browser/media/webrtc/webrtc_internals.cc
@@ -10,11 +10,19 @@
#include "build/build_config.h"
#include "content/browser/media/webrtc/webrtc_internals_ui_observer.h"
#include "content/browser/web_contents/web_contents_view.h"
+#include "content/common/media/peer_connection_tracker_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/power_save_blocker.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h"
+#include "ipc/ipc_platform_file.h"
+
+#if defined(OS_WIN)
+#define IntToStringType base::IntToString16
+#else
+#define IntToStringType base::IntToString
+#endif
using base::ProcessId;
using std::string;
@@ -37,6 +45,40 @@ static base::ListValue* EnsureLogList(base::DictionaryValue* dict) {
return log;
}
+#if defined(ENABLE_WEBRTC)
+// Creates a file used for handing over to the renderer.
Henrik Grunell 2016/04/07 09:22:33 Webrtc internals is not the right place to handle
Ivo-OOO until feb 6 2016/04/07 12:10:50 Thanks for pointing that out, I was not aware of t
+IPC::PlatformFileForTransit CreateFileForProcess(
+ const base::FilePath& file_path,
+ base::ProcessHandle process) {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ base::File event_log_file(
+ file_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_APPEND);
+ if (!event_log_file.IsValid()) {
+ VLOG(1) << "Could not open event log file, error="
+ << event_log_file.error_details();
+ return IPC::InvalidPlatformFileForTransit();
+ }
+ return IPC::TakeFileHandleForProcess(std::move(event_log_file), process);
+}
+
+void SendEventLogFileToRenderer(int render_process_id,
+ int local_id,
+ IPC::PlatformFileForTransit file_for_transit) {
+#if defined(OS_ANDROID)
+ const int64_t max_file_size = 10000000;
+#else
+ const int64_t max_file_size = 30000000;
+#endif
+ if (file_for_transit == IPC::InvalidPlatformFileForTransit()) {
+ return;
+ }
+ RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
+ if (rph) {
+ rph->Send(new PeerConnectionTracker_StartEventLog(
+ local_id, file_for_transit, max_file_size));
+ }
+}
+#endif
} // namespace
WebRTCInternals::PendingUpdate::PendingUpdate(
@@ -67,6 +109,7 @@ WebRTCInternals::WebRTCInternals(int aggregate_updates_ms)
: audio_debug_recordings_(false),
event_log_recordings_(false),
selecting_event_log_(false),
+ number_event_log_files_(0),
aggregate_updates_ms_(aggregate_updates_ms),
weak_factory_(this) {
// TODO(grunell): Shouldn't all the webrtc_internals* files be excluded from the
@@ -117,6 +160,19 @@ void WebRTCInternals::OnAddPeerConnection(int render_process_id,
peer_connection_data_.Append(dict);
CreateOrReleasePowerSaveBlocker();
+ if (event_log_recordings_ && number_event_log_files_ > 0) {
+ number_event_log_files_--;
+ base::FilePath file_path = event_log_recordings_file_path_;
+ file_path = file_path.AddExtension(IntToStringType(render_process_id));
+ file_path = file_path.AddExtension(IntToStringType(lid));
+
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&CreateFileForProcess, file_path,
+ base::GetCurrentProcessHandle()),
+ base::Bind(&SendEventLogFileToRenderer, render_process_id, lid));
+ }
+
if (observers_.might_have_observers())
SendUpdate("addPeerConnection", dict->CreateDeepCopy());
@@ -338,15 +394,23 @@ void WebRTCInternals::SetEventLogRecordings(
#endif
} else {
event_log_recordings_ = false;
+ number_event_log_files_ = 0;
// Tear down the dialog since the user has unchecked the audio debug
// recordings box.
- select_file_dialog_ = nullptr;
DCHECK(select_file_dialog_->HasOneRef());
+ select_file_dialog_ = nullptr;
+
+ for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) {
+ base::DictionaryValue* record = NULL;
+ peer_connection_data_.GetDictionary(i, &record);
- for (RenderProcessHost::iterator i(
- content::RenderProcessHost::AllHostsIterator());
- !i.IsAtEnd(); i.Advance()) {
- i.GetCurrentValue()->DisableEventLogRecordings();
+ int rid, lid;
+ record->GetInteger("rid", &rid);
+ record->GetInteger("lid", &lid);
+ auto rph = RenderProcessHost::FromID(rid);
+ if (rph) {
+ rph->Send(new PeerConnectionTracker_StopEventLog(lid));
+ }
}
}
#endif
@@ -467,6 +531,11 @@ void WebRTCInternals::OnRendererExit(int render_process_id) {
void WebRTCInternals::EnableAudioDebugRecordingsOnAllRenderProcessHosts() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
+#if defined(OS_ANDROID)
+ number_event_log_files_ = 3;
+#else
+ number_event_log_files_ = 10;
+#endif
audio_debug_recordings_ = true;
for (RenderProcessHost::iterator i(
content::RenderProcessHost::AllHostsIterator());
@@ -480,11 +549,27 @@ void WebRTCInternals::EnableEventLogRecordingsOnAllRenderProcessHosts() {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
event_log_recordings_ = true;
- for (RenderProcessHost::iterator i(
- content::RenderProcessHost::AllHostsIterator());
- !i.IsAtEnd(); i.Advance()) {
- i.GetCurrentValue()->EnableEventLogRecordings(
- event_log_recordings_file_path_);
+ for (size_t i = 0; i < peer_connection_data_.GetSize(); ++i) {
+ if (number_event_log_files_ <= 0) {
+ VLOG(1) << "Maximum number of WebRTC event log files reached.";
+ break;
+ }
+ number_event_log_files_--;
+ base::DictionaryValue* record = NULL;
+ peer_connection_data_.GetDictionary(i, &record);
+
+ int rid, lid;
+ record->GetInteger("rid", &rid);
+ record->GetInteger("lid", &lid);
+ base::FilePath file_path = event_log_recordings_file_path_;
+ file_path = file_path.AddExtension(IntToStringType(rid));
+ file_path = file_path.AddExtension(IntToStringType(lid));
+
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&CreateFileForProcess, file_path,
+ base::GetCurrentProcessHandle()),
+ base::Bind(&SendEventLogFileToRenderer, rid, lid));
}
}
#endif
« no previous file with comments | « content/browser/media/webrtc/webrtc_internals.h ('k') | content/browser/renderer_host/render_process_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698