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 "chromeos/dbus/shill_manager_client.h" | 5 #include "chromeos/dbus/shill_manager_client.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/chromeos/chromeos_version.h" | 8 #include "base/chromeos/chromeos_version.h" |
| 9 #include "base/logging.h" |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "base/values.h" | 11 #include "base/values.h" |
11 #include "chromeos/dbus/shill_manager_client_stub.h" | 12 #include "chromeos/dbus/shill_manager_client_stub.h" |
12 #include "chromeos/dbus/shill_property_changed_observer.h" | 13 #include "chromeos/dbus/shill_property_changed_observer.h" |
13 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
14 #include "dbus/message.h" | 15 #include "dbus/message.h" |
15 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
16 #include "dbus/object_proxy.h" | 17 #include "dbus/object_proxy.h" |
17 #include "dbus/values_util.h" | 18 #include "dbus/values_util.h" |
18 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
19 | 20 |
20 namespace chromeos { | 21 namespace chromeos { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
| 25 const char kIncompleteServiceProperties[] = "Error.IncompleteServiceProperties"; |
| 26 const char kIncompleteServicePropertiesMessage[] = |
| 27 "Service properties are incomplete."; |
| 28 |
24 // Returns whether the properties have the required keys or not. | 29 // Returns whether the properties have the required keys or not. |
25 bool AreServicePropertiesValid(const base::DictionaryValue& properties) { | 30 bool AreServicePropertiesValidWithMode( |
26 if (properties.HasKey(flimflam::kGuidProperty)) | 31 const base::DictionaryValue& properties, |
| 32 const ShillManagerClient::ErrorCallback& error_callback) { |
| 33 if (properties.HasKey(flimflam::kGuidProperty) || |
| 34 (properties.HasKey(flimflam::kTypeProperty) && |
| 35 properties.HasKey(flimflam::kSecurityProperty) && |
| 36 properties.HasKey(flimflam::kModeProperty) && |
| 37 properties.HasKey(flimflam::kSSIDProperty))) { |
27 return true; | 38 return true; |
28 return properties.HasKey(flimflam::kTypeProperty) && | 39 } |
29 properties.HasKey(flimflam::kSecurityProperty) && | 40 error_callback.Run(kIncompleteServiceProperties, |
30 properties.HasKey(flimflam::kSSIDProperty); | 41 kIncompleteServicePropertiesMessage); |
| 42 return false; |
| 43 } |
| 44 |
| 45 // DEPRECATED: Keep this only for backward compatibility with NetworkLibrary. |
| 46 // Returns whether the properties have the required keys or not. |
| 47 // TODO(pneubeck): remove this once NetworkLibrary is gone (crbug/230799). |
| 48 bool AreServicePropertiesValid( |
| 49 const base::DictionaryValue& properties, |
| 50 const ShillManagerClient::ErrorCallback& error_callback) { |
| 51 if (properties.HasKey(flimflam::kGuidProperty) || |
| 52 (properties.HasKey(flimflam::kTypeProperty) && |
| 53 properties.HasKey(flimflam::kSecurityProperty) && |
| 54 properties.HasKey(flimflam::kSSIDProperty))) { |
| 55 return true; |
| 56 } |
| 57 error_callback.Run(kIncompleteServiceProperties, |
| 58 kIncompleteServicePropertiesMessage); |
| 59 return false; |
31 } | 60 } |
32 | 61 |
33 // Appends a string-to-variant dictionary to the writer. | 62 // Appends a string-to-variant dictionary to the writer. |
34 void AppendServicePropertiesDictionary( | 63 void AppendServicePropertiesDictionary( |
35 dbus::MessageWriter* writer, | 64 dbus::MessageWriter* writer, |
36 const base::DictionaryValue& dictionary) { | 65 const base::DictionaryValue& dictionary) { |
37 dbus::MessageWriter array_writer(NULL); | 66 dbus::MessageWriter array_writer(NULL); |
38 writer->OpenArray("{sv}", &array_writer); | 67 writer->OpenArray("{sv}", &array_writer); |
39 for (base::DictionaryValue::Iterator it(dictionary); | 68 for (base::DictionaryValue::Iterator it(dictionary); |
40 !it.IsAtEnd(); | 69 !it.IsAtEnd(); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 writer.AppendString(type); | 168 writer.AppendString(type); |
140 helper_.CallVoidMethodWithErrorCallback(&method_call, | 169 helper_.CallVoidMethodWithErrorCallback(&method_call, |
141 callback, | 170 callback, |
142 error_callback); | 171 error_callback); |
143 } | 172 } |
144 | 173 |
145 virtual void ConfigureService( | 174 virtual void ConfigureService( |
146 const base::DictionaryValue& properties, | 175 const base::DictionaryValue& properties, |
147 const ObjectPathCallback& callback, | 176 const ObjectPathCallback& callback, |
148 const ErrorCallback& error_callback) OVERRIDE { | 177 const ErrorCallback& error_callback) OVERRIDE { |
149 DCHECK(AreServicePropertiesValid(properties)); | 178 if (!AreServicePropertiesValid(properties, error_callback)) { |
| 179 NOTREACHED() << kIncompleteServicePropertiesMessage; |
| 180 return; |
| 181 } |
150 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, | 182 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, |
151 flimflam::kConfigureServiceFunction); | 183 flimflam::kConfigureServiceFunction); |
152 dbus::MessageWriter writer(&method_call); | 184 dbus::MessageWriter writer(&method_call); |
153 AppendServicePropertiesDictionary(&writer, properties); | 185 AppendServicePropertiesDictionary(&writer, properties); |
154 helper_.CallObjectPathMethodWithErrorCallback(&method_call, | 186 helper_.CallObjectPathMethodWithErrorCallback(&method_call, |
155 callback, | 187 callback, |
156 error_callback); | 188 error_callback); |
157 } | 189 } |
158 | 190 |
| 191 virtual void ConfigureServiceForProfile( |
| 192 const dbus::ObjectPath& profile_path, |
| 193 const base::DictionaryValue& properties, |
| 194 const ObjectPathCallback& callback, |
| 195 const ErrorCallback& error_callback) OVERRIDE { |
| 196 if (!AreServicePropertiesValidWithMode(properties, error_callback)) { |
| 197 NOTREACHED() << kIncompleteServicePropertiesMessage; |
| 198 return; |
| 199 } |
| 200 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, |
| 201 shill::kConfigureServiceForProfileFunction); |
| 202 dbus::MessageWriter writer(&method_call); |
| 203 writer.AppendObjectPath(dbus::ObjectPath(profile_path)); |
| 204 AppendServicePropertiesDictionary(&writer, properties); |
| 205 helper_.CallObjectPathMethodWithErrorCallback(&method_call, |
| 206 callback, |
| 207 error_callback); |
| 208 } |
| 209 |
159 virtual void GetService( | 210 virtual void GetService( |
160 const base::DictionaryValue& properties, | 211 const base::DictionaryValue& properties, |
161 const ObjectPathCallback& callback, | 212 const ObjectPathCallback& callback, |
162 const ErrorCallback& error_callback) OVERRIDE { | 213 const ErrorCallback& error_callback) OVERRIDE { |
163 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, | 214 dbus::MethodCall method_call(flimflam::kFlimflamManagerInterface, |
164 flimflam::kGetServiceFunction); | 215 flimflam::kGetServiceFunction); |
165 dbus::MessageWriter writer(&method_call); | 216 dbus::MessageWriter writer(&method_call); |
166 AppendServicePropertiesDictionary(&writer, properties); | 217 AppendServicePropertiesDictionary(&writer, properties); |
167 helper_.CallObjectPathMethodWithErrorCallback(&method_call, | 218 helper_.CallObjectPathMethodWithErrorCallback(&method_call, |
168 callback, | 219 callback, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 ShillManagerClient* ShillManagerClient::Create( | 317 ShillManagerClient* ShillManagerClient::Create( |
267 DBusClientImplementationType type, | 318 DBusClientImplementationType type, |
268 dbus::Bus* bus) { | 319 dbus::Bus* bus) { |
269 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) | 320 if (type == REAL_DBUS_CLIENT_IMPLEMENTATION) |
270 return new ShillManagerClientImpl(bus); | 321 return new ShillManagerClientImpl(bus); |
271 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); | 322 DCHECK_EQ(STUB_DBUS_CLIENT_IMPLEMENTATION, type); |
272 return new ShillManagerClientStub(); | 323 return new ShillManagerClientStub(); |
273 } | 324 } |
274 | 325 |
275 } // namespace chromeos | 326 } // namespace chromeos |
OLD | NEW |