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

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

Issue 9958045: Reimplement Libcros fucntions using FlimflamProfileClient (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 8 months 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 | Annotate | Revision Log
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/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 Libcros network functions or not.
55 bool g_libcros_network_functions_enabled = true;
56
40 } // namespace 57 } // namespace
41 58
59 void SetLibcrosNetworkFunctionsEnabled(bool enabled) {
60 g_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
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_libcros_network_functions_enabled) {
104 chromeos::DeleteServiceFromProfile(profile_path, service_path);
105 } else {
106 DBusThreadManager::Get()->GetFlimflamProfileClient()->DeleteEntry(
107 dbus::ObjectPath(profile_path), service_path, base::Bind(&DoNothing));
108 }
83 } 109 }
84 110
85 void CrosRequestCellularDataPlanUpdate(const char* modem_service_path) { 111 void CrosRequestCellularDataPlanUpdate(const char* modem_service_path) {
86 chromeos::RequestCellularDataPlanUpdate(modem_service_path); 112 chromeos::RequestCellularDataPlanUpdate(modem_service_path);
87 } 113 }
88 114
89 NetworkPropertiesMonitor CrosMonitorNetworkManagerProperties( 115 NetworkPropertiesMonitor CrosMonitorNetworkManagerProperties(
90 MonitorPropertyGValueCallback callback, 116 MonitorPropertyGValueCallback callback,
91 void* object) { 117 void* object) {
92 return chromeos::MonitorNetworkManagerProperties(callback, object); 118 return chromeos::MonitorNetworkManagerProperties(callback, object);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 // The newly allocated callback will be deleted in OnRequestNetworkProperties. 189 // The newly allocated callback will be deleted in OnRequestNetworkProperties.
164 chromeos::RequestNetworkDeviceProperties( 190 chromeos::RequestNetworkDeviceProperties(
165 device_path, 191 device_path,
166 &OnRequestNetworkProperties, 192 &OnRequestNetworkProperties,
167 new OnRequestNetworkPropertiesCallback(callback)); 193 new OnRequestNetworkPropertiesCallback(callback));
168 } 194 }
169 195
170 void CrosRequestNetworkProfileProperties( 196 void CrosRequestNetworkProfileProperties(
171 const char* profile_path, 197 const char* profile_path,
172 const NetworkPropertiesCallback& callback) { 198 const NetworkPropertiesCallback& callback) {
173 // The newly allocated callback will be deleted in OnRequestNetworkProperties. 199 if (g_libcros_network_functions_enabled) {
174 chromeos::RequestNetworkProfileProperties( 200 // The newly allocated callback will be deleted in
175 profile_path, 201 // OnRequestNetworkProperties.
176 &OnRequestNetworkProperties, 202 chromeos::RequestNetworkProfileProperties(
177 new OnRequestNetworkPropertiesCallback(callback)); 203 profile_path,
204 &OnRequestNetworkProperties,
205 new OnRequestNetworkPropertiesCallback(callback));
206 } else {
207 DBusThreadManager::Get()->GetFlimflamProfileClient()->GetProperties(
208 dbus::ObjectPath(profile_path),
209 base::Bind(&RunCallbackWithDictionaryValue, callback, profile_path));
210 }
178 } 211 }
179 212
180 void CrosRequestNetworkProfileEntryProperties( 213 void CrosRequestNetworkProfileEntryProperties(
181 const char* profile_path, 214 const char* profile_path,
182 const char* profile_entry_path, 215 const char* profile_entry_path,
183 const NetworkPropertiesCallback& callback) { 216 const NetworkPropertiesCallback& callback) {
184 // The newly allocated callback will be deleted in OnRequestNetworkProperties. 217 if (g_libcros_network_functions_enabled) {
185 chromeos::RequestNetworkProfileEntryProperties( 218 // The newly allocated callback will be deleted in
186 profile_path, 219 // OnRequestNetworkProperties.
187 profile_entry_path, 220 chromeos::RequestNetworkProfileEntryProperties(
188 &OnRequestNetworkProperties, 221 profile_path,
189 new OnRequestNetworkPropertiesCallback(callback)); 222 profile_entry_path,
223 &OnRequestNetworkProperties,
224 new OnRequestNetworkPropertiesCallback(callback));
225 } else {
226 DBusThreadManager::Get()->GetFlimflamProfileClient()->GetEntry(
227 dbus::ObjectPath(profile_path),
228 profile_entry_path,
229 base::Bind(&RunCallbackWithDictionaryValue,
230 callback,
231 profile_entry_path));
232 }
190 } 233 }
191 234
192 void CrosRequestHiddenWifiNetworkProperties( 235 void CrosRequestHiddenWifiNetworkProperties(
193 const char* ssid, 236 const char* ssid,
194 const char* security, 237 const char* security,
195 const NetworkPropertiesCallback& callback) { 238 const NetworkPropertiesCallback& callback) {
196 // The newly allocated callback will be deleted in OnRequestNetworkProperties. 239 // The newly allocated callback will be deleted in OnRequestNetworkProperties.
197 chromeos::RequestHiddenWifiNetworkProperties( 240 chromeos::RequestHiddenWifiNetworkProperties(
198 ssid, 241 ssid,
199 security, 242 security,
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 void CrosConfigureService(const char* identifier, 347 void CrosConfigureService(const char* identifier,
305 const base::DictionaryValue& properties, 348 const base::DictionaryValue& properties,
306 NetworkActionCallback callback, 349 NetworkActionCallback callback,
307 void* object) { 350 void* object) {
308 ScopedGHashTable ghash( 351 ScopedGHashTable ghash(
309 ConvertDictionaryValueToStringValueGHashTable(properties)); 352 ConvertDictionaryValueToStringValueGHashTable(properties));
310 chromeos::ConfigureService(identifier, ghash.get(), callback, object); 353 chromeos::ConfigureService(identifier, ghash.get(), callback, object);
311 } 354 }
312 355
313 } // namespace chromeos 356 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/cros/cros_network_functions.h ('k') | chrome/browser/chromeos/cros/cros_network_functions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698