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

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

Issue 11662004: Refactor NetworkLibraryImplBase::LoadOncNetworks. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Initial patch. Created 8 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/cros/network_library_impl_base.cc
diff --git a/chrome/browser/chromeos/cros/network_library_impl_base.cc b/chrome/browser/chromeos/cros/network_library_impl_base.cc
index dad65ed86e972cf5787dde59cacae03d9ab6f4f3..f16c47365e84b43d39a0a56b5d6f7f281dab751a 100644
--- a/chrome/browser/chromeos/cros/network_library_impl_base.cc
+++ b/chrome/browser/chromeos/cros/network_library_impl_base.cc
@@ -10,6 +10,7 @@
#include "base/metrics/histogram.h"
#include "base/stl_util.h"
#include "chrome/browser/chromeos/cros/native_network_parser.h"
+#include "chrome/browser/chromeos/cros/network_constants.h"
#include "chrome/browser/chromeos/cros/onc_network_parser.h"
#include "chrome/browser/chromeos/network_login_observer.h"
#include "chromeos/network/onc/onc_certificate_importer.h"
@@ -1126,13 +1127,10 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,
VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks";
OncNetworkParser parser(*network_configs, source);
- // Parse all networks. Bail out if that fails.
- NetworkOncMap added_onc_map;
- ScopedVector<Network> networks;
for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) {
// Parse Open Network Configuration blob into a temporary Network object.
bool marked_for_removal = false;
- Network* network = parser.ParseNetwork(i, &marked_for_removal);
+ scoped_ptr<Network> network(parser.ParseNetwork(i, &marked_for_removal));
if (!network) {
LOG(ERROR) << "Error during ONC parsing network at index " << i
<< " from " << onc::GetSourceAsString(source);
@@ -1147,45 +1145,31 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,
network->type() != TYPE_ETHERNET) {
LOG(WARNING) << "Ignoring device-level policy-pushed network of type "
<< network->type();
- delete network;
continue;
}
- networks.push_back(network);
- if (!(source == onc::ONC_SOURCE_USER_IMPORT &&
- marked_for_removal)) {
- added_onc_map[network->unique_id()] = parser.GetNetworkConfig(i);
- }
-
- if (marked_for_removal)
+ if (source == onc::ONC_SOURCE_USER_IMPORT && marked_for_removal) {
+ // User import supports the removal of networks by ID.
removal_ids.insert(network->unique_id());
- }
-
- // Update the ONC map.
- for (NetworkOncMap::iterator iter(added_onc_map.begin());
- iter != added_onc_map.end(); ++iter) {
- const base::DictionaryValue*& entry = network_onc_map_[iter->first];
- delete entry;
- entry = iter->second->DeepCopy();
- }
+ continue;
+ }
- // Configure the networks. While doing so, collect unique identifiers of the
- // networks that are defined in the ONC blob in |network_ids|. They're 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.
- for (std::vector<Network*>::iterator iter(networks.begin());
- iter != networks.end(); ++iter) {
- Network* network = *iter;
-
- // Don't configure a network that is supposed to be removed. For
- // policy-managed networks, the "remove" functionality of ONC is ignored.
- if (source == onc::ONC_SOURCE_USER_IMPORT &&
- removal_ids.find(network->unique_id()) != removal_ids.end()) {
+ if (marked_for_removal) {
+ // Don't configure a network that is supposed to be removed. For
Greg Spencer (Chromium) 2012/12/21 17:52:45 nit: You could put the comment above the "if" and
pneubeck (no reviews) 2013/01/08 13:40:23 Done.
+ // policy-managed networks, the "remove" functionality of ONC is
+ // irrelevant. Instead in general, all previously configured networks
Greg Spencer (Chromium) 2012/12/21 17:52:45 nit: add a comma: "Instead, in general,"
pneubeck (no reviews) 2013/01/08 13:40:23 Done.
+ // that are no longer configured are removed.
continue;
}
- DictionaryValue dict;
+ // Update the ONC map.
+ const base::DictionaryValue*& entry =
+ network_onc_map_[network->unique_id()];
+ delete entry;
+ entry = parser.GetNetworkConfig(i)->DeepCopy();
+
+ // Configure the network.
+ base::DictionaryValue dict;
for (Network::PropertyMap::const_iterator props =
network->property_map_.begin();
props != network->property_map_.end(); ++props) {
@@ -1214,6 +1198,10 @@ bool NetworkLibraryImplBase::LoadOncNetworks(const std::string& onc_blob,
CallConfigureService(network->unique_id(), &dict);
}
+ // Store the unique identifier of the network that is defined in the ONC
+ // blob in |network_ids|. The identifiers are 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.
network_ids.insert(network->unique_id());
}
}
« 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