Commit 1e0ea868 authored by Steven Bennetts's avatar Steven Bennetts Committed by Commit Bot

network_icon: Use GUID instead of path to track state in cache

NetworkHandler uses Shill service paths to identify network services,
but the forthcoming mojo API and the rest of the UI code uses GUID
so this code needs to switch to GUID to support the mojo API.

Bug: 923444
Change-Id: I739b36762b6f380ae70e054eba9284bad2773ba9
Reviewed-on: https://chromium-review.googlesource.com/c/1470939
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#636603}
parent 89a33901
......@@ -39,7 +39,7 @@ namespace {
// class used for maintaining a map of network state and images.
class NetworkIconImpl {
public:
NetworkIconImpl(const std::string& path,
NetworkIconImpl(const std::string& guid,
IconType icon_type,
NetworkType network_type);
......@@ -106,14 +106,14 @@ NetworkIconMap* GetIconMap(IconType icon_type) {
}
void PurgeIconMap(IconType icon_type,
const std::set<std::string>& network_paths) {
const std::set<std::string>& network_guids) {
NetworkIconMap* icon_map = GetIconMapInstance(icon_type, false);
if (!icon_map)
return;
for (NetworkIconMap::iterator loop_iter = icon_map->begin();
loop_iter != icon_map->end();) {
NetworkIconMap::iterator cur_iter = loop_iter++;
if (network_paths.count(cur_iter->first) == 0) {
if (network_guids.count(cur_iter->first) == 0) {
delete cur_iter->second;
icon_map->erase(cur_iter);
}
......@@ -304,7 +304,7 @@ gfx::ImageSkia GetConnectingVpnImage(IconType icon_type) {
} // namespace
NetworkIconState::NetworkIconState(const chromeos::NetworkState* network) {
path = network->path();
guid = network->guid();
name = network->name();
const std::string& network_type = network->type();
......@@ -361,7 +361,7 @@ NetworkIconState::~NetworkIconState() = default;
//------------------------------------------------------------------------------
// NetworkIconImpl
NetworkIconImpl::NetworkIconImpl(const std::string& path,
NetworkIconImpl::NetworkIconImpl(const std::string& guid,
IconType icon_type,
NetworkType network_type)
: icon_type_(icon_type) {
......@@ -471,11 +471,11 @@ NetworkIconImpl* FindAndUpdateImageImpl(const NetworkIconState& network,
// Find or add the icon.
NetworkIconMap* icon_map = GetIconMap(icon_type);
NetworkIconImpl* icon;
NetworkIconMap::iterator iter = icon_map->find(network.path);
NetworkIconMap::iterator iter = icon_map->find(network.guid);
if (iter == icon_map->end()) {
VLOG(1) << "new NetworkIconImpl: " << network.name;
icon = new NetworkIconImpl(network.path, icon_type, network.type);
icon_map->insert(std::make_pair(network.path, icon));
icon = new NetworkIconImpl(network.guid, icon_type, network.type);
icon_map->insert(std::make_pair(network.guid, icon));
} else {
VLOG(1) << "found NetworkIconImpl: " << network.name;
icon = iter->second;
......@@ -644,12 +644,12 @@ base::string16 GetLabelForNetwork(const NetworkIconState& network,
return base::UTF8ToUTF16(network.name);
}
void PurgeNetworkIconCache(const std::set<std::string>& network_paths) {
PurgeIconMap(ICON_TYPE_TRAY_OOBE, network_paths);
PurgeIconMap(ICON_TYPE_TRAY_REGULAR, network_paths);
PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths);
PurgeIconMap(ICON_TYPE_LIST, network_paths);
PurgeIconMap(ICON_TYPE_MENU_LIST, network_paths);
void PurgeNetworkIconCache(const std::set<std::string>& network_guids) {
PurgeIconMap(ICON_TYPE_TRAY_OOBE, network_guids);
PurgeIconMap(ICON_TYPE_TRAY_REGULAR, network_guids);
PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_guids);
PurgeIconMap(ICON_TYPE_LIST, network_guids);
PurgeIconMap(ICON_TYPE_MENU_LIST, network_guids);
}
SignalStrength GetSignalStrengthForNetwork(
......
......@@ -46,7 +46,7 @@ struct ASH_EXPORT NetworkIconState {
NetworkIconState& operator=(const NetworkIconState& other);
~NetworkIconState();
std::string path;
std::string guid;
std::string name;
NetworkType type;
ConnectionStateType connection_state;
......@@ -128,10 +128,10 @@ ASH_EXPORT gfx::ImageSkia GetImageForNewWifiNetwork(SkColor icon_color,
ASH_EXPORT base::string16 GetLabelForNetwork(const NetworkIconState&,
IconType icon_type);
// Called periodically with the current list of network paths. Removes cached
// Called periodically with the current list of network guids. Removes cached
// entries that are no longer in the list.
ASH_EXPORT void PurgeNetworkIconCache(
const std::set<std::string>& network_paths);
const std::set<std::string>& network_guids);
// 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
......
......@@ -21,12 +21,12 @@ void PurgeNetworkIconCache() {
NetworkStateHandler::NetworkStateList networks;
NetworkHandler::Get()->network_state_handler()->GetVisibleNetworkList(
&networks);
std::set<std::string> network_paths;
std::set<std::string> network_guids;
for (NetworkStateHandler::NetworkStateList::iterator iter = networks.begin();
iter != networks.end(); ++iter) {
network_paths.insert((*iter)->path());
network_guids.insert((*iter)->guid());
}
network_icon::PurgeNetworkIconCache(network_paths);
network_icon::PurgeNetworkIconCache(network_guids);
}
} // namespace
......
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