Commit 352892bf authored by Tamir Duberstein's avatar Tamir Duberstein Committed by Commit Bot

[fuchsia] Migrate NetInterface::features to bits

Bug: 1099393
Change-Id: Id9076b0c92ac0583ffd8cb845663db3ff236c381
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2353294Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Reviewed-by: default avatarDavid Benjamin <davidben@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Commit-Queue: Tamir Duberstein <tamird@google.com>
Cr-Commit-Position: refs/heads/master@{#798901}
parent 43298a05
......@@ -14,10 +14,9 @@ namespace chromecast {
std::unique_ptr<net::NetworkChangeNotifier>
NetworkChangeNotifierFactoryFuchsia::CreateInstance() {
uint32_t required_features =
GetSwitchValueBoolean(switches::kRequireWlan, false)
? fuchsia::hardware::ethernet::INFO_FEATURE_WLAN
: 0;
auto required_features = GetSwitchValueBoolean(switches::kRequireWlan, false)
? fuchsia::hardware::ethernet::Features::WLAN
: fuchsia::hardware::ethernet::Features();
// Caller assumes ownership.
return std::make_unique<net::NetworkChangeNotifierFuchsia>(required_features);
......
......@@ -243,7 +243,7 @@ std::unique_ptr<NetworkChangeNotifier> NetworkChangeNotifier::CreateIfNeeded(
return std::make_unique<NetworkChangeNotifierMac>();
#elif defined(OS_FUCHSIA)
return std::make_unique<NetworkChangeNotifierFuchsia>(
0 /* required_features */);
fuchsia::hardware::ethernet::Features());
#else
NOTIMPLEMENTED();
return NULL;
......
......@@ -23,7 +23,7 @@
namespace net {
NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia(
uint32_t required_features)
fuchsia::hardware::ethernet::Features required_features)
: NetworkChangeNotifierFuchsia(base::ComponentContextForProcess()
->svc()
->Connect<fuchsia::netstack::Netstack>(),
......@@ -31,7 +31,7 @@ NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia(
NetworkChangeNotifierFuchsia::NetworkChangeNotifierFuchsia(
fidl::InterfaceHandle<fuchsia::netstack::Netstack> netstack,
uint32_t required_features,
fuchsia::hardware::ethernet::Features required_features,
SystemDnsConfigChangeNotifier* system_dns_config_notifier)
: NetworkChangeNotifier(NetworkChangeCalculatorParams(),
system_dns_config_notifier),
......@@ -100,18 +100,16 @@ void NetworkChangeNotifierFuchsia::OnRouteTableReceived(
base::flat_set<IPAddress> addresses;
for (auto& interface : interfaces) {
// Filter out loopback and invalid connection types.
auto loopback = static_cast<decltype(interface.features)>(
fuchsia::hardware::ethernet::INFO_FEATURE_LOOPBACK);
if ((internal::ConvertConnectionType(interface) ==
NetworkChangeNotifier::CONNECTION_NONE) ||
((interface.features & loopback) == loopback)) {
(interface.features &
fuchsia::hardware::ethernet::Features::LOOPBACK) ==
fuchsia::hardware::ethernet::Features::LOOPBACK) {
continue;
}
// Filter out interfaces that do not meet the |required_features_|.
auto required_features =
static_cast<decltype(interface.features)>(required_features_);
if ((interface.features & required_features) != required_features) {
if ((interface.features & required_features_) != required_features_) {
continue;
}
......
......@@ -23,9 +23,9 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia
: public NetworkChangeNotifier {
public:
// Registers for asynchronous notifications of changes to network interfaces.
// Interfaces can be filtered out by passing in |required_features|, which is
// defined in fuchsia::hardware::ethernet.
explicit NetworkChangeNotifierFuchsia(uint32_t required_features);
// Interfaces are filtered by |required_features|.
explicit NetworkChangeNotifierFuchsia(
fuchsia::hardware::ethernet::Features required_features);
~NetworkChangeNotifierFuchsia() override;
// NetworkChangeNotifier implementation.
......@@ -35,11 +35,10 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia
friend class NetworkChangeNotifierFuchsiaTest;
// 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.
// Interfaces are filtered by |required_features|.
NetworkChangeNotifierFuchsia(
fidl::InterfaceHandle<fuchsia::netstack::Netstack> netstack,
uint32_t required_features,
fuchsia::hardware::ethernet::Features required_features,
SystemDnsConfigChangeNotifier* system_dns_config_notifier = nullptr);
// Forwards the network interface list along with the result of
......@@ -54,9 +53,8 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierFuchsia
std::vector<fuchsia::netstack::NetInterface> interfaces,
std::vector<fuchsia::netstack::RouteTableEntry> table);
// 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_;
// Required features for an interface to be taken into account.
const fuchsia::hardware::ethernet::Features required_features_;
fuchsia::netstack::NetstackPtr netstack_;
......
......@@ -303,7 +303,8 @@ class NetworkChangeNotifierFuchsiaTest : public testing::Test {
// populate from the list of interfaces which have already been added to
// |netstack_|. |observer_| is registered last, so that tests need only
// express expectations on changes they make themselves.
void CreateNotifier(uint32_t required_features = 0) {
void CreateNotifier(
fuchsia::hardware::ethernet::Features required_features = {}) {
// Ensure that the Netstack internal state is up-to-date before the
// notifier queries it.
netstack_.FlushNetstackThread();
......@@ -357,8 +358,7 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, NotifyNetworkChangeOnInitialIPChange) {
// Set a live interface with an IP address and create the notifier.
std::vector<fuchsia::netstack::NetInterface> interfaces(1);
interfaces[0] = DefaultNetInterface();
interfaces[0].features = static_cast<decltype(interfaces[0].features)>(
fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
interfaces[0].features = fuchsia::hardware::ethernet::Features::WLAN;
netstack_.SetInterfaces(interfaces);
CreateNotifier();
......@@ -560,8 +560,7 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, InterfaceAdded) {
std::vector<fuchsia::netstack::NetInterface> interfaces(1);
interfaces[0] = DefaultNetInterface();
interfaces[0].features = static_cast<decltype(interfaces[0].features)>(
fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
interfaces[0].features = fuchsia::hardware::ethernet::Features::WLAN;
netstack_.SetInterfaces(interfaces);
......@@ -596,8 +595,7 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, SecondaryInterfaceDeletedNoop) {
TEST_F(NetworkChangeNotifierFuchsiaTest, FoundWiFi) {
std::vector<fuchsia::netstack::NetInterface> interfaces(1);
interfaces[0] = DefaultNetInterface();
interfaces[0].features = static_cast<decltype(interfaces[0].features)>(
fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
interfaces[0].features = fuchsia::hardware::ethernet::Features::WLAN;
netstack_.SetInterfaces(interfaces);
CreateNotifier();
......@@ -608,11 +606,10 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, FoundWiFi) {
TEST_F(NetworkChangeNotifierFuchsiaTest, FindsInterfaceWithRequiredFeature) {
std::vector<fuchsia::netstack::NetInterface> interfaces(1);
interfaces[0] = DefaultNetInterface();
interfaces[0].features = static_cast<decltype(interfaces[0].features)>(
fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
interfaces[0].features = fuchsia::hardware::ethernet::Features::WLAN;
netstack_.SetInterfaces(interfaces);
CreateNotifier(fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
CreateNotifier(fuchsia::hardware::ethernet::Features::WLAN);
EXPECT_EQ(NetworkChangeNotifier::ConnectionType::CONNECTION_WIFI,
notifier_->GetCurrentConnectionType());
}
......@@ -622,7 +619,7 @@ TEST_F(NetworkChangeNotifierFuchsiaTest, IgnoresInterfaceWithMissingFeature) {
interfaces[0] = DefaultNetInterface();
netstack_.SetInterfaces(interfaces);
CreateNotifier(fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
CreateNotifier(fuchsia::hardware::ethernet::Features::WLAN);
EXPECT_EQ(NetworkChangeNotifier::ConnectionType::CONNECTION_NONE,
notifier_->GetCurrentConnectionType());
}
......
......@@ -60,13 +60,12 @@ NetworkInterface NetworkInterfaceFromAddress(
NetworkChangeNotifier::ConnectionType ConvertConnectionType(
const fuchsia::netstack::NetInterface& iface) {
auto wlan = static_cast<decltype(iface.features)>(
fuchsia::hardware::ethernet::INFO_FEATURE_WLAN);
auto up =
static_cast<decltype(iface.flags)>(fuchsia::netstack::NetInterfaceFlagUp);
if ((iface.flags & up) != up) {
return NetworkChangeNotifier::CONNECTION_NONE;
} else if ((iface.features & wlan) == wlan) {
} else if ((iface.features & fuchsia::hardware::ethernet::Features::WLAN) ==
fuchsia::hardware::ethernet::Features::WLAN) {
return NetworkChangeNotifier::CONNECTION_WIFI;
}
return NetworkChangeNotifier::CONNECTION_UNKNOWN;
......@@ -122,11 +121,11 @@ bool GetNetworkList(NetworkInterfaceList* networks, int policy) {
}
for (auto& interface : interfaces) {
auto loopback = static_cast<decltype(interface.features)>(
fuchsia::hardware::ethernet::INFO_FEATURE_LOOPBACK);
if ((internal::ConvertConnectionType(interface) ==
NetworkChangeNotifier::CONNECTION_NONE) ||
((interface.features & loopback) == loopback)) {
(interface.features &
fuchsia::hardware::ethernet::Features::LOOPBACK) ==
fuchsia::hardware::ethernet::Features::LOOPBACK) {
continue;
}
......
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