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/network/network_configuration_handler.h" | 5 #include "chromeos/network/network_configuration_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chromeos/dbus/dbus_method_call_status.h" | 15 #include "chromeos/dbus/dbus_method_call_status.h" |
16 #include "chromeos/dbus/dbus_thread_manager.h" | 16 #include "chromeos/dbus/dbus_thread_manager.h" |
17 #include "chromeos/dbus/shill_manager_client.h" | 17 #include "chromeos/dbus/shill_manager_client.h" |
18 #include "chromeos/dbus/shill_service_client.h" | 18 #include "chromeos/dbus/shill_service_client.h" |
19 #include "dbus/object_path.h" | 19 #include "dbus/object_path.h" |
20 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
21 | 21 |
22 namespace chromeos { | 22 namespace chromeos { |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 const char kLogModule[] = "NetworkConfigurationHandler"; | |
27 | |
28 NetworkConfigurationHandler* g_configuration_handler_instance = NULL; | 26 NetworkConfigurationHandler* g_configuration_handler_instance = NULL; |
29 | 27 |
30 // None of these error messages are user-facing: they should only appear in | 28 // None of these error messages are user-facing: they should only appear in |
31 // logs. | 29 // logs. |
32 const char kErrorsListTag[] = "errors"; | 30 const char kErrorsListTag[] = "errors"; |
33 const char kClearPropertiesFailedError[] = "Error.ClearPropertiesFailed"; | 31 const char kClearPropertiesFailedError[] = "Error.ClearPropertiesFailed"; |
34 const char kClearPropertiesFailedErrorMessage[] = "Clear properties failed"; | 32 const char kClearPropertiesFailedErrorMessage[] = "Clear properties failed"; |
35 const char kDBusFailedError[] = "Error.DBusFailed"; | 33 const char kDBusFailedError[] = "Error.DBusFailed"; |
36 const char kDBusFailedErrorMessage[] = "DBus call failed."; | 34 const char kDBusFailedErrorMessage[] = "DBus call failed."; |
37 | 35 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 139 |
142 void NetworkConfigurationHandler::SetProperties( | 140 void NetworkConfigurationHandler::SetProperties( |
143 const std::string& service_path, | 141 const std::string& service_path, |
144 const base::DictionaryValue& properties, | 142 const base::DictionaryValue& properties, |
145 const base::Closure& callback, | 143 const base::Closure& callback, |
146 const network_handler::ErrorCallback& error_callback) const { | 144 const network_handler::ErrorCallback& error_callback) const { |
147 DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService( | 145 DBusThreadManager::Get()->GetShillManagerClient()->ConfigureService( |
148 properties, | 146 properties, |
149 base::Bind(&IgnoreObjectPathCallback, callback), | 147 base::Bind(&IgnoreObjectPathCallback, callback), |
150 base::Bind(&network_handler::ShillErrorCallbackFunction, | 148 base::Bind(&network_handler::ShillErrorCallbackFunction, |
151 kLogModule, service_path, error_callback)); | 149 service_path, error_callback)); |
152 } | 150 } |
153 | 151 |
154 void NetworkConfigurationHandler::ClearProperties( | 152 void NetworkConfigurationHandler::ClearProperties( |
155 const std::string& service_path, | 153 const std::string& service_path, |
156 const std::vector<std::string>& names, | 154 const std::vector<std::string>& names, |
157 const base::Closure& callback, | 155 const base::Closure& callback, |
158 const network_handler::ErrorCallback& error_callback) { | 156 const network_handler::ErrorCallback& error_callback) { |
159 DBusThreadManager::Get()->GetShillServiceClient()->ClearProperties( | 157 DBusThreadManager::Get()->GetShillServiceClient()->ClearProperties( |
160 dbus::ObjectPath(service_path), | 158 dbus::ObjectPath(service_path), |
161 names, | 159 names, |
162 base::Bind(&ClearPropertiesCallback, | 160 base::Bind(&ClearPropertiesCallback, |
163 names, | 161 names, |
164 service_path, | 162 service_path, |
165 callback, | 163 callback, |
166 error_callback), | 164 error_callback), |
167 base::Bind(&network_handler::ShillErrorCallbackFunction, | 165 base::Bind(&network_handler::ShillErrorCallbackFunction, |
168 kLogModule, service_path, error_callback)); | 166 service_path, error_callback)); |
169 } | 167 } |
170 | 168 |
171 void NetworkConfigurationHandler::Connect( | 169 void NetworkConfigurationHandler::Connect( |
172 const std::string& service_path, | 170 const std::string& service_path, |
173 const base::Closure& callback, | 171 const base::Closure& callback, |
174 const network_handler::ErrorCallback& error_callback) const { | 172 const network_handler::ErrorCallback& error_callback) const { |
175 DBusThreadManager::Get()->GetShillServiceClient()->Connect( | 173 DBusThreadManager::Get()->GetShillServiceClient()->Connect( |
176 dbus::ObjectPath(service_path), | 174 dbus::ObjectPath(service_path), |
177 callback, | 175 callback, |
178 base::Bind(&network_handler::ShillErrorCallbackFunction, | 176 base::Bind(&network_handler::ShillErrorCallbackFunction, |
179 kLogModule, service_path, error_callback)); | 177 service_path, error_callback)); |
180 } | 178 } |
181 | 179 |
182 void NetworkConfigurationHandler::Disconnect( | 180 void NetworkConfigurationHandler::Disconnect( |
183 const std::string& service_path, | 181 const std::string& service_path, |
184 const base::Closure& callback, | 182 const base::Closure& callback, |
185 const network_handler::ErrorCallback& error_callback) const { | 183 const network_handler::ErrorCallback& error_callback) const { |
186 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( | 184 DBusThreadManager::Get()->GetShillServiceClient()->Disconnect( |
187 dbus::ObjectPath(service_path), | 185 dbus::ObjectPath(service_path), |
188 callback, | 186 callback, |
189 base::Bind(&network_handler::ShillErrorCallbackFunction, | 187 base::Bind(&network_handler::ShillErrorCallbackFunction, |
190 kLogModule, service_path, error_callback)); | 188 service_path, error_callback)); |
191 } | 189 } |
192 | 190 |
193 void NetworkConfigurationHandler::CreateConfiguration( | 191 void NetworkConfigurationHandler::CreateConfiguration( |
194 const base::DictionaryValue& properties, | 192 const base::DictionaryValue& properties, |
195 const network_handler::StringResultCallback& callback, | 193 const network_handler::StringResultCallback& callback, |
196 const network_handler::ErrorCallback& error_callback) const { | 194 const network_handler::ErrorCallback& error_callback) const { |
197 ShillManagerClient* manager = | 195 ShillManagerClient* manager = |
198 DBusThreadManager::Get()->GetShillManagerClient(); | 196 DBusThreadManager::Get()->GetShillManagerClient(); |
199 | 197 |
200 std::string type; | 198 std::string type; |
201 properties.GetStringWithoutPathExpansion(flimflam::kTypeProperty, &type); | 199 properties.GetStringWithoutPathExpansion(flimflam::kTypeProperty, &type); |
202 // Shill supports ConfigureServiceForProfile only for network type WiFi. In | 200 // Shill supports ConfigureServiceForProfile only for network type WiFi. In |
203 // all other cases, we have to rely on GetService for now. This is | 201 // all other cases, we have to rely on GetService for now. This is |
204 // unproblematic for VPN (user profile only), but will lead to inconsistencies | 202 // unproblematic for VPN (user profile only), but will lead to inconsistencies |
205 // with WiMax, for example. | 203 // with WiMax, for example. |
206 if (type == flimflam::kTypeWifi) { | 204 if (type == flimflam::kTypeWifi) { |
207 std::string profile; | 205 std::string profile; |
208 properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty, | 206 properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty, |
209 &profile); | 207 &profile); |
210 manager->ConfigureServiceForProfile( | 208 manager->ConfigureServiceForProfile( |
211 dbus::ObjectPath(profile), | 209 dbus::ObjectPath(profile), |
212 properties, | 210 properties, |
213 base::Bind(&RunCreateNetworkCallback, callback), | 211 base::Bind(&RunCreateNetworkCallback, callback), |
214 base::Bind(&network_handler::ShillErrorCallbackFunction, | 212 base::Bind(&network_handler::ShillErrorCallbackFunction, |
215 kLogModule, "", error_callback)); | 213 "", error_callback)); |
216 } else { | 214 } else { |
217 manager->GetService( | 215 manager->GetService( |
218 properties, | 216 properties, |
219 base::Bind(&RunCreateNetworkCallback, callback), | 217 base::Bind(&RunCreateNetworkCallback, callback), |
220 base::Bind(&network_handler::ShillErrorCallbackFunction, | 218 base::Bind(&network_handler::ShillErrorCallbackFunction, |
221 kLogModule, "", error_callback)); | 219 "", error_callback)); |
222 } | 220 } |
223 } | 221 } |
224 | 222 |
225 void NetworkConfigurationHandler::RemoveConfiguration( | 223 void NetworkConfigurationHandler::RemoveConfiguration( |
226 const std::string& service_path, | 224 const std::string& service_path, |
227 const base::Closure& callback, | 225 const base::Closure& callback, |
228 const network_handler::ErrorCallback& error_callback) const { | 226 const network_handler::ErrorCallback& error_callback) const { |
229 DBusThreadManager::Get()->GetShillServiceClient()->Remove( | 227 DBusThreadManager::Get()->GetShillServiceClient()->Remove( |
230 dbus::ObjectPath(service_path), | 228 dbus::ObjectPath(service_path), |
231 callback, | 229 callback, |
232 base::Bind(&network_handler::ShillErrorCallbackFunction, | 230 base::Bind(&network_handler::ShillErrorCallbackFunction, |
233 kLogModule, service_path, error_callback)); | 231 service_path, error_callback)); |
234 } | 232 } |
235 | 233 |
236 NetworkConfigurationHandler::NetworkConfigurationHandler() { | 234 NetworkConfigurationHandler::NetworkConfigurationHandler() { |
237 } | 235 } |
238 | 236 |
239 NetworkConfigurationHandler::~NetworkConfigurationHandler() { | 237 NetworkConfigurationHandler::~NetworkConfigurationHandler() { |
240 } | 238 } |
241 | 239 |
242 } // namespace chromeos | 240 } // namespace chromeos |
OLD | NEW |