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

Side by Side 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: Rebased. Created 7 years, 11 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 (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 "chrome/browser/chromeos/cros/network_library_impl_base.h" 5 #include "chrome/browser/chromeos/cros/network_library_impl_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_reader.h" 8 #include "base/json/json_reader.h"
9 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "chrome/browser/chromeos/cros/native_network_parser.h" 12 #include "chrome/browser/chromeos/cros/native_network_parser.h"
13 #include "chrome/browser/chromeos/cros/network_constants.h"
13 #include "chrome/browser/chromeos/cros/onc_network_parser.h" 14 #include "chrome/browser/chromeos/cros/onc_network_parser.h"
14 #include "chrome/browser/chromeos/network_login_observer.h" 15 #include "chrome/browser/chromeos/network_login_observer.h"
15 #include "chromeos/network/onc/onc_certificate_importer.h" 16 #include "chromeos/network/onc/onc_certificate_importer.h"
16 #include "chromeos/network/onc/onc_constants.h" 17 #include "chromeos/network/onc/onc_constants.h"
17 #include "chromeos/network/onc/onc_signature.h" 18 #include "chromeos/network/onc/onc_signature.h"
18 #include "chromeos/network/onc/onc_utils.h" 19 #include "chromeos/network/onc/onc_utils.h"
19 #include "chromeos/network/onc/onc_validator.h" 20 #include "chromeos/network/onc/onc_validator.h"
20 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
21 #include "crypto/nss_util.h" // crypto::GetTPMTokenInfo() for 802.1X and VPN. 22 #include "crypto/nss_util.h" // crypto::GetTPMTokenInfo() for 802.1X and VPN.
22 #include "grit/generated_resources.h" 23 #include "grit/generated_resources.h"
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
1119 } 1120 }
1120 } 1121 }
1121 1122
1122 std::set<std::string> removal_ids; 1123 std::set<std::string> removal_ids;
1123 std::set<std::string>& network_ids(network_source_map_[source]); 1124 std::set<std::string>& network_ids(network_source_map_[source]);
1124 network_ids.clear(); 1125 network_ids.clear();
1125 if (has_network_configurations) { 1126 if (has_network_configurations) {
1126 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks"; 1127 VLOG(2) << "ONC file has " << network_configs->GetSize() << " networks";
1127 OncNetworkParser parser(*network_configs, source); 1128 OncNetworkParser parser(*network_configs, source);
1128 1129
1129 // Parse all networks. Bail out if that fails.
1130 NetworkOncMap added_onc_map;
1131 ScopedVector<Network> networks;
1132 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) { 1130 for (int i = 0; i < parser.GetNetworkConfigsSize(); i++) {
1133 // Parse Open Network Configuration blob into a temporary Network object. 1131 // Parse Open Network Configuration blob into a temporary Network object.
1134 bool marked_for_removal = false; 1132 bool marked_for_removal = false;
1135 Network* network = parser.ParseNetwork(i, &marked_for_removal); 1133 scoped_ptr<Network> network(parser.ParseNetwork(i, &marked_for_removal));
1136 if (!network) { 1134 if (!network) {
1137 LOG(ERROR) << "Error during ONC parsing network at index " << i 1135 LOG(ERROR) << "Error during ONC parsing network at index " << i
1138 << " from " << onc::GetSourceAsString(source); 1136 << " from " << onc::GetSourceAsString(source);
1139 success = false; 1137 success = false;
1140 continue; 1138 continue;
1141 } 1139 }
1142 1140
1143 // Disallow anything but WiFi and Ethernet for device-level policy (which 1141 // Disallow anything but WiFi and Ethernet for device-level policy (which
1144 // corresponds to shared networks). See also http://crosbug.com/28741. 1142 // corresponds to shared networks). See also http://crosbug.com/28741.
1145 if (source == onc::ONC_SOURCE_DEVICE_POLICY && 1143 if (source == onc::ONC_SOURCE_DEVICE_POLICY &&
1146 network->type() != TYPE_WIFI && 1144 network->type() != TYPE_WIFI &&
1147 network->type() != TYPE_ETHERNET) { 1145 network->type() != TYPE_ETHERNET) {
1148 LOG(WARNING) << "Ignoring device-level policy-pushed network of type " 1146 LOG(WARNING) << "Ignoring device-level policy-pushed network of type "
1149 << network->type(); 1147 << network->type();
1150 delete network;
1151 continue; 1148 continue;
1152 } 1149 }
1153 1150
1154 networks.push_back(network); 1151 if (source == onc::ONC_SOURCE_USER_IMPORT && marked_for_removal) {
1155 if (!(source == onc::ONC_SOURCE_USER_IMPORT && 1152 // User import supports the removal of networks by ID.
1156 marked_for_removal)) {
1157 added_onc_map[network->unique_id()] = parser.GetNetworkConfig(i);
1158 }
1159
1160 if (marked_for_removal)
1161 removal_ids.insert(network->unique_id()); 1153 removal_ids.insert(network->unique_id());
1162 }
1163
1164 // Update the ONC map.
1165 for (NetworkOncMap::iterator iter(added_onc_map.begin());
1166 iter != added_onc_map.end(); ++iter) {
1167 const base::DictionaryValue*& entry = network_onc_map_[iter->first];
1168 delete entry;
1169 entry = iter->second->DeepCopy();
1170 }
1171
1172 // Configure the networks. While doing so, collect unique identifiers of the
1173 // networks that are defined in the ONC blob in |network_ids|. They're later
1174 // used to clean out any previously-existing networks that had been
1175 // configured through policy but are no longer specified in the updated ONC
1176 // blob.
1177 for (std::vector<Network*>::iterator iter(networks.begin());
1178 iter != networks.end(); ++iter) {
1179 Network* network = *iter;
1180
1181 // Don't configure a network that is supposed to be removed. For
1182 // policy-managed networks, the "remove" functionality of ONC is ignored.
1183 if (source == onc::ONC_SOURCE_USER_IMPORT &&
1184 removal_ids.find(network->unique_id()) != removal_ids.end()) {
1185 continue; 1154 continue;
1186 } 1155 }
1187 1156
1188 DictionaryValue dict; 1157 // Don't configure a network that is supposed to be removed. For
1158 // policy-managed networks, the "remove" functionality of ONC is
1159 // irrelevant. Instead, in general, all previously configured networks
1160 // that are no longer configured are removed.
1161 if (marked_for_removal)
1162 continue;
1163
1164 // Update the ONC map.
1165 const base::DictionaryValue*& entry =
1166 network_onc_map_[network->unique_id()];
1167 delete entry;
1168 entry = parser.GetNetworkConfig(i)->DeepCopy();
1169
1170 // Configure the network.
1171 base::DictionaryValue dict;
1189 for (Network::PropertyMap::const_iterator props = 1172 for (Network::PropertyMap::const_iterator props =
1190 network->property_map_.begin(); 1173 network->property_map_.begin();
1191 props != network->property_map_.end(); ++props) { 1174 props != network->property_map_.end(); ++props) {
1192 std::string key = 1175 std::string key =
1193 NativeNetworkParser::property_mapper()->GetKey(props->first); 1176 NativeNetworkParser::property_mapper()->GetKey(props->first);
1194 if (!key.empty()) 1177 if (!key.empty())
1195 dict.SetWithoutPathExpansion(key, props->second->DeepCopy()); 1178 dict.SetWithoutPathExpansion(key, props->second->DeepCopy());
1196 else 1179 else
1197 VLOG(2) << "Property " << props->first << " will not be sent"; 1180 VLOG(2) << "Property " << props->first << " will not be sent";
1198 } 1181 }
1199 1182
1200 // Set the appropriate profile for |source|. 1183 // Set the appropriate profile for |source|.
1201 if (profile != NULL) 1184 if (profile != NULL)
1202 dict.SetString(flimflam::kProfileProperty, profile->path); 1185 dict.SetString(flimflam::kProfileProperty, profile->path);
1203 1186
1204 // For Ethernet networks, apply them to the current Ethernet service. 1187 // For Ethernet networks, apply them to the current Ethernet service.
1205 if (network->type() == TYPE_ETHERNET) { 1188 if (network->type() == TYPE_ETHERNET) {
1206 const EthernetNetwork* ethernet = ethernet_network(); 1189 const EthernetNetwork* ethernet = ethernet_network();
1207 if (ethernet) { 1190 if (ethernet) {
1208 CallConfigureService(ethernet->unique_id(), &dict); 1191 CallConfigureService(ethernet->unique_id(), &dict);
1209 } else { 1192 } else {
1210 LOG(WARNING) << "Tried to import ONC with an Ethernet network when " 1193 LOG(WARNING) << "Tried to import ONC with an Ethernet network when "
1211 << "there is no active Ethernet connection."; 1194 << "there is no active Ethernet connection.";
1212 } 1195 }
1213 } else { 1196 } else {
1214 CallConfigureService(network->unique_id(), &dict); 1197 CallConfigureService(network->unique_id(), &dict);
1215 } 1198 }
1216 1199
1200 // Store the unique identifier of the network that is defined in the ONC
1201 // blob in |network_ids|. The identifiers are later used to clean out any
1202 // previously-existing networks that had been configured through policy
1203 // but are no longer specified in the updated ONC blob.
1217 network_ids.insert(network->unique_id()); 1204 network_ids.insert(network->unique_id());
1218 } 1205 }
1219 } 1206 }
1220 1207
1221 if (from_policy) { 1208 if (from_policy) {
1222 // For policy-managed networks, go through the list of existing remembered 1209 // For policy-managed networks, go through the list of existing remembered
1223 // networks and clean out the ones that no longer have a definition in the 1210 // networks and clean out the ones that no longer have a definition in the
1224 // ONC blob. We first collect the networks and do the actual deletion later 1211 // ONC blob. We first collect the networks and do the actual deletion later
1225 // because ForgetNetwork() changes the remembered network vectors. 1212 // because ForgetNetwork() changes the remembered network vectors.
1226 ForgetNetworksById(source, network_ids, false); 1213 ForgetNetworksById(source, network_ids, false);
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 GetTpmInfo(); 1732 GetTpmInfo();
1746 return tpm_slot_; 1733 return tpm_slot_;
1747 } 1734 }
1748 1735
1749 const std::string& NetworkLibraryImplBase::GetTpmPin() { 1736 const std::string& NetworkLibraryImplBase::GetTpmPin() {
1750 GetTpmInfo(); 1737 GetTpmInfo();
1751 return tpm_pin_; 1738 return tpm_pin_;
1752 } 1739 }
1753 1740
1754 } // namespace chromeos 1741 } // namespace chromeos
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