| 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_manager_client_stub.h" | 5 #include "chromeos/dbus/shill_manager_client_stub.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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 explicit ValueEquals(const Value* first) : first_(first) {} | 32 explicit ValueEquals(const Value* first) : first_(first) {} |
| 33 bool operator()(const Value* second) const { | 33 bool operator()(const Value* second) const { |
| 34 return first_->Equals(second); | 34 return first_->Equals(second); |
| 35 } | 35 } |
| 36 const Value* first_; | 36 const Value* first_; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 ShillManagerClientStub::ShillManagerClientStub() | 41 ShillManagerClientStub::ShillManagerClientStub() |
| 42 : weak_ptr_factory_(this) { | 42 : weak_ptr_factory_(this) { |
| 43 SetDefaultProperties(); | 43 SetDefaultProperties(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 ShillManagerClientStub::~ShillManagerClientStub() {} | 46 ShillManagerClientStub::~ShillManagerClientStub() {} |
| 47 | 47 |
| 48 // ShillManagerClient overrides. | 48 // ShillManagerClient overrides. |
| 49 | 49 |
| 50 void ShillManagerClientStub::AddPropertyChangedObserver( | 50 void ShillManagerClientStub::AddPropertyChangedObserver( |
| 51 ShillPropertyChangedObserver* observer) { | 51 ShillPropertyChangedObserver* observer) { |
| 52 observer_list_.AddObserver(observer); | 52 observer_list_.AddObserver(observer); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 base::TimeDelta::FromSeconds(kDisableTechnologyDelaySeconds)); | 173 base::TimeDelta::FromSeconds(kDisableTechnologyDelaySeconds)); |
| 174 } else { | 174 } else { |
| 175 SetTechnologyEnabled(type, callback, false); | 175 SetTechnologyEnabled(type, callback, false); |
| 176 } | 176 } |
| 177 } | 177 } |
| 178 | 178 |
| 179 void ShillManagerClientStub::ConfigureService( | 179 void ShillManagerClientStub::ConfigureService( |
| 180 const base::DictionaryValue& properties, | 180 const base::DictionaryValue& properties, |
| 181 const ObjectPathCallback& callback, | 181 const ObjectPathCallback& callback, |
| 182 const ErrorCallback& error_callback) { | 182 const ErrorCallback& error_callback) { |
| 183 if (callback.is_null()) | |
| 184 return; | |
| 185 | |
| 186 ShillServiceClient::TestInterface* service_client = | 183 ShillServiceClient::TestInterface* service_client = |
| 187 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 184 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 188 | 185 |
| 189 std::string guid; | 186 std::string guid; |
| 190 std::string type; | 187 std::string type; |
| 191 if (!properties.GetString(flimflam::kGuidProperty, &guid) || | 188 if (!properties.GetString(flimflam::kGuidProperty, &guid) || |
| 192 !properties.GetString(flimflam::kTypeProperty, &type)) { | 189 !properties.GetString(flimflam::kTypeProperty, &type)) { |
| 190 LOG(ERROR) << "ConfigureService requies GUID and Type to be defined"; |
| 193 // If the properties aren't filled out completely, then just return an empty | 191 // If the properties aren't filled out completely, then just return an empty |
| 194 // object path. | 192 // object path. |
| 195 MessageLoop::current()->PostTask( | 193 if (!callback.is_null()) { |
| 196 FROM_HERE, base::Bind(callback, dbus::ObjectPath())); | 194 MessageLoop::current()->PostTask( |
| 195 FROM_HERE, base::Bind(callback, dbus::ObjectPath())); |
| 196 } |
| 197 return; | 197 return; |
| 198 } | 198 } |
| 199 | 199 |
| 200 // For the purposes of this stub, we're going to assume that the GUID property | 200 // For the purposes of this stub, we're going to assume that the GUID property |
| 201 // is set to the service path because we don't want to re-implement Shill's | 201 // is set to the service path because we don't want to re-implement Shill's |
| 202 // property matching magic here. | 202 // property matching magic here. |
| 203 std::string service_path = guid; | 203 std::string service_path = guid; |
| 204 | 204 |
| 205 std::string ipconfig_path; | 205 std::string ipconfig_path; |
| 206 properties.GetString(shill::kIPConfigProperty, &ipconfig_path); | 206 properties.GetString(shill::kIPConfigProperty, &ipconfig_path); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 224 // Now set all the properties. | 224 // Now set all the properties. |
| 225 for (base::DictionaryValue::Iterator iter(*merged_properties); | 225 for (base::DictionaryValue::Iterator iter(*merged_properties); |
| 226 !iter.IsAtEnd(); iter.Advance()) { | 226 !iter.IsAtEnd(); iter.Advance()) { |
| 227 service_client->SetServiceProperty(service_path, iter.key(), iter.value()); | 227 service_client->SetServiceProperty(service_path, iter.key(), iter.value()); |
| 228 } | 228 } |
| 229 | 229 |
| 230 ShillProfileClient::TestInterface* profile_test = | 230 ShillProfileClient::TestInterface* profile_test = |
| 231 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); | 231 DBusThreadManager::Get()->GetShillProfileClient()->GetTestInterface(); |
| 232 profile_test->AddService(service_path); | 232 profile_test->AddService(service_path); |
| 233 | 233 |
| 234 MessageLoop::current()->PostTask( | 234 if (!callback.is_null()) { |
| 235 FROM_HERE, base::Bind(callback, dbus::ObjectPath(service_path))); | 235 MessageLoop::current()->PostTask( |
| 236 FROM_HERE, base::Bind(callback, dbus::ObjectPath(service_path))); |
| 237 } |
| 236 } | 238 } |
| 237 | 239 |
| 238 void ShillManagerClientStub::ConfigureServiceForProfile( | 240 void ShillManagerClientStub::ConfigureServiceForProfile( |
| 239 const dbus::ObjectPath& profile_path, | 241 const dbus::ObjectPath& profile_path, |
| 240 const base::DictionaryValue& properties, | 242 const base::DictionaryValue& properties, |
| 241 const ObjectPathCallback& callback, | 243 const ObjectPathCallback& callback, |
| 242 const ErrorCallback& error_callback) { | 244 const ErrorCallback& error_callback) { |
| 243 std::string profile_property; | 245 std::string profile_property; |
| 244 properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty, | 246 properties.GetStringWithoutPathExpansion(flimflam::kProfileProperty, |
| 245 &profile_property); | 247 &profile_property); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 if (GetListProperty(flimflam::kDevicesProperty)->Remove( | 314 if (GetListProperty(flimflam::kDevicesProperty)->Remove( |
| 313 device_path_value, NULL)) { | 315 device_path_value, NULL)) { |
| 314 CallNotifyObserversPropertyChanged(flimflam::kDevicesProperty, 0); | 316 CallNotifyObserversPropertyChanged(flimflam::kDevicesProperty, 0); |
| 315 } | 317 } |
| 316 } | 318 } |
| 317 | 319 |
| 318 void ShillManagerClientStub::ClearDevices() { | 320 void ShillManagerClientStub::ClearDevices() { |
| 319 stub_properties_.Remove(flimflam::kDevicesProperty, NULL); | 321 stub_properties_.Remove(flimflam::kDevicesProperty, NULL); |
| 320 } | 322 } |
| 321 | 323 |
| 322 void ShillManagerClientStub::ClearServices() { | |
| 323 stub_properties_.Remove(flimflam::kServicesProperty, NULL); | |
| 324 stub_properties_.Remove(flimflam::kServiceWatchListProperty, NULL); | |
| 325 } | |
| 326 | |
| 327 void ShillManagerClientStub::AddService(const std::string& service_path, | |
| 328 bool add_to_watch_list) { | |
| 329 if (GetListProperty(flimflam::kServicesProperty)->AppendIfNotPresent( | |
| 330 base::Value::CreateStringValue(service_path))) { | |
| 331 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | |
| 332 } | |
| 333 if (add_to_watch_list) | |
| 334 AddServiceToWatchList(service_path); | |
| 335 } | |
| 336 | |
| 337 void ShillManagerClientStub::AddServiceAtIndex(const std::string& service_path, | |
| 338 size_t index, | |
| 339 bool add_to_watch_list) { | |
| 340 base::StringValue path_value(service_path); | |
| 341 base::ListValue* service_list = | |
| 342 GetListProperty(flimflam::kServicesProperty); | |
| 343 base::ListValue::iterator iter = | |
| 344 std::find_if(service_list->begin(), service_list->end(), | |
| 345 ValueEquals(&path_value)); | |
| 346 if (iter != service_list->end()) | |
| 347 service_list->Erase(iter, NULL); | |
| 348 service_list->Insert(index, path_value.DeepCopy()); | |
| 349 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | |
| 350 if (add_to_watch_list) | |
| 351 AddServiceToWatchList(service_path); | |
| 352 } | |
| 353 | |
| 354 void ShillManagerClientStub::RemoveService(const std::string& service_path) { | |
| 355 base::StringValue service_path_value(service_path); | |
| 356 if (GetListProperty(flimflam::kServicesProperty)->Remove( | |
| 357 service_path_value, NULL)) { | |
| 358 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | |
| 359 } | |
| 360 if (GetListProperty(flimflam::kServiceWatchListProperty)->Remove( | |
| 361 service_path_value, NULL)) { | |
| 362 CallNotifyObserversPropertyChanged( | |
| 363 flimflam::kServiceWatchListProperty, 0); | |
| 364 } | |
| 365 } | |
| 366 | |
| 367 void ShillManagerClientStub::AddTechnology(const std::string& type, | 324 void ShillManagerClientStub::AddTechnology(const std::string& type, |
| 368 bool enabled) { | 325 bool enabled) { |
| 369 if (GetListProperty(flimflam::kAvailableTechnologiesProperty)-> | 326 if (GetListProperty(flimflam::kAvailableTechnologiesProperty)-> |
| 370 AppendIfNotPresent(base::Value::CreateStringValue(type))) { | 327 AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| 371 CallNotifyObserversPropertyChanged( | 328 CallNotifyObserversPropertyChanged( |
| 372 flimflam::kAvailableTechnologiesProperty, 0); | 329 flimflam::kAvailableTechnologiesProperty, 0); |
| 373 } | 330 } |
| 374 if (enabled && | 331 if (enabled && |
| 375 GetListProperty(flimflam::kEnabledTechnologiesProperty)-> | 332 GetListProperty(flimflam::kEnabledTechnologiesProperty)-> |
| 376 AppendIfNotPresent(base::Value::CreateStringValue(type))) { | 333 AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 407 CallNotifyObserversPropertyChanged( | 364 CallNotifyObserversPropertyChanged( |
| 408 shill::kUninitializedTechnologiesProperty, 0); | 365 shill::kUninitializedTechnologiesProperty, 0); |
| 409 } | 366 } |
| 410 } | 367 } |
| 411 } | 368 } |
| 412 | 369 |
| 413 void ShillManagerClientStub::ClearProperties() { | 370 void ShillManagerClientStub::ClearProperties() { |
| 414 stub_properties_.Clear(); | 371 stub_properties_.Clear(); |
| 415 } | 372 } |
| 416 | 373 |
| 374 void ShillManagerClientStub::MoveServiceToIndex( |
| 375 const std::string& service_path, |
| 376 size_t index, |
| 377 bool add_to_watch_list) { |
| 378 base::StringValue path_value(service_path); |
| 379 base::ListValue* service_list = GetListProperty(flimflam::kServicesProperty); |
| 380 base::ListValue::iterator iter = |
| 381 std::find_if(service_list->begin(), service_list->end(), |
| 382 ValueEquals(&path_value)); |
| 383 if (iter == service_list->end()) { |
| 384 LOG(ERROR) << "Service not found to move: " << service_path; |
| 385 return; |
| 386 } |
| 387 service_list->Erase(iter, NULL); |
| 388 service_list->Insert(index, path_value.DeepCopy()); |
| 389 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 390 if (add_to_watch_list) |
| 391 AddServiceToWatchList(service_path); |
| 392 } |
| 393 |
| 394 void ShillManagerClientStub::AddManagerService(const std::string& service_path, |
| 395 bool add_to_watch_list) { |
| 396 if (GetListProperty(flimflam::kServicesProperty)->AppendIfNotPresent( |
| 397 base::Value::CreateStringValue(service_path))) { |
| 398 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 399 } |
| 400 if (add_to_watch_list) |
| 401 AddServiceToWatchList(service_path); |
| 402 } |
| 403 |
| 404 void ShillManagerClientStub::RemoveManagerService( |
| 405 const std::string& service_path) { |
| 406 base::StringValue service_path_value(service_path); |
| 407 if (GetListProperty(flimflam::kServicesProperty)->Remove( |
| 408 service_path_value, NULL)) { |
| 409 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 410 } |
| 411 if (GetListProperty(flimflam::kServiceWatchListProperty)->Remove( |
| 412 service_path_value, NULL)) { |
| 413 CallNotifyObserversPropertyChanged( |
| 414 flimflam::kServiceWatchListProperty, 0); |
| 415 } |
| 416 } |
| 417 |
| 418 void ShillManagerClientStub::ClearManagerServices() { |
| 419 stub_properties_.Remove(flimflam::kServicesProperty, NULL); |
| 420 stub_properties_.Remove(flimflam::kServiceWatchListProperty, NULL); |
| 421 } |
| 422 |
| 417 void ShillManagerClientStub::AddGeoNetwork( | 423 void ShillManagerClientStub::AddGeoNetwork( |
| 418 const std::string& technology, | 424 const std::string& technology, |
| 419 const base::DictionaryValue& network) { | 425 const base::DictionaryValue& network) { |
| 420 base::ListValue* list_value = NULL; | 426 base::ListValue* list_value = NULL; |
| 421 if (!stub_geo_networks_.GetListWithoutPathExpansion( | 427 if (!stub_geo_networks_.GetListWithoutPathExpansion( |
| 422 technology, &list_value)) { | 428 technology, &list_value)) { |
| 423 list_value = new base::ListValue; | 429 list_value = new base::ListValue; |
| 424 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); | 430 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); |
| 425 } | 431 } |
| 426 list_value->Append(network.DeepCopy()); | 432 list_value->Append(network.DeepCopy()); |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 base::FundamentalValue(false)); | 600 base::FundamentalValue(false)); |
| 595 } | 601 } |
| 596 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 602 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 597 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, | 603 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, |
| 598 0); | 604 0); |
| 599 if (!callback.is_null()) | 605 if (!callback.is_null()) |
| 600 MessageLoop::current()->PostTask(FROM_HERE, callback); | 606 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 601 } | 607 } |
| 602 | 608 |
| 603 } // namespace chromeos | 609 } // namespace chromeos |
| OLD | NEW |