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

Unified Diff: chromeos/network/network_state_handler.cc

Issue 289383004: Merge FavoriteState into NetworkState (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chromeos/network/network_state_handler.cc
diff --git a/chromeos/network/network_state_handler.cc b/chromeos/network/network_state_handler.cc
index 77b0b2744b6831fd005b90b656633289a1b03df5..0c8971af9020abe3bfd448ff949aa5fc62a1d82e 100644
--- a/chromeos/network/network_state_handler.cc
+++ b/chromeos/network/network_state_handler.cc
@@ -15,7 +15,6 @@
#include "base/strings/stringprintf.h"
#include "base/values.h"
#include "chromeos/network/device_state.h"
-#include "chromeos/network/favorite_state.h"
#include "chromeos/network/managed_state.h"
#include "chromeos/network/network_event_log.h"
#include "chromeos/network/network_state.h"
@@ -38,8 +37,6 @@ std::string GetManagedStateLogType(const ManagedState* state) {
switch (state->managed_type()) {
case ManagedState::MANAGED_TYPE_NETWORK:
return "Network";
- case ManagedState::MANAGED_TYPE_FAVORITE:
- return "Favorite";
case ManagedState::MANAGED_TYPE_DEVICE:
return "Device";
}
@@ -64,7 +61,6 @@ NetworkStateHandler::NetworkStateHandler() {
NetworkStateHandler::~NetworkStateHandler() {
STLDeleteContainerPointers(network_list_.begin(), network_list_.end());
- STLDeleteContainerPointers(favorite_list_.begin(), favorite_list_.end());
STLDeleteContainerPointers(device_list_.begin(), device_list_.end());
}
@@ -190,19 +186,6 @@ const NetworkState* NetworkStateHandler::DefaultNetwork() const {
return GetNetworkState(default_network_path_);
}
-const FavoriteState* NetworkStateHandler::DefaultFavoriteNetwork() const {
- const NetworkState* default_network = DefaultNetwork();
- if (!default_network)
- return NULL;
- const FavoriteState* default_favorite = GetFavoriteStateFromServicePath(
- default_network->path(), true /* configured_only */);
- DCHECK(default_network->type() != shill::kTypeWifi || default_favorite)
- << "No favorite for: " << default_network->path();
- DCHECK(!default_favorite || default_favorite->update_received())
- << "No update received for: " << default_network->path();
- return default_favorite;
-}
-
const NetworkState* NetworkStateHandler::ConnectedNetworkByType(
const NetworkTypePattern& type) const {
for (ManagedStateList::const_iterator iter = network_list_.begin();
@@ -262,54 +245,20 @@ std::string NetworkStateHandler::FormattedHardwareAddressForType(
return network_util::FormattedMacAddress(device->mac_address());
}
-void NetworkStateHandler::GetNetworkList(NetworkStateList* list) const {
- GetNetworkListByType(NetworkTypePattern::Default(), list);
+void NetworkStateHandler::GetVisibleNetworkList(NetworkStateList* list) const {
+ GetNetworkListByType(NetworkTypePattern::Default(),
+ false /* configured_only */,
+ true /* visible_only */,
+ 0 /* no limit */,
+ list);
}
void NetworkStateHandler::GetNetworkListByType(const NetworkTypePattern& type,
+ bool configured_only,
+ bool visible_only,
+ int limit,
NetworkStateList* list) const {
DCHECK(list);
- list->clear();
- for (ManagedStateList::const_iterator iter = network_list_.begin();
- iter != network_list_.end(); ++iter) {
- const NetworkState* network = (*iter)->AsNetworkState();
- DCHECK(network);
- if (network->update_received() && network->Matches(type))
- list->push_back(network);
- }
-}
-
-void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const {
- GetDeviceListByType(NetworkTypePattern::Default(), list);
-}
-
-void NetworkStateHandler::GetDeviceListByType(const NetworkTypePattern& type,
- DeviceStateList* list) const {
- DCHECK(list);
- list->clear();
- for (ManagedStateList::const_iterator iter = device_list_.begin();
- iter != device_list_.end(); ++iter) {
- const DeviceState* device = (*iter)->AsDeviceState();
- DCHECK(device);
- if (device->update_received() && device->Matches(type))
- list->push_back(device);
- }
-}
-
-void NetworkStateHandler::GetFavoriteList(FavoriteStateList* list) const {
- GetFavoriteListByType(NetworkTypePattern::Default(),
- true /* configured_only */,
- false /* visible_only */,
- 0 /* no limit */,
- list);
-}
-
-void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type,
- bool configured_only,
- bool visible_only,
- int limit,
- FavoriteStateList* list) const {
- DCHECK(list);
std::set<std::string> visible_networks;
if (visible_only) {
// Prepare a set of visible network service paths for fast lookup.
@@ -318,53 +267,70 @@ void NetworkStateHandler::GetFavoriteListByType(const NetworkTypePattern& type,
visible_networks.insert((*iter)->path());
}
}
- FavoriteStateList result;
+ NetworkStateList result;
list->clear();
int count = 0;
- for (ManagedStateList::const_iterator iter = favorite_list_.begin();
- iter != favorite_list_.end(); ++iter) {
- const FavoriteState* favorite = (*iter)->AsFavoriteState();
- DCHECK(favorite);
- if (!favorite->update_received() || !favorite->Matches(type))
+ for (ManagedStateList::const_iterator iter = network_list_.begin();
+ iter != network_list_.end(); ++iter) {
+ const NetworkState* network = (*iter)->AsNetworkState();
+ DCHECK(network);
+ if (!network->update_received() || !network->Matches(type))
continue;
- if (configured_only && !favorite->IsInProfile())
+ if (configured_only && !network->IsInProfile())
continue;
- if (visible_only && !ContainsKey(visible_networks, favorite->path()))
+ if (visible_only && !ContainsKey(visible_networks, network->path()))
continue;
- list->push_back(favorite);
+ list->push_back(network);
if (limit > 0 && ++count >= limit)
break;
}
}
-const FavoriteState* NetworkStateHandler::GetFavoriteStateFromServicePath(
+const NetworkState* NetworkStateHandler::GetNetworkStateFromServicePath(
const std::string& service_path,
bool configured_only) const {
ManagedState* managed =
- GetModifiableManagedState(&favorite_list_, service_path);
+ GetModifiableManagedState(&network_list_, service_path);
if (!managed)
return NULL;
- const FavoriteState* favorite = managed->AsFavoriteState();
- DCHECK(favorite);
- if (!favorite->update_received() ||
- (configured_only && !favorite->IsInProfile())) {
+ const NetworkState* network = managed->AsNetworkState();
+ DCHECK(network);
+ if (!network->update_received() ||
+ (configured_only && !network->IsInProfile())) {
return NULL;
}
- return favorite;
+ return network;
}
-const FavoriteState* NetworkStateHandler::GetFavoriteStateFromGuid(
+const NetworkState* NetworkStateHandler::GetNetworkStateFromGuid(
const std::string& guid) const {
DCHECK(!guid.empty());
- for (ManagedStateList::const_iterator iter = favorite_list_.begin();
- iter != favorite_list_.end(); ++iter) {
- const FavoriteState* favorite = (*iter)->AsFavoriteState();
- if (favorite->guid() == guid)
- return favorite;
+ for (ManagedStateList::const_iterator iter = network_list_.begin();
+ iter != network_list_.end(); ++iter) {
+ const NetworkState* network = (*iter)->AsNetworkState();
+ if (network->guid() == guid)
+ return network;
}
return NULL;
}
+void NetworkStateHandler::GetDeviceList(DeviceStateList* list) const {
+ GetDeviceListByType(NetworkTypePattern::Default(), list);
+}
+
+void NetworkStateHandler::GetDeviceListByType(const NetworkTypePattern& type,
+ DeviceStateList* list) const {
+ DCHECK(list);
+ list->clear();
+ for (ManagedStateList::const_iterator iter = device_list_.begin();
+ iter != device_list_.end(); ++iter) {
+ const DeviceState* device = (*iter)->AsDeviceState();
+ DCHECK(device);
+ if (device->update_received() && device->Matches(type))
+ list->push_back(device);
+ }
+}
+
void NetworkStateHandler::RequestScan() const {
NET_LOG_USER("RequestScan", "");
shill_property_handler_->RequestScan();
@@ -407,7 +373,7 @@ void NetworkStateHandler::SetCheckPortalList(
shill_property_handler_->SetCheckPortalList(check_portal_list);
}
-const FavoriteState* NetworkStateHandler::GetEAPForEthernet(
+const NetworkState* NetworkStateHandler::GetEAPForEthernet(
const std::string& service_path) const {
const NetworkState* network = GetNetworkState(service_path);
if (!network) {
@@ -436,12 +402,12 @@ const FavoriteState* NetworkStateHandler::GetEAPForEthernet(
if (!device->eap_authentication_completed())
return NULL;
- FavoriteStateList list;
- GetFavoriteListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap),
- true /* configured_only */,
- false /* visible_only */,
- 1 /* limit */,
- &list);
+ NetworkStateList list;
+ GetNetworkListByType(NetworkTypePattern::Primitive(shill::kTypeEthernetEap),
+ true /* configured_only */,
+ false /* visible_only */,
+ 1 /* limit */,
+ &list);
if (list.empty()) {
NET_LOG_ERROR("GetEAPForEthernet",
base::StringPrintf(
@@ -456,14 +422,29 @@ const FavoriteState* NetworkStateHandler::GetEAPForEthernet(
//------------------------------------------------------------------------------
// ShillPropertyHandler::Delegate overrides
+void NetworkStateHandler::UpdateManagedDevices(const base::ListValue& entries) {
+ UpdateManagedList(ManagedState::MANAGED_TYPE_DEVICE, entries);
+}
+
+void NetworkStateHandler::UpdateManagedNetworks(
+ const base::ListValue& entries,
+ bool complete_list) {
+ if (complete_list) {
stevenjb 2014/05/28 23:06:10 elim {}
+ UpdateManagedList(ManagedState::MANAGED_TYPE_NETWORK, entries);
+ } else {
+ UpdateVisibleNetworks(entries);
+ }
+}
+
void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type,
const base::ListValue& entries) {
ManagedStateList* managed_list = GetManagedList(type);
- NET_LOG_DEBUG(base::StringPrintf("UpdateManagedList:%d", type),
+ NET_LOG_DEBUG("UpdateManagedList: " + ManagedState::TypeToString(type),
base::StringPrintf("%" PRIuS, entries.GetSize()));
// Create a map of existing entries. Assumes all entries in |managed_list|
// are unique.
- std::map<std::string, ManagedState*> managed_map;
+ typedef std::map<std::string, ManagedState*> ManagedMap;
+ ManagedMap managed_map;
for (ManagedStateList::iterator iter = managed_list->begin();
iter != managed_list->end(); ++iter) {
ManagedState* managed = *iter;
@@ -482,9 +463,8 @@ void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type,
NET_LOG_ERROR(base::StringPrintf("Bad path in list:%d", type), path);
continue;
}
- std::map<std::string, ManagedState*>::iterator found =
- managed_map.find(path);
ManagedState* managed;
+ ManagedMap::iterator found = managed_map.find(path);
if (found == managed_map.end()) {
if (list_entries.count(path) != 0) {
NET_LOG_ERROR("Duplicate entry in list", path);
@@ -497,18 +477,54 @@ void NetworkStateHandler::UpdateManagedList(ManagedState::ManagedType type,
managed_list->push_back(managed);
managed_map.erase(found);
}
+ NET_LOG_DEBUG("Managed Entry: " + ManagedState::TypeToString(type), path);
list_entries.insert(path);
}
// Delete any remaining entries in managed_map.
STLDeleteContainerPairSecondPointers(managed_map.begin(), managed_map.end());
}
+void NetworkStateHandler::UpdateVisibleNetworks(
+ const base::ListValue& entries) {
+ NET_LOG_DEBUG(base::StringPrintf("UpdateVisibleNetworks"),
+ base::StringPrintf("%" PRIuS, entries.GetSize()));
+ // Clear visible state of all networks.
+ ManagedStateList* network_list =
+ GetManagedList(ManagedState::MANAGED_TYPE_NETWORK);
+ typedef std::map<std::string, NetworkState*> NetworkMap;
+ NetworkMap network_map;
+ for (ManagedStateList::iterator iter = network_list->begin();
+ iter != network_list->end(); ++iter) {
+ NetworkState* network = (*iter)->AsNetworkState();
+ network_map[network->path()] = network;
+ network->set_visible(false);
+ }
+ for (base::ListValue::const_iterator iter = entries.begin();
+ iter != entries.end(); ++iter) {
+ std::string path;
+ (*iter)->GetAsString(&path);
+ if (path.empty() || path == shill::kFlimflamServicePath) {
+ NET_LOG_ERROR(base::StringPrintf("Bad path in visible networks"), path);
+ continue;
+ }
+ NetworkMap::iterator found = network_map.find(path);
+ if (found != network_map.end()) {
stevenjb 2014/05/28 23:06:10 ContainsKey
+ NetworkState* network = found->second;
+ network->set_visible(true);
+ }
+ }
+}
+
void NetworkStateHandler::ProfileListChanged() {
NET_LOG_EVENT("ProfileListChanged", "Re-Requesting Network Properties");
- for (ManagedStateList::iterator iter = favorite_list_.begin();
- iter != favorite_list_.end(); ++iter) {
+ for (ManagedStateList::iterator iter = network_list_.begin();
+ iter != network_list_.end(); ++iter) {
+ NetworkState* network = (*iter)->AsNetworkState();
+ DCHECK(network);
+ if (!network->IsInProfile())
+ continue;
shill_property_handler_->RequestProperties(
- ManagedState::MANAGED_TYPE_NETWORK, (*iter)->path());
+ ManagedState::MANAGED_TYPE_NETWORK, network->path());
}
}
@@ -519,16 +535,9 @@ void NetworkStateHandler::UpdateManagedStateProperties(
ManagedStateList* managed_list = GetManagedList(type);
ManagedState* managed = GetModifiableManagedState(managed_list, path);
if (!managed) {
- if (type != ManagedState::MANAGED_TYPE_FAVORITE) {
- // The network has been removed from the list of visible networks.
- NET_LOG_DEBUG("UpdateManagedStateProperties: Not found", path);
- return;
- }
- // A Favorite may not have been created yet if it was added later (e.g.
- // through ConfigureService) since ServiceCompleteList updates are not
- // emitted. Add and update the state here.
- managed = ManagedState::Create(type, path);
- managed_list->push_back(managed);
+ // The network has been removed from the list of visible networks.
stevenjb 2014/05/28 23:06:10 list of networks
+ NET_LOG_DEBUG("UpdateManagedStateProperties: Not found", path);
+ return;
}
managed->set_update_received();
@@ -538,14 +547,13 @@ void NetworkStateHandler::UpdateManagedStateProperties(
if (type == ManagedState::MANAGED_TYPE_NETWORK) {
UpdateNetworkStateProperties(managed->AsNetworkState(), properties);
} else {
- // Device, Favorite
+ // Device
for (base::DictionaryValue::Iterator iter(properties);
!iter.IsAtEnd(); iter.Advance()) {
managed->PropertyChanged(iter.key(), iter.value());
}
managed->InitialPropertiesReceived(properties);
}
- UpdateGuid(managed);
managed->set_update_requested(false);
}
@@ -569,20 +577,14 @@ void NetworkStateHandler::UpdateNetworkStateProperties(
NET_LOG_EVENT("NetworkPropertiesUpdated", GetManagedStateLogName(network));
NotifyNetworkPropertiesUpdated(network);
}
+ UpdateGuid(network);
}
void NetworkStateHandler::UpdateNetworkServiceProperty(
const std::string& service_path,
const std::string& key,
const base::Value& value) {
- // Update any associated FavoriteState.
- ManagedState* favorite =
- GetModifiableManagedState(&favorite_list_, service_path);
bool changed = false;
- if (favorite)
- changed |= favorite->PropertyChanged(key, value);
-
- // Update the NetworkState.
NetworkState* network = GetModifiableNetworkState(service_path);
if (!network)
return;
@@ -631,7 +633,7 @@ void NetworkStateHandler::UpdateNetworkServiceProperty(
// All property updates signal 'NetworkPropertiesUpdated'.
NotifyNetworkPropertiesUpdated(network);
- // If added to a Profile, request a full update so that a FavoriteState
+ // If added to a Profile, request a full update so that a NetworkState
// gets created.
if (prev_profile_path.empty() && !network->profile_path().empty())
RequestUpdateForNetwork(service_path);
@@ -657,7 +659,11 @@ void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path,
if (key == shill::kEapAuthenticationCompletedProperty) {
// Notify a change for each Ethernet service using this device.
NetworkStateList ethernet_services;
- GetNetworkListByType(NetworkTypePattern::Ethernet(), &ethernet_services);
+ GetNetworkListByType(NetworkTypePattern::Ethernet(),
+ false /* configured_only */,
+ false /* visible_only */,
+ 1 /* limit */,
+ &ethernet_services);
for (NetworkStateList::const_iterator it = ethernet_services.begin();
it != ethernet_services.end(); ++it) {
const NetworkState* ethernet_service = *it;
@@ -708,25 +714,20 @@ void NetworkStateHandler::ManagedStateListChanged(
FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_,
NetworkListChanged());
// Update UMA stats.
- UMA_HISTOGRAM_COUNTS_100("Networks.Visible", network_list_.size());
- } else if (type == ManagedState::MANAGED_TYPE_FAVORITE) {
- NET_LOG_DEBUG("FavoriteListChanged",
- base::StringPrintf("Size:%" PRIuS, favorite_list_.size()));
- // The FavoriteState list only changes when the NetworkState list changes,
- // so no need to signal observers here again.
-
- // Update UMA stats.
- size_t shared = 0, unshared = 0;
- for (ManagedStateList::iterator iter = favorite_list_.begin();
- iter != favorite_list_.end(); ++iter) {
- FavoriteState* favorite = (*iter)->AsFavoriteState();
- if (!favorite->IsInProfile())
- continue;
- if (favorite->IsPrivate())
- ++unshared;
- else
- ++shared;
+ size_t shared = 0, unshared = 0, visible = 0;
+ for (ManagedStateList::iterator iter = network_list_.begin();
+ iter != network_list_.end(); ++iter) {
+ NetworkState* network = (*iter)->AsNetworkState();
+ if (network->visible())
+ ++visible;
+ if (network->IsInProfile()) {
+ if (network->IsPrivate())
+ ++unshared;
+ else
+ ++shared;
+ }
}
+ UMA_HISTOGRAM_COUNTS_100("Networks.Visible", visible);
UMA_HISTOGRAM_COUNTS_100("Networks.RememberedShared", shared);
UMA_HISTOGRAM_COUNTS_100("Networks.RememberedUnshared", unshared);
} else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
@@ -737,7 +738,7 @@ void NetworkStateHandler::ManagedStateListChanged(
devices += ", ";
devices += (*iter)->name();
}
- NET_LOG_EVENT("DeviceList:", devices);
+ NET_LOG_EVENT("DeviceList", devices);
NotifyDeviceListChanged();
} else {
NOTREACHED();
@@ -775,47 +776,27 @@ void NetworkStateHandler::DefaultNetworkServiceChanged(
//------------------------------------------------------------------------------
// Private methods
-void NetworkStateHandler::UpdateGuid(ManagedState* managed) {
- if (managed->managed_type() == ManagedState::MANAGED_TYPE_FAVORITE) {
- FavoriteState* favorite = managed->AsFavoriteState();
- std::string specifier = favorite->GetSpecifier();
- if (!favorite->guid().empty()) {
- // If the favorite is saved in a profile, remove the entry from the map.
- // Otherwise ensure that the entry matches the specified GUID.
- if (favorite->IsInProfile())
- specifier_guid_map_.erase(specifier);
- else
- specifier_guid_map_[specifier] = favorite->guid();
- return;
- }
- // Ensure that the FavoriteState has a valid GUID.
- std::string guid;
- SpecifierGuidMap::iterator iter = specifier_guid_map_.find(specifier);
- if (iter != specifier_guid_map_.end()) {
- guid = iter->second;
- } else {
- guid = base::GenerateGUID();
- specifier_guid_map_[specifier] = guid;
- }
- favorite->SetGuid(guid);
- NetworkState* network = GetModifiableNetworkState(favorite->path());
- if (network)
- network->SetGuid(guid);
- } else if (managed->managed_type() == ManagedState::MANAGED_TYPE_NETWORK) {
- // If the GUID is not set and a corresponding FavoriteState exists, get the
- // GUID from the FavoriteState. Otherwise it will get set when the Favorite
- // is created.
- NetworkState* network = managed->AsNetworkState();
- if (!network->guid().empty())
- return;
- // ShillPropertyHandler will always call UpdateManagedStateProperties with
- // type FAVORITE before type NETWORK, so there should always be a
- // corresponding FavoriteState here.
- FavoriteState* favorite = GetModifiableFavoriteState(network->path());
- DCHECK(favorite);
- if (favorite && !favorite->guid().empty())
- network->SetGuid(favorite->guid());
+void NetworkStateHandler::UpdateGuid(NetworkState* network) {
+ std::string specifier = network->GetSpecifier();
+ if (!network->guid().empty()) {
+ // If the network is saved in a profile, remove the entry from the map.
+ // Otherwise ensure that the entry matches the specified GUID.
+ if (network->IsInProfile())
+ specifier_guid_map_.erase(specifier);
+ else
+ specifier_guid_map_[specifier] = network->guid();
+ return;
+ }
+ // Ensure that the NetworkState has a valid GUID.
+ std::string guid;
+ SpecifierGuidMap::iterator iter = specifier_guid_map_.find(specifier);
+ if (iter != specifier_guid_map_.end()) {
+ guid = iter->second;
+ } else {
+ guid = base::GenerateGUID();
+ specifier_guid_map_[specifier] = guid;
}
+ network->SetGuid(guid);
}
void NetworkStateHandler::NotifyDeviceListChanged() {
@@ -842,15 +823,6 @@ NetworkState* NetworkStateHandler::GetModifiableNetworkState(
return managed->AsNetworkState();
}
-FavoriteState* NetworkStateHandler::GetModifiableFavoriteState(
- const std::string& service_path) const {
- ManagedState* managed =
- GetModifiableManagedState(&favorite_list_, service_path);
- if (!managed)
- return NULL;
- return managed->AsFavoriteState();
-}
-
ManagedState* NetworkStateHandler::GetModifiableManagedState(
const ManagedStateList* managed_list,
const std::string& path) const {
@@ -868,8 +840,6 @@ NetworkStateHandler::ManagedStateList* NetworkStateHandler::GetManagedList(
switch (type) {
case ManagedState::MANAGED_TYPE_NETWORK:
return &network_list_;
- case ManagedState::MANAGED_TYPE_FAVORITE:
- return &favorite_list_;
case ManagedState::MANAGED_TYPE_DEVICE:
return &device_list_;
}

Powered by Google App Engine
This is Rietveld 408576698