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
Review URL: https://codereview.webrtc.org/2097653002 .
Committed: https://crrev.com/a6bdb0990a659ff9e7c4374f5033a6bcc4fbfb21
Cr-Original-Commit-Position: refs/heads/master@{#13283}
Cr-Commit-Position: refs/heads/master@{#13306}
diff --git a/webrtc/api/peerconnectioninterface_unittest.cc b/webrtc/api/peerconnectioninterface_unittest.cc
index 71233e0..843a312 100644
--- a/webrtc/api/peerconnectioninterface_unittest.cc
+++ b/webrtc/api/peerconnectioninterface_unittest.cc
@@ -1066,6 +1066,28 @@
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<webrtc::PeerConnectionFactoryInterface> pc_factory(
+ webrtc::CreatePeerConnectionFactory(
+ &network_thread, rtc::Thread::Current(), rtc::Thread::Current(),
+ nullptr, nullptr, nullptr));
+ std::unique_ptr<cricket::FakePortAllocator> port_allocator(
+ new cricket::FakePortAllocator(&network_thread, nullptr));
+ cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
+ PeerConnectionInterface::RTCConfiguration config;
+ rtc::scoped_refptr<PeerConnectionInterface> 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);