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) { ...@@ -24,8 +24,6 @@ bool PeerConnectionTrackerHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true; bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PeerConnectionTrackerHost, message) IPC_BEGIN_MESSAGE_MAP(PeerConnectionTrackerHost, message)
IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddPeerConnection,
OnAddPeerConnection)
IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddStandardStats, IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddStandardStats,
OnAddStandardStats) OnAddStandardStats)
IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddLegacyStats, IPC_MESSAGE_HANDLER(PeerConnectionTrackerHost_AddLegacyStats,
...@@ -61,20 +59,27 @@ void PeerConnectionTrackerHost::OnChannelClosing() { ...@@ -61,20 +59,27 @@ void PeerConnectionTrackerHost::OnChannelClosing() {
base::PowerMonitor::RemoveObserver(this); base::PowerMonitor::RemoveObserver(this);
} }
void PeerConnectionTrackerHost::OnAddPeerConnection( void PeerConnectionTrackerHost::AddPeerConnection(
const PeerConnectionInfo& info) { mojom::PeerConnectionInfoPtr info) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); // 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(); WebRTCInternals* webrtc_internals = WebRTCInternals::GetInstance();
if (webrtc_internals) { if (webrtc_internals) {
webrtc_internals->OnAddPeerConnection( webrtc_internals->OnAddPeerConnection(
render_process_id_, peer_pid(), info.lid, info.url, render_process_id_, peer_pid(), info->lid, info->url,
info.rtc_configuration, info.constraints); info->rtc_configuration, info->constraints);
} }
WebRtcEventLogger* const logger = WebRtcEventLogger::Get(); WebRtcEventLogger* const logger = WebRtcEventLogger::Get();
if (logger) { if (logger) {
logger->PeerConnectionAdded(render_process_id_, info.lid, logger->PeerConnectionAdded(render_process_id_, info->lid,
base::OnceCallback<void(bool)>()); base::OnceCallback<void(bool)>());
} }
} }
......
...@@ -14,8 +14,6 @@ ...@@ -14,8 +14,6 @@
#include "content/public/browser/browser_message_filter.h" #include "content/public/browser/browser_message_filter.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
struct PeerConnectionInfo;
namespace base { namespace base {
class ListValue; class ListValue;
} // namespace base } // namespace base
...@@ -49,12 +47,12 @@ class PeerConnectionTrackerHost ...@@ -49,12 +47,12 @@ class PeerConnectionTrackerHost
private: private:
// Handlers for IPC messages coming from the renderer. // Handlers for IPC messages coming from the renderer.
void OnAddPeerConnection(const PeerConnectionInfo& info);
void OnAddStandardStats(int lid, const base::ListValue& value); void OnAddStandardStats(int lid, const base::ListValue& value);
void OnAddLegacyStats(int lid, const base::ListValue& value); void OnAddLegacyStats(int lid, const base::ListValue& value);
void SendOnSuspendOnUIThread(); void SendOnSuspendOnUIThread();
// mojom::PeerConnectionTrackerHost implementation. // mojom::PeerConnectionTrackerHost implementation.
void AddPeerConnection(mojom::PeerConnectionInfoPtr info) override;
void RemovePeerConnection(int lid) override; void RemovePeerConnection(int lid) override;
void UpdatePeerConnection(int lid, void UpdatePeerConnection(int lid,
const std::string& type, const std::string& type,
......
...@@ -4,6 +4,21 @@ ...@@ -4,6 +4,21 @@
module content.mojom; 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 // This interface allows forwarding PeerConnection events to WebRTCInternals in
// the browser process. // the browser process.
interface PeerConnectionTrackerHost { interface PeerConnectionTrackerHost {
...@@ -11,6 +26,10 @@ interface PeerConnectionTrackerHost { ...@@ -11,6 +26,10 @@ interface PeerConnectionTrackerHost {
// TODO(vm.arjun): Migrate rest of the messages, // TODO(vm.arjun): Migrate rest of the messages,
// https://bugs.chromium.org/p/chromium/issues/detail?id=792801 // 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 // Notifies WebRTCInternals about the removal of the peer connection
// identified with local id |lid|. // identified with local id |lid|.
RemovePeerConnection(int32 lid); RemovePeerConnection(int32 lid);
......
...@@ -14,21 +14,7 @@ ...@@ -14,21 +14,7 @@
#define IPC_MESSAGE_EXPORT CONTENT_EXPORT #define IPC_MESSAGE_EXPORT CONTENT_EXPORT
#define IPC_MESSAGE_START PeerConnectionTrackerMsgStart #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. // Messages sent from PeerConnectionTracker to PeerConnectionTrackerHost.
IPC_MESSAGE_CONTROL1(PeerConnectionTrackerHost_AddPeerConnection,
PeerConnectionInfo /* info */)
IPC_MESSAGE_CONTROL2(PeerConnectionTrackerHost_AddStandardStats, IPC_MESSAGE_CONTROL2(PeerConnectionTrackerHost_AddStandardStats,
int /* lid */, int /* lid */,
base::ListValue /* value */) base::ListValue /* value */)
......
...@@ -708,19 +708,21 @@ void PeerConnectionTracker::RegisterPeerConnection( ...@@ -708,19 +708,21 @@ void PeerConnectionTracker::RegisterPeerConnection(
DCHECK(pc_handler); DCHECK(pc_handler);
DCHECK_EQ(GetLocalIDForHandler(pc_handler), -1); DCHECK_EQ(GetLocalIDForHandler(pc_handler), -1);
DVLOG(1) << "PeerConnectionTracker::RegisterPeerConnection()"; DVLOG(1) << "PeerConnectionTracker::RegisterPeerConnection()";
PeerConnectionInfo info; auto info = mojom::PeerConnectionInfo::New();
info.lid = GetNextLocalID(); info->lid = GetNextLocalID();
info.rtc_configuration = SerializeConfiguration(config); info->rtc_configuration = SerializeConfiguration(config);
info.constraints = SerializeMediaConstraints(constraints); info->constraints = SerializeMediaConstraints(constraints);
if (frame) if (frame)
info.url = frame->GetDocument().Url().GetString().Utf8(); info->url = frame->GetDocument().Url().GetString().Utf8();
else else
info.url = "test:testing"; info->url = "test:testing";
SendTarget()->Send(new PeerConnectionTrackerHost_AddPeerConnection(info));
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( void PeerConnectionTracker::UnregisterPeerConnection(
......
...@@ -60,6 +60,7 @@ class MockPeerConnectionTrackerHost : public mojom::PeerConnectionTrackerHost { ...@@ -60,6 +60,7 @@ class MockPeerConnectionTrackerHost : public mojom::PeerConnectionTrackerHost {
MockPeerConnectionTrackerHost() : binding_(this) {} MockPeerConnectionTrackerHost() : binding_(this) {}
MOCK_METHOD3(UpdatePeerConnection, MOCK_METHOD3(UpdatePeerConnection,
void(int, const std::string&, const std::string&)); void(int, const std::string&, const std::string&));
MOCK_METHOD1(AddPeerConnection, void(mojom::PeerConnectionInfoPtr));
MOCK_METHOD1(RemovePeerConnection, void(int)); MOCK_METHOD1(RemovePeerConnection, void(int));
MOCK_METHOD2(OnPeerConnectionSessionIdSet, void(int, const std::string&)); MOCK_METHOD2(OnPeerConnectionSessionIdSet, void(int, const std::string&));
MOCK_METHOD5(GetUserMedia, MOCK_METHOD5(GetUserMedia,
...@@ -119,24 +120,6 @@ std::unique_ptr<blink::WebRTCRtpTransceiver> CreateDefaultTransceiver( ...@@ -119,24 +120,6 @@ std::unique_ptr<blink::WebRTCRtpTransceiver> CreateDefaultTransceiver(
namespace { 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. // TODO(https://crbug.com/868868): Move this into a separate file.
class MockPeerConnectionHandler : public RTCPeerConnectionHandler { class MockPeerConnectionHandler : public RTCPeerConnectionHandler {
public: public:
...@@ -159,24 +142,22 @@ class PeerConnectionTrackerTest : public ::testing::Test { ...@@ -159,24 +142,22 @@ class PeerConnectionTrackerTest : public ::testing::Test {
tracker_.reset(new PeerConnectionTracker( tracker_.reset(new PeerConnectionTracker(
mock_host_->CreateInterfacePtrAndBind(), mock_host_->CreateInterfacePtrAndBind(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting())); blink::scheduler::GetSingleThreadTaskRunnerForTesting()));
target_thread_.reset(new MockSendTargetThread());
tracker_->OverrideSendTargetForTesting(target_thread_.get());
} }
void CreateAndRegisterPeerConnectionHandler() { void CreateAndRegisterPeerConnectionHandler() {
mock_handler_.reset(new MockPeerConnectionHandler()); mock_handler_.reset(new MockPeerConnectionHandler());
EXPECT_CALL(*target_thread_, OnAddPeerConnection(_)); EXPECT_CALL(*mock_host_, AddPeerConnection(_));
tracker_->RegisterPeerConnection( tracker_->RegisterPeerConnection(
mock_handler_.get(), mock_handler_.get(),
webrtc::PeerConnectionInterface::RTCConfiguration(), webrtc::PeerConnectionInterface::RTCConfiguration(),
blink::WebMediaConstraints(), nullptr); blink::WebMediaConstraints(), nullptr);
task_environment_.RunUntilIdle();
} }
protected: protected:
base::test::SingleThreadTaskEnvironment task_environment_; base::test::SingleThreadTaskEnvironment task_environment_;
std::unique_ptr<MockPeerConnectionTrackerHost> mock_host_; std::unique_ptr<MockPeerConnectionTrackerHost> mock_host_;
std::unique_ptr<PeerConnectionTracker> tracker_; std::unique_ptr<PeerConnectionTracker> tracker_;
std::unique_ptr<MockSendTargetThread> target_thread_;
std::unique_ptr<MockPeerConnectionHandler> mock_handler_; 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