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