Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/ui/webui/options/chromeos/internet_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1219 // and continue in the callback. | 1219 // and continue in the callback. |
| 1220 chromeos::CrosRequestNetworkServiceProperties( | 1220 chromeos::CrosRequestNetworkServiceProperties( |
| 1221 network->service_path(), | 1221 network->service_path(), |
| 1222 base::Bind(&InternetOptionsHandler::PopulateDictionaryDetailsCallback, | 1222 base::Bind(&InternetOptionsHandler::PopulateDictionaryDetailsCallback, |
| 1223 weak_factory_.GetWeakPtr(), network)); | 1223 weak_factory_.GetWeakPtr(), network)); |
| 1224 } | 1224 } |
| 1225 | 1225 |
| 1226 void InternetOptionsHandler::PopulateDictionaryDetailsCallback( | 1226 void InternetOptionsHandler::PopulateDictionaryDetailsCallback( |
| 1227 const chromeos::Network* network, | 1227 const chromeos::Network* network, |
| 1228 const std::string& service_path, | 1228 const std::string& service_path, |
| 1229 const base::DictionaryValue* shill_properties) { | 1229 scoped_ptr<base::DictionaryValue> shill_properties) { |
| 1230 chromeos::CrosListIPConfigs( | |
| 1231 network->device_path(), | |
| 1232 base::Bind(&InternetOptionsHandler::PopulateIPConfigsCallback, | |
| 1233 weak_factory_.GetWeakPtr(), | |
| 1234 network, | |
| 1235 base::Passed(&shill_properties))); | |
|
Greg Spencer (Chromium)
2012/11/05 21:05:31
This is why the dictionary callback needs to use a
| |
| 1236 } | |
| 1237 | |
| 1238 void InternetOptionsHandler::PopulateIPConfigsCallback( | |
| 1239 const chromeos::Network* network, | |
| 1240 scoped_ptr<base::DictionaryValue> shill_properties, | |
| 1241 const chromeos::NetworkIPConfigVector& ipconfigs, | |
| 1242 const std::string& hardware_address) { | |
| 1230 if (VLOG_IS_ON(2)) { | 1243 if (VLOG_IS_ON(2)) { |
| 1231 std::string properties_json; | 1244 std::string properties_json; |
| 1232 base::JSONWriter::WriteWithOptions(shill_properties, | 1245 base::JSONWriter::WriteWithOptions(shill_properties.get(), |
| 1233 base::JSONWriter::OPTIONS_PRETTY_PRINT, | 1246 base::JSONWriter::OPTIONS_PRETTY_PRINT, |
| 1234 &properties_json); | 1247 &properties_json); |
| 1235 VLOG(2) << "Shill Properties: " << std::endl << properties_json; | 1248 VLOG(2) << "Shill Properties: " << std::endl << properties_json; |
| 1236 } | 1249 } |
| 1237 | 1250 |
| 1238 Profile::FromWebUI(web_ui())->GetProxyConfigTracker()->UISetCurrentNetwork( | 1251 Profile::FromWebUI(web_ui())->GetProxyConfigTracker()->UISetCurrentNetwork( |
| 1239 network->service_path()); | 1252 network->service_path()); |
| 1240 | 1253 |
| 1241 const chromeos::NetworkUIData& ui_data = network->ui_data(); | 1254 const chromeos::NetworkUIData& ui_data = network->ui_data(); |
| 1242 const chromeos::NetworkPropertyUIData property_ui_data(ui_data); | 1255 const chromeos::NetworkPropertyUIData property_ui_data(ui_data); |
| 1243 const base::DictionaryValue* onc = | 1256 const base::DictionaryValue* onc = |
| 1244 cros_->FindOncForNetwork(network->unique_id()); | 1257 cros_->FindOncForNetwork(network->unique_id()); |
| 1245 | 1258 |
| 1246 base::DictionaryValue dictionary; | 1259 base::DictionaryValue dictionary; |
| 1247 std::string hardware_address; | |
| 1248 chromeos::NetworkIPConfigVector ipconfigs = cros_->GetIPConfigs( | |
| 1249 network->device_path(), &hardware_address, | |
| 1250 chromeos::NetworkLibrary::FORMAT_COLON_SEPARATED_HEX); | |
| 1251 if (!hardware_address.empty()) | 1260 if (!hardware_address.empty()) |
| 1252 dictionary.SetString(kTagHardwareAddress, hardware_address); | 1261 dictionary.SetString(kTagHardwareAddress, hardware_address); |
| 1253 | 1262 |
| 1254 // The DHCP IPConfig contains the values that are actually in use at the | 1263 // The DHCP IPConfig contains the values that are actually in use at the |
| 1255 // moment, even if some are overridden by static IP values. | 1264 // moment, even if some are overridden by static IP values. |
| 1256 scoped_ptr<DictionaryValue> ipconfig_dhcp(new DictionaryValue); | 1265 scoped_ptr<DictionaryValue> ipconfig_dhcp(new DictionaryValue); |
| 1257 std::string ipconfig_name_servers; | 1266 std::string ipconfig_name_servers; |
| 1258 for (chromeos::NetworkIPConfigVector::const_iterator it = ipconfigs.begin(); | 1267 for (chromeos::NetworkIPConfigVector::const_iterator it = ipconfigs.begin(); |
| 1259 it != ipconfigs.end(); ++it) { | 1268 it != ipconfigs.end(); ++it) { |
| 1260 const chromeos::NetworkIPConfig& ipconfig = *it; | 1269 const chromeos::NetworkIPConfig& ipconfig = *it; |
| 1261 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) { | 1270 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) { |
| 1262 ipconfig_dhcp->SetString(kIpConfigAddress, ipconfig.address); | 1271 ipconfig_dhcp->SetString(kIpConfigAddress, ipconfig.address); |
| 1263 VLOG(2) << "Found DHCP Address: " << ipconfig.address; | 1272 VLOG(2) << "Found DHCP Address: " << ipconfig.address; |
| 1264 ipconfig_dhcp->SetString(kIpConfigNetmask, ipconfig.netmask); | 1273 ipconfig_dhcp->SetString(kIpConfigNetmask, ipconfig.netmask); |
| 1265 VLOG(2) << "Found DHCP Netmask: " << ipconfig.netmask; | 1274 VLOG(2) << "Found DHCP Netmask: " << ipconfig.netmask; |
| 1266 ipconfig_dhcp->SetString(kIpConfigGateway, ipconfig.gateway); | 1275 ipconfig_dhcp->SetString(kIpConfigGateway, ipconfig.gateway); |
| 1267 VLOG(2) << "Found DHCP Gateway: " << ipconfig.gateway; | 1276 VLOG(2) << "Found DHCP Gateway: " << ipconfig.gateway; |
| 1268 ipconfig_dhcp->SetString(kIpConfigNameServers, ipconfig.name_servers); | 1277 ipconfig_dhcp->SetString(kIpConfigNameServers, ipconfig.name_servers); |
| 1269 ipconfig_name_servers = ipconfig.name_servers; // save for later | 1278 ipconfig_name_servers = ipconfig.name_servers; // save for later |
| 1270 VLOG(2) << "Found DHCP Name Servers: " << ipconfig.name_servers; | 1279 VLOG(2) << "Found DHCP Name Servers: " << ipconfig.name_servers; |
| 1271 break; | 1280 break; |
| 1272 } | 1281 } |
| 1273 } | 1282 } |
| 1274 SetValueDictionary(&dictionary, kDictionaryIpConfig, ipconfig_dhcp.release(), | 1283 SetValueDictionary(&dictionary, kDictionaryIpConfig, ipconfig_dhcp.release(), |
| 1275 property_ui_data); | 1284 property_ui_data); |
| 1276 | 1285 |
| 1277 std::string name_server_type = kNameServerTypeAutomatic; | 1286 std::string name_server_type = kNameServerTypeAutomatic; |
| 1278 if (shill_properties) { | 1287 if (shill_properties.get()) { |
| 1279 int automatic_ip_config = 0; | 1288 int automatic_ip_config = 0; |
| 1280 scoped_ptr<DictionaryValue> static_ip_dict( | 1289 scoped_ptr<DictionaryValue> static_ip_dict( |
| 1281 BuildIPInfoDictionary(*shill_properties, true, &automatic_ip_config)); | 1290 BuildIPInfoDictionary(*shill_properties, true, &automatic_ip_config)); |
| 1282 dictionary.SetBoolean(kIpConfigAutoConfig, automatic_ip_config == 0); | 1291 dictionary.SetBoolean(kIpConfigAutoConfig, automatic_ip_config == 0); |
| 1283 DCHECK(automatic_ip_config == 3 || automatic_ip_config == 0) | 1292 DCHECK(automatic_ip_config == 3 || automatic_ip_config == 0) |
| 1284 << "UI doesn't support automatic specification of individual " | 1293 << "UI doesn't support automatic specification of individual " |
| 1285 << "static IP parameters."; | 1294 << "static IP parameters."; |
| 1286 scoped_ptr<DictionaryValue> saved_ip_dict( | 1295 scoped_ptr<DictionaryValue> saved_ip_dict( |
| 1287 BuildIPInfoDictionary(*shill_properties, false, NULL)); | 1296 BuildIPInfoDictionary(*shill_properties, false, NULL)); |
| 1288 dictionary.Set(kDictionarySavedIp, saved_ip_dict.release()); | 1297 dictionary.Set(kDictionarySavedIp, saved_ip_dict.release()); |
| 1289 | 1298 |
| 1290 // Determine what kind of name server setting we have by comparing the | 1299 // Determine what kind of name server setting we have by comparing the |
| 1291 // StaticIP and Google values with the ipconfig values. | 1300 // StaticIP and Google values with the ipconfig values. |
| 1292 std::string static_ip_nameservers; | 1301 std::string static_ip_nameservers; |
| 1293 static_ip_dict->GetString(kIpConfigNameServers, &static_ip_nameservers); | 1302 static_ip_dict->GetString(kIpConfigNameServers, &static_ip_nameservers); |
| 1294 | 1303 |
| 1295 if (!static_ip_nameservers.empty() && | 1304 if (!static_ip_nameservers.empty() && |
| 1296 static_ip_nameservers == ipconfig_name_servers) { | 1305 static_ip_nameservers == ipconfig_name_servers) { |
| 1297 name_server_type = kNameServerTypeUser; | 1306 name_server_type = kNameServerTypeUser; |
| 1298 } | 1307 } |
| 1299 if (ipconfig_name_servers == kGoogleNameServers) { | 1308 if (ipconfig_name_servers == kGoogleNameServers) { |
| 1300 name_server_type = kNameServerTypeGoogle; | 1309 name_server_type = kNameServerTypeGoogle; |
| 1301 } | 1310 } |
| 1302 SetValueDictionary(&dictionary, | 1311 SetValueDictionary(&dictionary, |
| 1303 kDictionaryStaticIp, | 1312 kDictionaryStaticIp, |
| 1304 static_ip_dict.release(), | 1313 static_ip_dict.release(), |
| 1305 property_ui_data); | 1314 property_ui_data); |
| 1306 } else { | 1315 } else { |
| 1307 LOG(ERROR) << "Unable to fetch IP configuration for " << service_path; | 1316 LOG(ERROR) << "Unable to fetch IP configuration"; |
| 1308 // If we were unable to fetch shill_properties for some reason, | 1317 // If we were unable to fetch shill_properties for some reason, |
| 1309 // then just go with some defaults. | 1318 // then just go with some defaults. |
| 1310 dictionary.SetBoolean(kIpConfigAutoConfig, false); | 1319 dictionary.SetBoolean(kIpConfigAutoConfig, false); |
| 1311 dictionary.Set(kDictionarySavedIp, new DictionaryValue); | 1320 dictionary.Set(kDictionarySavedIp, new DictionaryValue); |
| 1312 SetValueDictionary(&dictionary, kDictionaryStaticIp, new DictionaryValue, | 1321 SetValueDictionary(&dictionary, kDictionaryStaticIp, new DictionaryValue, |
| 1313 property_ui_data); | 1322 property_ui_data); |
| 1314 } | 1323 } |
| 1315 | 1324 |
| 1316 chromeos::ConnectionType type = network->type(); | 1325 chromeos::ConnectionType type = network->type(); |
| 1317 dictionary.SetInteger(kTagType, type); | 1326 dictionary.SetInteger(kTagType, type); |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1812 | 1821 |
| 1813 dictionary->SetBoolean(kTagWimaxEnabled, cros_->wimax_enabled()); | 1822 dictionary->SetBoolean(kTagWimaxEnabled, cros_->wimax_enabled()); |
| 1814 dictionary->SetBoolean(kTagWimaxAvailable, cros_->wimax_available()); | 1823 dictionary->SetBoolean(kTagWimaxAvailable, cros_->wimax_available()); |
| 1815 dictionary->SetBoolean(kTagWimaxBusy, cros_->wimax_busy()); | 1824 dictionary->SetBoolean(kTagWimaxBusy, cros_->wimax_busy()); |
| 1816 // TODO(kevers): The use of 'offline_mode' is not quite correct. Update once | 1825 // TODO(kevers): The use of 'offline_mode' is not quite correct. Update once |
| 1817 // we have proper back-end support. | 1826 // we have proper back-end support. |
| 1818 dictionary->SetBoolean(kTagAirplaneMode, cros_->offline_mode()); | 1827 dictionary->SetBoolean(kTagAirplaneMode, cros_->offline_mode()); |
| 1819 } | 1828 } |
| 1820 | 1829 |
| 1821 } // namespace options | 1830 } // namespace options |
| OLD | NEW |