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

Side by Side Diff: chrome/browser/chromeos/cros/cros_network_functions.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/cros_network_functions.h" 5 #include "chrome/browser/chromeos/cros/cros_network_functions.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string_tokenizer.h" 10 #include "base/string_tokenizer.h"
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 void DoNothingWithCallStatus(DBusMethodCallStatus call_status) {} 215 void DoNothingWithCallStatus(DBusMethodCallStatus call_status) {}
216 216
217 // Ignores errors. 217 // Ignores errors.
218 void IgnoreErrors(const std::string& error_name, 218 void IgnoreErrors(const std::string& error_name,
219 const std::string& error_message) {} 219 const std::string& error_message) {}
220 220
221 // A callback used to implement CrosRequest*Properties functions. 221 // A callback used to implement CrosRequest*Properties functions.
222 void RunCallbackWithDictionaryValue(const NetworkPropertiesCallback& callback, 222 void RunCallbackWithDictionaryValue(const NetworkPropertiesCallback& callback,
223 const std::string& path, 223 const std::string& path,
224 DBusMethodCallStatus call_status, 224 DBusMethodCallStatus call_status,
225 const base::DictionaryValue& value) { 225 scoped_ptr<base::DictionaryValue> value) {
226 callback.Run(path, call_status == DBUS_METHOD_CALL_SUCCESS ? &value : NULL); 226 if (call_status == DBUS_METHOD_CALL_SUCCESS) {
227 callback.Run(path, value.Pass());
228 } else {
229 scoped_ptr<base::DictionaryValue> empty(NULL);
230 callback.Run(path, empty.Pass());
231 }
227 } 232 }
228 233
229 // A callback used to implement CrosRequest*Properties functions. 234 // A callback used to implement CrosRequest*Properties functions.
230 void RunCallbackWithDictionaryValueNoStatus( 235 void RunCallbackWithDictionaryValueNoStatus(
231 const NetworkPropertiesCallback& callback, 236 const NetworkPropertiesCallback& callback,
232 const std::string& path, 237 const std::string& path,
233 const base::DictionaryValue& value) { 238 scoped_ptr<base::DictionaryValue> value) {
234 callback.Run(path, &value); 239 callback.Run(path, value.Pass());
235 } 240 }
236 241
237 // A callback used to implement the error callback for CrosRequest*Properties 242 // A callback used to implement the error callback for CrosRequest*Properties
238 // functions. 243 // functions.
239 void RunCallbackWithDictionaryValueError( 244 void RunCallbackWithDictionaryValueError(
240 const NetworkPropertiesCallback& callback, 245 const NetworkPropertiesCallback& callback,
241 const std::string& path, 246 const std::string& path,
242 const std::string& error_name, 247 const std::string& error_name,
243 const std::string& error_message) { 248 const std::string& error_message) {
244 callback.Run(path, NULL); 249 scoped_ptr<base::DictionaryValue> null_dict(NULL);
250 callback.Run(path, null_dict.Pass());
245 } 251 }
246 252
247 // Used as a callback for ShillManagerClient::GetService 253 // Used as a callback for ShillManagerClient::GetService
248 void OnGetService(const NetworkPropertiesCallback& callback, 254 void OnGetService(const NetworkPropertiesCallback& callback,
249 const dbus::ObjectPath& service_path) { 255 const dbus::ObjectPath& service_path) {
250 VLOG(1) << "OnGetServiceService: " << service_path.value(); 256 VLOG(1) << "OnGetServiceService: " << service_path.value();
251 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( 257 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties(
252 service_path, base::Bind(&RunCallbackWithDictionaryValue, 258 service_path, base::Bind(&RunCallbackWithDictionaryValue,
253 callback, 259 callback,
254 service_path.value())); 260 service_path.value()));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 ipconfig_vector->push_back( 345 ipconfig_vector->push_back(
340 NetworkIPConfig(device_path, 346 NetworkIPConfig(device_path,
341 ParseIPConfigType(type_string), 347 ParseIPConfigType(type_string),
342 address, 348 address,
343 CrosPrefixLengthToNetmask(prefix_len), 349 CrosPrefixLengthToNetmask(prefix_len),
344 gateway, 350 gateway,
345 name_servers_string)); 351 name_servers_string));
346 return true; 352 return true;
347 } 353 }
348 354
355 void ListIPConfigsCallback(const NetworkGetIPConfigsCallback& callback,
356 const std::string& device_path,
357 DBusMethodCallStatus call_status,
358 scoped_ptr<base::DictionaryValue> properties) {
359 DCHECK(properties.get());
360 NetworkIPConfigVector ipconfig_vector;
361 std::string hardware_address;
362 const ListValue* ips = NULL;
363 if (call_status != DBUS_METHOD_CALL_SUCCESS ||
364 !properties->GetListWithoutPathExpansion(flimflam::kIPConfigsProperty,
365 &ips)) {
366 callback.Run(ipconfig_vector, hardware_address);
367 return;
368 }
369
370 for (size_t i = 0; i < ips->GetSize(); i++) {
371 std::string ipconfig_path;
372 if (!ips->GetString(i, &ipconfig_path)) {
373 LOG(WARNING) << "Found NULL ip for device " << device_path;
374 continue;
375 }
376 ParseIPConfig(device_path, ipconfig_path, &ipconfig_vector);
377 }
378 // Get the hardware address as well.
379 properties->GetStringWithoutPathExpansion(flimflam::kAddressProperty,
380 &hardware_address);
381
382 callback.Run(ipconfig_vector, hardware_address);
383 }
384
349 } // namespace 385 } // namespace
350 386
351 SMS::SMS() 387 SMS::SMS()
352 : validity(0), 388 : validity(0),
353 msgclass(0) { 389 msgclass(0) {
354 } 390 }
355 391
356 SMS::~SMS() {} 392 SMS::~SMS() {}
357 393
358 bool CrosActivateCellularModem(const std::string& service_path, 394 bool CrosActivateCellularModem(const std::string& service_path,
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
647 } 683 }
648 684
649 bool CrosSetOfflineMode(bool offline) { 685 bool CrosSetOfflineMode(bool offline) {
650 base::FundamentalValue value(offline); 686 base::FundamentalValue value(offline);
651 DBusThreadManager::Get()->GetShillManagerClient()->SetProperty( 687 DBusThreadManager::Get()->GetShillManagerClient()->SetProperty(
652 flimflam::kOfflineModeProperty, value, base::Bind(&DoNothing), 688 flimflam::kOfflineModeProperty, value, base::Bind(&DoNothing),
653 base::Bind(&IgnoreErrors)); 689 base::Bind(&IgnoreErrors));
654 return true; 690 return true;
655 } 691 }
656 692
657 bool CrosListIPConfigs(const std::string& device_path, 693 void CrosListIPConfigs(const std::string& device_path,
658 NetworkIPConfigVector* ipconfig_vector, 694 const NetworkGetIPConfigsCallback& callback) {
659 std::vector<std::string>* ipconfig_paths, 695 const dbus::ObjectPath device_object_path(device_path);
660 std::string* hardware_address) { 696 DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties(
697 device_object_path,
698 base::Bind(&ListIPConfigsCallback, callback, device_path));
699 }
700
701 bool CrosListIPConfigsAndBlock(const std::string& device_path,
702 NetworkIPConfigVector* ipconfig_vector,
703 std::vector<std::string>* ipconfig_paths,
704 std::string* hardware_address) {
661 if (hardware_address) 705 if (hardware_address)
662 hardware_address->clear(); 706 hardware_address->clear();
663 const dbus::ObjectPath device_object_path(device_path); 707 const dbus::ObjectPath device_object_path(device_path);
664 ShillDeviceClient* device_client = 708 ShillDeviceClient* device_client =
665 DBusThreadManager::Get()->GetShillDeviceClient(); 709 DBusThreadManager::Get()->GetShillDeviceClient();
666 // TODO(hashimoto): Remove this blocking D-Bus method call. 710 // TODO(hashimoto): Remove this blocking D-Bus method call.
667 // crosbug.com/29902 711 // crosbug.com/29902
668 scoped_ptr<base::DictionaryValue> properties( 712 scoped_ptr<base::DictionaryValue> properties(
669 device_client->CallGetPropertiesAndBlock(device_object_path)); 713 device_client->CallGetPropertiesAndBlock(device_object_path));
670 if (!properties.get()) 714 if (!properties.get())
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 const std::string& carrier, 948 const std::string& carrier,
905 const NetworkOperationCallback& callback) { 949 const NetworkOperationCallback& callback) {
906 DBusThreadManager::Get()->GetShillDeviceClient()->SetCarrier( 950 DBusThreadManager::Get()->GetShillDeviceClient()->SetCarrier(
907 dbus::ObjectPath(device_path), carrier, 951 dbus::ObjectPath(device_path), carrier,
908 base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE, 952 base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
909 std::string()), 953 std::string()),
910 base::Bind(&OnNetworkActionError, callback, device_path)); 954 base::Bind(&OnNetworkActionError, callback, device_path));
911 } 955 }
912 956
913 } // namespace chromeos 957 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698