Commit 715f5589 authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

peerconnection: Plumb frame to port allocator, rather than inferring it from the V8 context.

Inferring from the V8 context is very non-local and can easily break
if this doesn't occur within an inbound V8 call. Explicitly plumbing
the correct frame is preferred.

Bug: 832862
Change-Id: Ie3ab0602ca1cb75201c9663b13adfd6a3152a901
Reviewed-on: https://chromium-review.googlesource.com/c/1347435Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarSteve Anton <steveanton@chromium.org>
Commit-Queue: Jeremy Roman <jbroman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610882}
parent 79faeacd
......@@ -96,8 +96,8 @@ class SubstituteData;
class WebApplicationCacheHost;
class WebApplicationCacheHostClient;
class WebCookieJar;
class WebFrame;
class WebLayerTreeView;
class WebLocalFrame;
class WebMediaPlayer;
class WebMediaPlayerClient;
class WebMediaPlayerSource;
......@@ -117,7 +117,7 @@ class CORE_EXPORT LocalFrameClient : public FrameClient {
public:
~LocalFrameClient() override = default;
virtual WebFrame* GetWebFrame() const { return nullptr; }
virtual WebLocalFrame* GetWebFrame() const { return nullptr; }
virtual bool HasWebView() const = 0; // mainly for assertions
......
......@@ -9,6 +9,8 @@
namespace blink {
class LocalFrame;
// This class creates a single concrete instance of an IceTransportAdapter with
// a hook to allow creating dependencies on the main thread (the
// IceTransportAdapter is created on the worker thread).
......@@ -19,7 +21,7 @@ class IceTransportAdapterCrossThreadFactory {
virtual ~IceTransportAdapterCrossThreadFactory() = default;
// Construct any dependencies on the main thread. Can only be called once.
virtual void InitializeOnMainThread() = 0;
virtual void InitializeOnMainThread(LocalFrame&) = 0;
// Construct the IceTransportAdapter instance with the given delegate. Can
// only be called once.
......
......@@ -4,6 +4,7 @@
#include "third_party/blink/renderer/modules/peerconnection/adapters/ice_transport_proxy.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/ice_transport_host.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/web_rtc_cross_thread_copier.h"
#include "third_party/blink/renderer/platform/cross_thread_functional.h"
......@@ -12,7 +13,7 @@
namespace blink {
IceTransportProxy::IceTransportProxy(
FrameScheduler* frame_scheduler,
LocalFrame& frame,
scoped_refptr<base::SingleThreadTaskRunner> proxy_thread,
scoped_refptr<base::SingleThreadTaskRunner> host_thread,
Delegate* delegate,
......@@ -22,13 +23,13 @@ IceTransportProxy::IceTransportProxy(
host_(nullptr, base::OnTaskRunnerDeleter(host_thread_)),
delegate_(delegate),
connection_handle_for_scheduler_(
frame_scheduler->OnActiveConnectionCreated()),
frame.GetFrameScheduler()->OnActiveConnectionCreated()),
weak_ptr_factory_(this) {
DCHECK(host_thread_);
DCHECK(delegate_);
DCHECK(adapter_factory);
DCHECK(proxy_thread_->BelongsToCurrentThread());
adapter_factory->InitializeOnMainThread();
adapter_factory->InitializeOnMainThread(frame);
// Wait to initialize the host until the weak_ptr_factory_ is initialized.
// The IceTransportHost is constructed on the proxy thread but should only be
// interacted with via PostTask to the host thread. The OnTaskRunnerDeleter
......
......@@ -21,6 +21,7 @@ class Thread;
namespace blink {
class IceTransportHost;
class LocalFrame;
class QuicTransportProxy;
// This class allows the ICE implementation (P2PTransportChannel) to run on a
......@@ -60,7 +61,7 @@ class IceTransportProxy final {
// The P2PTransportChannel will be created with the given PortAllocator.
// The delegate must outlive the IceTransportProxy.
IceTransportProxy(
FrameScheduler* frame_scheduler,
LocalFrame& frame,
scoped_refptr<base::SingleThreadTaskRunner> proxy_thread,
scoped_refptr<base::SingleThreadTaskRunner> host_thread,
Delegate* delegate,
......
......@@ -24,7 +24,7 @@ class MockIceTransportAdapterCrossThreadFactory
}
// IceTransportAdapterCrossThreadFactory overrides.
void InitializeOnMainThread() override {}
void InitializeOnMainThread(LocalFrame&) override {}
std::unique_ptr<IceTransportAdapter> ConstructOnWorkerThread(
IceTransportAdapter::Delegate* delegate) override {
DCHECK(mock_adapter_);
......
......@@ -9,6 +9,7 @@
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/ice_transport_adapter_cross_thread_factory.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/ice_transport_adapter_impl.h"
#include "third_party/blink/renderer/modules/peerconnection/adapters/ice_transport_proxy.h"
......@@ -54,11 +55,11 @@ RTCIceCandidate* ConvertToRtcIceCandidate(const cricket::Candidate& candidate) {
class DefaultIceTransportAdapterCrossThreadFactory
: public IceTransportAdapterCrossThreadFactory {
public:
void InitializeOnMainThread() override {
void InitializeOnMainThread(LocalFrame& frame) override {
DCHECK(!port_allocator_);
DCHECK(!worker_thread_rtc_thread_);
port_allocator_ = Platform::Current()->CreateWebRtcPortAllocator(
WebLocalFrame::FrameForCurrentContext());
frame.Client()->GetWebFrame());
worker_thread_rtc_thread_ =
Platform::Current()->GetWebRtcWorkerThreadRtcThread();
}
......@@ -113,9 +114,9 @@ RTCIceTransport::RTCIceTransport(
LocalFrame* frame = To<Document>(context)->GetFrame();
DCHECK(frame);
proxy_.reset(new IceTransportProxy(
frame->GetFrameScheduler(), std::move(proxy_thread),
std::move(host_thread), this, std::move(adapter_factory)));
proxy_ = std::make_unique<IceTransportProxy>(*frame, std::move(proxy_thread),
std::move(host_thread), this,
std::move(adapter_factory));
GenerateLocalParameters();
}
......
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