Commit 1c0ac8a9 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Convert PeerConnectionTrackerHost_AddPeerConnection to mojo

This is a first step to convert the remaining old IPC messages
in content::PeerConnectionTracker to Mojo. At this time, this CL
converts PeerConnectionTrackerHost_AddPeerConnection.

The remaining messages will be converted on follow up steps.

This paves out the way to Onion souping peer_connection_tracker.cc|h.

BUG=787254
R=dcheng@chromium.org, guidou@chromium.org, haraken@chromium.org

Change-Id: I578bcd21ce68253377be853a5b05876bfa04aa13
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1823619Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Cr-Commit-Position: refs/heads/master@{#700177}
parent 21e0df9d
......@@ -24,8 +24,6 @@ bool PeerConnectionTrackerHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PeerConnectionTrackerHost, message)
IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddPeerConnection,
OnAddPeerConnection)
IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddStandardStats,
OnAddStandardStats)
IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddLegacyStats,
......@@ -61,20 +59,27 @@ void PeerConnectionTrackerHost::OnChannelClosing() {
base::PowerMonitor::RemoveObserver(this);
}
void PeerConnectionTrackerHost::OnAddPeerConnection(
const PeerConnectionInfo& info) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
void PeerConnectionTrackerHost::AddPeerConnection(
mojom::PeerConnectionInfoPtr info) {
// TODO(crbug.com/787254): Remove the thread jump on all the methods
// here, and make sure the mojo pipe is bound on the proper thread instead.
if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
base::PostTask(FROM_HERE, {BrowserThread::UI},
base::BindOnce(&PeerConnectionTrackerHost::AddPeerConnection,
this, std::move(info)));
return;
}
WebRTCInternals* webrtc_internals = WebRTCInternals::GetInstance();
if (webrtc_internals) {
webrtc_internals->OnAddPeerConnection(
render_process_id_, peer_pid(), info.lid, info.url,
info.rtc_configuration, info.constraints);
render_process_id_, peer_pid(), info->lid, info->url,
info->rtc_configuration, info->constraints);
}
WebRtcEventLogger* const logger = WebRtcEventLogger::Get();
if (logger) {
logger->PeerConnectionAdded(render_process_id_, info.lid,
logger->PeerConnectionAdded(render_process_id_, info->lid,
base::OnceCallback<void(bool)>());
}
}
......
......@@ -14,8 +14,6 @@
#include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/browser_thread.h"
struct PeerConnectionInfo;
namespace base {
class ListValue;
} // namespace base
......@@ -49,12 +47,12 @@ class PeerConnectionTrackerHost
private:
// Handlers for IPC messages coming from the renderer.
void OnAddPeerConnection(const PeerConnectionInfo& info);
void OnAddStandardStats(int lid, const base::ListValue& value);
void OnAddLegacyStats(int lid, const base::ListValue& value);
void SendOnSuspendOnUIThread();
// mojom::PeerConnectionTrackerHost implementation.
void AddPeerConnection(mojom::PeerConnectionInfoPtr info) override;
void RemovePeerConnection(int lid) override;
void UpdatePeerConnection(int lid,
const std::string& type,
......
......@@ -4,6 +4,21 @@
module content.mojom;
struct PeerConnectionInfo {
// ID of the peer connection. Unique only within the renderer process.
int32 lid;
// Serialized version of RTCConfiguration.
string rtc_configuration;
// Serialized version of blink::WebMediaConstraints.
string constraints;
// The URL of the blink::WebLocalFrame within which this peer connection
// lives. Used for debugging purposes (displayed by WebRTC-Internals).
string url;
};
// This interface allows forwarding PeerConnection events to WebRTCInternals in
// the browser process.
interface PeerConnectionTrackerHost {
......@@ -11,6 +26,10 @@ interface PeerConnectionTrackerHost {
// TODO(vm.arjun): Migrate rest of the messages,
// https://bugs.chromium.org/p/chromium/issues/detail?id=792801
// Notifies WebRTCInternals about the addition of the peer connection
// whose data is specified in |info|.
AddPeerConnection(PeerConnectionInfo info);
// Notifies WebRTCInternals about the removal of the peer connection
// identified with local id |lid|.
RemovePeerConnection(int32 lid);
......
......@@ -14,21 +14,7 @@
#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
#define IPC_MESSAGE_START PeerConnectionTrackerMsgStart
IPC_STRUCT_BEGIN(PeerConnectionInfo)
// ID of the peer connection. Unique only within the renderer process.
IPC_STRUCT_MEMBER(int, lid)
// Serialized version of RTCConfiguration.
IPC_STRUCT_MEMBER(std::string, rtc_configuration)
// Serialized version of blink::WebMediaConstraints.
IPC_STRUCT_MEMBER(std::string, constraints)
// The URL of the blink::WebLocalFrame within which this peer connection
// lives. Used for debugging purposes (displayed by WebRTC-Internals).
IPC_STRUCT_MEMBER(std::string, url)
IPC_STRUCT_END()
// Messages sent from PeerConnectionTracker to PeerConnectionTrackerHost.
IPC_MESSAGE_CONTROL1(PeerConnectionTrackerHost_AddPeerConnection,
PeerConnectionInfo /* info */)
IPC_MESSAGE_CONTROL2(PeerConnectionTrackerHost_AddStandardStats,
int /* lid */,
base::ListValue /* value */)
......
......@@ -708,19 +708,21 @@ void PeerConnectionTracker::RegisterPeerConnection(
DCHECK(pc_handler);
DCHECK_EQ(GetLocalIDForHandler(pc_handler), -1);
DVLOG(1) << "PeerConnectionTracker::RegisterPeerConnection()";
PeerConnectionInfo info;
auto info = mojom::PeerConnectionInfo::New();
info.lid = GetNextLocalID();
info.rtc_configuration = SerializeConfiguration(config);
info->lid = GetNextLocalID();
info->rtc_configuration = SerializeConfiguration(config);
info.constraints = SerializeMediaConstraints(constraints);
info->constraints = SerializeMediaConstraints(constraints);
if (frame)
info.url = frame->GetDocument().Url().GetString().Utf8();
info->url = frame->GetDocument().Url().GetString().Utf8();
else
info.url = "test:testing";
SendTarget()->Send(new PeerConnectionTrackerHost_AddPeerConnection(info));
info->url = "test:testing";
peer_connection_local_id_map_.insert(std::make_pair(pc_handler, info.lid));
int32_t lid = info->lid;
GetPeerConnectionTrackerHost()->AddPeerConnection(std::move(info));
peer_connection_local_id_map_.insert(std::make_pair(pc_handler, lid));
}
void PeerConnectionTracker::UnregisterPeerConnection(
......
......@@ -60,6 +60,7 @@ class MockPeerConnectionTrackerHost : public mojom::PeerConnectionTrackerHost {
MockPeerConnectionTrackerHost() : binding_(this) {}
MOCK_METHOD3(UpdatePeerConnection,
void(int, const std::string&, const std::string&));
MOCK_METHOD1(AddPeerConnection, void(mojom::PeerConnectionInfoPtr));
MOCK_METHOD1(RemovePeerConnection, void(int));
MOCK_METHOD2(OnPeerConnectionSessionIdSet, void(int, const std::string&));
MOCK_METHOD5(GetUserMedia,
......@@ -119,24 +120,6 @@ std::unique_ptr<blink::WebRTCRtpTransceiver> CreateDefaultTransceiver(
namespace {
class MockSendTargetThread : public MockRenderThread {
public:
MOCK_METHOD1(OnAddPeerConnection, void(PeerConnectionInfo));
private:
bool OnMessageReceived(const IPC::Message& msg) override;
};
bool MockSendTargetThread::OnMessageReceived(const IPC::Message& msg) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(MockSendTargetThread, msg)
IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddPeerConnection,
OnAddPeerConnection)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
// TODO(https://crbug.com/868868): Move this into a separate file.
class MockPeerConnectionHandler : public RTCPeerConnectionHandler {
public:
......@@ -159,24 +142,22 @@ class PeerConnectionTrackerTest : public ::testing::Test {
tracker_.reset(new PeerConnectionTracker(
mock_host_->CreateInterfacePtrAndBind(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting()));
target_thread_.reset(new MockSendTargetThread());
tracker_->OverrideSendTargetForTesting(target_thread_.get());
}
void CreateAndRegisterPeerConnectionHandler() {
mock_handler_.reset(new MockPeerConnectionHandler());
EXPECT_CALL(*target_thread_, OnAddPeerConnection(_));
EXPECT_CALL(*mock_host_, AddPeerConnection(_));
tracker_->RegisterPeerConnection(
mock_handler_.get(),
webrtc::PeerConnectionInterface::RTCConfiguration(),
blink::WebMediaConstraints(), nullptr);
task_environment_.RunUntilIdle();
}
protected:
base::test::SingleThreadTaskEnvironment task_environment_;
std::unique_ptr<MockPeerConnectionTrackerHost> mock_host_;
std::unique_ptr<PeerConnectionTracker> tracker_;
std::unique_ptr<MockSendTargetThread> target_thread_;
std::unique_ptr<MockPeerConnectionHandler> mock_handler_;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment