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

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

Issue 2936743003: Don't re-sort Chrome OS wifi network list (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/system/network/network_list.h" 5 #include "ash/system/network/network_list.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility>
8 9
9 #include "ash/resources/vector_icons/vector_icons.h" 10 #include "ash/resources/vector_icons/vector_icons.h"
10 #include "ash/shell.h" 11 #include "ash/shell.h"
11 #include "ash/shell_port.h" 12 #include "ash/shell_port.h"
12 #include "ash/strings/grit/ash_strings.h" 13 #include "ash/strings/grit/ash_strings.h"
13 #include "ash/system/network/network_icon.h" 14 #include "ash/system/network/network_icon.h"
14 #include "ash/system/network/network_icon_animation.h" 15 #include "ash/system/network/network_icon_animation.h"
15 #include "ash/system/network/network_info.h" 16 #include "ash/system/network/network_info.h"
16 #include "ash/system/network/network_state_list_detailed_view.h" 17 #include "ash/system/network/network_state_list_detailed_view.h"
17 #include "ash/system/networking_config_delegate.h" 18 #include "ash/system/networking_config_delegate.h"
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 // Add Tether networks. 321 // Add Tether networks.
321 NetworkStateHandler::NetworkStateList tether_network_list; 322 NetworkStateHandler::NetworkStateList tether_network_list;
322 handler->GetVisibleNetworkListByType(NetworkTypePattern::Tether(), 323 handler->GetVisibleNetworkListByType(NetworkTypePattern::Tether(),
323 &tether_network_list); 324 &tether_network_list);
324 for (const auto* tether_network : tether_network_list) { 325 for (const auto* tether_network : tether_network_list) {
325 network_list_.push_back( 326 network_list_.push_back(
326 base::MakeUnique<NetworkInfo>(tether_network->guid())); 327 base::MakeUnique<NetworkInfo>(tether_network->guid()));
327 } 328 }
328 329
329 UpdateNetworkIcons(); 330 UpdateNetworkIcons();
330 OrderNetworks();
331 UpdateNetworkListInternal(); 331 UpdateNetworkListInternal();
332 } 332 }
333 333
334 bool NetworkListView::IsNetworkEntry(views::View* view, 334 bool NetworkListView::IsNetworkEntry(views::View* view,
335 std::string* guid) const { 335 std::string* guid) const {
336 std::map<views::View*, std::string>::const_iterator found = 336 std::map<views::View*, std::string>::const_iterator found =
337 network_map_.find(view); 337 network_map_.find(view);
338 if (found == network_map_.end()) 338 if (found == network_map_.end())
339 return false; 339 return false;
340 *guid = found->second; 340 *guid = found->second;
(...skipping 16 matching lines...) Expand all
357 357
358 // Do not add Wi-Fi networks that are associated with a Tether network. 358 // Do not add Wi-Fi networks that are associated with a Tether network.
359 if (NetworkTypePattern::WiFi().MatchesType(network->type()) && 359 if (NetworkTypePattern::WiFi().MatchesType(network->type()) &&
360 !network->tether_guid().empty()) 360 !network->tether_guid().empty())
361 continue; 361 continue;
362 362
363 network_list_.push_back(base::MakeUnique<NetworkInfo>(network->guid())); 363 network_list_.push_back(base::MakeUnique<NetworkInfo>(network->guid()));
364 } 364 }
365 } 365 }
366 366
367 void NetworkListView::OrderNetworks() {
368 struct CompareNetwork {
369 explicit CompareNetwork(NetworkStateHandler* handler) : handler_(handler) {}
370
371 // Returns true if |network1| is less than (i.e. is ordered before)
372 // |network2|.
373 bool operator()(const std::unique_ptr<NetworkInfo>& network1,
374 const std::unique_ptr<NetworkInfo>& network2) {
375 const int order1 =
376 GetOrder(handler_->GetNetworkStateFromGuid(network1->guid));
377 const int order2 =
378 GetOrder(handler_->GetNetworkStateFromGuid(network2->guid));
379 if (order1 != order2)
380 return order1 < order2;
381 if (network1->connected != network2->connected)
382 return network1->connected;
383 if (network1->connecting != network2->connecting)
384 return network1->connecting;
385 return network1->guid.compare(network2->guid) < 0;
386 }
387
388 private:
389 static int GetOrder(const chromeos::NetworkState* network) {
390 if (!network)
391 return 999;
392 if (network->Matches(NetworkTypePattern::Ethernet()))
393 return 0;
394 if (network->Matches(NetworkTypePattern::Cellular()))
395 return 1;
396 if (network->Matches(NetworkTypePattern::Mobile()))
397 return 2;
398 if (network->Matches(NetworkTypePattern::WiFi()))
399 return 3;
stevenjb 2017/06/12 22:26:19 IIRC, Shill already provides this ordering for unc
Kevin Cernekee 2017/06/12 22:30:24 Yes, it sorts by technology before considering str
400 return 4;
401 }
402
403 NetworkStateHandler* handler_;
404 };
405 std::sort(network_list_.begin(), network_list_.end(),
406 CompareNetwork(NetworkHandler::Get()->network_state_handler()));
407 }
408
409 void NetworkListView::UpdateNetworkIcons() { 367 void NetworkListView::UpdateNetworkIcons() {
410 SCOPED_NET_LOG_IF_SLOW(); 368 SCOPED_NET_LOG_IF_SLOW();
411 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 369 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
412 370
413 // First, update state for all networks. 371 // First, update state for all networks.
414 bool animating = false; 372 bool animating = false;
415 373
416 for (auto& info : network_list_) { 374 for (auto& info : network_list_) {
417 const chromeos::NetworkState* network = 375 const chromeos::NetworkState* network =
418 handler->GetNetworkStateFromGuid(info->guid); 376 handler->GetNetworkStateFromGuid(info->guid);
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
787 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( 745 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets(
788 0, 0, 0, kTrayPopupLabelRightPadding))); 746 0, 0, 0, kTrayPopupLabelRightPadding)));
789 747
790 // Nothing to the right of the text. 748 // Nothing to the right of the text.
791 connection_warning->SetContainerVisible(TriView::Container::END, false); 749 connection_warning->SetContainerVisible(TriView::Container::END, false);
792 return connection_warning; 750 return connection_warning;
793 } 751 }
794 752
795 } // namespace tray 753 } // namespace tray
796 } // namespace ash 754 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698