From ba8d4337b7751e57161c8b0dfa77d3e4faeb953b Mon Sep 17 00:00:00 2001 From: deadbeef Date: Fri, 24 Jun 2016 14:05:11 -0700 Subject: [PATCH] Revert of Add virtual Initialize methods to PortAllocator and NetworkManager. (patchset #4 id:60001 of https://codereview.webrtc.org/2097653002/ ) Reason for revert: Didn't intend to land yet. Chromium CL still needed. Original issue's description: > Add virtual Initialize methods to PortAllocator and NetworkManager. > > This will allow PeerConnection to handle hopping to the right thread > and doing thread-specific initialization for the PortAllocator. > This eliminates a required thread-hop for whatever is passing the > PortAllocator into CreatePeerConnection. > > BUG=617648 > R=pthatcher@webrtc.org, skvlad@webrtc.org > > Committed: https://crrev.com/a6bdb0990a659ff9e7c4374f5033a6bcc4fbfb21 > Cr-Commit-Position: refs/heads/master@{#13283} TBR=pthatcher@webrtc.org,skvlad@webrtc.org # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=617648 Review-Url: https://codereview.webrtc.org/2092023004 Cr-Commit-Position: refs/heads/master@{#13284} --- webrtc/api/peerconnection.cc | 2 -- .../api/peerconnectioninterface_unittest.cc | 22 --------------- webrtc/base/network.h | 11 -------- webrtc/p2p/base/fakeportallocator.h | 27 +++++++------------ webrtc/p2p/base/portallocator.h | 13 +++------ 5 files changed, 12 insertions(+), 63 deletions(-) diff --git a/webrtc/api/peerconnection.cc b/webrtc/api/peerconnection.cc index fcce03d5c0..b9cb83e724 100644 --- a/webrtc/api/peerconnection.cc +++ b/webrtc/api/peerconnection.cc @@ -2139,8 +2139,6 @@ bool PeerConnection::InitializePortAllocator_n( return false; } - port_allocator_->Initialize(); - // To handle both internal and externally created port allocator, we will // enable BUNDLE here. int portallocator_flags = port_allocator_->flags(); diff --git a/webrtc/api/peerconnectioninterface_unittest.cc b/webrtc/api/peerconnectioninterface_unittest.cc index 6faecde37b..71233e0608 100644 --- a/webrtc/api/peerconnectioninterface_unittest.cc +++ b/webrtc/api/peerconnectioninterface_unittest.cc @@ -1066,28 +1066,6 @@ TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) { session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS); } -// Test that the PeerConnection initializes the port allocator passed into it, -// and on the correct thread. -TEST_F(PeerConnectionInterfaceTest, - CreatePeerConnectionInitializesPortAllocator) { - rtc::Thread network_thread; - network_thread.Start(); - rtc::scoped_refptr pc_factory( - webrtc::CreatePeerConnectionFactory( - &network_thread, rtc::Thread::Current(), rtc::Thread::Current(), - nullptr, nullptr, nullptr)); - std::unique_ptr port_allocator( - new cricket::FakePortAllocator(&network_thread, nullptr)); - cricket::FakePortAllocator* raw_port_allocator = port_allocator.get(); - PeerConnectionInterface::RTCConfiguration config; - rtc::scoped_refptr pc( - pc_factory_->CreatePeerConnection( - config, nullptr, std::move(port_allocator), nullptr, &observer_)); - // FakePortAllocator RTC_CHECKs that it's initialized on the right thread, - // so all we have to do here is check that it's initialized. - EXPECT_TRUE(raw_port_allocator->initialized()); -} - TEST_F(PeerConnectionInterfaceTest, AddStreams) { CreatePeerConnection(); AddVideoStream(kStreamLabel1); diff --git a/webrtc/base/network.h b/webrtc/base/network.h index fe51e4eafb..05943fb912 100644 --- a/webrtc/base/network.h +++ b/webrtc/base/network.h @@ -63,13 +63,6 @@ class DefaultLocalAddressProvider { // Generic network manager interface. It provides list of local // networks. -// -// Every method of NetworkManager (including the destructor) must be called on -// the same thread, except for the constructor which may be called on any -// thread. -// -// This allows constructing a NetworkManager subclass on one thread and -// passing it into an object that uses it on a different thread. class NetworkManager : public DefaultLocalAddressProvider { public: typedef std::vector NetworkList; @@ -92,10 +85,6 @@ class NetworkManager : public DefaultLocalAddressProvider { // Indicates a failure when getting list of network interfaces. sigslot::signal0<> SignalError; - // This should be called on the NetworkManager's thread before the - // NetworkManager is used. Subclasses may override this if necessary. - virtual void Initialize() {} - // Start/Stop monitoring of network interfaces // list. SignalNetworksChanged or SignalError is emitted immediately // after StartUpdating() is called. After that SignalNetworksChanged diff --git a/webrtc/p2p/base/fakeportallocator.h b/webrtc/p2p/base/fakeportallocator.h index 11969e0233..0bb9c6e66c 100644 --- a/webrtc/p2p/base/fakeportallocator.h +++ b/webrtc/p2p/base/fakeportallocator.h @@ -89,7 +89,7 @@ class TestUDPPort : public UDPPort { class FakePortAllocatorSession : public PortAllocatorSession { public: FakePortAllocatorSession(PortAllocator* allocator, - rtc::Thread* network_thread, + rtc::Thread* worker_thread, rtc::PacketSocketFactory* factory, const std::string& content_name, int component, @@ -100,7 +100,7 @@ class FakePortAllocatorSession : public PortAllocatorSession { ice_ufrag, ice_pwd, allocator->flags()), - network_thread_(network_thread), + worker_thread_(worker_thread), factory_(factory), ipv4_network_("network", "unittest", @@ -129,7 +129,7 @@ class FakePortAllocatorSession : public PortAllocatorSession { (rtc::HasIPv6Enabled() && (flags() & PORTALLOCATOR_ENABLE_IPV6)) ? ipv6_network_ : ipv4_network_; - port_.reset(TestUDPPort::Create(network_thread_, factory_, &network, + port_.reset(TestUDPPort::Create(worker_thread_, factory_, &network, network.GetBestIP(), 0, 0, username(), password(), std::string(), false)); port_->SignalDestroyed.connect( @@ -195,7 +195,7 @@ class FakePortAllocatorSession : public PortAllocatorSession { port_.release(); } - rtc::Thread* network_thread_; + rtc::Thread* worker_thread_; rtc::PacketSocketFactory* factory_; rtc::Network ipv4_network_; rtc::Network ipv6_network_; @@ -213,21 +213,15 @@ class FakePortAllocatorSession : public PortAllocatorSession { class FakePortAllocator : public cricket::PortAllocator { public: - FakePortAllocator(rtc::Thread* network_thread, + FakePortAllocator(rtc::Thread* worker_thread, rtc::PacketSocketFactory* factory) - : network_thread_(network_thread), factory_(factory) { + : worker_thread_(worker_thread), factory_(factory) { if (factory_ == NULL) { - owned_factory_.reset(new rtc::BasicPacketSocketFactory(network_thread_)); + owned_factory_.reset(new rtc::BasicPacketSocketFactory(worker_thread_)); factory_ = owned_factory_.get(); } } - void Initialize() override { - // Port allocator should be initialized on the network thread. - RTC_CHECK(network_thread_->IsCurrent()); - initialized_ = true; - } - void SetNetworkIgnoreMask(int network_ignore_mask) override {} cricket::PortAllocatorSession* CreateSessionInternal( @@ -235,18 +229,15 @@ class FakePortAllocator : public cricket::PortAllocator { int component, const std::string& ice_ufrag, const std::string& ice_pwd) override { - return new FakePortAllocatorSession(this, network_thread_, factory_, + return new FakePortAllocatorSession(this, worker_thread_, factory_, content_name, component, ice_ufrag, ice_pwd); } - bool initialized() const { return initialized_; } - private: - rtc::Thread* network_thread_; + rtc::Thread* worker_thread_; rtc::PacketSocketFactory* factory_; std::unique_ptr owned_factory_; - bool initialized_ = false; }; } // namespace cricket diff --git a/webrtc/p2p/base/portallocator.h b/webrtc/p2p/base/portallocator.h index 6a32b9668f..7d2a59f278 100644 --- a/webrtc/p2p/base/portallocator.h +++ b/webrtc/p2p/base/portallocator.h @@ -221,12 +221,8 @@ class PortAllocatorSession : public sigslot::has_slots<> { friend class PortAllocator; }; -// Every method of PortAllocator (including the destructor) must be called on -// the same thread, except for the constructor which may be called on any -// thread. -// -// This allows constructing a PortAllocator subclass on one thread and -// passing it into an object that uses it on a different thread. +// Note that this class should only be used on one thread. +// This includes calling the destructor. class PortAllocator : public sigslot::has_slots<> { public: PortAllocator() : @@ -236,13 +232,10 @@ class PortAllocator : public sigslot::has_slots<> { step_delay_(kDefaultStepDelay), allow_tcp_listen_(true), candidate_filter_(CF_ALL) { + // This will allow us to have old behavior on non webrtc clients. } virtual ~PortAllocator() {} - // This should be called on the PortAllocator's thread before the - // PortAllocator is used. Subclasses may override this if necessary. - virtual void Initialize() {} - // Set STUN and TURN servers to be used in future sessions, and set // candidate pool size, as described in JSEP. //