Commit f13e1e42 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

Eliminate NetworkState dependency from network_icon.cc

NetowrkState usage has been mostly removed from non test consumers of
network_icon.cc.

This removes the single remaining usage in GetSignalStrengthForNetwork,
updates the tests and removes the NetworkState dependency entirely.

This also includes a bit of cleanup to cros_network_config.cc to
separate NetworkStateHandler dependencies from NetworkState/DeviceState
dependencies in the file local helper functions. (These were
temporarily used in the tests but that was reverted, but the cleanup
still seems useful).

Bug: 862420
Change-Id: I566505e5a4f22538d8a862eeb5fcfc9f3c3ffd79
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1600306
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659750}
parent 5610aeea
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_state_test_helper.h" #include "chromeos/network/network_state_test_helper.h"
#include "chromeos/services/network_config/public/cpp/cros_network_config_test_helper.h" #include "chromeos/services/network_config/public/cpp/cros_network_config_test_helper.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
...@@ -20,6 +21,9 @@ ...@@ -20,6 +21,9 @@
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image_unittest_util.h" #include "ui/gfx/image/image_unittest_util.h"
using chromeos::network_config::mojom::ConnectionStateType;
using chromeos::network_config::mojom::NetworkType;
namespace ash { namespace ash {
namespace { namespace {
...@@ -101,9 +105,17 @@ class ActiveNetworkIconTest : public testing::Test { ...@@ -101,9 +105,17 @@ class ActiveNetworkIconTest : public testing::Test {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
gfx::ImageSkia ImageForNetwork(const chromeos::NetworkState* network) { gfx::ImageSkia ImageForNetwork(
chromeos::network_config::mojom::NetworkType type,
chromeos::network_config::mojom::ConnectionStateType connection_state,
int signal_strength = 100) {
std::string id = base::StringPrintf("reference_%d", reference_count_++);
chromeos::network_config::mojom::NetworkStatePropertiesPtr
reference_properties =
network_state_helper().CreateStandaloneNetworkProperties(
id, type, connection_state, signal_strength);
return network_icon::GetImageForNonVirtualNetwork( return network_icon::GetImageForNonVirtualNetwork(
network_icon::NetworkIconState(network), icon_type_, network_icon::NetworkIconState(reference_properties.get()), icon_type_,
false /* show_vpn_badge */); false /* show_vpn_badge */);
} }
...@@ -122,18 +134,6 @@ class ActiveNetworkIconTest : public testing::Test { ...@@ -122,18 +134,6 @@ class ActiveNetworkIconTest : public testing::Test {
network_state_helper().SetServiceProperty(service_path, key, value); network_state_helper().SetServiceProperty(service_path, key, value);
} }
std::unique_ptr<chromeos::NetworkState> CreateStandaloneNetworkState(
const std::string& type,
const std::string& connection_state,
int signal_strength = 100) {
std::string id = base::StringPrintf("reference_%d", reference_count_++);
VLOG(1) << "CreateStandaloneNetworkState: " << id << " type: " << type
<< " State: " << connection_state
<< " Strength: " << signal_strength;
return network_state_helper().CreateStandaloneNetworkState(
id, type, connection_state, signal_strength);
}
chromeos::NetworkStateTestHelper& network_state_helper() { chromeos::NetworkStateTestHelper& network_state_helper() {
return network_config_helper_.network_state_helper(); return network_config_helper_.network_state_helper();
} }
...@@ -190,17 +190,17 @@ TEST_F(ActiveNetworkIconTest, GetSingleImage) { ...@@ -190,17 +190,17 @@ TEST_F(ActiveNetworkIconTest, GetSingleImage) {
bool animating; bool animating;
gfx::ImageSkia image = gfx::ImageSkia image =
active_network_icon()->GetSingleImage(icon_type(), &animating); active_network_icon()->GetSingleImage(icon_type(), &animating);
std::unique_ptr<chromeos::NetworkState> reference_network = EXPECT_TRUE(AreImagesEqual(
CreateStandaloneNetworkState(shill::kTypeCellular, shill::kStateOnline); image,
EXPECT_TRUE(AreImagesEqual(image, ImageForNetwork(reference_network.get()))); ImageForNetwork(NetworkType::kCellular, ConnectionStateType::kOnline)));
EXPECT_FALSE(animating); EXPECT_FALSE(animating);
// Cellular + WiFi connected = WiFi connected icon // Cellular + WiFi connected = WiFi connected icon
SetupWiFi(shill::kStateOnline); SetupWiFi(shill::kStateOnline);
image = active_network_icon()->GetSingleImage(icon_type(), &animating); image = active_network_icon()->GetSingleImage(icon_type(), &animating);
reference_network = EXPECT_TRUE(AreImagesEqual(
CreateStandaloneNetworkState(shill::kTypeWifi, shill::kStateOnline); image,
EXPECT_TRUE(AreImagesEqual(image, ImageForNetwork(reference_network.get()))); ImageForNetwork(NetworkType::kWiFi, ConnectionStateType::kOnline)));
EXPECT_FALSE(animating); EXPECT_FALSE(animating);
// Cellular + WiFi connecting = WiFi connecting icon // Cellular + WiFi connecting = WiFi connecting icon
...@@ -210,15 +210,17 @@ TEST_F(ActiveNetworkIconTest, GetSingleImage) { ...@@ -210,15 +210,17 @@ TEST_F(ActiveNetworkIconTest, GetSingleImage) {
base::Value(50)); base::Value(50));
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
image = active_network_icon()->GetSingleImage(icon_type(), &animating); image = active_network_icon()->GetSingleImage(icon_type(), &animating);
reference_network = CreateStandaloneNetworkState( EXPECT_TRUE(AreImagesEqual(
shill::kTypeWifi, shill::kStateAssociation, 50); image, ImageForNetwork(NetworkType::kWiFi,
EXPECT_TRUE(AreImagesEqual(image, ImageForNetwork(reference_network.get()))); ConnectionStateType::kConnecting, 50)));
EXPECT_TRUE(animating); EXPECT_TRUE(animating);
// Cellular + WiFi connecting + Ethernet = WiFi connecting icon // Cellular + WiFi connecting + Ethernet = WiFi connecting icon
SetupEthernet(); SetupEthernet();
image = active_network_icon()->GetSingleImage(icon_type(), &animating); image = active_network_icon()->GetSingleImage(icon_type(), &animating);
EXPECT_TRUE(AreImagesEqual(image, ImageForNetwork(reference_network.get()))); EXPECT_TRUE(AreImagesEqual(
image, ImageForNetwork(NetworkType::kWiFi,
ConnectionStateType::kConnecting, 50)));
EXPECT_TRUE(animating); EXPECT_TRUE(animating);
// Cellular + WiFi connected + Ethernet = No icon // Cellular + WiFi connected + Ethernet = No icon
...@@ -240,10 +242,9 @@ TEST_F(ActiveNetworkIconTest, CellularUninitialized) { ...@@ -240,10 +242,9 @@ TEST_F(ActiveNetworkIconTest, CellularUninitialized) {
bool animating; bool animating;
gfx::ImageSkia image = gfx::ImageSkia image =
active_network_icon()->GetSingleImage(icon_type(), &animating); active_network_icon()->GetSingleImage(icon_type(), &animating);
std::unique_ptr<chromeos::NetworkState> reference_network = EXPECT_TRUE(
CreateStandaloneNetworkState(shill::kTypeCellular, AreImagesEqual(image, ImageForNetwork(NetworkType::kCellular,
shill::kStateAssociation); ConnectionStateType::kConnecting)));
EXPECT_TRUE(AreImagesEqual(image, ImageForNetwork(reference_network.get())));
EXPECT_TRUE(animating); EXPECT_TRUE(animating);
} }
...@@ -260,10 +261,9 @@ TEST_F(ActiveNetworkIconTest, CellularScanning) { ...@@ -260,10 +261,9 @@ TEST_F(ActiveNetworkIconTest, CellularScanning) {
bool animating; bool animating;
gfx::ImageSkia image = gfx::ImageSkia image =
active_network_icon()->GetSingleImage(icon_type(), &animating); active_network_icon()->GetSingleImage(icon_type(), &animating);
std::unique_ptr<chromeos::NetworkState> reference_network = EXPECT_TRUE(
CreateStandaloneNetworkState(shill::kTypeCellular, AreImagesEqual(image, ImageForNetwork(NetworkType::kCellular,
shill::kStateAssociation); ConnectionStateType::kConnecting)));
EXPECT_TRUE(AreImagesEqual(image, ImageForNetwork(reference_network.get())));
EXPECT_TRUE(animating); EXPECT_TRUE(animating);
} }
......
...@@ -90,6 +90,11 @@ const NetworkState* GetCurrentNetwork() { ...@@ -90,6 +90,11 @@ const NetworkState* GetCurrentNetwork() {
base::string16 GetSubLabelForConnectedNetwork(const NetworkState* network) { base::string16 GetSubLabelForConnectedNetwork(const NetworkState* network) {
DCHECK(network && network->IsConnectedState()); DCHECK(network && network->IsConnectedState());
if (!network->Matches(NetworkTypePattern::Wireless())) {
return l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED);
}
if (NetworkTypePattern::Cellular().MatchesType(network->type())) { if (NetworkTypePattern::Cellular().MatchesType(network->type())) {
if (network->network_technology() == shill::kNetworkTechnology1Xrtt) { if (network->network_technology() == shill::kNetworkTechnology1Xrtt) {
return l10n_util::GetStringUTF16( return l10n_util::GetStringUTF16(
...@@ -137,7 +142,10 @@ base::string16 GetSubLabelForConnectedNetwork(const NetworkState* network) { ...@@ -137,7 +142,10 @@ base::string16 GetSubLabelForConnectedNetwork(const NetworkState* network) {
IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED); IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED);
} }
switch (network_icon::GetSignalStrengthForNetwork(network)) { switch (network_icon::GetSignalStrength(network->signal_strength())) {
case network_icon::SignalStrength::NONE:
return l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED);
case network_icon::SignalStrength::WEAK: case network_icon::SignalStrength::WEAK:
return l10n_util::GetStringUTF16( return l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_NETWORK_SIGNAL_WEAK_SUBLABEL); IDS_ASH_STATUS_TRAY_NETWORK_SIGNAL_WEAK_SUBLABEL);
...@@ -147,10 +155,10 @@ base::string16 GetSubLabelForConnectedNetwork(const NetworkState* network) { ...@@ -147,10 +155,10 @@ base::string16 GetSubLabelForConnectedNetwork(const NetworkState* network) {
case network_icon::SignalStrength::STRONG: case network_icon::SignalStrength::STRONG:
return l10n_util::GetStringUTF16( return l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_NETWORK_SIGNAL_STRONG_SUBLABEL); IDS_ASH_STATUS_TRAY_NETWORK_SIGNAL_STRONG_SUBLABEL);
default:
return l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED);
} }
NOTREACHED();
return l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED);
} }
} // namespace } // namespace
......
...@@ -16,10 +16,6 @@ ...@@ -16,10 +16,6 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_type_pattern.h"
#include "chromeos/network/onc/onc_translation_tables.h"
#include "chromeos/network/tether_constants.h"
#include "chromeos/services/network_config/public/cpp/cros_network_config_util.h" #include "chromeos/services/network_config/public/cpp/cros_network_config_util.h"
#include "components/onc/onc_constants.h" #include "components/onc/onc_constants.h"
#include "components/vector_icons/vector_icons.h" #include "components/vector_icons/vector_icons.h"
...@@ -30,7 +26,6 @@ ...@@ -30,7 +26,6 @@
#include "ui/gfx/skia_util.h" #include "ui/gfx/skia_util.h"
#include "ui/gfx/vector_icon_types.h" #include "ui/gfx/vector_icon_types.h"
using chromeos::NetworkTypePattern;
using chromeos::network_config::mojom::ActivationStateType; using chromeos::network_config::mojom::ActivationStateType;
using chromeos::network_config::mojom::ConnectionStateType; using chromeos::network_config::mojom::ConnectionStateType;
using chromeos::network_config::mojom::NetworkType; using chromeos::network_config::mojom::NetworkType;
...@@ -296,6 +291,8 @@ gfx::ImageSkia GetIcon(const NetworkIconState& network, ...@@ -296,6 +291,8 @@ gfx::ImageSkia GetIcon(const NetworkIconState& network,
return gfx::CreateVectorIcon(kNetworkVpnIcon, return gfx::CreateVectorIcon(kNetworkVpnIcon,
GetDefaultColorForIconType(ICON_TYPE_LIST)); GetDefaultColorForIconType(ICON_TYPE_LIST));
} }
DCHECK_GE(strength_index, 0) << "Strength not set for type: " << network.type;
DCHECK_LT(strength_index, kNumNetworkImages);
return GetImageForIndex(ImageTypeForNetworkType(network.type), icon_type, return GetImageForIndex(ImageTypeForNetworkType(network.type), icon_type,
strength_index); strength_index);
} }
...@@ -308,56 +305,13 @@ gfx::ImageSkia GetConnectingVpnImage(IconType icon_type) { ...@@ -308,56 +305,13 @@ gfx::ImageSkia GetConnectingVpnImage(IconType icon_type) {
} // namespace } // namespace
NetworkIconState::NetworkIconState(const chromeos::NetworkState* network) {
guid = network->guid();
name = network->name();
const std::string& network_type = network->type();
if (NetworkTypePattern::Cellular().MatchesType(network_type) ||
NetworkTypePattern::Wimax().MatchesType(network_type)) {
type = NetworkType::kCellular;
} else if (NetworkTypePattern::Ethernet().MatchesType(network_type)) {
type = NetworkType::kEthernet;
} else if (NetworkTypePattern::Tether().MatchesType(network_type)) {
type = NetworkType::kTether;
} else if (NetworkTypePattern::VPN().MatchesType(network_type)) {
type = NetworkType::kVPN;
} else {
type = NetworkType::kWiFi;
}
if (network->IsCaptivePortal()) {
connection_state = ConnectionStateType::kPortal;
} else if (network->IsConnectedState()) {
connection_state = ConnectionStateType::kConnected;
} else if (network->IsConnectingState()) {
connection_state = ConnectionStateType::kConnecting;
} else {
connection_state = ConnectionStateType::kNotConnected;
}
security = network->GetMojoSecurity();
if (type == NetworkType::kCellular) {
if (!network->network_technology().empty()) {
chromeos::onc::TranslateStringToONC(
chromeos::onc::kNetworkTechnologyTable, network->network_technology(),
&network_technology);
}
}
activation_state = network->GetMojoActivationState();
signal_strength = network->signal_strength();
is_roaming = network->IndicateRoaming();
}
NetworkIconState::NetworkIconState( NetworkIconState::NetworkIconState(
const chromeos::network_config::mojom::NetworkStateProperties* network) { const chromeos::network_config::mojom::NetworkStateProperties* network) {
guid = network->guid; guid = network->guid;
name = network->name; name = network->name;
type = network->type; type = network->type;
connection_state = network->connection_state; connection_state = network->connection_state;
if (type == NetworkType::kCellular && network->cellular) { if (type == NetworkType::kCellular) {
activation_state = network->cellular->activation_state; activation_state = network->cellular->activation_state;
network_technology = network->cellular->network_technology; network_technology = network->cellular->network_technology;
is_roaming = network->cellular->roaming; is_roaming = network->cellular->roaming;
...@@ -365,16 +319,16 @@ NetworkIconState::NetworkIconState( ...@@ -365,16 +319,16 @@ NetworkIconState::NetworkIconState(
} else { } else {
activation_state = ActivationStateType::kUnknown; activation_state = ActivationStateType::kUnknown;
} }
if (type == NetworkType::kTether && network->tether) { if (type == NetworkType::kTether) {
signal_strength = network->tether->signal_strength; signal_strength = network->tether->signal_strength;
} }
if (type == NetworkType::kWiFi && network->wifi) { if (type == NetworkType::kWiFi) {
security = network->wifi->security; security = network->wifi->security;
signal_strength = network->wifi->signal_strength; signal_strength = network->wifi->signal_strength;
} else { } else {
security = chromeos::network_config::mojom::SecurityType::kNone; security = chromeos::network_config::mojom::SecurityType::kNone;
} }
if (type == NetworkType::kWiMAX && network->wimax) { if (type == NetworkType::kWiMAX) {
signal_strength = network->wimax->signal_strength; signal_strength = network->wimax->signal_strength;
} }
} }
...@@ -409,8 +363,8 @@ void NetworkIconImpl::Update(const NetworkIconState& network, ...@@ -409,8 +363,8 @@ void NetworkIconImpl::Update(const NetworkIconState& network,
} }
NetworkType type = network.type; NetworkType type = network.type;
if (type == NetworkType::kCellular || type == NetworkType::kTether || if (chromeos::network_config::NetworkTypeMatchesType(
type == NetworkType::kWiFi) { type, NetworkType::kWireless)) {
dirty |= UpdateWirelessStrengthIndex(network); dirty |= UpdateWirelessStrengthIndex(network);
} }
...@@ -679,16 +633,12 @@ void PurgeNetworkIconCache(const std::set<std::string>& network_guids) { ...@@ -679,16 +633,12 @@ void PurgeNetworkIconCache(const std::set<std::string>& network_guids) {
PurgeIconMap(ICON_TYPE_MENU_LIST, network_guids); PurgeIconMap(ICON_TYPE_MENU_LIST, network_guids);
} }
SignalStrength GetSignalStrengthForNetwork( SignalStrength GetSignalStrength(int strength) {
const chromeos::NetworkState* network) {
if (!network->Matches(NetworkTypePattern::Wireless()))
return SignalStrength::NOT_WIRELESS;
// Decide whether the signal is considered weak, medium or strong based on the // Decide whether the signal is considered weak, medium or strong based on the
// strength index. Each signal strength corresponds to a bucket which // strength index. Each signal strength corresponds to a bucket which
// attempted to be split evenly from |kNumNetworkImages| - 1. Remainders go // attempted to be split evenly from |kNumNetworkImages| - 1. Remainders go
// first to the lowest bucket and then the second lowest bucket. // first to the lowest bucket and then the second lowest bucket.
const int index = StrengthIndex(network->signal_strength()); const int index = StrengthIndex(strength);
if (index == 0) if (index == 0)
return SignalStrength::NONE; return SignalStrength::NONE;
const int seperations = kNumNetworkImages - 1; const int seperations = kNumNetworkImages - 1;
......
...@@ -15,17 +15,11 @@ ...@@ -15,17 +15,11 @@
#include "ui/gfx/image/canvas_image_source.h" #include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
namespace chromeos {
class NetworkState;
}
namespace ash { namespace ash {
namespace network_icon { namespace network_icon {
// TODO(stevenjb): Replace with network_config::mojom::NetworkStateProperties. // TODO(stevenjb): Replace with network_config::mojom::NetworkStateProperties.
struct ASH_EXPORT NetworkIconState { struct ASH_EXPORT NetworkIconState {
// Constructs a NetworkIconState from a NetworkState.
explicit NetworkIconState(const chromeos::NetworkState* network);
// Constructs a NetworkIconState from mojom::NetworkStateProperties. // Constructs a NetworkIconState from mojom::NetworkStateProperties.
explicit NetworkIconState( explicit NetworkIconState(
const chromeos::network_config::mojom::NetworkStateProperties* network); const chromeos::network_config::mojom::NetworkStateProperties* network);
...@@ -54,7 +48,7 @@ enum IconType { ...@@ -54,7 +48,7 @@ enum IconType {
}; };
// Strength of a wireless signal. // Strength of a wireless signal.
enum class SignalStrength { NONE, WEAK, MEDIUM, STRONG, NOT_WIRELESS }; enum class SignalStrength { NONE, WEAK, MEDIUM, STRONG };
// Returns true if |icon_state| is connected or portal. // Returns true if |icon_state| is connected or portal.
bool IsConnected(const NetworkIconState& icon_state); bool IsConnected(const NetworkIconState& icon_state);
...@@ -124,10 +118,8 @@ ASH_EXPORT void PurgeNetworkIconCache( ...@@ -124,10 +118,8 @@ ASH_EXPORT void PurgeNetworkIconCache(
const std::set<std::string>& network_guids); const std::set<std::string>& network_guids);
// Called by ChromeVox to give a verbal indication of the network icon. Returns // Called by ChromeVox to give a verbal indication of the network icon. Returns
// the signal strength of |network|, if it is a network type with a signal // a signal strength enum for |strength| value 0-100.
// strength. ASH_EXPORT SignalStrength GetSignalStrength(int strength);
ASH_EXPORT SignalStrength
GetSignalStrengthForNetwork(const chromeos::NetworkState* network);
} // namespace network_icon } // namespace network_icon
} // namespace ash } // namespace ash
......
This diff is collapsed.
...@@ -10,17 +10,8 @@ ...@@ -10,17 +10,8 @@
#include "ash/system/network/active_network_icon.h" #include "ash/system/network/active_network_icon.h"
#include "ash/system/network/network_icon.h" #include "ash/system/network/network_icon.h"
#include "base/logging.h" #include "base/logging.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "third_party/cros_system_api/dbus/service_constants.h"
#include "ui/gfx/image/image_skia.h" #include "ui/gfx/image/image_skia.h"
using chromeos::NetworkConnectionHandler;
using chromeos::NetworkHandler;
using chromeos::NetworkState;
using chromeos::NetworkStateHandler;
using chromeos::NetworkTypePattern;
namespace ash { namespace ash {
namespace tray { namespace tray {
......
...@@ -126,31 +126,34 @@ void NetworkTrayView::UpdateConnectionStatus( ...@@ -126,31 +126,34 @@ void NetworkTrayView::UpdateConnectionStatus(
IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED,
base::UTF8ToUTF16(connected_network->name())); base::UTF8ToUTF16(connected_network->name()));
// Retrieve the string describing the signal strength, if it is applicable if (connected_network->Matches(NetworkTypePattern::Wireless())) {
// to |connected_network|. // Retrieve the string describing the signal strength, if it is applicable
base::string16 signal_strength_string; // to |connected_network|.
switch (network_icon::GetSignalStrengthForNetwork(connected_network)) { base::string16 signal_strength_string;
case SignalStrength::NONE: switch (network_icon::GetSignalStrength(
case SignalStrength::NOT_WIRELESS: connected_network->signal_strength())) {
break; case SignalStrength::NONE:
case SignalStrength::WEAK: break;
signal_strength_string = case SignalStrength::WEAK:
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_SIGNAL_WEAK); signal_strength_string = l10n_util::GetStringUTF16(
break; IDS_ASH_STATUS_TRAY_NETWORK_SIGNAL_WEAK);
case SignalStrength::MEDIUM: break;
signal_strength_string = l10n_util::GetStringUTF16( case SignalStrength::MEDIUM:
IDS_ASH_STATUS_TRAY_NETWORK_SIGNAL_MEDIUM); signal_strength_string = l10n_util::GetStringUTF16(
break; IDS_ASH_STATUS_TRAY_NETWORK_SIGNAL_MEDIUM);
case SignalStrength::STRONG: break;
signal_strength_string = l10n_util::GetStringUTF16( case SignalStrength::STRONG:
IDS_ASH_STATUS_TRAY_NETWORK_SIGNAL_STRONG); signal_strength_string = l10n_util::GetStringUTF16(
break; IDS_ASH_STATUS_TRAY_NETWORK_SIGNAL_STRONG);
} break;
}
if (!signal_strength_string.empty()) {
new_connection_status_string = l10n_util::GetStringFUTF16( if (!signal_strength_string.empty()) {
IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED_ACCESSIBLE, new_connection_status_string = l10n_util::GetStringFUTF16(
base::UTF8ToUTF16(connected_network->name()), signal_strength_string); IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED_ACCESSIBLE,
base::UTF8ToUTF16(connected_network->name()),
signal_strength_string);
}
} }
connection_status_tooltip_ = new_connection_status_string; connection_status_tooltip_ = new_connection_status_string;
} else { } else {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "chromeos/components/tether/fake_active_host.h" #include "chromeos/components/tether/fake_active_host.h"
#include "chromeos/network/network_state.h" #include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_state_test_helper.h" #include "chromeos/network/network_state_test_helper.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chromeos/components/tether/network_configuration_remover.h" #include "chromeos/components/tether/network_configuration_remover.h"
#include "chromeos/components/tether/tether_session_completion_logger.h" #include "chromeos/components/tether/tether_session_completion_logger.h"
#include "chromeos/network/network_state.h" #include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_state_test_helper.h" #include "chromeos/network/network_state_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/cros_system_api/dbus/shill/dbus-constants.h" #include "third_party/cros_system_api/dbus/shill/dbus-constants.h"
......
...@@ -176,6 +176,8 @@ source_set("test_support") { ...@@ -176,6 +176,8 @@ source_set("test_support") {
"//base", "//base",
"//chromeos:test_utils", "//chromeos:test_utils",
"//chromeos/dbus:test_support", "//chromeos/dbus:test_support",
"//chromeos/services/network_config/public/cpp",
"//chromeos/services/network_config/public/mojom",
"//dbus", "//dbus",
"//net:test_support", "//net:test_support",
"//testing/gmock", "//testing/gmock",
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "chromeos/dbus/shill/shill_clients.h" #include "chromeos/dbus/shill/shill_clients.h"
#include "chromeos/network/network_state_handler.h" #include "chromeos/network/network_state_handler.h"
#include "chromeos/network/onc/onc_utils.h" #include "chromeos/network/onc/onc_utils.h"
#include "chromeos/services/network_config/public/cpp/cros_network_config_util.h"
#include "dbus/object_path.h" #include "dbus/object_path.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/cros_system_api/dbus/service_constants.h" #include "third_party/cros_system_api/dbus/service_constants.h"
...@@ -135,19 +136,52 @@ void NetworkStateTestHelper::SetServiceProperty(const std::string& service_path, ...@@ -135,19 +136,52 @@ void NetworkStateTestHelper::SetServiceProperty(const std::string& service_path,
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
} }
std::unique_ptr<NetworkState> network_config::mojom::NetworkStatePropertiesPtr
NetworkStateTestHelper::CreateStandaloneNetworkState( NetworkStateTestHelper::CreateStandaloneNetworkProperties(
const std::string& id, const std::string& id,
const std::string& type, network_config::mojom::NetworkType type,
const std::string& connection_state, network_config::mojom::ConnectionStateType connection_state,
int signal_strength) { int signal_strength) {
auto network = std::make_unique<NetworkState>(id); auto network = network_config::mojom::NetworkStateProperties::New();
network->SetGuid(id); network->guid = id;
network->set_name(id); network->name = id;
network->set_type(type); network->type = type;
network->set_visible(true); network->connection_state = connection_state;
network->SetConnectionState(connection_state); switch (type) {
network->set_signal_strength(signal_strength); case network_config::mojom::NetworkType::kAll:
case network_config::mojom::NetworkType::kMobile:
case network_config::mojom::NetworkType::kWireless:
NOTREACHED();
break;
case network_config::mojom::NetworkType::kCellular: {
auto cellular = network_config::mojom::CellularStateProperties::New();
cellular->signal_strength = signal_strength;
network->cellular = std::move(cellular);
break;
}
case network_config::mojom::NetworkType::kEthernet:
break;
case network_config::mojom::NetworkType::kTether: {
auto tether = network_config::mojom::TetherStateProperties::New();
tether->signal_strength = signal_strength;
network->tether = std::move(tether);
break;
}
case network_config::mojom::NetworkType::kVPN:
break;
case network_config::mojom::NetworkType::kWiFi: {
auto wifi = network_config::mojom::WiFiStateProperties::New();
wifi->signal_strength = signal_strength;
network->wifi = std::move(wifi);
break;
}
case network_config::mojom::NetworkType::kWiMAX: {
auto wimax = network_config::mojom::WiMAXStateProperties::New();
wimax->signal_strength = signal_strength;
network->wimax = std::move(wimax);
break;
}
}
return network; return network;
} }
......
...@@ -13,10 +13,12 @@ ...@@ -13,10 +13,12 @@
#include "chromeos/dbus/shill/shill_manager_client.h" #include "chromeos/dbus/shill/shill_manager_client.h"
#include "chromeos/dbus/shill/shill_profile_client.h" #include "chromeos/dbus/shill/shill_profile_client.h"
#include "chromeos/dbus/shill/shill_service_client.h" #include "chromeos/dbus/shill/shill_service_client.h"
#include "chromeos/network/network_state_handler.h" #include "chromeos/services/network_config/public/mojom/cros_network_config.mojom.h"
namespace chromeos { namespace chromeos {
class NetworkStateHandler;
// Helper class for tests that use NetworkStateHandler. Handles initialization, // Helper class for tests that use NetworkStateHandler. Handles initialization,
// shutdown, and adds default profiles and a wifi device (but no services). // shutdown, and adds default profiles and a wifi device (but no services).
// NOTE: This is not intended to be used with NetworkHandler::Initialize() // NOTE: This is not intended to be used with NetworkHandler::Initialize()
...@@ -57,10 +59,11 @@ class NetworkStateTestHelper { ...@@ -57,10 +59,11 @@ class NetworkStateTestHelper {
const std::string& key, const std::string& key,
const base::Value& value); const base::Value& value);
std::unique_ptr<NetworkState> CreateStandaloneNetworkState( network_config::mojom::NetworkStatePropertiesPtr
CreateStandaloneNetworkProperties(
const std::string& id, const std::string& id,
const std::string& type, network_config::mojom::NetworkType type,
const std::string& connection_state, network_config::mojom::ConnectionStateType connection_state,
int signal_strength); int signal_strength);
// Returns the path used for the shared and user profiles. // Returns the path used for the shared and user profiles.
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "chromeos/network/managed_network_configuration_handler_impl.h" #include "chromeos/network/managed_network_configuration_handler_impl.h"
#include "chromeos/network/network_configuration_handler.h" #include "chromeos/network/network_configuration_handler.h"
#include "chromeos/network/network_profile_handler.h" #include "chromeos/network/network_profile_handler.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_state_test_helper.h" #include "chromeos/network/network_state_test_helper.h"
#include "chromeos/network/onc/onc_utils.h" #include "chromeos/network/onc/onc_utils.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
......
...@@ -117,9 +117,8 @@ mojom::DeviceStateType GetMojoDeviceStateType( ...@@ -117,9 +117,8 @@ mojom::DeviceStateType GetMojoDeviceStateType(
return mojom::DeviceStateType::kUnavailable; return mojom::DeviceStateType::kUnavailable;
} }
mojom::NetworkStatePropertiesPtr NetworkStateToMojo( mojom::NetworkStatePropertiesPtr NetworkStateToMojo(const NetworkState* network,
NetworkStateHandler* network_state_handler, const DeviceState* device) {
const NetworkState* network) {
mojom::NetworkType type = ShillTypeToMojo(network->type()); mojom::NetworkType type = ShillTypeToMojo(network->type());
if (type == mojom::NetworkType::kAll) { if (type == mojom::NetworkType::kAll) {
NET_LOG(ERROR) << "Unexpected network type: " << network->type() NET_LOG(ERROR) << "Unexpected network type: " << network->type()
...@@ -157,8 +156,6 @@ mojom::NetworkStatePropertiesPtr NetworkStateToMojo( ...@@ -157,8 +156,6 @@ mojom::NetworkStatePropertiesPtr NetworkStateToMojo(
onc::kNetworkTechnologyTable); onc::kNetworkTechnologyTable);
cellular->roaming = network->IndicateRoaming(); cellular->roaming = network->IndicateRoaming();
cellular->signal_strength = network->signal_strength(); cellular->signal_strength = network->signal_strength();
const DeviceState* device =
network_state_handler->GetDeviceState(network->device_path());
if (device) { if (device) {
cellular->scanning = device->scanning(); cellular->scanning = device->scanning();
cellular->sim_absent = device->IsSimAbsent(); cellular->sim_absent = device->IsSimAbsent();
...@@ -223,8 +220,8 @@ mojom::NetworkStatePropertiesPtr NetworkStateToMojo( ...@@ -223,8 +220,8 @@ mojom::NetworkStatePropertiesPtr NetworkStateToMojo(
} }
mojom::DeviceStatePropertiesPtr DeviceStateToMojo( mojom::DeviceStatePropertiesPtr DeviceStateToMojo(
NetworkStateHandler* network_state_handler, const DeviceState* device,
const DeviceState* device) { mojom::DeviceStateType technology_state) {
mojom::NetworkType type = ShillTypeToMojo(device->type()); mojom::NetworkType type = ShillTypeToMojo(device->type());
if (type == mojom::NetworkType::kAll) { if (type == mojom::NetworkType::kAll) {
NET_LOG(ERROR) << "Unexpected device type: " << device->type() NET_LOG(ERROR) << "Unexpected device type: " << device->type()
...@@ -232,17 +229,10 @@ mojom::DeviceStatePropertiesPtr DeviceStateToMojo( ...@@ -232,17 +229,10 @@ mojom::DeviceStatePropertiesPtr DeviceStateToMojo(
return nullptr; return nullptr;
} }
mojom::DeviceStateType state =
GetMojoDeviceStateType(network_state_handler->GetTechnologyState(
NetworkTypePattern::Primitive(device->type())));
if (state == mojom::DeviceStateType::kUnavailable) {
NET_LOG(ERROR) << "Device state unavailable";
return nullptr;
}
auto result = mojom::DeviceStateProperties::New(); auto result = mojom::DeviceStateProperties::New();
result->type = type; result->type = type;
result->scanning = device->scanning(); result->scanning = device->scanning();
result->state = state; result->state = technology_state;
result->managed_network_available = result->managed_network_available =
!device->available_managed_network_path().empty(); !device->available_managed_network_path().empty();
...@@ -290,7 +280,8 @@ void CrosNetworkConfig::GetNetworkState(const std::string& guid, ...@@ -290,7 +280,8 @@ void CrosNetworkConfig::GetNetworkState(const std::string& guid,
std::move(callback).Run(nullptr); std::move(callback).Run(nullptr);
return; return;
} }
std::move(callback).Run(NetworkStateToMojo(network_state_handler_, network)); std::move(callback).Run(NetworkStateToMojo(
network, network_state_handler_->GetDeviceState(network->device_path())));
} }
void CrosNetworkConfig::GetNetworkStateList( void CrosNetworkConfig::GetNetworkStateList(
...@@ -323,8 +314,9 @@ void CrosNetworkConfig::GetNetworkStateList( ...@@ -323,8 +314,9 @@ void CrosNetworkConfig::GetNetworkStateList(
} }
std::vector<mojom::NetworkStatePropertiesPtr> result; std::vector<mojom::NetworkStatePropertiesPtr> result;
for (const NetworkState* network : networks) { for (const NetworkState* network : networks) {
mojom::NetworkStatePropertiesPtr mojo_network = mojom::NetworkStatePropertiesPtr mojo_network = NetworkStateToMojo(
NetworkStateToMojo(network_state_handler_, network); network,
network_state_handler_->GetDeviceState(network->device_path()));
if (mojo_network) if (mojo_network)
result.emplace_back(std::move(mojo_network)); result.emplace_back(std::move(mojo_network));
} }
...@@ -337,8 +329,15 @@ void CrosNetworkConfig::GetDeviceStateList( ...@@ -337,8 +329,15 @@ void CrosNetworkConfig::GetDeviceStateList(
network_state_handler_->GetDeviceList(&devices); network_state_handler_->GetDeviceList(&devices);
std::vector<mojom::DeviceStatePropertiesPtr> result; std::vector<mojom::DeviceStatePropertiesPtr> result;
for (const DeviceState* device : devices) { for (const DeviceState* device : devices) {
mojom::DeviceStateType technology_state =
GetMojoDeviceStateType(network_state_handler_->GetTechnologyState(
NetworkTypePattern::Primitive(device->type())));
if (technology_state == mojom::DeviceStateType::kUnavailable) {
NET_LOG(ERROR) << "Device state unavailable: " << device->name();
continue;
}
mojom::DeviceStatePropertiesPtr mojo_device = mojom::DeviceStatePropertiesPtr mojo_device =
DeviceStateToMojo(network_state_handler_, device); DeviceStateToMojo(device, technology_state);
if (mojo_device) if (mojo_device)
result.emplace_back(std::move(mojo_device)); result.emplace_back(std::move(mojo_device));
} }
...@@ -362,8 +361,9 @@ void CrosNetworkConfig::ActiveNetworksChanged( ...@@ -362,8 +361,9 @@ void CrosNetworkConfig::ActiveNetworksChanged(
const std::vector<const NetworkState*>& active_networks) { const std::vector<const NetworkState*>& active_networks) {
std::vector<mojom::NetworkStatePropertiesPtr> result; std::vector<mojom::NetworkStatePropertiesPtr> result;
for (const NetworkState* network : active_networks) { for (const NetworkState* network : active_networks) {
mojom::NetworkStatePropertiesPtr mojo_network = mojom::NetworkStatePropertiesPtr mojo_network = NetworkStateToMojo(
NetworkStateToMojo(network_state_handler_, network); network,
network_state_handler_->GetDeviceState(network->device_path()));
if (mojo_network) if (mojo_network)
result.emplace_back(std::move(mojo_network)); result.emplace_back(std::move(mojo_network));
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "chromeos/services/network_config/network_config_service.h" #include "chromeos/services/network_config/network_config_service.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/services/network_config/public/cpp/cros_network_config_test_helper.h" #include "chromeos/services/network_config/public/cpp/cros_network_config_test_helper.h"
#include "chromeos/services/network_config/public/cpp/cros_network_config_test_observer.h" #include "chromeos/services/network_config/public/cpp/cros_network_config_test_observer.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
......
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