| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 GetListProperty(flimflam::kDevicesProperty)->Clear(); | 321 GetListProperty(flimflam::kDevicesProperty)->Clear(); |
| 320 CallNotifyObserversPropertyChanged(flimflam::kDevicesProperty, 0); | 322 CallNotifyObserversPropertyChanged(flimflam::kDevicesProperty, 0); |
| 321 } | 323 } |
| 322 | 324 |
| 323 void ShillManagerClientStub::ClearServices() { | |
| 324 GetListProperty(flimflam::kServicesProperty)->Clear(); | |
| 325 GetListProperty(flimflam::kServiceWatchListProperty)->Clear(); | |
| 326 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | |
| 327 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, 0); | |
| 328 } | |
| 329 | |
| 330 void ShillManagerClientStub::AddService(const std::string& service_path, | |
| 331 bool add_to_watch_list) { | |
| 332 if (GetListProperty(flimflam::kServicesProperty)->AppendIfNotPresent( | |
| 333 base::Value::CreateStringValue(service_path))) { | |
| 334 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | |
| 335 } | |
| 336 if (add_to_watch_list) | |
| 337 AddServiceToWatchList(service_path); | |
| 338 } | |
| 339 | |
| 340 void ShillManagerClientStub::AddServiceAtIndex(const std::string& service_path, | |
| 341 size_t index, | |
| 342 bool add_to_watch_list) { | |
| 343 base::StringValue path_value(service_path); | |
| 344 base::ListValue* service_list = | |
| 345 GetListProperty(flimflam::kServicesProperty); | |
| 346 base::ListValue::iterator iter = | |
| 347 std::find_if(service_list->begin(), service_list->end(), | |
| 348 ValueEquals(&path_value)); | |
| 349 if (iter != service_list->end()) | |
| 350 service_list->Erase(iter, NULL); | |
| 351 service_list->Insert(index, path_value.DeepCopy()); | |
| 352 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | |
| 353 if (add_to_watch_list) | |
| 354 AddServiceToWatchList(service_path); | |
| 355 } | |
| 356 | |
| 357 void ShillManagerClientStub::RemoveService(const std::string& service_path) { | |
| 358 base::StringValue service_path_value(service_path); | |
| 359 if (GetListProperty(flimflam::kServicesProperty)->Remove( | |
| 360 service_path_value, NULL)) { | |
| 361 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | |
| 362 } | |
| 363 if (GetListProperty(flimflam::kServiceWatchListProperty)->Remove( | |
| 364 service_path_value, NULL)) { | |
| 365 CallNotifyObserversPropertyChanged( | |
| 366 flimflam::kServiceWatchListProperty, 0); | |
| 367 } | |
| 368 } | |
| 369 | |
| 370 void ShillManagerClientStub::AddTechnology(const std::string& type, | 325 void ShillManagerClientStub::AddTechnology(const std::string& type, |
| 371 bool enabled) { | 326 bool enabled) { |
| 372 if (GetListProperty(flimflam::kAvailableTechnologiesProperty)-> | 327 if (GetListProperty(flimflam::kAvailableTechnologiesProperty)-> |
| 373 AppendIfNotPresent(base::Value::CreateStringValue(type))) { | 328 AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| 374 CallNotifyObserversPropertyChanged( | 329 CallNotifyObserversPropertyChanged( |
| 375 flimflam::kAvailableTechnologiesProperty, 0); | 330 flimflam::kAvailableTechnologiesProperty, 0); |
| 376 } | 331 } |
| 377 if (enabled && | 332 if (enabled && |
| 378 GetListProperty(flimflam::kEnabledTechnologiesProperty)-> | 333 GetListProperty(flimflam::kEnabledTechnologiesProperty)-> |
| 379 AppendIfNotPresent(base::Value::CreateStringValue(type))) { | 334 AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 410 CallNotifyObserversPropertyChanged( | 365 CallNotifyObserversPropertyChanged( |
| 411 shill::kUninitializedTechnologiesProperty, 0); | 366 shill::kUninitializedTechnologiesProperty, 0); |
| 412 } | 367 } |
| 413 } | 368 } |
| 414 } | 369 } |
| 415 | 370 |
| 416 void ShillManagerClientStub::ClearProperties() { | 371 void ShillManagerClientStub::ClearProperties() { |
| 417 stub_properties_.Clear(); | 372 stub_properties_.Clear(); |
| 418 } | 373 } |
| 419 | 374 |
| 375 void ShillManagerClientStub::MoveServiceToIndex( |
| 376 const std::string& service_path, |
| 377 size_t index, |
| 378 bool add_to_watch_list) { |
| 379 base::StringValue path_value(service_path); |
| 380 base::ListValue* service_list = GetListProperty(flimflam::kServicesProperty); |
| 381 base::ListValue::iterator iter = |
| 382 std::find_if(service_list->begin(), service_list->end(), |
| 383 ValueEquals(&path_value)); |
| 384 if (iter == service_list->end()) { |
| 385 LOG(ERROR) << "Service not found to move: " << service_path; |
| 386 return; |
| 387 } |
| 388 service_list->Erase(iter, NULL); |
| 389 service_list->Insert(index, path_value.DeepCopy()); |
| 390 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 391 if (add_to_watch_list) |
| 392 AddServiceToWatchList(service_path); |
| 393 } |
| 394 |
| 395 void ShillManagerClientStub::AddManagerService(const std::string& service_path, |
| 396 bool add_to_watch_list) { |
| 397 if (GetListProperty(flimflam::kServicesProperty)->AppendIfNotPresent( |
| 398 base::Value::CreateStringValue(service_path))) { |
| 399 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 400 } |
| 401 if (add_to_watch_list) |
| 402 AddServiceToWatchList(service_path); |
| 403 } |
| 404 |
| 405 void ShillManagerClientStub::RemoveManagerService( |
| 406 const std::string& service_path) { |
| 407 base::StringValue service_path_value(service_path); |
| 408 if (GetListProperty(flimflam::kServicesProperty)->Remove( |
| 409 service_path_value, NULL)) { |
| 410 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 411 } |
| 412 if (GetListProperty(flimflam::kServiceWatchListProperty)->Remove( |
| 413 service_path_value, NULL)) { |
| 414 CallNotifyObserversPropertyChanged( |
| 415 flimflam::kServiceWatchListProperty, 0); |
| 416 } |
| 417 } |
| 418 |
| 419 void ShillManagerClientStub::ClearManagerServices() { |
| 420 GetListProperty(flimflam::kServicesProperty)->Clear(); |
| 421 GetListProperty(flimflam::kServiceWatchListProperty)->Clear(); |
| 422 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 423 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, 0); |
| 424 } |
| 425 |
| 420 void ShillManagerClientStub::AddGeoNetwork( | 426 void ShillManagerClientStub::AddGeoNetwork( |
| 421 const std::string& technology, | 427 const std::string& technology, |
| 422 const base::DictionaryValue& network) { | 428 const base::DictionaryValue& network) { |
| 423 base::ListValue* list_value = NULL; | 429 base::ListValue* list_value = NULL; |
| 424 if (!stub_geo_networks_.GetListWithoutPathExpansion( | 430 if (!stub_geo_networks_.GetListWithoutPathExpansion( |
| 425 technology, &list_value)) { | 431 technology, &list_value)) { |
| 426 list_value = new base::ListValue; | 432 list_value = new base::ListValue; |
| 427 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); | 433 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); |
| 428 } | 434 } |
| 429 list_value->Append(network.DeepCopy()); | 435 list_value->Append(network.DeepCopy()); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 base::FundamentalValue(false)); | 611 base::FundamentalValue(false)); |
| 606 } | 612 } |
| 607 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 613 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 608 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, | 614 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, |
| 609 0); | 615 0); |
| 610 if (!callback.is_null()) | 616 if (!callback.is_null()) |
| 611 MessageLoop::current()->PostTask(FROM_HERE, callback); | 617 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 612 } | 618 } |
| 613 | 619 |
| 614 } // namespace chromeos | 620 } // namespace chromeos |
| OLD | NEW |