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

Side by Side Diff: chrome/browser/chromeos/cros/network_library_impl_cros.cc

Issue 11367048: This is the first pass at making GetIPConfigs asynchronous. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 1 month 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
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_cros.h" 5 #include "chrome/browser/chromeos/cros/network_library_impl_cros.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_writer.h" // for debug output only. 9 #include "base/json/json_writer.h" // for debug output only.
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) { 227 void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) {
228 DCHECK(network); 228 DCHECK(network);
229 CrosRequestNetworkServiceConnect( 229 CrosRequestNetworkServiceConnect(
230 network->service_path(), 230 network->service_path(),
231 base::Bind(&NetworkLibraryImplCros::NetworkConnectCallback, 231 base::Bind(&NetworkLibraryImplCros::NetworkConnectCallback,
232 weak_ptr_factory_.GetWeakPtr())); 232 weak_ptr_factory_.GetWeakPtr()));
233 } 233 }
234 234
235 void NetworkLibraryImplCros::WifiServiceUpdateAndConnect( 235 void NetworkLibraryImplCros::WifiServiceUpdateAndConnect(
236 const std::string& service_path, 236 const std::string& service_path,
237 const base::DictionaryValue* properties) { 237 scoped_ptr<base::DictionaryValue> properties) {
238 if (properties) { 238 if (properties.get()) {
239 Network* network = ParseNetwork(service_path, *properties); 239 Network* network = ParseNetwork(service_path, *properties);
240 CHECK_EQ(network->type(), TYPE_WIFI); 240 CHECK_EQ(network->type(), TYPE_WIFI);
241 ConnectToWifiNetworkUsingConnectData(static_cast<WifiNetwork*>(network)); 241 ConnectToWifiNetworkUsingConnectData(static_cast<WifiNetwork*>(network));
242 } 242 }
243 } 243 }
244 244
245 void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect( 245 void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect(
246 const std::string& ssid, ConnectionSecurity security) { 246 const std::string& ssid, ConnectionSecurity security) {
247 // Asynchronously request service properties and call 247 // Asynchronously request service properties and call
248 // WifiServiceUpdateAndConnect. 248 // WifiServiceUpdateAndConnect.
249 CrosRequestHiddenWifiNetworkProperties( 249 CrosRequestHiddenWifiNetworkProperties(
250 ssid, 250 ssid,
251 SecurityToString(security), 251 SecurityToString(security),
252 base::Bind(&NetworkLibraryImplCros::WifiServiceUpdateAndConnect, 252 base::Bind(&NetworkLibraryImplCros::WifiServiceUpdateAndConnect,
253 weak_ptr_factory_.GetWeakPtr())); 253 weak_ptr_factory_.GetWeakPtr()));
254 } 254 }
255 255
256 void NetworkLibraryImplCros::VPNServiceUpdateAndConnect( 256 void NetworkLibraryImplCros::VPNServiceUpdateAndConnect(
257 const std::string& service_path, 257 const std::string& service_path,
258 const base::DictionaryValue* properties) { 258 scoped_ptr<base::DictionaryValue> properties) {
259 if (properties) { 259 if (properties.get()) {
260 VLOG(1) << "Connecting to new VPN Service: " << service_path; 260 VLOG(1) << "Connecting to new VPN Service: " << service_path;
261 Network* network = ParseNetwork(service_path, *properties); 261 Network* network = ParseNetwork(service_path, *properties);
262 CHECK_EQ(network->type(), TYPE_VPN); 262 CHECK_EQ(network->type(), TYPE_VPN);
263 ConnectToVirtualNetworkUsingConnectData( 263 ConnectToVirtualNetworkUsingConnectData(
264 static_cast<VirtualNetwork*>(network)); 264 static_cast<VirtualNetwork*>(network));
265 } else { 265 } else {
266 LOG(WARNING) << "Unable to create VPN Service: " << service_path; 266 LOG(WARNING) << "Unable to create VPN Service: " << service_path;
267 } 267 }
268 } 268 }
269 269
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 void NetworkLibraryImplCros::RefreshIPConfig(Network* network) { 471 void NetworkLibraryImplCros::RefreshIPConfig(Network* network) {
472 DCHECK(network); 472 DCHECK(network);
473 CrosRequestNetworkDeviceProperties( 473 CrosRequestNetworkDeviceProperties(
474 network->device_path(), 474 network->device_path(),
475 base::Bind(&NetworkLibraryImplCros::RefreshIPConfigCallback, 475 base::Bind(&NetworkLibraryImplCros::RefreshIPConfigCallback,
476 weak_ptr_factory_.GetWeakPtr())); 476 weak_ptr_factory_.GetWeakPtr()));
477 } 477 }
478 478
479 void NetworkLibraryImplCros::RefreshIPConfigCallback( 479 void NetworkLibraryImplCros::RefreshIPConfigCallback(
480 const std::string& device_path, 480 const std::string& device_path,
481 const base::DictionaryValue* properties) { 481 scoped_ptr<base::DictionaryValue> properties) {
482 const ListValue* ips = NULL; 482 const ListValue* ips = NULL;
483 if (!properties->GetListWithoutPathExpansion( 483 if (!properties->GetListWithoutPathExpansion(
484 flimflam::kIPConfigsProperty, &ips)) 484 flimflam::kIPConfigsProperty, &ips))
485 return; 485 return;
486 486
487 for (size_t i = 0; i < ips->GetSize(); i++) { 487 for (size_t i = 0; i < ips->GetSize(); i++) {
488 std::string ipconfig_path; 488 std::string ipconfig_path;
489 if (!ips->GetString(i, &ipconfig_path)) 489 if (!ips->GetString(i, &ipconfig_path))
490 continue; 490 continue;
491 CrosRequestIPConfigRefresh(ipconfig_path); 491 CrosRequestIPConfigRefresh(ipconfig_path);
(...skipping 19 matching lines...) Expand all
511 CrosRequestNetworkServiceDisconnect(service_path); 511 CrosRequestNetworkServiceDisconnect(service_path);
512 CrosRequestRemoveNetworkService(service_path); 512 CrosRequestRemoveNetworkService(service_path);
513 } 513 }
514 514
515 void NetworkLibraryImplCros::EnableOfflineMode(bool enable) { 515 void NetworkLibraryImplCros::EnableOfflineMode(bool enable) {
516 // If network device is already enabled/disabled, then don't do anything. 516 // If network device is already enabled/disabled, then don't do anything.
517 if (CrosSetOfflineMode(enable)) 517 if (CrosSetOfflineMode(enable))
518 offline_mode_ = enable; 518 offline_mode_ = enable;
519 } 519 }
520 520
521 NetworkIPConfigVector NetworkLibraryImplCros::GetIPConfigs( 521
522 void NetworkLibraryImplCros::GetIPConfigsCallback(
523 const NetworkGetIPConfigsCallback& callback,
524 HardwareAddressFormat format,
525 const NetworkIPConfigVector& ipconfig_vector,
526 const std::string& hardware_address) {
527 std::string hardware_address_tmp = hardware_address;
528 for (size_t i = 0; i < hardware_address_tmp.size(); ++i)
529 hardware_address_tmp[i] = toupper(hardware_address_tmp[i]);
530 if (format == FORMAT_COLON_SEPARATED_HEX) {
531 if (hardware_address_tmp.size() % 2 == 0) {
532 std::string output;
533 for (size_t i = 0; i < hardware_address_tmp.size(); ++i) {
534 if ((i != 0) && (i % 2 == 0))
535 output.push_back(':');
536 output.push_back(hardware_address_tmp[i]);
537 }
538 hardware_address_tmp.swap(output);
539 }
540 } else {
541 DCHECK_EQ(format, FORMAT_RAW_HEX);
542 }
543 callback.Run(ipconfig_vector, hardware_address_tmp);
544 }
545
546 void NetworkLibraryImplCros::GetIPConfigs(
547 const std::string& device_path,
548 HardwareAddressFormat format,
549 const NetworkGetIPConfigsCallback& callback) {
550 CrosListIPConfigs(device_path,
551 base::Bind(&NetworkLibraryImplCros::GetIPConfigsCallback,
552 weak_ptr_factory_.GetWeakPtr(),
553 callback,
554 format));
555 }
556
557 NetworkIPConfigVector NetworkLibraryImplCros::GetIPConfigsAndBlock(
522 const std::string& device_path, 558 const std::string& device_path,
523 std::string* hardware_address, 559 std::string* hardware_address,
524 HardwareAddressFormat format) { 560 HardwareAddressFormat format) {
525 NetworkIPConfigVector ipconfig_vector; 561 NetworkIPConfigVector ipconfig_vector;
526 CrosListIPConfigs(device_path, &ipconfig_vector, NULL, hardware_address); 562 CrosListIPConfigsAndBlock(device_path,
563 &ipconfig_vector,
564 NULL,
565 hardware_address);
527 566
528 for (size_t i = 0; i < hardware_address->size(); ++i) 567 for (size_t i = 0; i < hardware_address->size(); ++i)
529 (*hardware_address)[i] = toupper((*hardware_address)[i]); 568 (*hardware_address)[i] = toupper((*hardware_address)[i]);
530 if (format == FORMAT_COLON_SEPARATED_HEX) { 569 if (format == FORMAT_COLON_SEPARATED_HEX) {
531 if (hardware_address->size() % 2 == 0) { 570 if (hardware_address->size() % 2 == 0) {
532 std::string output; 571 std::string output;
533 for (size_t i = 0; i < hardware_address->size(); ++i) { 572 for (size_t i = 0; i < hardware_address->size(); ++i) {
534 if ((i != 0) && (i % 2 == 0)) 573 if ((i != 0) && (i % 2 == 0))
535 output.push_back(':'); 574 output.push_back(':');
536 output.push_back((*hardware_address)[i]); 575 output.push_back((*hardware_address)[i]);
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 } 729 }
691 base::TimeDelta delta = base::TimeTicks::Now() - start; 730 base::TimeDelta delta = base::TimeTicks::Now() - start;
692 VLOG(2) << "NetworkManagerStatusChanged: time: " 731 VLOG(2) << "NetworkManagerStatusChanged: time: "
693 << delta.InMilliseconds() << " ms."; 732 << delta.InMilliseconds() << " ms.";
694 HISTOGRAM_TIMES("CROS_NETWORK_UPDATE", delta); 733 HISTOGRAM_TIMES("CROS_NETWORK_UPDATE", delta);
695 return true; 734 return true;
696 } 735 }
697 736
698 void NetworkLibraryImplCros::NetworkManagerUpdate( 737 void NetworkLibraryImplCros::NetworkManagerUpdate(
699 const std::string& manager_path, 738 const std::string& manager_path,
700 const base::DictionaryValue* properties) { 739 scoped_ptr<base::DictionaryValue> properties) {
701 if (!properties) { 740 if (!properties.get()) {
702 LOG(ERROR) << "Error retrieving manager properties: " << manager_path; 741 LOG(ERROR) << "Error retrieving manager properties: " << manager_path;
703 return; 742 return;
704 } 743 }
705 VLOG(1) << "Received NetworkManagerUpdate."; 744 VLOG(1) << "Received NetworkManagerUpdate.";
706 745
707 for (DictionaryValue::key_iterator iter = properties->begin_keys(); 746 for (DictionaryValue::key_iterator iter = properties->begin_keys();
708 iter != properties->end_keys(); ++iter) { 747 iter != properties->end_keys(); ++iter) {
709 const std::string& key = *iter; 748 const std::string& key = *iter;
710 const Value* value; 749 const Value* value;
711 bool res = properties->GetWithoutPathExpansion(key, &value); 750 bool res = properties->GetWithoutPathExpansion(key, &value);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 CrosRequestNetworkServiceProperties( 898 CrosRequestNetworkServiceProperties(
860 service_path, 899 service_path,
861 base::Bind(&NetworkLibraryImplCros::NetworkServiceUpdate, 900 base::Bind(&NetworkLibraryImplCros::NetworkServiceUpdate,
862 weak_ptr_factory_.GetWeakPtr())); 901 weak_ptr_factory_.GetWeakPtr()));
863 } 902 }
864 } 903 }
865 } 904 }
866 905
867 void NetworkLibraryImplCros::NetworkServiceUpdate( 906 void NetworkLibraryImplCros::NetworkServiceUpdate(
868 const std::string& service_path, 907 const std::string& service_path,
869 const base::DictionaryValue* properties) { 908 scoped_ptr<base::DictionaryValue> properties) {
870 if (!properties) 909 if (!properties.get())
871 return; // Network no longer in visible list, ignore. 910 return; // Network no longer in visible list, ignore.
872 VLOG(2) << "NetworkServiceUpdate: " << service_path; 911 VLOG(2) << "NetworkServiceUpdate: " << service_path;
873 ParseNetwork(service_path, *properties); 912 ParseNetwork(service_path, *properties);
874 } 913 }
875 914
876 // Called from NetworkServiceUpdate and WifiServiceUpdateAndConnect. 915 // Called from NetworkServiceUpdate and WifiServiceUpdateAndConnect.
877 Network* NetworkLibraryImplCros::ParseNetwork( 916 Network* NetworkLibraryImplCros::ParseNetwork(
878 const std::string& service_path, const DictionaryValue& info) { 917 const std::string& service_path, const DictionaryValue& info) {
879 Network* network = FindNetworkByPath(service_path); 918 Network* network = FindNetworkByPath(service_path);
880 if (!network) { 919 if (!network) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 VLOG(1) << " Requesting Profile: " << profile.path; 1009 VLOG(1) << " Requesting Profile: " << profile.path;
971 CrosRequestNetworkProfileProperties( 1010 CrosRequestNetworkProfileProperties(
972 profile.path, 1011 profile.path,
973 base::Bind(&NetworkLibraryImplCros::UpdateProfile, 1012 base::Bind(&NetworkLibraryImplCros::UpdateProfile,
974 weak_ptr_factory_.GetWeakPtr())); 1013 weak_ptr_factory_.GetWeakPtr()));
975 } 1014 }
976 } 1015 }
977 1016
978 void NetworkLibraryImplCros::UpdateProfile( 1017 void NetworkLibraryImplCros::UpdateProfile(
979 const std::string& profile_path, 1018 const std::string& profile_path,
980 const base::DictionaryValue* properties) { 1019 scoped_ptr<base::DictionaryValue> properties) {
981 if (!properties) { 1020 if (!properties.get()) {
982 LOG(ERROR) << "Error retrieving profile: " << profile_path; 1021 LOG(ERROR) << "Error retrieving profile: " << profile_path;
983 return; 1022 return;
984 } 1023 }
985 VLOG(1) << "UpdateProfile for path: " << profile_path; 1024 VLOG(1) << "UpdateProfile for path: " << profile_path;
986 const ListValue* profile_entries(NULL); 1025 const ListValue* profile_entries(NULL);
987 properties->GetList(flimflam::kEntriesProperty, &profile_entries); 1026 properties->GetList(flimflam::kEntriesProperty, &profile_entries);
988 if (!profile_entries) { 1027 if (!profile_entries) {
989 LOG(ERROR) << "'Entries' property is missing."; 1028 LOG(ERROR) << "'Entries' property is missing.";
990 return; 1029 return;
991 } 1030 }
(...skipping 26 matching lines...) Expand all
1018 CrosRequestNetworkProfileEntryProperties( 1057 CrosRequestNetworkProfileEntryProperties(
1019 profile_path, 1058 profile_path,
1020 service_path, 1059 service_path,
1021 base::Bind(&NetworkLibraryImplCros::RememberedNetworkServiceUpdate, 1060 base::Bind(&NetworkLibraryImplCros::RememberedNetworkServiceUpdate,
1022 weak_ptr_factory_.GetWeakPtr())); 1061 weak_ptr_factory_.GetWeakPtr()));
1023 } 1062 }
1024 } 1063 }
1025 1064
1026 void NetworkLibraryImplCros::RememberedNetworkServiceUpdate( 1065 void NetworkLibraryImplCros::RememberedNetworkServiceUpdate(
1027 const std::string& service_path, 1066 const std::string& service_path,
1028 const base::DictionaryValue* properties) { 1067 scoped_ptr<base::DictionaryValue> properties) {
1029 if (!properties) { 1068 if (!properties.get()) {
1030 // Remembered network no longer exists. 1069 // Remembered network no longer exists.
1031 DeleteRememberedNetwork(service_path); 1070 DeleteRememberedNetwork(service_path);
1032 } else { 1071 } else {
1033 ParseRememberedNetwork(service_path, *properties); 1072 ParseRememberedNetwork(service_path, *properties);
1034 } 1073 }
1035 } 1074 }
1036 1075
1037 // Returns NULL if |service_path| refers to a network that is not a 1076 // Returns NULL if |service_path| refers to a network that is not a
1038 // remembered type. Called from RememberedNetworkServiceUpdate. 1077 // remembered type. Called from RememberedNetworkServiceUpdate.
1039 Network* NetworkLibraryImplCros::ParseRememberedNetwork( 1078 Network* NetworkLibraryImplCros::ParseRememberedNetwork(
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); 1162 for (NetworkDeviceMap::iterator iter = old_device_map.begin();
1124 iter != old_device_map.end(); ++iter) { 1163 iter != old_device_map.end(); ++iter) {
1125 DeleteDeviceFromDeviceObserversMap(iter->first); 1164 DeleteDeviceFromDeviceObserversMap(iter->first);
1126 // Delete device. 1165 // Delete device.
1127 delete iter->second; 1166 delete iter->second;
1128 } 1167 }
1129 } 1168 }
1130 1169
1131 void NetworkLibraryImplCros::NetworkDeviceUpdate( 1170 void NetworkLibraryImplCros::NetworkDeviceUpdate(
1132 const std::string& device_path, 1171 const std::string& device_path,
1133 const base::DictionaryValue* properties) { 1172 scoped_ptr<base::DictionaryValue> properties) {
1134 if (!properties) { 1173 if (!properties.get()) {
1135 // device no longer exists. 1174 // device no longer exists.
1136 DeleteDevice(device_path); 1175 DeleteDevice(device_path);
1137 } else { 1176 } else {
1138 ParseNetworkDevice(device_path, *properties); 1177 ParseNetworkDevice(device_path, *properties);
1139 } 1178 }
1140 } 1179 }
1141 1180
1142 void NetworkLibraryImplCros::ParseNetworkDevice(const std::string& device_path, 1181 void NetworkLibraryImplCros::ParseNetworkDevice(const std::string& device_path,
1143 const DictionaryValue& info) { 1182 const DictionaryValue& info) {
1144 NetworkDeviceMap::iterator found = device_map_.find(device_path); 1183 NetworkDeviceMap::iterator found = device_map_.find(device_path);
(...skipping 16 matching lines...) Expand all
1161 if (device && device->type() == TYPE_CELLULAR) 1200 if (device && device->type() == TYPE_CELLULAR)
1162 UpdateCellularDeviceStatus(device, PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING); 1201 UpdateCellularDeviceStatus(device, PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING);
1163 1202
1164 NotifyNetworkManagerChanged(false); // Not forced. 1203 NotifyNetworkManagerChanged(false); // Not forced.
1165 AddNetworkDeviceObserver(device_path, network_device_observer_.get()); 1204 AddNetworkDeviceObserver(device_path, network_device_observer_.get());
1166 } 1205 }
1167 1206
1168 void NetworkLibraryImplCros::SetIPParametersCallback( 1207 void NetworkLibraryImplCros::SetIPParametersCallback(
1169 const IPParameterInfo& info, 1208 const IPParameterInfo& info,
1170 const std::string& service_path, 1209 const std::string& service_path,
1171 const base::DictionaryValue* properties) { 1210 scoped_ptr<base::DictionaryValue> properties) {
1172 // crbug.com/146616 will fix this once we have better 1211 // crbug.com/146616 will fix this once we have better
1173 // handling of shill errors. 1212 // handling of shill errors.
1174 if (!properties) 1213 if (!properties.get())
1175 return; 1214 return;
1176 1215
1177 // Find the properties we're going to set, and minimize the DBus calls below 1216 // Find the properties we're going to set, and minimize the DBus calls below
1178 // by not clearing if it's already cleared, and not setting if it's already 1217 // by not clearing if it's already cleared, and not setting if it's already
1179 // set to the same value. Also, don't reconnect at the end if nothing changed. 1218 // set to the same value. Also, don't reconnect at the end if nothing changed.
1180 bool something_changed = false; 1219 bool something_changed = false;
1181 std::string current_address; 1220 std::string current_address;
1182 int32 current_prefixlen = -1; 1221 int32 current_prefixlen = -1;
1183 std::string current_gateway; 1222 std::string current_gateway;
1184 std::string current_name_servers; 1223 std::string current_name_servers;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 // Find the network associated with this service path, and attempt to refresh 1322 // Find the network associated with this service path, and attempt to refresh
1284 // its IP parameters, so that the changes to the service properties can take 1323 // its IP parameters, so that the changes to the service properties can take
1285 // effect. 1324 // effect.
1286 Network* network = FindNetworkByPath(service_path); 1325 Network* network = FindNetworkByPath(service_path);
1287 1326
1288 if (network && network->connecting_or_connected()) 1327 if (network && network->connecting_or_connected())
1289 RefreshIPConfig(network); 1328 RefreshIPConfig(network);
1290 } 1329 }
1291 1330
1292 } // namespace chromeos 1331 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698