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

Unified Diff: chrome/browser/media/webrtc_event_log_handler.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: Removed content/public/ interface, used RenderProcessHost instead. Created 4 years, 7 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: chrome/browser/media/webrtc_event_log_handler.cc
diff --git a/chrome/browser/media/webrtc_event_log_handler.cc b/chrome/browser/media/webrtc_event_log_handler.cc
index 0d9baccce4be9ff2de0f7586f9bd9508f533285f..948d772799d9ce11df0e3ab68213a0042e3d4dc4 100644
--- a/chrome/browser/media/webrtc_event_log_handler.cc
+++ b/chrome/browser/media/webrtc_event_log_handler.cc
@@ -15,8 +15,10 @@
#include "chrome/browser/media/webrtc_log_list.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
+#include "content/common/media/peer_connection_tracker_messages.h"
ncarter (slow) 2016/05/18 21:49:56 As general a rule, IPC messages are not part of th
Henrik Grunell 2016/05/19 14:10:41 Ah, good point. The IPC should be done over conten
Ivo-OOO until feb 6 2016/05/20 14:58:48 I moved the IPC sending code into content/, in a n
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
+#include "ipc/ipc_platform_file.h"
using content::BrowserThread;
@@ -26,22 +28,77 @@ const char WebRtcEventLogHandler::kWebRtcEventLogHandlerKey[] =
namespace {
+#if defined(OS_ANDROID)
+const int kMaxNumberLogFiles = 3;
+#else
+const int kMaxNumberLogFiles = 10;
+#endif
+
// Returns a path name to be used as prefix for RTC event log files.
-base::FilePath GetWebRtcEventLogPrefixPath(const base::FilePath& directory,
- uint64_t rtc_event_log_id) {
+base::FilePath GetWebRtcEventLogPrefixPath(const base::FilePath& directory) {
static const char kWebRtcEventLogFilePrefix[] = "WebRtcEventLog.";
- return directory.AppendASCII(kWebRtcEventLogFilePrefix +
- base::Int64ToString(rtc_event_log_id));
+ return directory.AppendASCII(kWebRtcEventLogFilePrefix);
+}
+
+// Appends the IDs to the RTC event log file name.
+base::FilePath GetWebRtcEventLogPath(const base::FilePath& base_file,
+ int render_process_id,
+ uint64_t rtc_event_log_id) {
+ return base_file.AddExtension(base::IntToString(render_process_id))
+ .AddExtension(base::Uint64ToString(rtc_event_log_id));
+}
+
+// Opens a logfile to pass on to the renderer.
+IPC::PlatformFileForTransit CreateFileForProcess(
+ const base::FilePath& base_path,
+ int render_process_id,
+ uint64_t rtc_event_log_id) {
+ DCHECK_CURRENTLY_ON(BrowserThread::FILE);
+ base::FilePath file_path =
+ GetWebRtcEventLogPath(base_path, render_process_id, rtc_event_log_id);
+ 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 WebRTC event log file, error="
+ << event_log_file.error_details();
+ return IPC::InvalidPlatformFileForTransit();
+ }
+ return IPC::TakePlatformFileForTransit(std::move(event_log_file));
}
+void SendEventLogFileToRenderer(content::RenderProcessHost* rph,
+ int local_id,
+ IPC::PlatformFileForTransit file_for_transit) {
+ if (file_for_transit == IPC::InvalidPlatformFileForTransit()) {
+ return;
+ }
+ rph->Send(
+ new PeerConnectionTracker_StartEventLog(local_id, file_for_transit));
+}
} // namespace
-WebRtcEventLogHandler::WebRtcEventLogHandler(Profile* profile)
- : profile_(profile),
+WebRtcEventLogHandler::WebRtcEventLogHandler(int process_id, Profile* profile)
+ : render_process_id(process_id),
+ profile_(profile),
is_rtc_event_logging_in_progress_(false),
+ number_active_log_files_(0),
current_rtc_event_log_id_(0) {
DCHECK(profile_);
thread_checker_.DetachFromThread();
+ content::RenderProcessHost* host =
+ content::RenderProcessHost::FromID(process_id);
+ using StartEventLogFn =
+ void (WebRtcEventLogHandler::*)(const base::FilePath& file_path);
+ using StopEventLogFn = void (WebRtcEventLogHandler::*)();
+ StartEventLogFn start_fn = &WebRtcEventLogHandler::StartWebRtcEventLogging;
+ StopEventLogFn stop_fn = &WebRtcEventLogHandler::StopWebRtcEventLogging;
+ if (host) {
+ host->RegisterEventLogHandler(base::Bind(start_fn, this),
+ base::Bind(stop_fn, this));
+ host->RegisterPeerConnectionCallbacks(
+ base::Bind(&WebRtcEventLogHandler::OnPeerConnectionAdded, this),
+ base::Bind(&WebRtcEventLogHandler::OnPeerConnectionRemoved, this));
+ }
}
WebRtcEventLogHandler::~WebRtcEventLogHandler() {}
@@ -60,6 +117,28 @@ void WebRtcEventLogHandler::StartWebRtcEventLogging(
delay, callback, error_callback));
}
+void WebRtcEventLogHandler::StartWebRtcEventLogging(
+ const base::FilePath& file_path) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+ content::RenderProcessHost* host =
+ content::RenderProcessHost::FromID(render_process_id);
+ if (host) {
+ is_rtc_event_logging_in_progress_ = true;
+ base_file_path_ = file_path;
+ number_active_log_files_ = 0;
+ for (int local_id : active_peer_connection_local_id_) {
+ if (number_active_log_files_ < kMaxNumberLogFiles) {
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&CreateFileForProcess, file_path, render_process_id,
+ local_id),
+ base::Bind(&SendEventLogFileToRenderer, host, local_id));
+ number_active_log_files_++;
+ }
+ }
+ }
+}
+
void WebRtcEventLogHandler::StopWebRtcEventLogging(
content::RenderProcessHost* host,
const RecordingDoneCallback& callback,
@@ -74,6 +153,38 @@ void WebRtcEventLogHandler::StopWebRtcEventLogging(
error_callback));
}
+void WebRtcEventLogHandler::StopWebRtcEventLogging() {
+ is_rtc_event_logging_in_progress_ = false;
+ content::RenderProcessHost* host =
+ content::RenderProcessHost::FromID(render_process_id);
+ if (host) {
+ for (int local_id : active_peer_connection_local_id_) {
+ host->Send(new PeerConnectionTracker_StopEventLog(local_id));
+ }
+ }
+}
+
+void WebRtcEventLogHandler::OnPeerConnectionAdded(int connection_id) {
+ active_peer_connection_local_id_.insert(connection_id);
+ if (is_rtc_event_logging_in_progress_ &&
+ number_active_log_files_ < kMaxNumberLogFiles) {
+ content::RenderProcessHost* host =
+ content::RenderProcessHost::FromID(render_process_id);
+ if (host) {
+ BrowserThread::PostTaskAndReplyWithResult(
+ BrowserThread::FILE, FROM_HERE,
+ base::Bind(&CreateFileForProcess, base_file_path_, render_process_id,
+ connection_id),
+ base::Bind(&SendEventLogFileToRenderer, host, connection_id));
+ number_active_log_files_++;
+ }
+ }
+}
+
+void WebRtcEventLogHandler::OnPeerConnectionRemoved(int connection_id) {
+ active_peer_connection_local_id_.erase(connection_id);
+}
+
base::FilePath WebRtcEventLogHandler::GetLogDirectoryAndEnsureExists() {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
base::FilePath log_dir_path =
@@ -98,11 +209,8 @@ void WebRtcEventLogHandler::DoStartWebRtcEventLogging(
error_callback.Run("RTC event logging already in progress");
return;
}
-
- is_rtc_event_logging_in_progress_ = true;
- base::FilePath prefix_path =
- GetWebRtcEventLogPrefixPath(log_directory, ++current_rtc_event_log_id_);
- host->EnableEventLogRecordings(prefix_path);
+ base::FilePath prefix_path = GetWebRtcEventLogPrefixPath(log_directory);
+ StartWebRtcEventLogging(prefix_path);
if (delay.is_zero()) {
const bool is_stopped = false, is_manual_stop = false;
@@ -129,8 +237,9 @@ void WebRtcEventLogHandler::DoStopWebRtcEventLogging(
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK_LE(rtc_event_log_id, current_rtc_event_log_id_);
- base::FilePath prefix_path =
- GetWebRtcEventLogPrefixPath(log_directory, rtc_event_log_id);
+ base::FilePath prefix_path = GetWebRtcEventLogPrefixPath(log_directory);
+ base::FilePath file_path =
+ GetWebRtcEventLogPath(prefix_path, host->GetID(), rtc_event_log_id);
// Prevent an old posted DoStopWebRtcEventLogging() call to stop a newer dump.
// This could happen in a sequence like:
// Start(10); // Start dump 1. Post Stop() to run after 10 seconds.
@@ -138,7 +247,7 @@ void WebRtcEventLogHandler::DoStopWebRtcEventLogging(
// Start(20); // Start dump 2. Posted Stop() for 1 should not stop dump 2.
if (rtc_event_log_id < current_rtc_event_log_id_) {
const bool is_stopped = false;
- callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop);
+ callback.Run(file_path.AsUTF8Unsafe(), is_stopped, is_manual_stop);
return;
}
@@ -147,8 +256,7 @@ void WebRtcEventLogHandler::DoStopWebRtcEventLogging(
return;
}
- host->DisableEventLogRecordings();
- is_rtc_event_logging_in_progress_ = false;
+ StopWebRtcEventLogging();
const bool is_stopped = true;
- callback.Run(prefix_path.AsUTF8Unsafe(), is_stopped, is_manual_stop);
+ callback.Run(file_path.AsUTF8Unsafe(), is_stopped, is_manual_stop);
}

Powered by Google App Engine
This is Rietveld 408576698