Commit 5bc17745 authored by Moe Ahmadi's avatar Moe Ahmadi Committed by Commit Bot

Revert "Enable connectivity checker for fuchsia"

This reverts commit 9df0aa65.

Reason for revert:
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/fuchsia-x64-cast/11742
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/fuchsia-arm64-cast/11675

Original change's description:
> Enable connectivity checker for fuchsia
> 
> We are using the default connectivity checker, and adding the switch
> |--require-wlan| to allow developers to force connections to only WLAN
> network interfaces.
> 
> Fuchsia devices typically have an ethernet cable connected for
> development, which causes the connectivity checker to always return connected.
> For some tests and development, we need to force the usage of WLAN
> interfaces, thus this switch was needed.
> 
> Run cast with --require-wlan, observe disconnected
> 
> Bug: 777973
> Test: net_unittests && Run cast with no flags, observe connected &&
> Change-Id: I359c57a83ce42eb81e5795c0c2c7b711b907471e
> Reviewed-on: https://chromium-review.googlesource.com/c/1419903
> Reviewed-by: Paul Jensen <pauljensen@chromium.org>
> Reviewed-by: Luke Halliwell <halliwell@chromium.org>
> Reviewed-by: Wez <wez@chromium.org>
> Commit-Queue: Aidan Wolter <awolter@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#625258}

TBR=wez@chromium.org,pauljensen@chromium.org,halliwell@chromium.org,awolter@chromium.org

Change-Id: I5ea25b3824c74669aa4180706da8d9ada7d244a6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 777973
Reviewed-on: https://chromium-review.googlesource.com/c/1431015Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625283}
parent 3a0c4c90
......@@ -32,9 +32,6 @@ const char kOverrideMetricsUploadUrl[] = "override-metrics-upload-url";
// Disable features that require WiFi management.
const char kNoWifi[] = "no-wifi";
// Only connect to WLAN interfaces.
const char kRequireWlan[] = "require-wlan";
// Pass the app id information to the renderer process, to be used for logging.
// last-launched-app should be the app that just launched and is spawning the
// renderer.
......
......@@ -30,7 +30,6 @@ extern const char kOverrideMetricsUploadUrl[];
// Network switches
extern const char kNoWifi[];
extern const char kRequireWlan[];
// Switches to communicate app state information
extern const char kLastLaunchedApp[];
......
......@@ -77,11 +77,9 @@
#include "components/crash/content/browser/child_exit_observer_android.h"
#include "components/crash/content/browser/child_process_crash_observer_android.h"
#include "net/android/network_change_notifier_factory_android.h"
#elif defined(OS_FUCHSIA)
#include "chromecast/net/network_change_notifier_factory_fuchsia.h"
#else // defined(OS_FUCHSIA)
#else
#include "chromecast/net/network_change_notifier_factory_cast.h"
#endif // !(defined(OS_ANDROID) || defined(OS_FUCHSIA))
#endif
#if defined(OS_FUCHSIA)
#include "chromecast/net/fake_connectivity_checker.h"
......@@ -378,13 +376,10 @@ void CastBrowserMainParts::PreMainMessageLoopStart() {
#if defined(OS_ANDROID)
net::NetworkChangeNotifier::SetFactory(
new net::NetworkChangeNotifierFactoryAndroid());
#elif defined(OS_FUCHSIA)
net::NetworkChangeNotifier::SetFactory(
new NetworkChangeNotifierFactoryFuchsia());
#else // defined(OS_FUCHSIA)
#elif !defined(OS_FUCHSIA)
net::NetworkChangeNotifier::SetFactory(
new NetworkChangeNotifierFactoryCast());
#endif // !(defined(OS_ANDROID) || defined(OS_FUCHSIA))
#endif // !defined(OS_FUCHSIA)
}
void CastBrowserMainParts::PostMainMessageLoopStart() {
......@@ -468,10 +463,17 @@ void CastBrowserMainParts::PreMainMessageLoopRun() {
cast_browser_process_->SetNetLog(net_log_.get());
url_request_context_factory_->InitializeOnUIThread(net_log_.get());
#if defined(OS_FUCHSIA)
// TODO(777973): Switch to using the real ConnectivityChecker once setup works
// properly.
LOG(WARNING) << "Using FakeConnectivityChecker.";
cast_browser_process_->SetConnectivityChecker(new FakeConnectivityChecker());
#else
cast_browser_process_->SetConnectivityChecker(ConnectivityChecker::Create(
base::CreateSingleThreadTaskRunnerWithTraits(
{content::BrowserThread::IO}),
url_request_context_factory_->GetSystemGetter()));
#endif // defined(OS_FUCHSIA)
cast_browser_process_->SetBrowserContext(
std::make_unique<CastBrowserContext>(url_request_context_factory_));
......
......@@ -35,15 +35,6 @@ cast_source_set("net") {
"//components/proxy_config",
"//net",
]
if (is_fuchsia) {
sources += [
"network_change_notifier_factory_fuchsia.cc",
"network_change_notifier_factory_fuchsia.h",
]
deps += [ "//third_party/fuchsia-sdk/sdk:hardware_ethernet" ]
}
}
cast_source_set("small_message_socket") {
......
// Copyright 2019 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.
#include "chromecast/net/network_change_notifier_factory_fuchsia.h"
#include <fuchsia/hardware/ethernet/cpp/fidl.h>
#include "base/command_line.h"
#include "chromecast/base/chromecast_switches.h"
#include "net/base/network_change_notifier_fuchsia.h"
namespace chromecast {
net::NetworkChangeNotifier*
NetworkChangeNotifierFactoryFuchsia::CreateInstance() {
uint32_t required_features =
base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kRequireWlan)
? fuchsia::hardware::ethernet::INFO_FEATURE_WLAN
: 0;
// Caller assumes ownership.
return new net::NetworkChangeNotifierFuchsia(required_features);
}
NetworkChangeNotifierFactoryFuchsia::NetworkChangeNotifierFactoryFuchsia() =
default;
NetworkChangeNotifierFactoryFuchsia::~NetworkChangeNotifierFactoryFuchsia() =
default;
} // namespace chromecast
// Copyright 2019 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 CHROMECAST_NET_NETWORK_CHANGE_NOTIFIER_FACTORY_FUCHSIA_H_
#define CHROMECAST_NET_NETWORK_CHANGE_NOTIFIER_FACTORY_FUCHSIA_H_
#include "base/macros.h"
#include "net/base/network_change_notifier_factory.h"
namespace chromecast {
class NetworkChangeNotifierFactoryFuchsia
: public net::NetworkChangeNotifierFactory {
public:
NetworkChangeNotifierFactoryFuchsia();
~NetworkChangeNotifierFactoryFuchsia() override;
// net::NetworkChangeNotifierFactory implementation:
net::NetworkChangeNotifier* CreateInstance() override;
private:
DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierFactoryFuchsia);
};
} // namespace chromecast
#endif // CHROMECAST_NET_NETWORK_CHANGE_NOTIFIER_FACTORY_FUCHSIA_H_
......@@ -2012,7 +2012,6 @@ component("net") {
"base/network_change_notifier_fuchsia.cc",
"base/network_change_notifier_fuchsia.h",
"base/network_interfaces_fuchsia.cc",
"base/network_interfaces_fuchsia.h",
"base/platform_mime_util_fuchsia.cc",
"cert/test_root_certs_fuchsia.cc",
]
......
......@@ -219,7 +219,7 @@ NetworkChangeNotifier* NetworkChangeNotifier::Create() {
#elif defined(OS_MACOSX)
return new NetworkChangeNotifierMac();
#elif defined(OS_FUCHSIA)
return new NetworkChangeNotifierFuchsia(0 /* required_features */);
return new NetworkChangeNotifierFuchsia();
#else
NOTIMPLEMENTED();
return NULL;
......
......@@ -37,17 +37,14 @@ std::function<R(Args...)> WrapCallbackAsFunction(
} // namespace
NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia(
uint32_t required_features)
NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia()
: NetworkChangeNotifierFuchsia(
base::fuchsia::ComponentContext::GetDefault()
->ConnectToService<fuchsia::netstack::Netstack>(),
required_features) {}
->ConnectToService<fuchsia::netstack::Netstack>()) {}
NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia(
fuchsia::netstack::NetstackPtr netstack,
uint32_t required_features)
: netstack_(std::move(netstack)), required_features_(required_features) {
fuchsia::netstack::NetstackPtr netstack)
: netstack_(std::move(netstack)) {
DCHECK(netstack_);
netstack_.set_error_handler([](zx_status_t status) {
......@@ -93,52 +90,39 @@ void NetworkChangeNotifierFuchsia::OnRouteTableReceived(
base::OnceClosure on_initialized_cb,
std::vector<fuchsia::netstack::NetInterface> interfaces,
std::vector<fuchsia::netstack::RouteTableEntry> route_table) {
// Create a set of NICs that have default routes (ie 0.0.0.0).
base::flat_set<uint32_t> default_route_ids;
for (const auto& route : route_table) {
if (MaskPrefixLength(
internal::FuchsiaIpAddressToIPAddress(route.netmask)) == 0) {
default_route_ids.insert(route.nicid);
// Find the default interface in the routing table.
auto default_route_interface = std::find_if(
route_table.begin(), route_table.end(),
[](const fuchsia::netstack::RouteTableEntry& rt) {
return MaskPrefixLength(
internal::FuchsiaIpAddressToIPAddress(rt.netmask)) == 0;
});
// Find the default interface in the NetInterface list.
const fuchsia::netstack::NetInterface* default_interface = nullptr;
if (default_route_interface != route_table.end()) {
for (const auto& cur_interface : interfaces) {
if (cur_interface.id == default_route_interface->nicid) {
default_interface = &cur_interface;
}
}
}
ConnectionType connection_type = CONNECTION_NONE;
base::flat_set<IPAddress> addresses;
for (auto& interface : interfaces) {
// Filter out loopback and invalid connection types.
if ((internal::ConvertConnectionType(interface) ==
NetworkChangeNotifier::CONNECTION_NONE) ||
(interface.features &
fuchsia::hardware::ethernet::INFO_FEATURE_LOOPBACK)) {
continue;
}
// Filter out interfaces that do not meet the |required_features_|.
if ((interface.features & required_features_) != required_features_) {
continue;
}
// Filter out interfaces with non-default routes.
if (!default_route_ids.contains(interface.id)) {
continue;
}
std::string ssid;
ConnectionType connection_type = CONNECTION_NONE;
if (default_interface) {
std::vector<NetworkInterface> flattened_interfaces =
internal::NetInterfaceToNetworkInterfaces(interface);
if (flattened_interfaces.empty()) {
continue;
}
// Add the addresses from this interface to the list of all addresses.
internal::NetInterfaceToNetworkInterfaces(*default_interface);
std::transform(
flattened_interfaces.begin(), flattened_interfaces.end(),
std::inserter(addresses, addresses.begin()),
[](const NetworkInterface& interface) { return interface.address; });
// Set the default connection to the first interface connection found.
if (connection_type == CONNECTION_NONE) {
if (!flattened_interfaces.empty()) {
connection_type = flattened_interfaces.front().type;
}
// TODO(https://crbug.com/848355): Treat SSID changes as IP address changes.
}
bool connection_type_changed = false;
......@@ -147,8 +131,6 @@ void NetworkChangeNotifierFuchsia::OnRouteTableReceived(
connection_type_changed = true;
}
// TODO(https://crbug.com/848355): Treat SSID changes as IP address changes.
if (addresses != cached_addresses_) {
std::swap(cached_addresses_, addresses);
if (on_initialized_cb.is_null()) {
......
......@@ -22,26 +22,19 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia
: public NetworkChangeNotifier {
public:
// Blocks execution until an initial interface list is received from
// |netstack_|. Interfaces can be filtered out by passing in
// |required_features|, which is defined in fuchsia::hardware::ethernet.
explicit NetworkChangeNotifierFuchsia(uint32_t required_features);
// |netstack_|.
NetworkChangeNotifierFuchsia();
~NetworkChangeNotifierFuchsia() override;
private:
friend class NetworkChangeNotifierFuchsiaTest;
FRIEND_TEST_ALL_PREFIXES(NetworkChangeNotifierFuchsiaTest,
FindsInterfaceWithRequiredFeature);
FRIEND_TEST_ALL_PREFIXES(NetworkChangeNotifierFuchsiaTest, FoundWiFi);
FRIEND_TEST_ALL_PREFIXES(NetworkChangeNotifierFuchsiaTest,
FoundWiFiNonDefault);
FRIEND_TEST_ALL_PREFIXES(NetworkChangeNotifierFuchsiaTest,
IgnoresInterfaceWithMissingFeature);
// For testing purposes. Receives a |netstack| pointer for easy mocking.
// Interfaces can be filtered out by passing in |required_features|, which is
// defined in fuchsia::hardware::ethernet.
NetworkChangeNotifierFuchsia(fuchsia::netstack::NetstackPtr netstack,
uint32_t required_features);
// For testing purposes.
explicit NetworkChangeNotifierFuchsia(
fuchsia::netstack::NetstackPtr netstack);
// Forwards the network interface list along with the result of
// GetRouteTable() to OnRouteTableReceived().
......@@ -70,10 +63,6 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia
fuchsia::netstack::NetstackPtr netstack_;
// Bitmap of required features for an interface to be taken into account. The
// features are defined in fuchsia::hardware::ethernet.
const uint32_t required_features_;
// Set of addresses from the previous query/update for the default interface.
base::flat_set<IPAddress> cached_addresses_;
......
......@@ -4,7 +4,6 @@
#include "net/base/network_change_notifier_fuchsia.h"
#include <fuchsia/hardware/ethernet/cpp/fidl.h>
#include <fuchsia/netstack/cpp/fidl_test_base.h>
#include <memory>
#include <utility>
......@@ -129,7 +128,7 @@ class FakeNetstack : public fuchsia::netstack::testing::Netstack_TestBase {
void GetRouteTable(GetRouteTableCallback callback) override {
std::vector<fuchsia::netstack::RouteTableEntry> table(2);
table[0] = CreateRouteTableEntry(kDefaultNic, true);
table[1] = CreateRouteTableEntry(kSecondaryNic, false);
table[1] = CreateRouteTableEntry(kSecondaryNic, true);
callback(std::move(table));
}
......@@ -161,9 +160,8 @@ class NetworkChangeNotifierFuchsiaTest : public testing::Test {
// Creates a NetworkChangeNotifier, which will be seeded with the list of
// interfaces which have already been added to |netstack_|.
void CreateNotifier(uint32_t required_features = 0) {
notifier_.reset(new NetworkChangeNotifierFuchsia(std::move(netstack_ptr_),
required_features));
void CreateNotifier() {
notifier_.reset(new NetworkChangeNotifierFuchsia(std::move(netstack_ptr_)));
NetworkChangeNotifier::AddNetworkChangeObserver(&observer_);
}
......@@ -470,25 +468,4 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, FoundWiFi) {
notifier_->GetCurrentConnectionType());
}
TEST_F(NetworkChangeNotifierFuchsiaTest, FindsInterfaceWithRequiredFeature) {
netstack_.PushInterface(
CreateNetInterface(kDefaultNic, fuchsia::netstack::NetInterfaceFlagUp,
fuchsia::hardware::ethernet::INFO_FEATURE_WLAN,
CreateIPv4Address(169, 254, 0, 1),
CreateIPv4Address(255, 255, 255, 0), {}));
CreateNotifier(fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
EXPECT_EQ(NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI,
notifier_->GetCurrentConnectionType());
}
TEST_F(NetworkChangeNotifierFuchsiaTest, IgnoresInterfaceWithMissingFeature) {
netstack_.PushInterface(
CreateNetInterface(kDefaultNic, fuchsia::netstack::NetInterfaceFlagUp, 0,
CreateIPv4Address(169, 254, 0, 1),
CreateIPv4Address(255, 255, 255, 0), {}));
CreateNotifier(fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
EXPECT_EQ(NetworkChangeNotifier::ConnectionType::CONNECTION_NONE,
notifier_->GetCurrentConnectionType());
}
} // namespace net
......@@ -16,6 +16,7 @@
#include "base/fuchsia/fuchsia_logging.h"
#include "base/strings/stringprintf.h"
#include "net/base/ip_endpoint.h"
#include "net/base/network_change_notifier.h"
#include "net/base/network_interfaces.h"
namespace net {
......@@ -24,6 +25,13 @@ namespace {
using ConnectionType = NetworkChangeNotifier::ConnectionType;
ConnectionType ConvertConnectionType(
const fuchsia::netstack::NetInterface& iface) {
return iface.features & fuchsia::hardware::ethernet::INFO_FEATURE_WLAN
? NetworkChangeNotifier::CONNECTION_WIFI
: NetworkChangeNotifier::CONNECTION_UNKNOWN;
}
// Converts a Netstack NetInterface |interface| to a Chrome NetworkInterface.
// NetInterfaces may be bound to multiple IPv6 addresses. |address_index| is
// used to specify which address to use for the conversion.
......@@ -57,16 +65,6 @@ NetworkInterface NetworkInterfaceFromAddress(
} // namespace
NetworkChangeNotifier::ConnectionType ConvertConnectionType(
const fuchsia::netstack::NetInterface& iface) {
if (!(iface.flags & fuchsia::netstack::NetInterfaceFlagUp)) {
return NetworkChangeNotifier::CONNECTION_NONE;
} else if (iface.features & fuchsia::hardware::ethernet::INFO_FEATURE_WLAN) {
return NetworkChangeNotifier::CONNECTION_WIFI;
}
return NetworkChangeNotifier::CONNECTION_UNKNOWN;
}
IPAddress FuchsiaIpAddressToIPAddress(const fuchsia::net::IpAddress& addr) {
if (addr.is_ipv4()) {
return IPAddress(addr.ipv4().addr.data(), addr.ipv4().addr.count());
......@@ -81,11 +79,13 @@ std::vector<NetworkInterface> NetInterfaceToNetworkInterfaces(
const fuchsia::netstack::NetInterface& iface_in) {
std::vector<NetworkInterface> output;
// If the interface is not currently up then there are no addresses to return.
if (internal::ConvertConnectionType(iface_in) ==
NetworkChangeNotifier::CONNECTION_NONE) {
// Check if the interface is up.
if (!(iface_in.flags & fuchsia::netstack::NetInterfaceFlagUp))
return output;
// Skip loopback.
if (iface_in.features & fuchsia::hardware::ethernet::INFO_FEATURE_LOOPBACK)
return output;
}
output.push_back(NetworkInterfaceFromAddress(iface_in, 0));
......@@ -115,13 +115,6 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
}
for (auto& interface : interfaces) {
if ((internal::ConvertConnectionType(interface) ==
NetworkChangeNotifier::CONNECTION_NONE) ||
(interface.features &
fuchsia::hardware::ethernet::INFO_FEATURE_LOOPBACK)) {
continue;
}
auto converted = internal::NetInterfaceToNetworkInterfaces(interface);
std::move(converted.begin(), converted.end(),
std::back_inserter(*networks));
......
......@@ -7,8 +7,6 @@
#include <vector>
#include "net/base/network_change_notifier.h"
namespace fuchsia {
namespace net {
class IpAddress;
......@@ -25,12 +23,6 @@ struct NetworkInterface;
namespace internal {
// Returns the //net ConnectionType for the supplied netstack interface
// description. Returns ConnectionType::CONNECTION_NONE if the interface is not
// "up".
NetworkChangeNotifier::ConnectionType ConvertConnectionType(
const fuchsia::netstack::NetInterface& iface);
// Converts a Fuchsia Netstack NetInterface object to NetworkInterface objects.
// Interfaces with more than one IPv6 address will yield multiple
// NetworkInterface objects, with friendly names to distinguish the different
......
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