Commit 8aa8a055 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

NetworkTypePattern: Introduce operator| and Physical()

This CL:
* Introduces NetworkTypePattern::operator| which makes some code a bit
  more intuitive (and reduces overhead).
* Add Physical() for enabling/disabling physical networks during OOBE.
  This reduces log spam on linux and potentially avoids unexpected
  behavior on devices (but the current behavior is probably harmless).

Bug: 756092
Change-Id: Ie27d02fd03875c1bb44e61510acd5179b672bd14
Reviewed-on: https://chromium-review.googlesource.com/828264Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524279}
parent f3ff2bc6
...@@ -294,10 +294,8 @@ void NetworkStateListDetailedView::UpdateHeaderButtons() { ...@@ -294,10 +294,8 @@ void NetworkStateListDetailedView::UpdateHeaderButtons() {
if (list_type_ == LIST_TYPE_NETWORK) { if (list_type_ == LIST_TYPE_NETWORK) {
NetworkStateHandler* network_state_handler = NetworkStateHandler* network_state_handler =
NetworkHandler::Get()->network_state_handler(); NetworkHandler::Get()->network_state_handler();
// TODO(crbug.com/756092): Add | operator to NetworkTypePattern. const bool scanning = network_state_handler->GetScanningByType(
const bool scanning = NetworkTypePattern::WiFi() | NetworkTypePattern::Tether());
network_state_handler->GetScanningByType(NetworkTypePattern::WiFi()) ||
network_state_handler->GetScanningByType(NetworkTypePattern::Tether());
ShowProgress(-1, scanning); ShowProgress(-1, scanning);
} }
} }
......
...@@ -135,9 +135,8 @@ class AppSession::AppWindowHandler : public AppWindowRegistry::Observer { ...@@ -135,9 +135,8 @@ class AppSession::AppWindowHandler : public AppWindowRegistry::Observer {
->GetAccountId())) { ->GetAccountId())) {
// If we were in demo mode, we disabled all our network technologies, // If we were in demo mode, we disabled all our network technologies,
// re-enable them. // re-enable them.
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
NetworkHandler::Get()->network_state_handler(); NetworkTypePattern::Physical(), true,
handler->SetTechnologyEnabled(NetworkTypePattern::NonVirtual(), true,
chromeos::network_handler::ErrorCallback()); chromeos::network_handler::ErrorCallback());
} }
......
...@@ -88,8 +88,8 @@ void DemoAppLauncher::OnProfileLoaded(Profile* profile) { ...@@ -88,8 +88,8 @@ void DemoAppLauncher::OnProfileLoaded(Profile* profile) {
// Disable network before launching the app. // Disable network before launching the app.
LOG(WARNING) << "Disabling network before launching demo app.."; LOG(WARNING) << "Disabling network before launching demo app..";
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
handler->SetTechnologyEnabled(NetworkTypePattern::NonVirtual(), false, NetworkTypePattern::Physical(), false,
chromeos::network_handler::ErrorCallback()); chromeos::network_handler::ErrorCallback());
OpenApplication(AppLaunchParams(profile, extension, OpenApplication(AppLaunchParams(profile, extension,
......
...@@ -269,8 +269,8 @@ void TetherService::DeviceListChanged() { ...@@ -269,8 +269,8 @@ void TetherService::DeviceListChanged() {
void TetherService::DevicePropertiesUpdated( void TetherService::DevicePropertiesUpdated(
const chromeos::DeviceState* device) { const chromeos::DeviceState* device) {
if (device->Matches(chromeos::NetworkTypePattern::Tether()) || if (device->Matches(chromeos::NetworkTypePattern::Tether() |
device->Matches(chromeos::NetworkTypePattern::WiFi())) { chromeos::NetworkTypePattern::WiFi())) {
UpdateEnabledState(); UpdateEnabledState();
} }
} }
......
...@@ -86,11 +86,10 @@ void NetworkScreenHandler::Show() { ...@@ -86,11 +86,10 @@ void NetworkScreenHandler::Show() {
return; return;
} }
// Make sure all our network technologies are turned on. On OOBE, the user // Make sure all physical network technologies are enabled. On OOBE, the user
// should be able to select any of the available networks on the device. // should be able to select any of the available networks on the device.
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
handler->SetTechnologyEnabled(NetworkTypePattern::NonVirtual(), handler->SetTechnologyEnabled(NetworkTypePattern::Physical(), true,
true,
chromeos::network_handler::ErrorCallback()); chromeos::network_handler::ErrorCallback());
base::DictionaryValue network_screen_params; base::DictionaryValue network_screen_params;
......
...@@ -18,6 +18,7 @@ const char kPatternDefault[] = "PatternDefault"; ...@@ -18,6 +18,7 @@ const char kPatternDefault[] = "PatternDefault";
const char kPatternWireless[] = "PatternWireless"; const char kPatternWireless[] = "PatternWireless";
const char kPatternMobile[] = "PatternMobile"; const char kPatternMobile[] = "PatternMobile";
const char kPatternNonVirtual[] = "PatternNonVirtual"; const char kPatternNonVirtual[] = "PatternNonVirtual";
const char kPatternPhysical[] = "PatternPhysical";
enum NetworkTypeBitFlag { enum NetworkTypeBitFlag {
kNetworkTypeNone = 0, kNetworkTypeNone = 0,
...@@ -71,6 +72,12 @@ NetworkTypePattern NetworkTypePattern::Mobile() { ...@@ -71,6 +72,12 @@ NetworkTypePattern NetworkTypePattern::Mobile() {
kNetworkTypeTether); kNetworkTypeTether);
} }
// static
NetworkTypePattern NetworkTypePattern::Physical() {
return NetworkTypePattern(kNetworkTypeWifi | kNetworkTypeWimax |
kNetworkTypeCellular | kNetworkTypeEthernet);
}
// static // static
NetworkTypePattern NetworkTypePattern::NonVirtual() { NetworkTypePattern NetworkTypePattern::NonVirtual() {
return NetworkTypePattern(~(kNetworkTypeVPN)); return NetworkTypePattern(~(kNetworkTypeVPN));
...@@ -139,6 +146,11 @@ bool NetworkTypePattern::MatchesPattern( ...@@ -139,6 +146,11 @@ bool NetworkTypePattern::MatchesPattern(
return pattern_ & other_pattern.pattern_; return pattern_ & other_pattern.pattern_;
} }
NetworkTypePattern NetworkTypePattern::operator|(
const NetworkTypePattern& other) const {
return NetworkTypePattern(pattern_ | other.pattern_);
}
std::string NetworkTypePattern::ToDebugString() const { std::string NetworkTypePattern::ToDebugString() const {
if (Equals(Default())) if (Equals(Default()))
return kPatternDefault; return kPatternDefault;
...@@ -146,6 +158,8 @@ std::string NetworkTypePattern::ToDebugString() const { ...@@ -146,6 +158,8 @@ std::string NetworkTypePattern::ToDebugString() const {
return kPatternWireless; return kPatternWireless;
if (Equals(Mobile())) if (Equals(Mobile()))
return kPatternMobile; return kPatternMobile;
if (Equals(Physical()))
return kPatternPhysical;
if (Equals(NonVirtual())) if (Equals(NonVirtual()))
return kPatternNonVirtual; return kPatternNonVirtual;
......
...@@ -23,6 +23,9 @@ class CHROMEOS_EXPORT NetworkTypePattern { ...@@ -23,6 +23,9 @@ class CHROMEOS_EXPORT NetworkTypePattern {
// Matches Cellular, WiMAX, or Tether networks. // Matches Cellular, WiMAX, or Tether networks.
static NetworkTypePattern Mobile(); static NetworkTypePattern Mobile();
// Matches Physical networks (i.e. excludes Tether and VPN).
static NetworkTypePattern Physical();
// Matches non virtual networks. // Matches non virtual networks.
static NetworkTypePattern NonVirtual(); static NetworkTypePattern NonVirtual();
...@@ -55,6 +58,8 @@ class CHROMEOS_EXPORT NetworkTypePattern { ...@@ -55,6 +58,8 @@ class CHROMEOS_EXPORT NetworkTypePattern {
// See the unit test for examples. // See the unit test for examples.
bool MatchesPattern(const NetworkTypePattern& other_pattern) const; bool MatchesPattern(const NetworkTypePattern& other_pattern) const;
NetworkTypePattern operator|(const NetworkTypePattern& other) const;
std::string ToDebugString() const; std::string ToDebugString() const;
private: private:
......
...@@ -19,6 +19,7 @@ class NetworkTypePatternTest : public testing::Test { ...@@ -19,6 +19,7 @@ class NetworkTypePatternTest : public testing::Test {
default_(NetworkTypePattern::Default()), default_(NetworkTypePattern::Default()),
ethernet_(NetworkTypePattern::Ethernet()), ethernet_(NetworkTypePattern::Ethernet()),
mobile_(NetworkTypePattern::Mobile()), mobile_(NetworkTypePattern::Mobile()),
physical_(NetworkTypePattern::Physical()),
non_virtual_(NetworkTypePattern::NonVirtual()), non_virtual_(NetworkTypePattern::NonVirtual()),
wimax_(NetworkTypePattern::Wimax()), wimax_(NetworkTypePattern::Wimax()),
wireless_(NetworkTypePattern::Wireless()), wireless_(NetworkTypePattern::Wireless()),
...@@ -38,6 +39,7 @@ class NetworkTypePatternTest : public testing::Test { ...@@ -38,6 +39,7 @@ class NetworkTypePatternTest : public testing::Test {
const NetworkTypePattern default_; const NetworkTypePattern default_;
const NetworkTypePattern ethernet_; const NetworkTypePattern ethernet_;
const NetworkTypePattern mobile_; const NetworkTypePattern mobile_;
const NetworkTypePattern physical_;
const NetworkTypePattern non_virtual_; const NetworkTypePattern non_virtual_;
const NetworkTypePattern wimax_; const NetworkTypePattern wimax_;
const NetworkTypePattern wireless_; const NetworkTypePattern wireless_;
...@@ -65,6 +67,14 @@ TEST_F(NetworkTypePatternTest, MatchesType) { ...@@ -65,6 +67,14 @@ TEST_F(NetworkTypePatternTest, MatchesType) {
EXPECT_FALSE(wireless_.MatchesType(shill::kTypeEthernet)); EXPECT_FALSE(wireless_.MatchesType(shill::kTypeEthernet));
EXPECT_FALSE(wireless_.MatchesType(shill::kTypeVPN)); EXPECT_FALSE(wireless_.MatchesType(shill::kTypeVPN));
// Networks managed by Shill (excludes Tether and VPN).
EXPECT_TRUE(physical_.MatchesType(shill::kTypeCellular));
EXPECT_TRUE(physical_.MatchesType(shill::kTypeWifi));
EXPECT_TRUE(physical_.MatchesType(shill::kTypeEthernet));
EXPECT_TRUE(physical_.MatchesType(shill::kTypeWimax));
EXPECT_FALSE(physical_.MatchesType(kTypeTether));
EXPECT_FALSE(physical_.MatchesType(shill::kTypeVPN));
// Non-virtual contains everything except VPN. // Non-virtual contains everything except VPN.
EXPECT_TRUE(non_virtual_.MatchesType(shill::kTypeCellular)); EXPECT_TRUE(non_virtual_.MatchesType(shill::kTypeCellular));
EXPECT_TRUE(non_virtual_.MatchesType(shill::kTypeWifi)); EXPECT_TRUE(non_virtual_.MatchesType(shill::kTypeWifi));
...@@ -121,6 +131,13 @@ TEST_F(NetworkTypePatternTest, Primitive) { ...@@ -121,6 +131,13 @@ TEST_F(NetworkTypePatternTest, Primitive) {
EXPECT_TRUE(primitive_wimax.Equals(wimax_)); EXPECT_TRUE(primitive_wimax.Equals(wimax_));
} }
TEST_F(NetworkTypePatternTest, Or) {
NetworkTypePattern compound = wifi_ | cellular_;
EXPECT_TRUE(cellular_.MatchesPattern(compound));
EXPECT_TRUE(wifi_.MatchesPattern(compound));
EXPECT_FALSE(ethernet_.MatchesPattern(compound));
}
TEST_F(NetworkTypePatternTest, ToDebugString) { TEST_F(NetworkTypePatternTest, ToDebugString) {
EXPECT_EQ(default_.ToDebugString(), "PatternDefault"); EXPECT_EQ(default_.ToDebugString(), "PatternDefault");
EXPECT_EQ(wireless_.ToDebugString(), "PatternWireless"); EXPECT_EQ(wireless_.ToDebugString(), "PatternWireless");
......
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