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() {
if (list_type_ == LIST_TYPE_NETWORK) {
NetworkStateHandler* network_state_handler =
NetworkHandler::Get()->network_state_handler();
// TODO(crbug.com/756092): Add | operator to NetworkTypePattern.
const bool scanning =
network_state_handler->GetScanningByType(NetworkTypePattern::WiFi()) ||
network_state_handler->GetScanningByType(NetworkTypePattern::Tether());
const bool scanning = network_state_handler->GetScanningByType(
NetworkTypePattern::WiFi() | NetworkTypePattern::Tether());
ShowProgress(-1, scanning);
}
}
......
......@@ -135,10 +135,9 @@ class AppSession::AppWindowHandler : public AppWindowRegistry::Observer {
->GetAccountId())) {
// If we were in demo mode, we disabled all our network technologies,
// re-enable them.
NetworkStateHandler* handler =
NetworkHandler::Get()->network_state_handler();
handler->SetTechnologyEnabled(NetworkTypePattern::NonVirtual(), true,
chromeos::network_handler::ErrorCallback());
NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
NetworkTypePattern::Physical(), true,
chromeos::network_handler::ErrorCallback());
}
app_session_->OnLastAppWindowClosed();
......
......@@ -88,9 +88,9 @@ void DemoAppLauncher::OnProfileLoaded(Profile* profile) {
// Disable network before launching the app.
LOG(WARNING) << "Disabling network before launching demo app..";
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
handler->SetTechnologyEnabled(NetworkTypePattern::NonVirtual(), false,
chromeos::network_handler::ErrorCallback());
NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
NetworkTypePattern::Physical(), false,
chromeos::network_handler::ErrorCallback());
OpenApplication(AppLaunchParams(profile, extension,
extensions::LAUNCH_CONTAINER_WINDOW,
......
......@@ -269,8 +269,8 @@ void TetherService::DeviceListChanged() {
void TetherService::DevicePropertiesUpdated(
const chromeos::DeviceState* device) {
if (device->Matches(chromeos::NetworkTypePattern::Tether()) ||
device->Matches(chromeos::NetworkTypePattern::WiFi())) {
if (device->Matches(chromeos::NetworkTypePattern::Tether() |
chromeos::NetworkTypePattern::WiFi())) {
UpdateEnabledState();
}
}
......
......@@ -86,11 +86,10 @@ void NetworkScreenHandler::Show() {
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.
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
handler->SetTechnologyEnabled(NetworkTypePattern::NonVirtual(),
true,
handler->SetTechnologyEnabled(NetworkTypePattern::Physical(), true,
chromeos::network_handler::ErrorCallback());
base::DictionaryValue network_screen_params;
......
......@@ -18,6 +18,7 @@ const char kPatternDefault[] = "PatternDefault";
const char kPatternWireless[] = "PatternWireless";
const char kPatternMobile[] = "PatternMobile";
const char kPatternNonVirtual[] = "PatternNonVirtual";
const char kPatternPhysical[] = "PatternPhysical";
enum NetworkTypeBitFlag {
kNetworkTypeNone = 0,
......@@ -71,6 +72,12 @@ NetworkTypePattern NetworkTypePattern::Mobile() {
kNetworkTypeTether);
}
// static
NetworkTypePattern NetworkTypePattern::Physical() {
return NetworkTypePattern(kNetworkTypeWifi | kNetworkTypeWimax |
kNetworkTypeCellular | kNetworkTypeEthernet);
}
// static
NetworkTypePattern NetworkTypePattern::NonVirtual() {
return NetworkTypePattern(~(kNetworkTypeVPN));
......@@ -139,6 +146,11 @@ bool NetworkTypePattern::MatchesPattern(
return pattern_ & other_pattern.pattern_;
}
NetworkTypePattern NetworkTypePattern::operator|(
const NetworkTypePattern& other) const {
return NetworkTypePattern(pattern_ | other.pattern_);
}
std::string NetworkTypePattern::ToDebugString() const {
if (Equals(Default()))
return kPatternDefault;
......@@ -146,6 +158,8 @@ std::string NetworkTypePattern::ToDebugString() const {
return kPatternWireless;
if (Equals(Mobile()))
return kPatternMobile;
if (Equals(Physical()))
return kPatternPhysical;
if (Equals(NonVirtual()))
return kPatternNonVirtual;
......
......@@ -23,6 +23,9 @@ class CHROMEOS_EXPORT NetworkTypePattern {
// Matches Cellular, WiMAX, or Tether networks.
static NetworkTypePattern Mobile();
// Matches Physical networks (i.e. excludes Tether and VPN).
static NetworkTypePattern Physical();
// Matches non virtual networks.
static NetworkTypePattern NonVirtual();
......@@ -55,6 +58,8 @@ class CHROMEOS_EXPORT NetworkTypePattern {
// See the unit test for examples.
bool MatchesPattern(const NetworkTypePattern& other_pattern) const;
NetworkTypePattern operator|(const NetworkTypePattern& other) const;
std::string ToDebugString() const;
private:
......
......@@ -19,6 +19,7 @@ class NetworkTypePatternTest : public testing::Test {
default_(NetworkTypePattern::Default()),
ethernet_(NetworkTypePattern::Ethernet()),
mobile_(NetworkTypePattern::Mobile()),
physical_(NetworkTypePattern::Physical()),
non_virtual_(NetworkTypePattern::NonVirtual()),
wimax_(NetworkTypePattern::Wimax()),
wireless_(NetworkTypePattern::Wireless()),
......@@ -38,6 +39,7 @@ class NetworkTypePatternTest : public testing::Test {
const NetworkTypePattern default_;
const NetworkTypePattern ethernet_;
const NetworkTypePattern mobile_;
const NetworkTypePattern physical_;
const NetworkTypePattern non_virtual_;
const NetworkTypePattern wimax_;
const NetworkTypePattern wireless_;
......@@ -65,6 +67,14 @@ TEST_F(NetworkTypePatternTest, MatchesType) {
EXPECT_FALSE(wireless_.MatchesType(shill::kTypeEthernet));
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.
EXPECT_TRUE(non_virtual_.MatchesType(shill::kTypeCellular));
EXPECT_TRUE(non_virtual_.MatchesType(shill::kTypeWifi));
......@@ -121,6 +131,13 @@ TEST_F(NetworkTypePatternTest, Primitive) {
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) {
EXPECT_EQ(default_.ToDebugString(), "PatternDefault");
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