Home | History | Annotate | Download | only in network
      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
      3 // found in the LICENSE file.
      4 
      5 #include "chromeos/network/cros_network_functions.h"
      6 
      7 #include "base/bind.h"
      8 #include "base/bind_helpers.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "base/values.h"
     11 #include "chromeos/dbus/dbus_thread_manager.h"
     12 #include "chromeos/dbus/shill_device_client.h"
     13 #include "chromeos/dbus/shill_ipconfig_client.h"
     14 #include "chromeos/dbus/shill_manager_client.h"
     15 #include "chromeos/dbus/shill_profile_client.h"
     16 #include "chromeos/dbus/shill_property_changed_observer.h"
     17 #include "chromeos/dbus/shill_service_client.h"
     18 #include "chromeos/network/network_util.h"
     19 #include "chromeos/network/sms_watcher.h"
     20 #include "dbus/object_path.h"
     21 #include "third_party/cros_system_api/dbus/service_constants.h"
     22 
     23 using base::DoNothing;
     24 
     25 namespace chromeos {
     26 
     27 namespace {
     28 
     29 // Class to watch network manager's properties without Libcros.
     30 class NetworkManagerPropertiesWatcher
     31     : public CrosNetworkWatcher,
     32       public ShillPropertyChangedObserver {
     33  public:
     34   NetworkManagerPropertiesWatcher(
     35       const NetworkPropertiesWatcherCallback& callback)
     36     : callback_(callback) {
     37     DBusThreadManager::Get()->GetShillManagerClient()->
     38         AddPropertyChangedObserver(this);
     39   }
     40 
     41   virtual ~NetworkManagerPropertiesWatcher() {
     42     DBusThreadManager::Get()->GetShillManagerClient()->
     43         RemovePropertyChangedObserver(this);
     44   }
     45 
     46   virtual void OnPropertyChanged(const std::string& name,
     47                                  const base::Value& value) OVERRIDE {
     48     callback_.Run(flimflam::kFlimflamServicePath, name, value);
     49   }
     50  private:
     51   NetworkPropertiesWatcherCallback callback_;
     52 };
     53 
     54 // Class to watch network service's properties without Libcros.
     55 class NetworkServicePropertiesWatcher
     56     : public CrosNetworkWatcher,
     57       public ShillPropertyChangedObserver {
     58  public:
     59   NetworkServicePropertiesWatcher(
     60       const NetworkPropertiesWatcherCallback& callback,
     61       const std::string& service_path) : service_path_(service_path),
     62                                          callback_(callback) {
     63     DBusThreadManager::Get()->GetShillServiceClient()->
     64         AddPropertyChangedObserver(dbus::ObjectPath(service_path), this);
     65   }
     66 
     67   virtual ~NetworkServicePropertiesWatcher() {
     68     DBusThreadManager::Get()->GetShillServiceClient()->
     69         RemovePropertyChangedObserver(dbus::ObjectPath(service_path_), this);
     70   }
     71 
     72   virtual void OnPropertyChanged(const std::string& name,
     73                                  const base::Value& value) OVERRIDE {
     74     callback_.Run(service_path_, name, value);
     75   }
     76 
     77  private:
     78   std::string service_path_;
     79   NetworkPropertiesWatcherCallback callback_;
     80 };
     81 
     82 // Class to watch network device's properties without Libcros.
     83 class NetworkDevicePropertiesWatcher
     84     : public CrosNetworkWatcher,
     85       public ShillPropertyChangedObserver {
     86  public:
     87   NetworkDevicePropertiesWatcher(
     88       const NetworkPropertiesWatcherCallback& callback,
     89       const std::string& device_path) : device_path_(device_path),
     90                                         callback_(callback) {
     91     DBusThreadManager::Get()->GetShillDeviceClient()->
     92         AddPropertyChangedObserver(dbus::ObjectPath(device_path), this);
     93   }
     94 
     95   virtual ~NetworkDevicePropertiesWatcher() {
     96     DBusThreadManager::Get()->GetShillDeviceClient()->
     97         RemovePropertyChangedObserver(dbus::ObjectPath(device_path_), this);
     98   }
     99 
    100   virtual void OnPropertyChanged(const std::string& name,
    101                                  const base::Value& value) OVERRIDE {
    102     callback_.Run(device_path_, name, value);
    103   }
    104 
    105  private:
    106   std::string device_path_;
    107   NetworkPropertiesWatcherCallback callback_;
    108 };
    109 
    110 // Gets a string property from dictionary.
    111 bool GetStringProperty(const base::DictionaryValue& dictionary,
    112                        const std::string& key,
    113                        std::string* out) {
    114   const bool result = dictionary.GetStringWithoutPathExpansion(key, out);
    115   LOG_IF(WARNING, !result) << "Cannnot get property " << key;
    116   return result;
    117 }
    118 
    119 // Gets an int64 property from dictionary.
    120 bool GetInt64Property(const base::DictionaryValue& dictionary,
    121                       const std::string& key,
    122                       int64* out) {
    123   // Int64 value is stored as a double because it cannot be fitted in int32.
    124   double value_double = 0;
    125   const bool result = dictionary.GetDoubleWithoutPathExpansion(key,
    126                                                                &value_double);
    127   if (result)
    128     *out = value_double;
    129   else
    130     LOG(WARNING) << "Cannnot get property " << key;
    131   return result;
    132 }
    133 
    134 // Gets a base::Time property from dictionary.
    135 bool GetTimeProperty(const base::DictionaryValue& dictionary,
    136                      const std::string& key,
    137                      base::Time* out) {
    138   int64 value_int64 = 0;
    139   if (!GetInt64Property(dictionary, key, &value_int64))
    140     return false;
    141   *out = base::Time::FromInternalValue(value_int64);
    142   return true;
    143 }
    144 
    145 // Does nothing. Used as a callback.
    146 void DoNothingWithCallStatus(DBusMethodCallStatus call_status) {}
    147 
    148 // Does nothing. Used as a callback.
    149 void DoNothingWithObjectPath(const dbus::ObjectPath& object_path) {}
    150 
    151 // Ignores errors.
    152 void IgnoreErrors(const std::string& error_name,
    153                   const std::string& error_message) {}
    154 
    155 // A callback used to implement CrosRequest*Properties functions.
    156 void RunCallbackWithDictionaryValue(const NetworkPropertiesCallback& callback,
    157                                     const std::string& path,
    158                                     DBusMethodCallStatus call_status,
    159                                     const base::DictionaryValue& value) {
    160   callback.Run(path, call_status == DBUS_METHOD_CALL_SUCCESS ? &value : NULL);
    161 }
    162 
    163 // A callback used to implement CrosRequest*Properties functions.
    164 void RunCallbackWithDictionaryValueNoStatus(
    165     const NetworkPropertiesCallback& callback,
    166     const std::string& path,
    167     const base::DictionaryValue& value) {
    168   callback.Run(path, &value);
    169 }
    170 
    171 // A callback used to implement the error callback for CrosRequest*Properties
    172 // functions.
    173 void RunCallbackWithDictionaryValueError(
    174     const NetworkPropertiesCallback& callback,
    175     const std::string& path,
    176     const std::string& error_name,
    177     const std::string& error_message) {
    178   callback.Run(path, NULL);
    179 }
    180 
    181 // Used as a callback for ShillManagerClient::GetService
    182 void OnGetService(const NetworkPropertiesCallback& callback,
    183                   const dbus::ObjectPath& service_path) {
    184   VLOG(1) << "OnGetServiceService: " << service_path.value();
    185   DBusThreadManager::Get()->GetShillServiceClient()->GetProperties(
    186       service_path, base::Bind(&RunCallbackWithDictionaryValue,
    187                                callback,
    188                                service_path.value()));
    189 }
    190 
    191 // A callback used to call a NetworkOperationCallback on error.
    192 void OnNetworkActionError(const NetworkOperationCallback& callback,
    193                           const std::string& path,
    194                           const std::string& error_name,
    195                           const std::string& error_message) {
    196   if (error_name.empty())
    197     callback.Run(path, NETWORK_METHOD_ERROR_LOCAL, "");
    198   else
    199     callback.Run(path, NETWORK_METHOD_ERROR_REMOTE, error_message);
    200 }
    201 
    202 IPConfigType ParseIPConfigType(const std::string& type) {
    203   if (type == flimflam::kTypeIPv4)
    204     return IPCONFIG_TYPE_IPV4;
    205   if (type == flimflam::kTypeIPv6)
    206     return IPCONFIG_TYPE_IPV6;
    207   if (type == flimflam::kTypeDHCP)
    208     return IPCONFIG_TYPE_DHCP;
    209   if (type == flimflam::kTypeBOOTP)
    210     return IPCONFIG_TYPE_BOOTP;
    211   if (type == flimflam::kTypeZeroConf)
    212     return IPCONFIG_TYPE_ZEROCONF;
    213   if (type == flimflam::kTypeDHCP6)
    214     return IPCONFIG_TYPE_DHCP6;
    215   if (type == flimflam::kTypePPP)
    216     return IPCONFIG_TYPE_PPP;
    217   return IPCONFIG_TYPE_UNKNOWN;
    218 }
    219 
    220 // Converts a list of name servers to a string.
    221 std::string ConvertNameSerersListToString(const base::ListValue& name_servers) {
    222   std::string result;
    223   for (size_t i = 0; i != name_servers.GetSize(); ++i) {
    224     std::string name_server;
    225     if (!name_servers.GetString(i, &name_server)) {
    226       LOG(ERROR) << "name_servers[" << i << "] is not a string.";
    227       continue;
    228     }
    229     if (!result.empty())
    230       result += ",";
    231     result += name_server;
    232   }
    233   return result;
    234 }
    235 
    236 // Gets NetworkIPConfigVector populated with data from a
    237 // given DBus object path.
    238 //
    239 // returns true on success.
    240 bool ParseIPConfig(const std::string& device_path,
    241                    const std::string& ipconfig_path,
    242                    NetworkIPConfigVector* ipconfig_vector) {
    243   ShillIPConfigClient* ipconfig_client =
    244       DBusThreadManager::Get()->GetShillIPConfigClient();
    245   // TODO(hashimoto): Remove this blocking D-Bus method call. crosbug.com/29902
    246   scoped_ptr<base::DictionaryValue> properties(
    247       ipconfig_client->CallGetPropertiesAndBlock(
    248           dbus::ObjectPath(ipconfig_path)));
    249   if (!properties.get())
    250     return false;
    251 
    252   std::string type_string;
    253   properties->GetStringWithoutPathExpansion(flimflam::kMethodProperty,
    254                                             &type_string);
    255   std::string address;
    256   properties->GetStringWithoutPathExpansion(flimflam::kAddressProperty,
    257                                             &address);
    258   int32 prefix_len = 0;
    259   properties->GetIntegerWithoutPathExpansion(flimflam::kPrefixlenProperty,
    260                                              &prefix_len);
    261   std::string gateway;
    262   properties->GetStringWithoutPathExpansion(flimflam::kGatewayProperty,
    263                                             &gateway);
    264   base::ListValue* name_servers = NULL;
    265   std::string name_servers_string;
    266   // store nameservers as a comma delimited list
    267   if (properties->GetListWithoutPathExpansion(flimflam::kNameServersProperty,
    268                                               &name_servers)) {
    269     name_servers_string = ConvertNameSerersListToString(*name_servers);
    270   } else {
    271     LOG(ERROR) << "Cannot get name servers.";
    272   }
    273   ipconfig_vector->push_back(
    274       NetworkIPConfig(device_path,
    275                       ParseIPConfigType(type_string),
    276                       address,
    277                       network_util::PrefixLengthToNetmask(prefix_len),
    278                       gateway,
    279                       name_servers_string));
    280   return true;
    281 }
    282 
    283 void ListIPConfigsCallback(const NetworkGetIPConfigsCallback& callback,
    284                            const std::string& device_path,
    285                            DBusMethodCallStatus call_status,
    286                            const base::DictionaryValue& properties) {
    287   NetworkIPConfigVector ipconfig_vector;
    288   std::string hardware_address;
    289   const base::ListValue* ips = NULL;
    290   if (call_status != DBUS_METHOD_CALL_SUCCESS ||
    291       !properties.GetListWithoutPathExpansion(flimflam::kIPConfigsProperty,
    292                                               &ips)) {
    293     callback.Run(ipconfig_vector, hardware_address);
    294     return;
    295   }
    296 
    297   for (size_t i = 0; i < ips->GetSize(); i++) {
    298     std::string ipconfig_path;
    299     if (!ips->GetString(i, &ipconfig_path)) {
    300       LOG(WARNING) << "Found NULL ip for device " << device_path;
    301       continue;
    302     }
    303     ParseIPConfig(device_path, ipconfig_path, &ipconfig_vector);
    304   }
    305   // Get the hardware address as well.
    306   properties.GetStringWithoutPathExpansion(flimflam::kAddressProperty,
    307                                            &hardware_address);
    308 
    309   callback.Run(ipconfig_vector, hardware_address);
    310 }
    311 
    312 }  // namespace
    313 
    314 bool CrosActivateCellularModem(const std::string& service_path,
    315                                const std::string& carrier) {
    316   return DBusThreadManager::Get()->GetShillServiceClient()->
    317       CallActivateCellularModemAndBlock(dbus::ObjectPath(service_path),
    318                                         carrier);
    319 }
    320 
    321 void CrosCompleteCellularActivation(const std::string& service_path) {
    322   return DBusThreadManager::Get()->GetShillServiceClient()->
    323       CompleteCellularActivation(dbus::ObjectPath(service_path),
    324                                  base::Bind(&DoNothing),
    325                                  base::Bind(&IgnoreErrors));
    326 }
    327 
    328 void CrosSetNetworkServiceProperty(const std::string& service_path,
    329                                    const std::string& property,
    330                                    const base::Value& value) {
    331   DBusThreadManager::Get()->GetShillServiceClient()->SetProperty(
    332       dbus::ObjectPath(service_path), property, value,
    333       base::Bind(&DoNothing),
    334       base::Bind(&IgnoreErrors));
    335 }
    336 
    337 void CrosClearNetworkServiceProperty(const std::string& service_path,
    338                                      const std::string& property) {
    339   DBusThreadManager::Get()->GetShillServiceClient()->ClearProperty(
    340       dbus::ObjectPath(service_path), property, base::Bind(&DoNothing),
    341       base::Bind(&IgnoreErrors));
    342 }
    343 
    344 void CrosSetNetworkDeviceProperty(const std::string& device_path,
    345                                   const std::string& property,
    346                                   const base::Value& value) {
    347   DBusThreadManager::Get()->GetShillDeviceClient()->SetProperty(
    348       dbus::ObjectPath(device_path), property, value, base::Bind(&DoNothing),
    349       base::Bind(&IgnoreErrors));
    350 }
    351 
    352 void CrosSetNetworkIPConfigProperty(const std::string& ipconfig_path,
    353                                     const std::string& property,
    354                                     const base::Value& value) {
    355   DBusThreadManager::Get()->GetShillIPConfigClient()->SetProperty(
    356       dbus::ObjectPath(ipconfig_path), property, value,
    357       base::Bind(&DoNothingWithCallStatus));
    358 }
    359 
    360 void CrosSetNetworkManagerProperty(const std::string& property,
    361                                    const base::Value& value) {
    362   DBusThreadManager::Get()->GetShillManagerClient()->SetProperty(
    363       property, value, base::Bind(&DoNothing),
    364       base::Bind(&IgnoreErrors));
    365 }
    366 
    367 void CrosDeleteServiceFromProfile(const std::string& profile_path,
    368                                   const std::string& service_path) {
    369   DBusThreadManager::Get()->GetShillProfileClient()->DeleteEntry(
    370       dbus::ObjectPath(profile_path),
    371       service_path,
    372       base::Bind(&DoNothing),
    373       base::Bind(&IgnoreErrors));
    374 }
    375 
    376 CrosNetworkWatcher* CrosMonitorNetworkManagerProperties(
    377     const NetworkPropertiesWatcherCallback& callback) {
    378   return new NetworkManagerPropertiesWatcher(callback);
    379 }
    380 
    381 CrosNetworkWatcher* CrosMonitorNetworkServiceProperties(
    382     const NetworkPropertiesWatcherCallback& callback,
    383     const std::string& service_path) {
    384   return new NetworkServicePropertiesWatcher(callback, service_path);
    385 }
    386 
    387 CrosNetworkWatcher* CrosMonitorNetworkDeviceProperties(
    388     const NetworkPropertiesWatcherCallback& callback,
    389     const std::string& device_path) {
    390   return new NetworkDevicePropertiesWatcher(callback, device_path);
    391 }
    392 
    393 CrosNetworkWatcher* CrosMonitorSMS(const std::string& modem_device_path,
    394                                    MonitorSMSCallback callback) {
    395   return new SMSWatcher(modem_device_path, callback);
    396 }
    397 
    398 void CrosRequestNetworkServiceConnect(
    399     const std::string& service_path,
    400     const NetworkOperationCallback& callback) {
    401   DBusThreadManager::Get()->GetShillServiceClient()->Connect(
    402       dbus::ObjectPath(service_path),
    403       base::Bind(callback, service_path, NETWORK_METHOD_ERROR_NONE,
    404                  std::string()),
    405       base::Bind(&OnNetworkActionError, callback, service_path));
    406 }
    407 
    408 void CrosRequestNetworkManagerProperties(
    409     const NetworkPropertiesCallback& callback) {
    410   DBusThreadManager::Get()->GetShillManagerClient()->GetProperties(
    411       base::Bind(&RunCallbackWithDictionaryValue,
    412                  callback,
    413                  flimflam::kFlimflamServicePath));
    414 }
    415 
    416 void CrosRequestNetworkServiceProperties(
    417     const std::string& service_path,
    418     const NetworkPropertiesCallback& callback) {
    419   DBusThreadManager::Get()->GetShillServiceClient()->GetProperties(
    420       dbus::ObjectPath(service_path),
    421       base::Bind(&RunCallbackWithDictionaryValue, callback, service_path));
    422 }
    423 
    424 void CrosRequestNetworkDeviceProperties(
    425     const std::string& device_path,
    426     const NetworkPropertiesCallback& callback) {
    427   DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties(
    428       dbus::ObjectPath(device_path),
    429       base::Bind(&RunCallbackWithDictionaryValue, callback, device_path));
    430 }
    431 
    432 void CrosRequestNetworkProfileProperties(
    433     const std::string& profile_path,
    434     const NetworkPropertiesCallback& callback) {
    435   DBusThreadManager::Get()->GetShillProfileClient()->GetProperties(
    436       dbus::ObjectPath(profile_path),
    437       base::Bind(&RunCallbackWithDictionaryValueNoStatus,
    438                  callback, profile_path),
    439       base::Bind(&RunCallbackWithDictionaryValueError, callback, profile_path));
    440 }
    441 
    442 void CrosRequestNetworkProfileEntryProperties(
    443     const std::string& profile_path,
    444     const std::string& profile_entry_path,
    445     const NetworkPropertiesCallback& callback) {
    446   DBusThreadManager::Get()->GetShillProfileClient()->GetEntry(
    447       dbus::ObjectPath(profile_path),
    448       profile_entry_path,
    449       base::Bind(&RunCallbackWithDictionaryValueNoStatus,
    450                  callback,
    451                  profile_entry_path),
    452       base::Bind(&RunCallbackWithDictionaryValueError,
    453                  callback,
    454                  profile_entry_path));
    455 }
    456 
    457 void CrosRequestHiddenWifiNetworkProperties(
    458     const std::string& ssid,
    459     const std::string& security,
    460     const NetworkPropertiesCallback& callback) {
    461   base::DictionaryValue properties;
    462   properties.SetWithoutPathExpansion(
    463       flimflam::kModeProperty,
    464       new base::StringValue(flimflam::kModeManaged));
    465   properties.SetWithoutPathExpansion(
    466       flimflam::kTypeProperty,
    467       new base::StringValue(flimflam::kTypeWifi));
    468   properties.SetWithoutPathExpansion(
    469       flimflam::kSSIDProperty,
    470       new base::StringValue(ssid));
    471   properties.SetWithoutPathExpansion(
    472       flimflam::kSecurityProperty,
    473       new base::StringValue(security));
    474   // shill.Manger.GetService() will apply the property changes in
    475   // |properties| and return a new or existing service to OnGetService().
    476   // OnGetService will then call GetProperties which will then call callback.
    477   DBusThreadManager::Get()->GetShillManagerClient()->GetService(
    478       properties, base::Bind(&OnGetService, callback),
    479       base::Bind(&IgnoreErrors));
    480 }
    481 
    482 void CrosRequestVirtualNetworkProperties(
    483     const std::string& service_name,
    484     const std::string& server_hostname,
    485     const std::string& provider_type,
    486     const NetworkPropertiesCallback& callback) {
    487   base::DictionaryValue properties;
    488   properties.SetWithoutPathExpansion(
    489       flimflam::kTypeProperty,
    490       new base::StringValue(flimflam::kTypeVPN));
    491   properties.SetWithoutPathExpansion(
    492       flimflam::kNameProperty,
    493       new base::StringValue(service_name));
    494   properties.SetWithoutPathExpansion(
    495       flimflam::kProviderHostProperty,
    496       new base::StringValue(server_hostname));
    497   properties.SetWithoutPathExpansion(
    498       flimflam::kProviderTypeProperty,
    499       new base::StringValue(provider_type));
    500 
    501   // shill.Manger.ConfigureService() will apply the property changes in
    502   // |properties| and pass a new or existing service to OnGetService().
    503   // OnGetService will then call GetProperties which will then call callback.
    504   DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService(
    505       properties, base::Bind(&OnGetService, callback),
    506       base::Bind(&IgnoreErrors));
    507 }
    508 
    509 void CrosRequestNetworkServiceDisconnect(const std::string& service_path) {
    510   DBusThreadManager::Get()->GetShillServiceClient()->Disconnect(
    511       dbus::ObjectPath(service_path), base::Bind(&DoNothing),
    512       base::Bind(&IgnoreErrors));
    513 }
    514 
    515 void CrosRequestRemoveNetworkService(const std::string& service_path) {
    516   DBusThreadManager::Get()->GetShillServiceClient()->Remove(
    517       dbus::ObjectPath(service_path), base::Bind(&DoNothing),
    518       base::Bind(&IgnoreErrors));
    519 }
    520 
    521 void CrosRequestNetworkScan(const std::string& network_type) {
    522   DBusThreadManager::Get()->GetShillManagerClient()->RequestScan(
    523       network_type, base::Bind(&DoNothing),
    524       base::Bind(&IgnoreErrors));
    525 }
    526 
    527 void CrosRequestNetworkDeviceEnable(const std::string& network_type,
    528                                     bool enable) {
    529   if (enable) {
    530     DBusThreadManager::Get()->GetShillManagerClient()->EnableTechnology(
    531         network_type, base::Bind(&DoNothing),
    532         base::Bind(&IgnoreErrors));
    533   } else {
    534     DBusThreadManager::Get()->GetShillManagerClient()->DisableTechnology(
    535         network_type, base::Bind(&DoNothing),
    536         base::Bind(&IgnoreErrors));
    537   }
    538 }
    539 
    540 void CrosRequestRequirePin(const std::string& device_path,
    541                            const std::string& pin,
    542                            bool enable,
    543                            const NetworkOperationCallback& callback) {
    544   DBusThreadManager::Get()->GetShillDeviceClient()->RequirePin(
    545       dbus::ObjectPath(device_path), pin, enable,
    546       base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
    547                  std::string()),
    548       base::Bind(&OnNetworkActionError, callback, device_path));
    549 }
    550 
    551 void CrosRequestEnterPin(const std::string& device_path,
    552                          const std::string& pin,
    553                          const NetworkOperationCallback& callback) {
    554   DBusThreadManager::Get()->GetShillDeviceClient()->EnterPin(
    555       dbus::ObjectPath(device_path), pin,
    556       base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
    557                  std::string()),
    558       base::Bind(&OnNetworkActionError, callback, device_path));
    559 }
    560 
    561 void CrosRequestUnblockPin(const std::string& device_path,
    562                            const std::string& unblock_code,
    563                            const std::string& pin,
    564                            const NetworkOperationCallback& callback) {
    565   DBusThreadManager::Get()->GetShillDeviceClient()->UnblockPin(
    566       dbus::ObjectPath(device_path), unblock_code, pin,
    567       base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
    568                  std::string()),
    569       base::Bind(&OnNetworkActionError, callback, device_path));
    570 }
    571 
    572 void CrosRequestChangePin(const std::string& device_path,
    573                           const std::string& old_pin,
    574                           const std::string& new_pin,
    575                           const NetworkOperationCallback& callback) {
    576   DBusThreadManager::Get()->GetShillDeviceClient()->ChangePin(
    577       dbus::ObjectPath(device_path), old_pin, new_pin,
    578       base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
    579                  std::string()),
    580       base::Bind(&OnNetworkActionError, callback, device_path));
    581 }
    582 
    583 void CrosProposeScan(const std::string& device_path) {
    584   DBusThreadManager::Get()->GetShillDeviceClient()->ProposeScan(
    585       dbus::ObjectPath(device_path), base::Bind(&DoNothingWithCallStatus));
    586 }
    587 
    588 void CrosRequestCellularRegister(const std::string& device_path,
    589                                  const std::string& network_id,
    590                                  const NetworkOperationCallback& callback) {
    591   DBusThreadManager::Get()->GetShillDeviceClient()->Register(
    592       dbus::ObjectPath(device_path), network_id,
    593       base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
    594                  std::string()),
    595       base::Bind(&OnNetworkActionError, callback, device_path));
    596 }
    597 
    598 void CrosListIPConfigs(const std::string& device_path,
    599                        const NetworkGetIPConfigsCallback& callback) {
    600   const dbus::ObjectPath device_object_path(device_path);
    601   DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties(
    602       device_object_path,
    603       base::Bind(&ListIPConfigsCallback, callback, device_path));
    604 }
    605 
    606 void CrosRequestIPConfigRefresh(const std::string& ipconfig_path) {
    607   DBusThreadManager::Get()->GetShillIPConfigClient()->Refresh(
    608       dbus::ObjectPath(ipconfig_path),
    609       base::Bind(&DoNothingWithCallStatus));
    610 }
    611 
    612 void CrosConfigureService(const base::DictionaryValue& properties) {
    613   DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService(
    614       properties, base::Bind(&DoNothingWithObjectPath),
    615       base::Bind(&IgnoreErrors));
    616 }
    617 
    618 // Changes the active cellular carrier.
    619 void CrosSetCarrier(const std::string& device_path,
    620                     const std::string& carrier,
    621                     const NetworkOperationCallback& callback) {
    622   DBusThreadManager::Get()->GetShillDeviceClient()->SetCarrier(
    623       dbus::ObjectPath(device_path), carrier,
    624       base::Bind(callback, device_path, NETWORK_METHOD_ERROR_NONE,
    625                  std::string()),
    626       base::Bind(&OnNetworkActionError, callback, device_path));
    627 }
    628 
    629 }  // namespace chromeos
    630