OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_service_client_stub.h" | 5 #include "chromeos/dbus/shill_service_client_stub.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 | 70 |
71 void ShillServiceClientStub::SetProperty(const dbus::ObjectPath& service_path, | 71 void ShillServiceClientStub::SetProperty(const dbus::ObjectPath& service_path, |
72 const std::string& name, | 72 const std::string& name, |
73 const base::Value& value, | 73 const base::Value& value, |
74 const base::Closure& callback, | 74 const base::Closure& callback, |
75 const ErrorCallback& error_callback) { | 75 const ErrorCallback& error_callback) { |
76 base::DictionaryValue* dict = NULL; | 76 base::DictionaryValue* dict = NULL; |
77 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 77 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
78 service_path.value(), &dict)) { | 78 service_path.value(), &dict)) { |
79 error_callback.Run("StubError", "Service not found"); | 79 error_callback.Run("Error.InvalidService", "Invalid Service"); |
80 return; | 80 return; |
81 } | 81 } |
82 if (name == flimflam::kStateProperty) { | 82 if (name == flimflam::kStateProperty) { |
83 // If we connect to a service, then we move it to the top of the list in | 83 // If we connect to a service, then we move it to the top of the list in |
84 // the manager client. | 84 // the manager client. |
85 std::string state; | 85 std::string state; |
86 if (value.GetAsString(&state) && state == flimflam::kStateOnline) { | 86 if (value.GetAsString(&state) && state == flimflam::kStateOnline) { |
87 ShillManagerClient* manager_client = | 87 ShillManagerClient* manager_client = |
88 DBusThreadManager::Get()->GetShillManagerClient(); | 88 DBusThreadManager::Get()->GetShillManagerClient(); |
89 manager_client->GetTestInterface()->RemoveService(service_path.value()); | 89 manager_client->GetTestInterface()->RemoveService(service_path.value()); |
(...skipping 12 matching lines...) Expand all Loading... |
102 } | 102 } |
103 | 103 |
104 void ShillServiceClientStub::ClearProperty( | 104 void ShillServiceClientStub::ClearProperty( |
105 const dbus::ObjectPath& service_path, | 105 const dbus::ObjectPath& service_path, |
106 const std::string& name, | 106 const std::string& name, |
107 const base::Closure& callback, | 107 const base::Closure& callback, |
108 const ErrorCallback& error_callback) { | 108 const ErrorCallback& error_callback) { |
109 base::DictionaryValue* dict = NULL; | 109 base::DictionaryValue* dict = NULL; |
110 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 110 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
111 service_path.value(), &dict)) { | 111 service_path.value(), &dict)) { |
112 error_callback.Run("StubError", "Service not found"); | 112 error_callback.Run("Error.InvalidService", "Invalid Service"); |
113 return; | 113 return; |
114 } | 114 } |
115 dict->Remove(name, NULL); | 115 dict->Remove(name, NULL); |
116 MessageLoop::current()->PostTask( | 116 MessageLoop::current()->PostTask( |
117 FROM_HERE, | 117 FROM_HERE, |
118 base::Bind(&ShillServiceClientStub::NotifyObserversPropertyChanged, | 118 base::Bind(&ShillServiceClientStub::NotifyObserversPropertyChanged, |
119 weak_ptr_factory_.GetWeakPtr(), service_path, name)); | 119 weak_ptr_factory_.GetWeakPtr(), service_path, name)); |
120 if (callback.is_null()) | 120 if (callback.is_null()) |
121 return; | 121 return; |
122 MessageLoop::current()->PostTask(FROM_HERE, callback); | 122 MessageLoop::current()->PostTask(FROM_HERE, callback); |
123 } | 123 } |
124 | 124 |
125 void ShillServiceClientStub::ClearProperties( | 125 void ShillServiceClientStub::ClearProperties( |
126 const dbus::ObjectPath& service_path, | 126 const dbus::ObjectPath& service_path, |
127 const std::vector<std::string>& names, | 127 const std::vector<std::string>& names, |
128 const ListValueCallback& callback, | 128 const ListValueCallback& callback, |
129 const ErrorCallback& error_callback) { | 129 const ErrorCallback& error_callback) { |
130 base::DictionaryValue* dict = NULL; | 130 base::DictionaryValue* dict = NULL; |
131 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 131 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
132 service_path.value(), &dict)) { | 132 service_path.value(), &dict)) { |
133 error_callback.Run("StubError", "Service not found"); | 133 error_callback.Run("Error.InvalidService", "Invalid Service"); |
134 return; | 134 return; |
135 } | 135 } |
136 scoped_ptr<base::ListValue> results(new base::ListValue); | 136 scoped_ptr<base::ListValue> results(new base::ListValue); |
137 for (std::vector<std::string>::const_iterator iter = names.begin(); | 137 for (std::vector<std::string>::const_iterator iter = names.begin(); |
138 iter != names.end(); ++iter) { | 138 iter != names.end(); ++iter) { |
139 dict->Remove(*iter, NULL); | 139 dict->Remove(*iter, NULL); |
140 results->AppendBoolean(true); | 140 results->AppendBoolean(true); |
141 } | 141 } |
142 for (std::vector<std::string>::const_iterator iter = names.begin(); | 142 for (std::vector<std::string>::const_iterator iter = names.begin(); |
143 iter != names.end(); ++iter) { | 143 iter != names.end(); ++iter) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 online_value, | 180 online_value, |
181 base::Bind(&base::DoNothing), | 181 base::Bind(&base::DoNothing), |
182 error_callback), | 182 error_callback), |
183 base::TimeDelta::FromSeconds(kConnectDelaySeconds)); | 183 base::TimeDelta::FromSeconds(kConnectDelaySeconds)); |
184 callback.Run(); | 184 callback.Run(); |
185 } | 185 } |
186 | 186 |
187 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, | 187 void ShillServiceClientStub::Disconnect(const dbus::ObjectPath& service_path, |
188 const base::Closure& callback, | 188 const base::Closure& callback, |
189 const ErrorCallback& error_callback) { | 189 const ErrorCallback& error_callback) { |
| 190 base::Value* service; |
| 191 if (!stub_services_.Get(service_path.value(), &service)) { |
| 192 error_callback.Run("Error.InvalidService", "Invalid Service"); |
| 193 return; |
| 194 } |
190 // Set Idle after a delay | 195 // Set Idle after a delay |
191 const int kConnectDelaySeconds = 2; | 196 const int kConnectDelaySeconds = 2; |
192 base::StringValue idle_value(flimflam::kStateIdle); | 197 base::StringValue idle_value(flimflam::kStateIdle); |
193 MessageLoop::current()->PostDelayedTask( | 198 MessageLoop::current()->PostDelayedTask( |
194 FROM_HERE, | 199 FROM_HERE, |
195 base::Bind(&ShillServiceClientStub::SetProperty, | 200 base::Bind(&ShillServiceClientStub::SetProperty, |
196 weak_ptr_factory_.GetWeakPtr(), | 201 weak_ptr_factory_.GetWeakPtr(), |
197 service_path, | 202 service_path, |
198 flimflam::kStateProperty, | 203 flimflam::kStateProperty, |
199 idle_value, | 204 idle_value, |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 284 |
280 void ShillServiceClientStub::SetDefaultProperties() { | 285 void ShillServiceClientStub::SetDefaultProperties() { |
281 // Add stub services. Note: names match Manager stub impl. | 286 // Add stub services. Note: names match Manager stub impl. |
282 AddService("stub_ethernet", "eth0", | 287 AddService("stub_ethernet", "eth0", |
283 flimflam::kTypeEthernet, | 288 flimflam::kTypeEthernet, |
284 flimflam::kStateOnline); | 289 flimflam::kStateOnline); |
285 | 290 |
286 AddService("stub_wifi1", "wifi1", | 291 AddService("stub_wifi1", "wifi1", |
287 flimflam::kTypeWifi, | 292 flimflam::kTypeWifi, |
288 flimflam::kStateOnline); | 293 flimflam::kStateOnline); |
| 294 SetServiceProperty("stub_wifi1", |
| 295 flimflam::kSecurityProperty, |
| 296 base::StringValue(flimflam::kSecurityWep)); |
289 | 297 |
290 AddService("stub_wifi2", "wifi2_PSK", | 298 AddService("stub_wifi2", "wifi2_PSK", |
291 flimflam::kTypeWifi, | 299 flimflam::kTypeWifi, |
292 flimflam::kStateIdle); | 300 flimflam::kStateIdle); |
293 base::StringValue psk_value(flimflam::kSecurityPsk); | |
294 SetServiceProperty("stub_wifi2", | 301 SetServiceProperty("stub_wifi2", |
295 flimflam::kSecurityProperty, | 302 flimflam::kSecurityProperty, |
296 psk_value); | 303 base::StringValue(flimflam::kSecurityPsk)); |
297 base::FundamentalValue strength_value(80); | 304 base::FundamentalValue strength_value(80); |
298 SetServiceProperty("stub_wifi2", | 305 SetServiceProperty("stub_wifi2", |
299 flimflam::kSignalStrengthProperty, | 306 flimflam::kSignalStrengthProperty, |
300 strength_value); | 307 strength_value); |
301 | 308 |
302 AddService("stub_cellular1", "cellular1", | 309 AddService("stub_cellular1", "cellular1", |
303 flimflam::kTypeCellular, | 310 flimflam::kTypeCellular, |
304 flimflam::kStateIdle); | 311 flimflam::kStateIdle); |
305 base::StringValue technology_value(flimflam::kNetworkTechnologyGsm); | 312 base::StringValue technology_value(flimflam::kNetworkTechnologyGsm); |
306 SetServiceProperty("stub_cellular1", | 313 SetServiceProperty("stub_cellular1", |
307 flimflam::kNetworkTechnologyProperty, | 314 flimflam::kNetworkTechnologyProperty, |
308 technology_value); | 315 technology_value); |
| 316 SetServiceProperty("stub_cellular1", |
| 317 flimflam::kActivationStateProperty, |
| 318 base::StringValue(flimflam::kActivationStateNotActivated)); |
| 319 SetServiceProperty("stub_cellular1", |
| 320 flimflam::kRoamingStateProperty, |
| 321 base::StringValue(flimflam::kRoamingStateHome)); |
309 } | 322 } |
310 | 323 |
311 void ShillServiceClientStub::PassStubServiceProperties( | 324 void ShillServiceClientStub::PassStubServiceProperties( |
312 const dbus::ObjectPath& service_path, | 325 const dbus::ObjectPath& service_path, |
313 const DictionaryValueCallback& callback) { | 326 const DictionaryValueCallback& callback) { |
314 base::DictionaryValue* dict = NULL; | 327 base::DictionaryValue* dict = NULL; |
315 if (!stub_services_.GetDictionaryWithoutPathExpansion( | 328 if (!stub_services_.GetDictionaryWithoutPathExpansion( |
316 service_path.value(), &dict)) { | 329 service_path.value(), &dict)) { |
317 base::DictionaryValue empty_dictionary; | 330 base::DictionaryValue empty_dictionary; |
318 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); | 331 callback.Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = | 370 std::map<dbus::ObjectPath, PropertyObserverList*>::iterator iter = |
358 observer_list_.find(device_path); | 371 observer_list_.find(device_path); |
359 if (iter != observer_list_.end()) | 372 if (iter != observer_list_.end()) |
360 return *(iter->second); | 373 return *(iter->second); |
361 PropertyObserverList* observer_list = new PropertyObserverList(); | 374 PropertyObserverList* observer_list = new PropertyObserverList(); |
362 observer_list_[device_path] = observer_list; | 375 observer_list_[device_path] = observer_list; |
363 return *observer_list; | 376 return *observer_list; |
364 } | 377 } |
365 | 378 |
366 } // namespace chromeos | 379 } // namespace chromeos |
OLD | NEW |