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

Status Tray: Network List: Fix edge cases

This fixes a few edge cases in the status tray network list:
* Crash when an existing guid moves to the end of the list.
* Incorrect filtering out of EthernetEAP in system tray
  (and other code). Mostly harmless but generates extra work.
* More readable/searchable filtering of default cellular network.

Bug: None
Change-Id: I66b075ed90d3332178f0c1caebcf457c2db15da5
Reviewed-on: https://chromium-review.googlesource.com/920790Reviewed-by: default avatarJenny Zhang <jennyz@chromium.org>
Commit-Queue: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537437}
parent d76f98f5
...@@ -567,7 +567,7 @@ void NetworkListView::UpdateNetworks( ...@@ -567,7 +567,7 @@ void NetworkListView::UpdateNetworks(
if (!NetworkTypePattern::NonVirtual().MatchesType(network->type())) if (!NetworkTypePattern::NonVirtual().MatchesType(network->type()))
continue; continue;
// If cellular is disabled, skip the default cellular service. // If cellular is disabled, skip the default cellular service.
if (network->Matches(NetworkTypePattern::Cellular()) && !cellular_enabled) if (network->IsDefaultCellular() && !cellular_enabled)
continue; continue;
network_list_.push_back(std::make_unique<NetworkInfo>(network->guid())); network_list_.push_back(std::make_unique<NetworkInfo>(network->guid()));
} }
...@@ -842,18 +842,21 @@ std::unique_ptr<std::set<std::string>> NetworkListView::UpdateNetworkChildren( ...@@ -842,18 +842,21 @@ std::unique_ptr<std::set<std::string>> NetworkListView::UpdateNetworkChildren(
for (const auto& info : network_list_) { for (const auto& info : network_list_) {
if (info->type != type) if (info->type != type)
continue; continue;
UpdateNetworkChild(index++, info.get()); if (UpdateNetworkChild(index, info.get()))
++index;
new_guids->insert(info->guid); new_guids->insert(info->guid);
} }
return new_guids; return new_guids;
} }
void NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) { bool NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) {
bool added = false;
HoverHighlightView* network_view = nullptr; HoverHighlightView* network_view = nullptr;
NetworkGuidMap::const_iterator found = network_guid_map_.find(info->guid); NetworkGuidMap::const_iterator found = network_guid_map_.find(info->guid);
if (found == network_guid_map_.end()) { if (found == network_guid_map_.end()) {
network_view = new HoverHighlightView(this); network_view = new HoverHighlightView(this);
UpdateViewForNetwork(network_view, *info); UpdateViewForNetwork(network_view, *info);
added = true;
} else { } else {
network_view = found->second; network_view = found->second;
if (NeedUpdateViewForNetwork(*info)) if (NeedUpdateViewForNetwork(*info))
...@@ -864,6 +867,7 @@ void NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) { ...@@ -864,6 +867,7 @@ void NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) {
network_view->SetEnabled(false); network_view->SetEnabled(false);
network_map_[network_view] = info->guid; network_map_[network_view] = info->guid;
network_guid_map_[info->guid] = network_view; network_guid_map_[info->guid] = network_view;
return added;
} }
void NetworkListView::PlaceViewAtIndex(views::View* view, int index) { void NetworkListView::PlaceViewAtIndex(views::View* view, int index) {
...@@ -871,8 +875,10 @@ void NetworkListView::PlaceViewAtIndex(views::View* view, int index) { ...@@ -871,8 +875,10 @@ void NetworkListView::PlaceViewAtIndex(views::View* view, int index) {
scroll_content()->AddChildViewAt(view, index); scroll_content()->AddChildViewAt(view, index);
} else { } else {
// No re-order and re-layout is necessary if |view| is already at |index|. // No re-order and re-layout is necessary if |view| is already at |index|.
if (scroll_content()->child_at(index) == view) if (index < scroll_content()->child_count() &&
scroll_content()->child_at(index) == view) {
return; return;
}
scroll_content()->ReorderChildView(view, index); scroll_content()->ReorderChildView(view, index);
} }
needs_relayout_ = true; needs_relayout_ = true;
......
...@@ -93,7 +93,8 @@ class NetworkListView : public NetworkStateListDetailedView, ...@@ -93,7 +93,8 @@ class NetworkListView : public NetworkStateListDetailedView,
std::unique_ptr<std::set<std::string>> UpdateNetworkChildren( std::unique_ptr<std::set<std::string>> UpdateNetworkChildren(
NetworkInfo::Type type, NetworkInfo::Type type,
int child_index); int child_index);
void UpdateNetworkChild(int index, const NetworkInfo* info); // Returns true if a new child was added.
bool UpdateNetworkChild(int index, const NetworkInfo* info);
// Reorders children of |scroll_content()| as necessary placing |view| at // Reorders children of |scroll_content()| as necessary placing |view| at
// |index|. // |index|.
......
...@@ -80,7 +80,7 @@ NetworkTypePattern NetworkTypePattern::Physical() { ...@@ -80,7 +80,7 @@ NetworkTypePattern NetworkTypePattern::Physical() {
// static // static
NetworkTypePattern NetworkTypePattern::NonVirtual() { NetworkTypePattern NetworkTypePattern::NonVirtual() {
return NetworkTypePattern(~(kNetworkTypeVPN)); return NetworkTypePattern(~(kNetworkTypeVPN | kNetworkTypeEthernetEap));
} }
// static // static
......
...@@ -26,7 +26,7 @@ class CHROMEOS_EXPORT NetworkTypePattern { ...@@ -26,7 +26,7 @@ class CHROMEOS_EXPORT NetworkTypePattern {
// Matches Physical networks (i.e. excludes Tether and VPN). // Matches Physical networks (i.e. excludes Tether and VPN).
static NetworkTypePattern Physical(); static NetworkTypePattern Physical();
// Matches non virtual networks. // Excludes virtual networks and EthernetEAP.
static NetworkTypePattern NonVirtual(); static NetworkTypePattern NonVirtual();
// Matches ethernet networks. // Matches ethernet networks.
......
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