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

Unified Diff: chrome/browser/chromeos/cros/network_library.cc

Issue 8804021: Proper management for policy-configured networks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/cros/onc_network_parser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/cros/network_library.cc
diff --git a/chrome/browser/chromeos/cros/network_library.cc b/chrome/browser/chromeos/cros/network_library.cc
index 26668ac615597c28d98b155e0651557a8bf857db..215c4768e12aa2381e437cc695b529ac84499c7c 100644
--- a/chrome/browser/chromeos/cros/network_library.cc
+++ b/chrome/browser/chromeos/cros/network_library.cc
@@ -162,6 +162,20 @@ void ValidateUTF8(const std::string& str, std::string* output) {
}
}
+NetworkProfileType GetProfileTypeForSource(NetworkUIData::ONCSource source) {
+ switch (source) {
+ case NetworkUIData::ONC_SOURCE_DEVICE_POLICY:
+ return PROFILE_SHARED;
+ case NetworkUIData::ONC_SOURCE_USER_POLICY:
+ return PROFILE_USER;
+ case NetworkUIData::ONC_SOURCE_NONE:
+ case NetworkUIData::ONC_SOURCE_USER_IMPORT:
+ return PROFILE_NONE;
+ }
+ NOTREACHED() << "Unknown ONC source " << source;
+ return PROFILE_NONE;
+}
+
////////////////////////////////////////////////////////////////////////////////
// glib
@@ -2846,14 +2860,31 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,
}
}
+ // Parse all networks. Bail out if that fails.
+ std::vector<Network*> networks;
stevenjb 2011/12/05 20:36:38 Can use ScopedVector here instead of STLDeleteElem
Mattias Nissler (ping if slow) 2011/12/05 20:58:29 Done.
for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) {
// Parse Open Network Configuration blob into a temporary Network object.
- scoped_ptr<Network> network(parser.ParseNetwork(i));
- if (!network.get()) {
+ Network* network = parser.ParseNetwork(i);
+ if (!network) {
DLOG(WARNING) << "Cannot parse network in ONC file";
+ STLDeleteElements(&networks);
return false;
}
+ networks.push_back(network);
+ }
+ // Configure the networks.
+ std::string profile_path(GetProfilePath(GetProfileTypeForSource(source)));
+
+ // This map collects the unique identifiers of the networks that are defined
+ // in this ONC blob. It's later used to clean out any previously-existing
+ // networks that had been configured through policy but are no longer
+ // specified in the updated ONC blob.
+ std::set<std::string> network_ids;
stevenjb 2011/12/05 20:36:38 These comments are a little confusing; the "Config
Mattias Nissler (ping if slow) 2011/12/05 20:58:29 Done.
+
+ for (std::vector<Network*>::iterator iter(networks.begin());
+ iter != networks.end(); ++iter) {
+ Network* network = *iter;
DictionaryValue dict;
for (Network::PropertyMap::const_iterator props =
network->property_map_.begin();
@@ -2866,8 +2897,43 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,
VLOG(2) << "Property " << props->first << " will not be sent";
}
+ // Set the appropriate profile for |source|.
+ if (!profile_path.empty())
+ dict.SetString(flimflam::kProfileProperty, profile_path);
+
CallConfigureService(network->unique_id(), &dict);
+ network_ids.insert(network->unique_id());
+ }
+
+ // Go through the list of existing remembered networks and clean out the ones
+ // that no longer have a definition in the ONC blob. We first collect the
+ // networks and the actual deletion later because ForgetNetwork() changes the
stevenjb 2011/12/05 20:36:38 s/and the/and do the/
Mattias Nissler (ping if slow) 2011/12/05 20:58:29 Done.
+ // remembered network vectors.
+ if (source != NetworkUIData::ONC_SOURCE_USER_IMPORT) {
+ std::vector<std::string> to_be_deleted;
+ for (WifiNetworkVector::iterator i(remembered_wifi_networks_.begin());
+ i != remembered_wifi_networks_.end(); ++i) {
+ WifiNetwork* network = *i;
+ if (NetworkUIData::GetONCSource(network) == source &&
+ network_ids.find(network->unique_id()) == network_ids.end())
+ to_be_deleted.push_back(network->service_path());
+ }
+
+ for (VirtualNetworkVector::iterator i(remembered_virtual_networks_.begin());
+ i != remembered_virtual_networks_.end(); ++i) {
+ VirtualNetwork* network = *i;
+ if (NetworkUIData::GetONCSource(network) == source &&
+ network_ids.find(network->unique_id()) == network_ids.end())
+ to_be_deleted.push_back(network->service_path());
+ }
+
+ for (std::vector<std::string>::const_iterator i(to_be_deleted.begin());
+ i != to_be_deleted.end(); ++i) {
+ ForgetNetwork(*i);
+ }
}
+
+ STLDeleteElements(&networks);
return parser.GetNetworkConfigsSize() != 0;
}
« no previous file with comments | « no previous file | chrome/browser/chromeos/cros/onc_network_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698