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/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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/chromeos/cros/gvalue_util.h" | 10 #include "chrome/browser/chromeos/cros/gvalue_util.h" |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" | |
| 12 #include "chromeos/dbus/flimflam_profile_client.h" | |
| 13 #include "dbus/object_path.h" | |
| 11 | 14 |
| 12 namespace chromeos { | 15 namespace chromeos { |
| 13 | 16 |
| 14 namespace { | 17 namespace { |
| 15 | 18 |
| 19 // Does nothing. Used as a callback. | |
| 20 void DoNothing(DBusMethodCallStatus call_status) {} | |
| 21 | |
| 16 // Callback used by OnRequestNetworkProperties. | 22 // Callback used by OnRequestNetworkProperties. |
| 17 typedef base::Callback<void(const char* path, | 23 typedef base::Callback<void(const char* path, |
| 18 const base::DictionaryValue* properties) | 24 const base::DictionaryValue* properties) |
| 19 > OnRequestNetworkPropertiesCallback; | 25 > OnRequestNetworkPropertiesCallback; |
| 20 | 26 |
| 21 // Handles responses for RequestNetwork*Properties functions. | 27 // Handles responses for RequestNetwork*Properties functions. |
| 22 void OnRequestNetworkProperties(void* object, | 28 void OnRequestNetworkProperties(void* object, |
| 23 const char* path, | 29 const char* path, |
| 24 GHashTable* properties) { | 30 GHashTable* properties) { |
| 25 OnRequestNetworkPropertiesCallback* callback = | 31 OnRequestNetworkPropertiesCallback* callback = |
| 26 static_cast<OnRequestNetworkPropertiesCallback*>(object); | 32 static_cast<OnRequestNetworkPropertiesCallback*>(object); |
| 27 DictionaryValue* properties_dictionary = NULL; | 33 DictionaryValue* properties_dictionary = NULL; |
| 28 if (properties) | 34 if (properties) |
| 29 properties_dictionary = | 35 properties_dictionary = |
| 30 ConvertStringValueGHashTableToDictionaryValue(properties); | 36 ConvertStringValueGHashTableToDictionaryValue(properties); |
| 31 | 37 |
| 32 // Deleters. | 38 // Deleters. |
| 33 scoped_ptr<OnRequestNetworkPropertiesCallback> callback_deleter(callback); | 39 scoped_ptr<OnRequestNetworkPropertiesCallback> callback_deleter(callback); |
| 34 scoped_ptr<DictionaryValue> properties_dictionary_deleter( | 40 scoped_ptr<DictionaryValue> properties_dictionary_deleter( |
| 35 properties_dictionary); | 41 properties_dictionary); |
| 36 | 42 |
| 37 callback->Run(path, properties_dictionary); | 43 callback->Run(path, properties_dictionary); |
| 38 } | 44 } |
| 39 | 45 |
| 46 // A callback used to implement CrosRequest*Properties functions. | |
| 47 void RunCallbackWithDictionaryValue(const NetworkPropertiesCallback& callback, | |
| 48 const char* path, | |
| 49 DBusMethodCallStatus call_status, | |
| 50 const base::DictionaryValue& value) { | |
| 51 callback.Run(path, call_status == DBUS_METHOD_CALL_SUCCESS ? &value : NULL); | |
| 52 } | |
| 53 | |
| 54 // A bool to remember whether we are using non-Libcros implementation or not. | |
| 55 bool g_non_libcros_network_functions_enabled = false; | |
| 56 | |
| 40 } // namespace | 57 } // namespace |
| 41 | 58 |
| 59 void EnableNonLibcrosNetworkFunctions(bool enabled) { | |
| 60 g_non_libcros_network_functions_enabled = enabled; | |
| 61 } | |
| 62 | |
| 42 bool CrosActivateCellularModem(const char* service_path, const char* carrier) { | 63 bool CrosActivateCellularModem(const char* service_path, const char* carrier) { |
| 43 return chromeos::ActivateCellularModem(service_path, carrier); | 64 return chromeos::ActivateCellularModem(service_path, carrier); |
| 44 } | 65 } |
| 45 | 66 |
| 46 void CrosSetNetworkServiceProperty(const char* service_path, | 67 void CrosSetNetworkServiceProperty(const char* service_path, |
| 47 const char* property, | 68 const char* property, |
| 48 const base::Value& value) { | 69 const base::Value& value) { |
| 49 ScopedGValue gvalue(ConvertValueToGValue(value)); | 70 ScopedGValue gvalue(ConvertValueToGValue(value)); |
| 50 chromeos::SetNetworkServicePropertyGValue(service_path, property, | 71 chromeos::SetNetworkServicePropertyGValue(service_path, property, |
| 51 gvalue.get()); | 72 gvalue.get()); |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 72 } | 93 } |
| 73 | 94 |
| 74 void CrosSetNetworkManagerProperty(const char* property, | 95 void CrosSetNetworkManagerProperty(const char* property, |
| 75 const base::Value& value) { | 96 const base::Value& value) { |
| 76 ScopedGValue gvalue(ConvertValueToGValue(value)); | 97 ScopedGValue gvalue(ConvertValueToGValue(value)); |
| 77 chromeos::SetNetworkManagerPropertyGValue(property, gvalue.get()); | 98 chromeos::SetNetworkManagerPropertyGValue(property, gvalue.get()); |
| 78 } | 99 } |
| 79 | 100 |
| 80 void CrosDeleteServiceFromProfile(const char* profile_path, | 101 void CrosDeleteServiceFromProfile(const char* profile_path, |
| 81 const char* service_path) { | 102 const char* service_path) { |
| 82 chromeos::DeleteServiceFromProfile(profile_path, service_path); | 103 if (!g_non_libcros_network_functions_enabled) { |
| 104 // Use Libcros. | |
| 105 chromeos::DeleteServiceFromProfile(profile_path, service_path); | |
| 106 return; | |
|
stevenjb
2012/04/12 17:34:36
I don't think this is a good place for early-exit
hashimoto
2012/04/13 05:27:22
I thought new (non libcros) implementations may be
| |
| 107 } | |
| 108 DBusThreadManager::Get()->GetFlimflamProfileClient()->DeleteEntry( | |
| 109 dbus::ObjectPath(profile_path), service_path, base::Bind(&DoNothing)); | |
| 83 } | 110 } |
| 84 | 111 |
| 85 void CrosRequestCellularDataPlanUpdate(const char* modem_service_path) { | 112 void CrosRequestCellularDataPlanUpdate(const char* modem_service_path) { |
| 86 chromeos::RequestCellularDataPlanUpdate(modem_service_path); | 113 chromeos::RequestCellularDataPlanUpdate(modem_service_path); |
| 87 } | 114 } |
| 88 | 115 |
| 89 NetworkPropertiesMonitor CrosMonitorNetworkManagerProperties( | 116 NetworkPropertiesMonitor CrosMonitorNetworkManagerProperties( |
| 90 MonitorPropertyGValueCallback callback, | 117 MonitorPropertyGValueCallback callback, |
| 91 void* object) { | 118 void* object) { |
| 92 return chromeos::MonitorNetworkManagerProperties(callback, object); | 119 return chromeos::MonitorNetworkManagerProperties(callback, object); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 // The newly allocated callback will be deleted in OnRequestNetworkProperties. | 190 // The newly allocated callback will be deleted in OnRequestNetworkProperties. |
| 164 chromeos::RequestNetworkDeviceProperties( | 191 chromeos::RequestNetworkDeviceProperties( |
| 165 device_path, | 192 device_path, |
| 166 &OnRequestNetworkProperties, | 193 &OnRequestNetworkProperties, |
| 167 new OnRequestNetworkPropertiesCallback(callback)); | 194 new OnRequestNetworkPropertiesCallback(callback)); |
| 168 } | 195 } |
| 169 | 196 |
| 170 void CrosRequestNetworkProfileProperties( | 197 void CrosRequestNetworkProfileProperties( |
| 171 const char* profile_path, | 198 const char* profile_path, |
| 172 const NetworkPropertiesCallback& callback) { | 199 const NetworkPropertiesCallback& callback) { |
| 173 // The newly allocated callback will be deleted in OnRequestNetworkProperties. | 200 if (!g_non_libcros_network_functions_enabled) { |
| 174 chromeos::RequestNetworkProfileProperties( | 201 // Use Libcros. |
|
stevenjb
2012/04/12 17:34:36
unnecessary comment here and elsewhere
hashimoto
2012/04/13 05:27:22
Done.
| |
| 175 profile_path, | 202 // The newly allocated callback will be deleted in |
| 176 &OnRequestNetworkProperties, | 203 // OnRequestNetworkProperties. |
| 177 new OnRequestNetworkPropertiesCallback(callback)); | 204 chromeos::RequestNetworkProfileProperties( |
| 205 profile_path, | |
| 206 &OnRequestNetworkProperties, | |
| 207 new OnRequestNetworkPropertiesCallback(callback)); | |
| 208 return; | |
| 209 } | |
| 210 DBusThreadManager::Get()->GetFlimflamProfileClient()->GetProperties( | |
| 211 dbus::ObjectPath(profile_path), | |
| 212 base::Bind(&RunCallbackWithDictionaryValue, callback, profile_path)); | |
| 178 } | 213 } |
| 179 | 214 |
| 180 void CrosRequestNetworkProfileEntryProperties( | 215 void CrosRequestNetworkProfileEntryProperties( |
| 181 const char* profile_path, | 216 const char* profile_path, |
| 182 const char* profile_entry_path, | 217 const char* profile_entry_path, |
| 183 const NetworkPropertiesCallback& callback) { | 218 const NetworkPropertiesCallback& callback) { |
| 184 // The newly allocated callback will be deleted in OnRequestNetworkProperties. | 219 if (!g_non_libcros_network_functions_enabled) { |
| 185 chromeos::RequestNetworkProfileEntryProperties( | 220 // Use Libcros. |
| 186 profile_path, | 221 // The newly allocated callback will be deleted in |
| 222 // OnRequestNetworkProperties. | |
| 223 chromeos::RequestNetworkProfileEntryProperties( | |
| 224 profile_path, | |
| 225 profile_entry_path, | |
| 226 &OnRequestNetworkProperties, | |
| 227 new OnRequestNetworkPropertiesCallback(callback)); | |
| 228 return; | |
| 229 } | |
| 230 DBusThreadManager::Get()->GetFlimflamProfileClient()->GetEntry( | |
| 231 dbus::ObjectPath(profile_path), | |
| 187 profile_entry_path, | 232 profile_entry_path, |
| 188 &OnRequestNetworkProperties, | 233 base::Bind(&RunCallbackWithDictionaryValue, |
| 189 new OnRequestNetworkPropertiesCallback(callback)); | 234 callback, |
| 235 profile_entry_path)); | |
| 190 } | 236 } |
| 191 | 237 |
| 192 void CrosRequestHiddenWifiNetworkProperties( | 238 void CrosRequestHiddenWifiNetworkProperties( |
| 193 const char* ssid, | 239 const char* ssid, |
| 194 const char* security, | 240 const char* security, |
| 195 const NetworkPropertiesCallback& callback) { | 241 const NetworkPropertiesCallback& callback) { |
| 196 // The newly allocated callback will be deleted in OnRequestNetworkProperties. | 242 // The newly allocated callback will be deleted in OnRequestNetworkProperties. |
| 197 chromeos::RequestHiddenWifiNetworkProperties( | 243 chromeos::RequestHiddenWifiNetworkProperties( |
| 198 ssid, | 244 ssid, |
| 199 security, | 245 security, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 304 void CrosConfigureService(const char* identifier, | 350 void CrosConfigureService(const char* identifier, |
| 305 const base::DictionaryValue& properties, | 351 const base::DictionaryValue& properties, |
| 306 NetworkActionCallback callback, | 352 NetworkActionCallback callback, |
| 307 void* object) { | 353 void* object) { |
| 308 ScopedGHashTable ghash( | 354 ScopedGHashTable ghash( |
| 309 ConvertDictionaryValueToStringValueGHashTable(properties)); | 355 ConvertDictionaryValueToStringValueGHashTable(properties)); |
| 310 chromeos::ConfigureService(identifier, ghash.get(), callback, object); | 356 chromeos::ConfigureService(identifier, ghash.get(), callback, object); |
| 311 } | 357 } |
| 312 | 358 |
| 313 } // namespace chromeos | 359 } // namespace chromeos |
| OLD | NEW |