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

Side by Side Diff: chromeos/network/network_state_handler.cc

Issue 330833003: Rely on Service.Visible instead of Manager.Services (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chromeos/network/network_state_handler.h" 5 #include "chromeos/network/network_state_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/format_macros.h" 8 #include "base/format_macros.h"
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 215
216 const NetworkState* NetworkStateHandler::FirstNetworkByType( 216 const NetworkState* NetworkStateHandler::FirstNetworkByType(
217 const NetworkTypePattern& type) const { 217 const NetworkTypePattern& type) const {
218 for (ManagedStateList::const_iterator iter = network_list_.begin(); 218 for (ManagedStateList::const_iterator iter = network_list_.begin();
219 iter != network_list_.end(); ++iter) { 219 iter != network_list_.end(); ++iter) {
220 const NetworkState* network = (*iter)->AsNetworkState(); 220 const NetworkState* network = (*iter)->AsNetworkState();
221 DCHECK(network); 221 DCHECK(network);
222 if (!network->update_received()) 222 if (!network->update_received())
223 continue; 223 continue;
224 if (!network->visible()) 224 if (!network->visible())
225 continue; 225 break;
pneubeck (no reviews) 2014/06/16 14:38:15 did the ordering by Shill change in the meanwhile
stevenjb 2014/06/16 19:54:49 This was an ordering issue that is now addressed i
226 if (network->Matches(type)) 226 if (network->Matches(type))
227 return network; 227 return network;
228 } 228 }
229 return NULL; 229 return NULL;
230 } 230 }
231 231
232 std::string NetworkStateHandler::FormattedHardwareAddressForType( 232 std::string NetworkStateHandler::FormattedHardwareAddressForType(
233 const NetworkTypePattern& type) const { 233 const NetworkTypePattern& type) const {
234 const DeviceState* device = NULL; 234 const DeviceState* device = NULL;
235 const NetworkState* network = ConnectedNetworkByType(type); 235 const NetworkState* network = ConnectedNetworkByType(type);
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 } else { 454 } else {
455 managed_list->push_back(found->second); 455 managed_list->push_back(found->second);
456 managed_map.erase(found); 456 managed_map.erase(found);
457 } 457 }
458 list_entries.insert(path); 458 list_entries.insert(path);
459 } 459 }
460 // Delete any remaining entries in managed_map. 460 // Delete any remaining entries in managed_map.
461 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end()); 461 STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end());
462 } 462 }
463 463
464 void NetworkStateHandler::UpdateVisibleNetworks(
465 const base::ListValue& entries) {
466 NET_LOG_DEBUG(base::StringPrintf("UpdateVisibleNetworks"),
467 base::StringPrintf("%" PRIuS, entries.GetSize()));
468 // Create a map of all networks and clear the visible state.
469 ManagedStateList* network_list =
470 GetManagedList(ManagedState::MANAGED_TYPE_NETWORK);
471 typedef std::map<std::string, NetworkState*> NetworkMap;
472 NetworkMap network_map;
473 for (ManagedStateList::iterator iter = network_list->begin();
474 iter != network_list->end(); ++iter) {
475 NetworkState* network = (*iter)->AsNetworkState();
476 network_map[network->path()] = network;
477 network->set_visible(false);
478 }
479 // Look up each entry and set the associated network to visible.
480 for (base::ListValue::const_iterator iter = entries.begin();
481 iter != entries.end(); ++iter) {
482 std::string path;
483 (*iter)->GetAsString(&path);
484 NetworkMap::iterator found = network_map.find(path);
485 if (found != network_map.end())
486 found->second->set_visible(true);
487 else
488 NET_LOG_DEBUG("Visible network not in list", path);
489 }
490 }
491
492 void NetworkStateHandler::ProfileListChanged() { 464 void NetworkStateHandler::ProfileListChanged() {
493 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties"); 465 NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties");
494 for (ManagedStateList::iterator iter = network_list_.begin(); 466 for (ManagedStateList::iterator iter = network_list_.begin();
495 iter != network_list_.end(); ++iter) { 467 iter != network_list_.end(); ++iter) {
496 NetworkState* network = (*iter)->AsNetworkState(); 468 NetworkState* network = (*iter)->AsNetworkState();
497 DCHECK(network); 469 DCHECK(network);
498 shill_property_handler_->RequestProperties( 470 shill_property_handler_->RequestProperties(
499 ManagedState::MANAGED_TYPE_NETWORK, network->path()); 471 ManagedState::MANAGED_TYPE_NETWORK, network->path());
500 } 472 }
501 } 473 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 bool changed = false; 531 bool changed = false;
560 NetworkState* network = GetModifiableNetworkState(service_path); 532 NetworkState* network = GetModifiableNetworkState(service_path);
561 if (!network) 533 if (!network)
562 return; 534 return;
563 std::string prev_connection_state = network->connection_state(); 535 std::string prev_connection_state = network->connection_state();
564 std::string prev_profile_path = network->profile_path(); 536 std::string prev_profile_path = network->profile_path();
565 changed |= network->PropertyChanged(key, value); 537 changed |= network->PropertyChanged(key, value);
566 if (!changed) 538 if (!changed)
567 return; 539 return;
568 540
569 if (key == shill::kStateProperty) { 541 if (key == shill::kStateProperty || key == shill::kVisibleProperty) {
570 if (ConnectionStateChanged(network, prev_connection_state)) { 542 if (ConnectionStateChanged(network, prev_connection_state)) {
571 OnNetworkConnectionStateChanged(network); 543 OnNetworkConnectionStateChanged(network);
572 // If the connection state changes, other properties such as IPConfig 544 // If the connection state changes, other properties such as IPConfig
573 // may have changed, so request a full update. 545 // may have changed, so request a full update.
574 RequestUpdateForNetwork(service_path); 546 RequestUpdateForNetwork(service_path);
575 } 547 }
576 } else { 548 } else {
577 std::string value_str; 549 std::string value_str;
578 value.GetAsString(&value_str); 550 value.GetAsString(&value_str);
579 // Some property changes are noisy and not interesting: 551 // Some property changes are noisy and not interesting:
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 645
674 void NetworkStateHandler::TechnologyListChanged() { 646 void NetworkStateHandler::TechnologyListChanged() {
675 // Eventually we would like to replace Technology state with Device state. 647 // Eventually we would like to replace Technology state with Device state.
676 // For now, treat technology state changes as device list changes. 648 // For now, treat technology state changes as device list changes.
677 NotifyDeviceListChanged(); 649 NotifyDeviceListChanged();
678 } 650 }
679 651
680 void NetworkStateHandler::ManagedStateListChanged( 652 void NetworkStateHandler::ManagedStateListChanged(
681 ManagedState::ManagedType type) { 653 ManagedState::ManagedType type) {
682 if (type == ManagedState::MANAGED_TYPE_NETWORK) { 654 if (type == ManagedState::MANAGED_TYPE_NETWORK) {
655 UpdateNetworkList();
pneubeck (no reviews) 2014/06/16 14:38:15 Just noting that networks are added at distributed
stevenjb 2014/06/16 19:54:49 So, I thought about this a bunch, and while in pra
683 // Notify observers that the list of networks has changed. 656 // Notify observers that the list of networks has changed.
684 NET_LOG_EVENT("NOTIFY:NetworkListChanged", 657 NET_LOG_EVENT("NOTIFY:NetworkListChanged",
685 base::StringPrintf("Size:%" PRIuS, network_list_.size())); 658 base::StringPrintf("Size:%" PRIuS, network_list_.size()));
686 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, 659 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
687 NetworkListChanged()); 660 NetworkListChanged());
688 // Update UMA stats.
689 size_t shared = 0, unshared = 0, visible = 0;
690 for (ManagedStateList::iterator iter = network_list_.begin();
691 iter != network_list_.end(); ++iter) {
692 NetworkState* network = (*iter)->AsNetworkState();
693 if (network->visible())
694 ++visible;
695 if (network->IsInProfile()) {
696 if (network->IsPrivate())
697 ++unshared;
698 else
699 ++shared;
700 }
701 }
702 UMA_HISTOGRAM_COUNTS_100("Networks.Visible", visible);
703 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared);
704 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared);
705 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { 661 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
706 std::string devices; 662 std::string devices;
707 for (ManagedStateList::const_iterator iter = device_list_.begin(); 663 for (ManagedStateList::const_iterator iter = device_list_.begin();
708 iter != device_list_.end(); ++iter) { 664 iter != device_list_.end(); ++iter) {
709 if (iter != device_list_.begin()) 665 if (iter != device_list_.begin())
710 devices += ", "; 666 devices += ", ";
711 devices += (*iter)->name(); 667 devices += (*iter)->name();
712 } 668 }
713 NET_LOG_EVENT("DeviceList", devices); 669 NET_LOG_EVENT("DeviceList", devices);
714 NotifyDeviceListChanged(); 670 NotifyDeviceListChanged();
715 } else { 671 } else {
716 NOTREACHED(); 672 NOTREACHED();
717 } 673 }
718 } 674 }
719 675
676 void NetworkStateHandler::UpdateNetworkList() {
677 // Sort networks as follows:
pneubeck (no reviews) 2014/06/16 14:38:15 Better also mention that it's a stable sort that m
stevenjb 2014/06/16 19:54:49 Done.
678 // * Connected or connecting networks (should be listed first by Shill)
679 // * Visible non-wifi networks
680 // * Visible wifi networks
681 // * Hidden (wifi) networks
682 // Also update UMA stats.
683 bool listing_active_networks = true;
684 size_t shared = 0, unshared = 0;
685 ManagedStateList active, wifi_visible, wifi_hidden;
pneubeck (no reviews) 2014/06/16 14:38:15 is there an expected case, where this reordering a
stevenjb 2014/06/16 19:54:49 Shill is sorting by type then by state, type, visi
686 for (ManagedStateList::iterator iter = network_list_.begin();
687 iter != network_list_.end(); ++iter) {
688 NetworkState* network = (*iter)->AsNetworkState();
689 if (network->IsConnectedState() || network->IsConnectingState()) {
690 active.push_back(network);
691 if (!listing_active_networks) {
692 NET_LOG_ERROR("Active network follows inactive network",
693 GetLogName(network));
694 }
695 } else {
696 listing_active_networks = false;
697 if (network->visible()) {
698 if (!NetworkTypePattern::WiFi().MatchesType(network->type())) {
699 // List visible non-wifi networks immediately after active networks.
pneubeck (no reviews) 2014/06/16 14:38:15 is this the difference to Shill's order? Note that
stevenjb 2014/06/16 19:54:49 Done.
700 active.push_back(network);
701 } else {
702 wifi_visible.push_back(network);
703 }
704 } else {
705 wifi_hidden.push_back(network);
706 }
707 }
708 if (network->IsInProfile()) {
709 if (network->IsPrivate())
710 ++unshared;
711 else
712 ++shared;
713 }
714 }
715
716 // Update |network_list_|.
717 network_list_.clear();
718 network_list_.insert(
719 network_list_.end(), active.begin(), active.end());
720 network_list_.insert(
721 network_list_.end(), wifi_visible.begin(), wifi_visible.end());
722 network_list_.insert(
723 network_list_.end(), wifi_hidden.begin(), wifi_hidden.end());
724
725 // Update histograms.
726 UMA_HISTOGRAM_COUNTS_100("Networks.Visible",
727 active.size() + wifi_visible.size());
pneubeck (no reviews) 2014/06/16 14:38:15 optional nit: use a visible counter
stevenjb 2014/06/16 19:54:49 Done.
728 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared);
729 UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared);
730 }
731
720 void NetworkStateHandler::DefaultNetworkServiceChanged( 732 void NetworkStateHandler::DefaultNetworkServiceChanged(
721 const std::string& service_path) { 733 const std::string& service_path) {
722 // Shill uses '/' for empty service path values; check explicitly for that. 734 // Shill uses '/' for empty service path values; check explicitly for that.
723 const char* kEmptyServicePath = "/"; 735 const char* kEmptyServicePath = "/";
724 std::string new_service_path = 736 std::string new_service_path =
725 (service_path != kEmptyServicePath) ? service_path : ""; 737 (service_path != kEmptyServicePath) ? service_path : "";
726 if (new_service_path == default_network_path_) 738 if (new_service_path == default_network_path_)
727 return; 739 return;
728 740
729 default_network_path_ = service_path; 741 default_network_path_ = service_path;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 if (type.MatchesType(shill::kTypeBluetooth)) 922 if (type.MatchesType(shill::kTypeBluetooth))
911 technologies.push_back(new std::string(shill::kTypeBluetooth)); 923 technologies.push_back(new std::string(shill::kTypeBluetooth));
912 if (type.MatchesType(shill::kTypeVPN)) 924 if (type.MatchesType(shill::kTypeVPN))
913 technologies.push_back(new std::string(shill::kTypeVPN)); 925 technologies.push_back(new std::string(shill::kTypeVPN));
914 926
915 CHECK_GT(technologies.size(), 0ul); 927 CHECK_GT(technologies.size(), 0ul);
916 return technologies.Pass(); 928 return technologies.Pass();
917 } 929 }
918 930
919 } // namespace chromeos 931 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698