Commit bc917af8 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

Migrate PeerConnectionTracker and PeerConnectionTrackerHost to Mojo

This is a preliminary step to Onion souping content::PeerConnectionTracker.

The CL migrates both content::PeerConnectionTracker (renderer) and
content::PeerConnectionTrackerHost (browser) classes away from old
IPC mechanism, to use Mojo.

Additionally, the CL removes from:

- PeerConnectionTracker
  * the inheritance from content::RenderThreadObserver, as well as the respective
  overridden methods, namely OnControlMessageReceived().

- PeerConnectionTrackerHost
  * the inheritance from content::BrowserMessageFilter and
    content::BrowserAssociatedInterface, as well as the respective overridden,
    namely OnMessageReceived(), OverrideThreadForMessage(), OnChannelConnected(),
    OnChannelClosing().

It is important to note that PeerConnectionTrackerHost now operates solely
on the UI thread, so the CL removes some threading jumps between UI and IO
threads.

Last, content/common/media/peer_connection_tracker_messages.h (which declares
the macro-based IPC messages) is now gone.

BUG=787254
TBR=jam@chromium.org

Change-Id: I3ce5af1853384146d893da2a34c333aad80f5255
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1831197
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarKen Buchanan <kenrb@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707672}
parent 951a351f
...@@ -9,48 +9,43 @@ ...@@ -9,48 +9,43 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/power_monitor/power_observer.h" #include "base/power_monitor/power_observer.h"
#include "base/process/process_handle.h"
#include "content/common/media/peer_connection_tracker.mojom.h" #include "content/common/media/peer_connection_tracker.mojom.h"
#include "content/public/browser/browser_associated_interface.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "content/public/browser/browser_message_filter.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "content/public/browser/browser_thread.h" #include "mojo/public/cpp/bindings/remote.h"
namespace base { namespace base {
class ListValue; class Value;
} // namespace base } // namespace base
namespace content { namespace content {
class RenderProcessHost;
// This class is the host for PeerConnectionTracker in the browser process // This class is the host for PeerConnectionTracker in the browser process
// managed by RenderProcessHostImpl. It receives PeerConnection events from // managed by RenderProcessHostImpl. It receives PeerConnection events from
// PeerConnectionTracker as IPC messages that it forwards to WebRTCInternals. // PeerConnectionTracker as IPC messages that it forwards to WebRTCInternals.
// It also forwards browser process events to PeerConnectionTracker via IPC. // It also forwards browser process events to PeerConnectionTracker via IPC.
class PeerConnectionTrackerHost class PeerConnectionTrackerHost : public base::PowerObserver,
: public BrowserMessageFilter, public mojom::PeerConnectionTrackerHost {
public base::PowerObserver,
public BrowserAssociatedInterface<mojom::PeerConnectionTrackerHost>,
public mojom::PeerConnectionTrackerHost {
public: public:
explicit PeerConnectionTrackerHost(int render_process_id); explicit PeerConnectionTrackerHost(RenderProcessHost* rph);
~PeerConnectionTrackerHost() override;
// content::BrowserMessageFilter override.
bool OnMessageReceived(const IPC::Message& message) override;
void OverrideThreadForMessage(const IPC::Message& message,
BrowserThread::ID* thread) override;
void OnChannelConnected(int32_t peer_pid) override;
void OnChannelClosing() override;
// base::PowerObserver override. // base::PowerObserver override.
void OnSuspend() override; void OnSuspend() override;
protected: // These methods call out to mojom::PeerConnectionManager on renderer side.
~PeerConnectionTrackerHost() override; void StartEventLog(int peer_connection_local_id, int output_period_ms);
void StopEventLog(int lid);
void GetStandardStats();
void GetLegacyStats();
private: void BindReceiver(
// Handlers for IPC messages coming from the renderer. mojo::PendingReceiver<mojom::PeerConnectionTrackerHost> pending_receiver);
void OnAddStandardStats(int lid, const base::ListValue& value);
void OnAddLegacyStats(int lid, const base::ListValue& value);
void SendOnSuspendOnUIThread();
private:
// mojom::PeerConnectionTrackerHost implementation. // mojom::PeerConnectionTrackerHost implementation.
void AddPeerConnection(mojom::PeerConnectionInfoPtr info) override; void AddPeerConnection(mojom::PeerConnectionInfoPtr info) override;
void RemovePeerConnection(int lid) override; void RemovePeerConnection(int lid) override;
...@@ -65,8 +60,13 @@ class PeerConnectionTrackerHost ...@@ -65,8 +60,13 @@ class PeerConnectionTrackerHost
const std::string& audio_constraints, const std::string& audio_constraints,
const std::string& video_constraints) override; const std::string& video_constraints) override;
void WebRtcEventLogWrite(int lid, const std::string& output) override; void WebRtcEventLogWrite(int lid, const std::string& output) override;
void AddStandardStats(int lid, base::Value value) override;
void AddLegacyStats(int lid, base::Value value) override;
int render_process_id_; int render_process_id_;
base::ProcessId peer_pid_;
mojo::Receiver<mojom::PeerConnectionTrackerHost> receiver_{this};
mojo::Remote<mojom::PeerConnectionManager> tracker_;
DISALLOW_COPY_AND_ASSIGN(PeerConnectionTrackerHost); DISALLOW_COPY_AND_ASSIGN(PeerConnectionTrackerHost);
}; };
......
...@@ -142,7 +142,6 @@ ...@@ -142,7 +142,6 @@
#include "content/common/content_switches_internal.h" #include "content/common/content_switches_internal.h"
#include "content/common/frame_messages.h" #include "content/common/frame_messages.h"
#include "content/common/in_process_child_thread_params.h" #include "content/common/in_process_child_thread_params.h"
#include "content/common/media/peer_connection_tracker_messages.h"
#include "content/common/resource_messages.h" #include "content/common/resource_messages.h"
#include "content/common/service_manager/child_connection.h" #include "content/common/service_manager/child_connection.h"
#include "content/common/service_manager/service_manager_connection_impl.h" #include "content/common/service_manager/service_manager_connection_impl.h"
...@@ -1848,8 +1847,6 @@ void RenderProcessHostImpl::CreateMessageFilters() { ...@@ -1848,8 +1847,6 @@ void RenderProcessHostImpl::CreateMessageFilters() {
GetBrowserContext(), storage_partition_impl_, widget_helper_.get()); GetBrowserContext(), storage_partition_impl_, widget_helper_.get());
AddFilter(render_frame_message_filter_.get()); AddFilter(render_frame_message_filter_.get());
peer_connection_tracker_host_ = new PeerConnectionTrackerHost(GetID());
AddFilter(peer_connection_tracker_host_.get());
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
AddFilter(new PepperRendererConnection(GetID())); AddFilter(new PepperRendererConnection(GetID()));
#endif #endif
...@@ -1982,6 +1979,15 @@ void RenderProcessHostImpl::CleanupCorbExceptionForPluginUponDestruction() { ...@@ -1982,6 +1979,15 @@ void RenderProcessHostImpl::CleanupCorbExceptionForPluginUponDestruction() {
cleanup_corb_exception_for_plugin_upon_destruction_ = true; cleanup_corb_exception_for_plugin_upon_destruction_ = true;
} }
PeerConnectionTrackerHost*
RenderProcessHostImpl::GetPeerConnectionTrackerHost() {
if (!peer_connection_tracker_host_) {
peer_connection_tracker_host_ =
std::make_unique<PeerConnectionTrackerHost>(this);
}
return peer_connection_tracker_host_.get();
}
void RenderProcessHostImpl::RegisterMojoInterfaces() { void RenderProcessHostImpl::RegisterMojoInterfaces() {
auto registry = std::make_unique<service_manager::BinderRegistry>(); auto registry = std::make_unique<service_manager::BinderRegistry>();
...@@ -2154,6 +2160,11 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() { ...@@ -2154,6 +2160,11 @@ void RenderProcessHostImpl::RegisterMojoInterfaces() {
registry->AddInterface( registry->AddInterface(
base::BindRepeating(&metrics::CreateSingleSampleMetricsProvider)); base::BindRepeating(&metrics::CreateSingleSampleMetricsProvider));
AddUIThreadInterface(
registry.get(),
base::BindRepeating(&RenderProcessHostImpl::BindPeerConnectionTrackerHost,
base::Unretained(this)));
AddUIThreadInterface( AddUIThreadInterface(
registry.get(), registry.get(),
base::BindRepeating( base::BindRepeating(
...@@ -3635,11 +3646,11 @@ RenderProcessHostImpl::StartRtpDump( ...@@ -3635,11 +3646,11 @@ RenderProcessHostImpl::StartRtpDump(
void RenderProcessHostImpl::EnableWebRtcEventLogOutput(int lid, void RenderProcessHostImpl::EnableWebRtcEventLogOutput(int lid,
int output_period_ms) { int output_period_ms) {
Send(new PeerConnectionTracker_StartEventLog(lid, output_period_ms)); GetPeerConnectionTrackerHost()->StartEventLog(lid, output_period_ms);
} }
void RenderProcessHostImpl::DisableWebRtcEventLogOutput(int lid) { void RenderProcessHostImpl::DisableWebRtcEventLogOutput(int lid) {
Send(new PeerConnectionTracker_StopEventLog(lid)); GetPeerConnectionTrackerHost()->StopEventLog(lid);
} }
IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() { IPC::ChannelProxy* RenderProcessHostImpl::GetChannel() {
...@@ -4699,6 +4710,11 @@ void RenderProcessHostImpl::CreateMediaStreamTrackMetricsHost( ...@@ -4699,6 +4710,11 @@ void RenderProcessHostImpl::CreateMediaStreamTrackMetricsHost(
media_stream_track_metrics_host_->BindReceiver(std::move(receiver)); media_stream_track_metrics_host_->BindReceiver(std::move(receiver));
} }
void RenderProcessHostImpl::BindPeerConnectionTrackerHost(
mojo::PendingReceiver<mojom::PeerConnectionTrackerHost> receiver) {
GetPeerConnectionTrackerHost()->BindReceiver(std::move(receiver));
}
#if BUILDFLAG(ENABLE_MDNS) #if BUILDFLAG(ENABLE_MDNS)
void RenderProcessHostImpl::CreateMdnsResponder( void RenderProcessHostImpl::CreateMdnsResponder(
mojo::PendingReceiver<network::mojom::MdnsResponder> receiver) { mojo::PendingReceiver<network::mojom::MdnsResponder> receiver) {
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "content/common/associated_interfaces.mojom.h" #include "content/common/associated_interfaces.mojom.h"
#include "content/common/child_process.mojom.h" #include "content/common/child_process.mojom.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/common/media/peer_connection_tracker.mojom.h"
#include "content/common/media/renderer_audio_output_stream_factory.mojom.h" #include "content/common/media/renderer_audio_output_stream_factory.mojom.h"
#include "content/common/renderer.mojom.h" #include "content/common/renderer.mojom.h"
#include "content/common/renderer_host.mojom.h" #include "content/common/renderer_host.mojom.h"
...@@ -567,6 +568,8 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -567,6 +568,8 @@ class CONTENT_EXPORT RenderProcessHostImpl
size_t keep_alive_ref_count() const { return keep_alive_ref_count_; } size_t keep_alive_ref_count() const { return keep_alive_ref_count_; }
PeerConnectionTrackerHost* GetPeerConnectionTrackerHost();
protected: protected:
// A proxy for our IPC::Channel that lives on the IO thread. // A proxy for our IPC::Channel that lives on the IO thread.
std::unique_ptr<IPC::ChannelProxy> channel_; std::unique_ptr<IPC::ChannelProxy> channel_;
...@@ -741,6 +744,9 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -741,6 +744,9 @@ class CONTENT_EXPORT RenderProcessHostImpl
mojo::PendingReceiver<blink::mojom::MediaStreamTrackMetricsHost> mojo::PendingReceiver<blink::mojom::MediaStreamTrackMetricsHost>
receiver); receiver);
void BindPeerConnectionTrackerHost(
mojo::PendingReceiver<mojom::PeerConnectionTrackerHost> receiver);
#if BUILDFLAG(ENABLE_MDNS) #if BUILDFLAG(ENABLE_MDNS)
void CreateMdnsResponder( void CreateMdnsResponder(
mojo::PendingReceiver<network::mojom::MdnsResponder> receiver); mojo::PendingReceiver<network::mojom::MdnsResponder> receiver);
...@@ -976,9 +982,7 @@ class CONTENT_EXPORT RenderProcessHostImpl ...@@ -976,9 +982,7 @@ class CONTENT_EXPORT RenderProcessHostImpl
// Forwards messages between WebRTCInternals in the browser process // Forwards messages between WebRTCInternals in the browser process
// and PeerConnectionTracker in the renderer process. // and PeerConnectionTracker in the renderer process.
// It holds a raw pointer to webrtc_eventlog_host_, and therefore should be std::unique_ptr<PeerConnectionTrackerHost> peer_connection_tracker_host_;
// defined below it so it is destructed first.
scoped_refptr<PeerConnectionTrackerHost> peer_connection_tracker_host_;
// Records the time when the process starts surviving for workers for UMA. // Records the time when the process starts surviving for workers for UMA.
base::TimeTicks keep_alive_start_time_; base::TimeTicks keep_alive_start_time_;
......
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "content/browser/renderer_host/media/peer_connection_tracker_host.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/browser/webrtc/webrtc_internals.h" #include "content/browser/webrtc/webrtc_internals.h"
#include "content/common/media/peer_connection_tracker_messages.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
...@@ -93,7 +94,9 @@ void WebRTCInternalsMessageHandler::OnGetStandardStats( ...@@ -93,7 +94,9 @@ void WebRTCInternalsMessageHandler::OnGetStandardStats(
for (RenderProcessHost::iterator i( for (RenderProcessHost::iterator i(
content::RenderProcessHost::AllHostsIterator()); content::RenderProcessHost::AllHostsIterator());
!i.IsAtEnd(); i.Advance()) { !i.IsAtEnd(); i.Advance()) {
i.GetCurrentValue()->Send(new PeerConnectionTracker_GetStandardStats()); auto* render_process_host =
static_cast<RenderProcessHostImpl*>(i.GetCurrentValue());
render_process_host->GetPeerConnectionTrackerHost()->GetStandardStats();
} }
} }
...@@ -102,7 +105,9 @@ void WebRTCInternalsMessageHandler::OnGetLegacyStats( ...@@ -102,7 +105,9 @@ void WebRTCInternalsMessageHandler::OnGetLegacyStats(
for (RenderProcessHost::iterator i( for (RenderProcessHost::iterator i(
content::RenderProcessHost::AllHostsIterator()); content::RenderProcessHost::AllHostsIterator());
!i.IsAtEnd(); i.Advance()) { !i.IsAtEnd(); i.Advance()) {
i.GetCurrentValue()->Send(new PeerConnectionTracker_GetLegacyStats()); auto* render_process_host =
static_cast<RenderProcessHostImpl*>(i.GetCurrentValue());
render_process_host->GetPeerConnectionTrackerHost()->GetLegacyStats();
} }
} }
......
...@@ -180,7 +180,6 @@ source_set("common") { ...@@ -180,7 +180,6 @@ source_set("common") {
"mac/font_loader.mm", "mac/font_loader.mm",
"media/cdm_info.cc", "media/cdm_info.cc",
"media/media_player_delegate_messages.h", "media/media_player_delegate_messages.h",
"media/peer_connection_tracker_messages.h",
"navigation_gesture.h", "navigation_gesture.h",
"navigation_params.cc", "navigation_params.cc",
"navigation_params.h", "navigation_params.h",
......
...@@ -42,12 +42,6 @@ ...@@ -42,12 +42,6 @@
#ifndef CONTENT_COMMON_MEDIA_MEDIA_PLAYER_DELEGATE_MESSAGES_H_ #ifndef CONTENT_COMMON_MEDIA_MEDIA_PLAYER_DELEGATE_MESSAGES_H_
#error "Failed to include content/common/media/media_player_delegate_messages.h" #error "Failed to include content/common/media/media_player_delegate_messages.h"
#endif #endif
#undef CONTENT_COMMON_MEDIA_PEER_CONNECTION_TRACKER_MESSAGES_H_
#include "content/common/media/peer_connection_tracker_messages.h"
#ifndef CONTENT_COMMON_MEDIA_PEER_CONNECTION_TRACKER_MESSAGES_H_
#error \
"Failed to include content/common/media/peer_connection_tracker_messages.h"
#endif
#undef CONTENT_COMMON_PAGE_MESSAGES_H_ #undef CONTENT_COMMON_PAGE_MESSAGES_H_
#include "content/common/page_messages.h" #include "content/common/page_messages.h"
#ifndef CONTENT_COMMON_PAGE_MESSAGES_H_ #ifndef CONTENT_COMMON_PAGE_MESSAGES_H_
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
module content.mojom; module content.mojom;
import "mojo/public/mojom/base/values.mojom";
struct PeerConnectionInfo { struct PeerConnectionInfo {
// ID of the peer connection. Unique only within the renderer process. // ID of the peer connection. Unique only within the renderer process.
int32 lid; int32 lid;
...@@ -19,6 +21,25 @@ struct PeerConnectionInfo { ...@@ -19,6 +21,25 @@ struct PeerConnectionInfo {
string url; string url;
}; };
// This interface collects data about each peer connection and sends it to the
// browser process.
interface PeerConnectionManager {
// Called when the browser process reports a suspend event from the OS.
OnSuspend();
// Enable WebRtc event log output.
StartEventLog(int32 peer_connection_local_id, int32 output_period_ms);
// Disable WebRtc event log output.
StopEventLog(int32 peer_connection_local_id);
// Requests standard PeerConnection stats for webrtc-internals.
GetStandardStats();
// Requests legacy PeerConnection stats for webrtc-internals.
GetLegacyStats();
};
// 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 {
...@@ -59,4 +80,14 @@ interface PeerConnectionTrackerHost { ...@@ -59,4 +80,14 @@ interface PeerConnectionTrackerHost {
// Logs WebRtc log for the connection id. // Logs WebRtc log for the connection id.
WebRtcEventLogWrite(int32 lid, string output); WebRtcEventLogWrite(int32 lid, string output);
// Adds standard PeerConnection stats for webrtc-internals.
// |lid| is the renderer local id,
// |value| is the list of stats reports.
AddStandardStats(int32 lid, mojo_base.mojom.ListValue value);
// Adds legacy PeerConnection stats for webrtc-internals.
// |lid| is the renderer local id,
// |value| is the list of stats reports.
AddLegacyStats(int32 lid, mojo_base.mojom.ListValue value);
}; };
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_COMMON_MEDIA_PEER_CONNECTION_TRACKER_MESSAGES_H_
#define CONTENT_COMMON_MEDIA_PEER_CONNECTION_TRACKER_MESSAGES_H_
#include "base/values.h"
#include "content/common/content_export.h"
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_platform_file.h"
#undef IPC_MESSAGE_EXPORT
#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
#define IPC_MESSAGE_START PeerConnectionTrackerMsgStart
// Messages sent from PeerConnectionTracker to PeerConnectionTrackerHost.
IPC_MESSAGE_CONTROL2(PeerConnectionTrackerHost_AddStandardStats,
int /* lid */,
base::ListValue /* value */)
IPC_MESSAGE_CONTROL2(PeerConnectionTrackerHost_AddLegacyStats,
int /* lid */,
base::ListValue /* value */)
// Messages sent to PeerConnectionTracker.
IPC_MESSAGE_CONTROL0(PeerConnectionTracker_GetStandardStats)
IPC_MESSAGE_CONTROL0(PeerConnectionTracker_GetLegacyStats)
IPC_MESSAGE_CONTROL0(PeerConnectionTracker_OnSuspend)
IPC_MESSAGE_CONTROL2(PeerConnectionTracker_StartEventLog,
int /* peer_connection_local_id */,
int /* output_period_ms */)
IPC_MESSAGE_CONTROL1(PeerConnectionTracker_StopEventLog,
int /* peer_connection_local_id */)
#endif // CONTENT_COMMON_MEDIA_PEER_CONNECTION_TRACKER_MESSAGES_H_
...@@ -32,6 +32,7 @@ const service_manager::Manifest& GetContentRendererManifest() { ...@@ -32,6 +32,7 @@ const service_manager::Manifest& GetContentRendererManifest() {
"content.mojom.ChildProcess", "content.mojom.ChildProcess",
"content.mojom.FrameFactory", "content.mojom.FrameFactory",
"content.mojom.MhtmlFileWriter", "content.mojom.MhtmlFileWriter",
"content.mojom.PeerConnectionManager",
"content.mojom.RenderWidgetWindowTreeClientFactory", "content.mojom.RenderWidgetWindowTreeClientFactory",
"content.mojom.ResourceUsageReporter", "content.mojom.ResourceUsageReporter",
"IPC.mojom.ChannelBootstrap", "IPC.mojom.ChannelBootstrap",
......
...@@ -7,14 +7,12 @@ ...@@ -7,14 +7,12 @@
#include <map> #include <map>
#include "base/compiler_specific.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/threading/thread_checker.h" #include "base/threading/thread_checker.h"
#include "content/common/media/peer_connection_tracker.mojom.h" #include "content/common/media/peer_connection_tracker.mojom.h"
#include "content/public/renderer/render_thread_observer.h" #include "mojo/public/cpp/bindings/receiver.h"
#include "ipc/ipc_platform_file.h" #include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/platform/web_media_stream.h"
#include "third_party/blink/public/platform/web_rtc_peer_connection_handler_client.h" #include "third_party/blink/public/platform/web_rtc_peer_connection_handler_client.h"
#include "third_party/blink/public/platform/web_rtc_rtp_transceiver.h" #include "third_party/blink/public/platform/web_rtc_rtp_transceiver.h"
#include "third_party/blink/public/platform/web_rtc_session_description.h" #include "third_party/blink/public/platform/web_rtc_session_description.h"
...@@ -36,21 +34,22 @@ class DataChannelInterface; ...@@ -36,21 +34,22 @@ class DataChannelInterface;
namespace content { namespace content {
class RTCPeerConnectionHandler; class RTCPeerConnectionHandler;
class RenderThread;
// This class collects data about each peer connection, // This class collects data about each peer connection,
// sends it to the browser process, and handles messages // sends it to the browser process, and handles messages
// from the browser process. // from the browser process.
class CONTENT_EXPORT PeerConnectionTracker class CONTENT_EXPORT PeerConnectionTracker
: public RenderThreadObserver, : public mojom::PeerConnectionManager,
public base::SupportsWeakPtr<PeerConnectionTracker> { public base::SupportsWeakPtr<PeerConnectionTracker> {
public: public:
static PeerConnectionTracker* GetInstance(); static PeerConnectionTracker* GetInstance();
// TODO(crbug.com/787254): Make these ctors private, and accessible to
// tests only.
explicit PeerConnectionTracker( explicit PeerConnectionTracker(
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner); scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner);
PeerConnectionTracker( PeerConnectionTracker(
mojom::PeerConnectionTrackerHostAssociatedPtr host, mojo::Remote<mojom::PeerConnectionTrackerHost> host,
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner); scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner);
~PeerConnectionTracker() override; ~PeerConnectionTracker() override;
...@@ -76,15 +75,12 @@ class CONTENT_EXPORT PeerConnectionTracker ...@@ -76,15 +75,12 @@ class CONTENT_EXPORT PeerConnectionTracker
kSetRemoteDescription, kSetRemoteDescription,
}; };
// RenderThreadObserver implementation. void Bind(mojo::PendingReceiver<mojom::PeerConnectionManager> receiver);
bool OnControlMessageReceived(const IPC::Message& message) override;
//
// The following methods send an update to the browser process when a // The following methods send an update to the browser process when a
// PeerConnection update happens. The caller should call the Track* methods // PeerConnection update happens. The caller should call the Track* methods
// after calling RegisterPeerConnection and before calling // after calling RegisterPeerConnection and before calling
// UnregisterPeerConnection, otherwise the Track* call has no effect. // UnregisterPeerConnection, otherwise the Track* call has no effect.
//
// Sends an update when a PeerConnection has been created in Javascript. This // Sends an update when a PeerConnection has been created in Javascript. This
// should be called once and only once for each PeerConnection. The // should be called once and only once for each PeerConnection. The
...@@ -221,10 +217,10 @@ class CONTENT_EXPORT PeerConnectionTracker ...@@ -221,10 +217,10 @@ class CONTENT_EXPORT PeerConnectionTracker
// Sends a new fragment on an RtcEventLog. // Sends a new fragment on an RtcEventLog.
virtual void TrackRtcEventLogWrite(RTCPeerConnectionHandler* pc_handler, virtual void TrackRtcEventLogWrite(RTCPeerConnectionHandler* pc_handler,
const std::string& output); const std::string& output);
// For testing: Override the class that gets posted messages.
void OverrideSendTargetForTesting(RenderThread* target);
private: private:
FRIEND_TEST_ALL_PREFIXES(PeerConnectionTrackerTest, OnSuspend);
// Assign a local ID to a peer connection so that the browser process can // Assign a local ID to a peer connection so that the browser process can
// uniquely identify a peer connection in the renderer process. // uniquely identify a peer connection in the renderer process.
// The return value will always be positive. // The return value will always be positive.
...@@ -240,18 +236,13 @@ class CONTENT_EXPORT PeerConnectionTracker ...@@ -240,18 +236,13 @@ class CONTENT_EXPORT PeerConnectionTracker
const blink::WebRTCRtpTransceiver& transceiver, const blink::WebRTCRtpTransceiver& transceiver,
size_t transceiver_index); size_t transceiver_index);
// IPC Message handler for getting all stats. // PeerConnectionTracker implementation.
void OnGetStandardStats(); void OnSuspend() override;
void OnGetLegacyStats(); void StartEventLog(int peer_connection_local_id,
int output_period_ms) override;
// Called when the browser process reports a suspend event from the OS. void StopEventLog(int peer_connection_local_id) override;
void OnSuspend(); void GetStandardStats() override;
void GetLegacyStats() override;
// IPC Message handler for starting event log.
void OnStartEventLog(int peer_connection_local_id, int output_period_ms);
// IPC Message handler for stopping event log.
void OnStopEventLog(int peer_connection_local_id);
// Called to deliver an update to the host (PeerConnectionTrackerHost). // Called to deliver an update to the host (PeerConnectionTrackerHost).
// |local_id| - The id of the registered RTCPeerConnectionHandler. // |local_id| - The id of the registered RTCPeerConnectionHandler.
...@@ -268,9 +259,8 @@ class CONTENT_EXPORT PeerConnectionTracker ...@@ -268,9 +259,8 @@ class CONTENT_EXPORT PeerConnectionTracker
const std::string& callback_type, const std::string& callback_type,
const std::string& value); const std::string& value);
RenderThread* SendTarget(); void AddStandardStats(int lid, base::Value value);
const mojom::PeerConnectionTrackerHostAssociatedPtr& void AddLegacyStats(int lid, base::Value value);
GetPeerConnectionTrackerHost();
// This map stores the local ID assigned to each RTCPeerConnectionHandler. // This map stores the local ID assigned to each RTCPeerConnectionHandler.
typedef std::map<RTCPeerConnectionHandler*, int> PeerConnectionLocalIdMap; typedef std::map<RTCPeerConnectionHandler*, int> PeerConnectionLocalIdMap;
...@@ -279,9 +269,8 @@ class CONTENT_EXPORT PeerConnectionTracker ...@@ -279,9 +269,8 @@ class CONTENT_EXPORT PeerConnectionTracker
// This keeps track of the next available local ID. // This keeps track of the next available local ID.
int next_local_id_; int next_local_id_;
THREAD_CHECKER(main_thread_); THREAD_CHECKER(main_thread_);
RenderThread* send_target_for_test_; mojo::Remote<mojom::PeerConnectionTrackerHost> peer_connection_tracker_host_;
mojom::PeerConnectionTrackerHostAssociatedPtr mojo::Receiver<mojom::PeerConnectionManager> receiver_{this};
peer_connection_tracker_host_ptr_;
scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
......
...@@ -6,11 +6,7 @@ ...@@ -6,11 +6,7 @@
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "content/common/media/peer_connection_tracker.mojom.h" #include "content/common/media/peer_connection_tracker.mojom.h"
#include "content/common/media/peer_connection_tracker_messages.h"
#include "content/public/test/mock_render_thread.h"
#include "content/renderer/media/webrtc/rtc_peer_connection_handler.h" #include "content/renderer/media/webrtc/rtc_peer_connection_handler.h"
#include "ipc/ipc_message_macros.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h" #include "third_party/blink/public/platform/scheduler/test/renderer_scheduler_test_support.h"
...@@ -57,7 +53,7 @@ const char* kDefaultReceiverString = ...@@ -57,7 +53,7 @@ const char* kDefaultReceiverString =
class MockPeerConnectionTrackerHost : public mojom::PeerConnectionTrackerHost { class MockPeerConnectionTrackerHost : public mojom::PeerConnectionTrackerHost {
public: public:
MockPeerConnectionTrackerHost() : binding_(this) {} MockPeerConnectionTrackerHost() {}
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(AddPeerConnection, void(mojom::PeerConnectionInfoPtr));
...@@ -70,15 +66,17 @@ class MockPeerConnectionTrackerHost : public mojom::PeerConnectionTrackerHost { ...@@ -70,15 +66,17 @@ class MockPeerConnectionTrackerHost : public mojom::PeerConnectionTrackerHost {
const std::string&, const std::string&,
const std::string&)); const std::string&));
MOCK_METHOD2(WebRtcEventLogWrite, void(int, const std::string&)); MOCK_METHOD2(WebRtcEventLogWrite, void(int, const std::string&));
mojom::PeerConnectionTrackerHostAssociatedPtr CreateInterfacePtrAndBind() { MOCK_METHOD2(AddStandardStats, void(int, base::Value));
mojom::PeerConnectionTrackerHostAssociatedPtr MOCK_METHOD2(AddLegacyStats, void(int, base::Value));
peer_connection_tracker_host_ptr_;
binding_.Bind(mojo::MakeRequestAssociatedWithDedicatedPipe( mojo::Remote<mojom::PeerConnectionTrackerHost> CreatePendingRemoteAndBind() {
&peer_connection_tracker_host_ptr_), receiver_.reset();
blink::scheduler::GetSingleThreadTaskRunnerForTesting()); return mojo::Remote<mojom::PeerConnectionTrackerHost>(
return peer_connection_tracker_host_ptr_; receiver_.BindNewPipeAndPassRemote(
blink::scheduler::GetSingleThreadTaskRunnerForTesting()));
} }
mojo::AssociatedBinding<mojom::PeerConnectionTrackerHost> binding_;
mojo::Receiver<mojom::PeerConnectionTrackerHost> receiver_{this};
}; };
// Creates a transceiver that is expected to be logged as // Creates a transceiver that is expected to be logged as
...@@ -140,7 +138,7 @@ class PeerConnectionTrackerTest : public ::testing::Test { ...@@ -140,7 +138,7 @@ class PeerConnectionTrackerTest : public ::testing::Test {
void CreateTrackerWithMocks() { void CreateTrackerWithMocks() {
mock_host_.reset(new MockPeerConnectionTrackerHost()); mock_host_.reset(new MockPeerConnectionTrackerHost());
tracker_.reset(new PeerConnectionTracker( tracker_.reset(new PeerConnectionTracker(
mock_host_->CreateInterfacePtrAndBind(), mock_host_->CreatePendingRemoteAndBind(),
blink::scheduler::GetSingleThreadTaskRunnerForTesting())); blink::scheduler::GetSingleThreadTaskRunnerForTesting()));
} }
...@@ -187,8 +185,7 @@ TEST_F(PeerConnectionTrackerTest, OnSuspend) { ...@@ -187,8 +185,7 @@ TEST_F(PeerConnectionTrackerTest, OnSuspend) {
CreateTrackerWithMocks(); CreateTrackerWithMocks();
CreateAndRegisterPeerConnectionHandler(); CreateAndRegisterPeerConnectionHandler();
EXPECT_CALL(*mock_handler_, CloseClientPeerConnection()); EXPECT_CALL(*mock_handler_, CloseClientPeerConnection());
std::unique_ptr<IPC::Message> message(new PeerConnectionTracker_OnSuspend()); tracker_->OnSuspend();
tracker_->OnControlMessageReceived(*message.get());
} }
TEST_F(PeerConnectionTrackerTest, AddTransceiverWithOptionalValuesPresent) { TEST_F(PeerConnectionTrackerTest, AddTransceiverWithOptionalValuesPresent) {
......
...@@ -753,8 +753,6 @@ void RenderThreadImpl::Init() { ...@@ -753,8 +753,6 @@ void RenderThreadImpl::Init() {
browser_plugin_manager_.reset(new BrowserPluginManager()); browser_plugin_manager_.reset(new BrowserPluginManager());
AddObserver(browser_plugin_manager_.get()); AddObserver(browser_plugin_manager_.get());
AddObserver(PeerConnectionTracker::GetInstance());
unfreezable_message_filter_ = new UnfreezableMessageFilter(this); unfreezable_message_filter_ = new UnfreezableMessageFilter(this);
AddFilter(unfreezable_message_filter_.get()); AddFilter(unfreezable_message_filter_.get());
...@@ -767,6 +765,13 @@ void RenderThreadImpl::Init() { ...@@ -767,6 +765,13 @@ void RenderThreadImpl::Init() {
registry->AddInterface(base::BindRepeating(CreateResourceUsageReporter, registry->AddInterface(base::BindRepeating(CreateResourceUsageReporter,
weak_factory_.GetWeakPtr()), weak_factory_.GetWeakPtr()),
base::ThreadTaskRunnerHandle::Get()); base::ThreadTaskRunnerHandle::Get());
registry->AddInterface(
// Unretained here is safe, since PeerConnectionTracker instance
// is a leaky singleton.
base::BindRepeating(
&PeerConnectionTracker::Bind,
base::Unretained(PeerConnectionTracker::GetInstance())),
base::ThreadTaskRunnerHandle::Get());
if (base::FeatureList::IsEnabled( if (base::FeatureList::IsEnabled(
blink::features::kOffMainThreadServiceWorkerStartup)) { blink::features::kOffMainThreadServiceWorkerStartup)) {
......
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