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

Onion soup IpcNetworkManager

This is phase 3.8 on the design document [1].

[1] https://docs.google.com/document/d/1AJKVA5U4nDkyDB9p4ROrggWXadCxyy-grKaE9KS5vOU/

CL moves ipc_network_manager.cc|h|test from
content/renderer/p2p to Blink. It places the header temporarily in
Blink's exposed API.

Last, note that <string> and <vector> STD headers are kept because
they are used to interface with third_party/webrtc APIs.

BUG=787254
R=guidou@chromium.org, haraken@chromium.org

Change-Id: I0743a2b3449c462840646c609c62073bf33dc287
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1792858
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695148}
parent 6a8e6770
......@@ -242,8 +242,6 @@ target(link_target_type, "renderer") {
"net_info_helper.h",
"p2p/host_address_request.cc",
"p2p/host_address_request.h",
"p2p/ipc_network_manager.cc",
"p2p/ipc_network_manager.h",
"p2p/ipc_socket_factory.cc",
"p2p/ipc_socket_factory.h",
"p2p/mdns_responder_adapter.cc",
......
......@@ -29,7 +29,6 @@
#include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/media/webrtc/rtc_peer_connection_handler.h"
#include "content/renderer/media/webrtc/stun_field_trial.h"
#include "content/renderer/p2p/ipc_network_manager.h"
#include "content/renderer/p2p/ipc_socket_factory.h"
#include "content/renderer/p2p/mdns_responder_adapter.h"
#include "content/renderer/p2p/port_allocator.h"
......@@ -45,6 +44,7 @@
#include "third_party/blink/public/platform/modules/mediastream/webrtc_uma_histograms.h"
#include "third_party/blink/public/platform/modules/p2p/empty_network_manager.h"
#include "third_party/blink/public/platform/modules/p2p/filtering_network_manager.h"
#include "third_party/blink/public/platform/modules/p2p/ipc_network_manager.h"
#include "third_party/blink/public/platform/modules/peerconnection/audio_codec_factory.h"
#include "third_party/blink/public/platform/modules/peerconnection/video_codec_factory.h"
#include "third_party/blink/public/platform/modules/webrtc/webrtc_logging.h"
......@@ -580,7 +580,7 @@ void PeerConnectionDependencyFactory::CreateIpcNetworkManagerOnWorkerThread(
base::WaitableEvent* event,
std::unique_ptr<MdnsResponderAdapter> mdns_responder) {
DCHECK(chrome_worker_thread_.task_runner()->BelongsToCurrentThread());
network_manager_ = std::make_unique<IpcNetworkManager>(
network_manager_ = std::make_unique<blink::IpcNetworkManager>(
p2p_socket_dispatcher_.get(), std::move(mdns_responder));
event->Signal();
}
......
......@@ -33,6 +33,7 @@ class Thread;
}
namespace blink {
class IpcNetworkManager;
class WebLocalFrame;
class WebRTCPeerConnectionHandler;
class WebRTCPeerConnectionHandlerClient;
......@@ -41,7 +42,6 @@ class WebRtcAudioDeviceImpl;
namespace content {
class IpcNetworkManager;
class IpcPacketSocketFactory;
class MdnsResponderAdapter;
class P2PPortAllocator;
......@@ -158,7 +158,7 @@ class CONTENT_EXPORT PeerConnectionDependencyFactory
// network_manager_ must be deleted on the worker thread. The network manager
// uses |p2p_socket_dispatcher_|.
std::unique_ptr<IpcNetworkManager> network_manager_;
std::unique_ptr<blink::IpcNetworkManager> network_manager_;
std::unique_ptr<IpcPacketSocketFactory> socket_factory_;
scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_;
......
......@@ -720,6 +720,11 @@ bool RendererBlinkPlatformImpl::IsWebRtcHWDecodingEnabled() {
switches::kDisableWebRtcHWDecoding);
}
bool RendererBlinkPlatformImpl::AllowsLoopbackInPeerConnection() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAllowLoopbackInPeerConnection);
}
blink::WebVideoCaptureImplManager*
RendererBlinkPlatformImpl::GetVideoCaptureImplManager() {
RenderThreadImpl* thread = RenderThreadImpl::current();
......
......@@ -161,6 +161,7 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
webrtc::VideoCodecType video_coded_type) override;
bool IsWebRtcHWEncodingEnabled() override;
bool IsWebRtcHWDecodingEnabled() override;
bool AllowsLoopbackInPeerConnection() override;
blink::WebVideoCaptureImplManager* GetVideoCaptureImplManager() override;
......
......@@ -1957,7 +1957,6 @@ test("content_unittests") {
"../renderer/media/webrtc/webrtc_media_stream_track_adapter_map_unittest.cc",
"../renderer/media/webrtc/webrtc_media_stream_track_adapter_unittest.cc",
"../renderer/media/webrtc/webrtc_set_description_observer_unittest.cc",
"../renderer/p2p/ipc_network_manager_unittest.cc",
"../renderer/peripheral_content_heuristic_unittest.cc",
"../renderer/queue_message_swap_promise_unittest.cc",
"../renderer/render_frame_metadata_observer_impl_unittest.cc",
......
......@@ -151,6 +151,7 @@ source_set("blink_headers") {
"platform/modules/mediastream/webrtc_uma_histograms.h",
"platform/modules/p2p/empty_network_manager.h",
"platform/modules/p2p/filtering_network_manager.h",
"platform/modules/p2p/ipc_network_manager.h",
"platform/modules/p2p/network_list_manager.h",
"platform/modules/p2p/network_list_observer.h",
"platform/modules/p2p/network_manager_uma.h",
......
......@@ -2,17 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_RENDERER_P2P_IPC_NETWORK_MANAGER_H_
#define CONTENT_RENDERER_P2P_IPC_NETWORK_MANAGER_H_
#ifndef THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_P2P_IPC_NETWORK_MANAGER_H_
#define THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_P2P_IPC_NETWORK_MANAGER_H_
#include <memory>
#include <vector>
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "content/common/content_export.h"
#include "third_party/blink/public/platform/modules/p2p/network_list_manager.h"
#include "third_party/blink/public/platform/modules/p2p/network_list_observer.h"
#include "third_party/blink/public/platform/web_common.h"
#include "third_party/webrtc/rtc_base/mdns_responder_interface.h"
#include "third_party/webrtc/rtc_base/network.h"
......@@ -20,7 +18,7 @@ namespace net {
class IPAddress;
} // namespace net
namespace content {
namespace blink {
// IpcNetworkManager is a NetworkManager for libjingle that gets a
// list of network interfaces from the browser.
......@@ -28,7 +26,7 @@ class IpcNetworkManager : public rtc::NetworkManagerBase,
public blink::NetworkListObserver {
public:
// Constructor doesn't take ownership of the |network_list_manager|.
CONTENT_EXPORT IpcNetworkManager(
BLINK_PLATFORM_EXPORT IpcNetworkManager(
blink::NetworkListManager* network_list_manager,
std::unique_ptr<webrtc::MdnsResponderInterface> mdns_responder);
~IpcNetworkManager() override;
......@@ -55,6 +53,6 @@ class IpcNetworkManager : public rtc::NetworkManagerBase,
base::WeakPtrFactory<IpcNetworkManager> weak_factory_{this};
};
} // namespace content
} // namespace blink
#endif // CONTENT_RENDERER_P2P_IPC_NETWORK_MANAGER_H_
#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_P2P_IPC_NETWORK_MANAGER_H_
......@@ -656,6 +656,8 @@ class BLINK_PLATFORM_EXPORT Platform {
virtual bool IsWebRtcHWDecodingEnabled() { return true; }
virtual bool AllowsLoopbackInPeerConnection() { return false; }
// VideoCapture -------------------------------------------------------
virtual WebVideoCaptureImplManager* GetVideoCaptureImplManager() {
......
......@@ -1229,6 +1229,7 @@ jumbo_component("platform") {
"mojo/string16_mojom_traits.h",
"p2p/empty_network_manager.cc",
"p2p/filtering_network_manager.cc",
"p2p/ipc_network_manager.cc",
"p2p/network_manager_uma.cc",
"peerconnection/audio_codec_factory.cc",
"peerconnection/rtc_answer_options_platform.h",
......@@ -1448,6 +1449,7 @@ jumbo_component("platform") {
"//crypto",
"//device/vr/public/mojom:mojom_blink",
"//gin",
"//jingle:webrtc_glue",
"//media",
"//media/capture/mojom:video_capture",
"//mojo/public/cpp/base",
......@@ -1809,6 +1811,7 @@ jumbo_source_set("blink_platform_unittests_sources") {
"mojo/kurl_security_origin_test.cc",
"mojo/string16_mojom_traits_test.cc",
"p2p/filtering_network_manager_test.cc",
"p2p/ipc_network_manager_test.cc",
"peerconnection/rtc_stats_test.cc",
"peerconnection/rtc_video_decoder_adapter_test.cc",
"peerconnection/rtc_video_encoder_test.cc",
......
include_rules = [
"+media/base/media_permission.h",
"+jingle/glue/utils.h",
"+net/base/ip_address.h",
"+net/base/network_change_notifier.h",
"+net/base/network_interfaces.h",
]
......@@ -202,6 +202,8 @@ void FilteringNetworkManager::FireEventIfStarted() {
ReportMetrics(true);
// Post a task to avoid reentrancy.
//
// TODO(crbug.com/787254): Use Frame-based TaskRunner here.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&FilteringNetworkManager::SendNetworksChangedSignal,
......
......@@ -2,26 +2,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/p2p/ipc_network_manager.h"
#include "third_party/blink/public/platform/modules/p2p/ipc_network_manager.h"
#include <string>
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/command_line.h"
#include "base/location.h"
#include "base/metrics/histogram_macros.h"
#include "base/single_thread_task_runner.h"
#include "base/sys_byteorder.h"
#include "base/threading/thread_task_runner_handle.h"
#include "content/public/common/content_switches.h"
#include "jingle/glue/utils.h"
#include "net/base/ip_address.h"
#include "net/base/network_change_notifier.h"
#include "net/base/network_interfaces.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/webrtc/rtc_base/socket_address.h"
namespace content {
namespace blink {
namespace {
......@@ -29,17 +29,17 @@ rtc::AdapterType ConvertConnectionTypeToAdapterType(
net::NetworkChangeNotifier::ConnectionType type) {
switch (type) {
case net::NetworkChangeNotifier::CONNECTION_UNKNOWN:
return rtc::ADAPTER_TYPE_UNKNOWN;
return rtc::ADAPTER_TYPE_UNKNOWN;
case net::NetworkChangeNotifier::CONNECTION_ETHERNET:
return rtc::ADAPTER_TYPE_ETHERNET;
return rtc::ADAPTER_TYPE_ETHERNET;
case net::NetworkChangeNotifier::CONNECTION_WIFI:
return rtc::ADAPTER_TYPE_WIFI;
return rtc::ADAPTER_TYPE_WIFI;
case net::NetworkChangeNotifier::CONNECTION_2G:
case net::NetworkChangeNotifier::CONNECTION_3G:
case net::NetworkChangeNotifier::CONNECTION_4G:
return rtc::ADAPTER_TYPE_CELLULAR;
return rtc::ADAPTER_TYPE_CELLULAR;
default:
return rtc::ADAPTER_TYPE_UNKNOWN;
return rtc::ADAPTER_TYPE_UNKNOWN;
}
}
......@@ -148,12 +148,11 @@ void IpcNetworkManager::OnNetworkListChanged(
}
set_default_local_addresses(ipv4_default, ipv6_default);
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAllowLoopbackInPeerConnection)) {
if (Platform::Current()->AllowsLoopbackInPeerConnection()) {
std::string name_v4("loopback_ipv4");
rtc::IPAddress ip_address_v4(INADDR_LOOPBACK);
rtc::Network* network_v4 = new rtc::Network(
name_v4, name_v4, ip_address_v4, 32, rtc::ADAPTER_TYPE_UNKNOWN);
rtc::Network* network_v4 = new rtc::Network(name_v4, name_v4, ip_address_v4,
32, rtc::ADAPTER_TYPE_UNKNOWN);
network_v4->set_default_local_address_provider(this);
network_v4->set_mdns_responder_provider(this);
network_v4->AddIP(ip_address_v4);
......@@ -197,4 +196,4 @@ void IpcNetworkManager::SendNetworksChangedSignal() {
SignalNetworksChanged();
}
} // namespace content
} // namespace blink
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/p2p/ipc_network_manager.h"
#include "third_party/blink/public/platform/modules/p2p/ipc_network_manager.h"
#include <algorithm>
#include <memory>
......@@ -14,7 +14,7 @@
#include "third_party/blink/public/platform/modules/p2p/network_list_manager.h"
#include "third_party/webrtc/rtc_base/mdns_responder_interface.h"
namespace content {
namespace blink {
namespace {
......@@ -198,4 +198,4 @@ TEST_F(IpcNetworkManagerTest,
EXPECT_EQ(mdns_responder, networks[1]->GetMdnsResponder());
}
} // namespace content
} // namespace blink
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