Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: ash/common/system/chromeos/network/network_list.cc

Issue 2698473007: Convert path usage in NetworkListViewBase subclasses to use guids. (Closed)
Patch Set: Tweak NetworkPortalNotificationControllerTest to create GUIDs for new NetworkStates. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/system/chromeos/network/network_list.h" 5 #include "ash/common/system/chromeos/network/network_list.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "ash/common/system/chromeos/network/network_icon.h" 9 #include "ash/common/system/chromeos/network/network_icon.h"
10 #include "ash/common/system/chromeos/network/network_icon_animation.h" 10 #include "ash/common/system/chromeos/network/network_icon_animation.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 CHECK(container()); 78 CHECK(container());
79 NetworkStateHandler::NetworkStateList network_list; 79 NetworkStateHandler::NetworkStateList network_list;
80 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 80 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
81 handler->GetVisibleNetworkList(&network_list); 81 handler->GetVisibleNetworkList(&network_list);
82 UpdateNetworks(network_list); 82 UpdateNetworks(network_list);
83 UpdateNetworkIcons(); 83 UpdateNetworkIcons();
84 UpdateNetworkListInternal(); 84 UpdateNetworkListInternal();
85 } 85 }
86 86
87 bool NetworkListView::IsNetworkEntry(views::View* view, 87 bool NetworkListView::IsNetworkEntry(views::View* view,
88 std::string* service_path) const { 88 std::string* guid) const {
89 std::map<views::View*, std::string>::const_iterator found = 89 std::map<views::View*, std::string>::const_iterator found =
90 network_map_.find(view); 90 network_map_.find(view);
91 if (found == network_map_.end()) 91 if (found == network_map_.end())
92 return false; 92 return false;
93 *service_path = found->second; 93 *guid = found->second;
94 return true; 94 return true;
95 } 95 }
96 96
97 void NetworkListView::UpdateNetworks( 97 void NetworkListView::UpdateNetworks(
98 const NetworkStateHandler::NetworkStateList& networks) { 98 const NetworkStateHandler::NetworkStateList& networks) {
99 SCOPED_NET_LOG_IF_SLOW(); 99 SCOPED_NET_LOG_IF_SLOW();
100 network_list_.clear(); 100 network_list_.clear();
101 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); 101 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern();
102 for (NetworkStateHandler::NetworkStateList::const_iterator iter = 102 for (NetworkStateHandler::NetworkStateList::const_iterator iter =
103 networks.begin(); 103 networks.begin();
104 iter != networks.end(); ++iter) { 104 iter != networks.end(); ++iter) {
105 const chromeos::NetworkState* network = *iter; 105 const chromeos::NetworkState* network = *iter;
106 if (!pattern.MatchesType(network->type())) 106 if (!pattern.MatchesType(network->type()))
107 continue; 107 continue;
108 network_list_.push_back(base::MakeUnique<NetworkInfo>(network->path())); 108 network_list_.push_back(base::MakeUnique<NetworkInfo>(network->guid()));
109 } 109 }
110 } 110 }
111 111
112 void NetworkListView::UpdateNetworkIcons() { 112 void NetworkListView::UpdateNetworkIcons() {
113 SCOPED_NET_LOG_IF_SLOW(); 113 SCOPED_NET_LOG_IF_SLOW();
114 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 114 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
115 115
116 // First, update state for all networks 116 // First, update state for all networks
117 bool animating = false; 117 bool animating = false;
118 118
119 for (auto& info : network_list_) { 119 for (auto& info : network_list_) {
120 const chromeos::NetworkState* network = 120 const chromeos::NetworkState* network =
121 handler->GetNetworkState(info->service_path); 121 handler->GetNetworkStateFromGuid(info->guid);
122 if (!network) 122 if (!network)
123 continue; 123 continue;
124 bool prohibited_by_policy = IsProhibitedByPolicy(network); 124 bool prohibited_by_policy = IsProhibitedByPolicy(network);
125 info->image = 125 info->image =
126 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); 126 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST);
127 info->label = 127 info->label =
128 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST); 128 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST);
129 info->highlight = 129 info->highlight =
130 network->IsConnectedState() || network->IsConnectingState(); 130 network->IsConnectedState() || network->IsConnectingState();
131 info->disable = 131 info->disable =
(...skipping 13 matching lines...) Expand all
145 if (animating) 145 if (animating)
146 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 146 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
147 else 147 else
148 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 148 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
149 } 149 }
150 150
151 void NetworkListView::UpdateNetworkListInternal() { 151 void NetworkListView::UpdateNetworkListInternal() {
152 SCOPED_NET_LOG_IF_SLOW(); 152 SCOPED_NET_LOG_IF_SLOW();
153 // Get the updated list entries 153 // Get the updated list entries
154 network_map_.clear(); 154 network_map_.clear();
155 std::set<std::string> new_service_paths; 155 std::set<std::string> new_guids;
156 bool needs_relayout = UpdateNetworkListEntries(&new_service_paths); 156 bool needs_relayout = UpdateNetworkListEntries(&new_guids);
157 157
158 // Remove old children 158 // Remove old children
159 std::set<std::string> remove_service_paths; 159 std::set<std::string> remove_guids;
160 for (ServicePathMap::const_iterator it = service_path_map_.begin(); 160 for (NetworkGuidMap::const_iterator it = network_guid_map_.begin();
161 it != service_path_map_.end(); ++it) { 161 it != network_guid_map_.end(); ++it) {
162 if (new_service_paths.find(it->first) == new_service_paths.end()) { 162 if (new_guids.find(it->first) == new_guids.end()) {
163 remove_service_paths.insert(it->first); 163 remove_guids.insert(it->first);
164 network_map_.erase(it->second); 164 network_map_.erase(it->second);
165 delete it->second; 165 delete it->second;
166 needs_relayout = true; 166 needs_relayout = true;
167 } 167 }
168 } 168 }
169 169
170 for (std::set<std::string>::const_iterator remove_it = 170 for (std::set<std::string>::const_iterator remove_it = remove_guids.begin();
171 remove_service_paths.begin(); 171 remove_it != remove_guids.end(); ++remove_it) {
172 remove_it != remove_service_paths.end(); ++remove_it) { 172 network_guid_map_.erase(*remove_it);
173 service_path_map_.erase(*remove_it);
174 } 173 }
175 174
176 if (needs_relayout) 175 if (needs_relayout)
177 HandleRelayout(); 176 HandleRelayout();
178 } 177 }
179 178
180 void NetworkListView::HandleRelayout() { 179 void NetworkListView::HandleRelayout() {
181 views::View* selected_view = nullptr; 180 views::View* selected_view = nullptr;
182 for (auto& iter : service_path_map_) { 181 for (auto& iter : network_guid_map_) {
183 if (delegate_->IsViewHovered(iter.second)) { 182 if (delegate_->IsViewHovered(iter.second)) {
184 selected_view = iter.second; 183 selected_view = iter.second;
185 break; 184 break;
186 } 185 }
187 } 186 }
188 container()->SizeToPreferredSize(); 187 container()->SizeToPreferredSize();
189 delegate_->RelayoutScrollList(); 188 delegate_->RelayoutScrollList();
190 if (selected_view) 189 if (selected_view)
191 container()->ScrollRectToVisible(selected_view->bounds()); 190 container()->ScrollRectToVisible(selected_view->bounds());
192 } 191 }
193 192
194 bool NetworkListView::UpdateNetworkListEntries( 193 bool NetworkListView::UpdateNetworkListEntries(
195 std::set<std::string>* new_service_paths) { 194 std::set<std::string>* new_guids) {
196 bool needs_relayout = false; 195 bool needs_relayout = false;
197 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 196 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
198 197
199 // Insert child views 198 // Insert child views
200 int index = 0; 199 int index = 0;
201 200
202 // Highlighted networks 201 // Highlighted networks
203 needs_relayout |= 202 needs_relayout |=
204 UpdateNetworkChildren(new_service_paths, &index, true /* highlighted */); 203 UpdateNetworkChildren(new_guids, &index, true /* highlighted */);
205 204
206 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); 205 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern();
207 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) { 206 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) {
208 // Cellular initializing 207 // Cellular initializing
209 int message_id = network_icon::GetCellularUninitializedMsg(); 208 int message_id = network_icon::GetCellularUninitializedMsg();
210 if (!message_id && 209 if (!message_id &&
211 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && 210 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) &&
212 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { 211 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) {
213 message_id = IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS; 212 message_id = IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS;
214 } 213 }
(...skipping 12 matching lines...) Expand all
227 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED 226 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED
228 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; 227 : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
229 } 228 }
230 needs_relayout |= 229 needs_relayout |=
231 UpdateInfoLabel(message_id, index, &no_wifi_networks_view_); 230 UpdateInfoLabel(message_id, index, &no_wifi_networks_view_);
232 if (message_id) 231 if (message_id)
233 ++index; 232 ++index;
234 } 233 }
235 234
236 // Un-highlighted networks 235 // Un-highlighted networks
237 needs_relayout |= UpdateNetworkChildren(new_service_paths, &index, 236 needs_relayout |=
238 false /* not highlighted */); 237 UpdateNetworkChildren(new_guids, &index, false /* not highlighted */);
239 238
240 // No networks or other messages (fallback) 239 // No networks or other messages (fallback)
241 if (index == 0) { 240 if (index == 0) {
242 needs_relayout |= UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index, 241 needs_relayout |= UpdateInfoLabel(IDS_ASH_STATUS_TRAY_NO_NETWORKS, index,
243 &no_wifi_networks_view_); 242 &no_wifi_networks_view_);
244 } 243 }
245 244
246 return needs_relayout; 245 return needs_relayout;
247 } 246 }
248 247
249 bool NetworkListView::UpdateNetworkChildren( 248 bool NetworkListView::UpdateNetworkChildren(std::set<std::string>* new_guids,
250 std::set<std::string>* new_service_paths, 249 int* child_index,
251 int* child_index, 250 bool highlighted) {
252 bool highlighted) {
253 bool needs_relayout = false; 251 bool needs_relayout = false;
254 int index = *child_index; 252 int index = *child_index;
255 for (auto& info : network_list_) { 253 for (auto& info : network_list_) {
256 if (info->highlight != highlighted) 254 if (info->highlight != highlighted)
257 continue; 255 continue;
258 needs_relayout |= UpdateNetworkChild(index++, info.get()); 256 needs_relayout |= UpdateNetworkChild(index++, info.get());
259 new_service_paths->insert(info->service_path); 257 new_guids->insert(info->guid);
260 } 258 }
261 *child_index = index; 259 *child_index = index;
262 return needs_relayout; 260 return needs_relayout;
263 } 261 }
264 262
265 bool NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) { 263 bool NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) {
266 bool needs_relayout = false; 264 bool needs_relayout = false;
267 views::View* network_view = nullptr; 265 views::View* network_view = nullptr;
268 ServicePathMap::const_iterator found = 266 NetworkGuidMap::const_iterator found = network_guid_map_.find(info->guid);
269 service_path_map_.find(info->service_path); 267 if (found == network_guid_map_.end()) {
270 if (found == service_path_map_.end()) {
271 network_view = delegate_->CreateViewForNetwork(*info); 268 network_view = delegate_->CreateViewForNetwork(*info);
272 container()->AddChildViewAt(network_view, index); 269 container()->AddChildViewAt(network_view, index);
273 needs_relayout = true; 270 needs_relayout = true;
274 } else { 271 } else {
275 network_view = found->second; 272 network_view = found->second;
276 network_view->RemoveAllChildViews(true); 273 network_view->RemoveAllChildViews(true);
277 delegate_->UpdateViewForNetwork(network_view, *info); 274 delegate_->UpdateViewForNetwork(network_view, *info);
278 network_view->Layout(); 275 network_view->Layout();
279 network_view->SchedulePaint(); 276 network_view->SchedulePaint();
280 needs_relayout = PlaceViewAtIndex(network_view, index); 277 needs_relayout = PlaceViewAtIndex(network_view, index);
281 } 278 }
282 if (info->disable) 279 if (info->disable)
283 network_view->SetEnabled(false); 280 network_view->SetEnabled(false);
284 network_map_[network_view] = info->service_path; 281 network_map_[network_view] = info->guid;
285 service_path_map_[info->service_path] = network_view; 282 network_guid_map_[info->guid] = network_view;
286 return needs_relayout; 283 return needs_relayout;
287 } 284 }
288 285
289 bool NetworkListView::PlaceViewAtIndex(views::View* view, int index) { 286 bool NetworkListView::PlaceViewAtIndex(views::View* view, int index) {
290 if (container()->child_at(index) == view) 287 if (container()->child_at(index) == view)
291 return false; 288 return false;
292 container()->ReorderChildView(view, index); 289 container()->ReorderChildView(view, index);
293 return true; 290 return true;
294 } 291 }
295 292
(...skipping 20 matching lines...) Expand all
316 needs_relayout = true; 313 needs_relayout = true;
317 } 314 }
318 return needs_relayout; 315 return needs_relayout;
319 } 316 }
320 317
321 void NetworkListView::NetworkIconChanged() { 318 void NetworkListView::NetworkIconChanged() {
322 Update(); 319 Update();
323 } 320 }
324 321
325 } // namespace ash 322 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/network/network_list.h ('k') | ash/common/system/chromeos/network/network_list_md.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698