| 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()); |
| 430 } | 436 } |
| 431 | 437 |
| 432 void ShillManagerClientStub::AddProfile(const std::string& profile_path) { | 438 void ShillManagerClientStub::AddProfile(const std::string& profile_path) { |
| 433 const char* key = flimflam::kProfilesProperty; | 439 const char* key = flimflam::kProfilesProperty; |
| 434 if (GetListProperty(key)->AppendIfNotPresent( | 440 if (GetListProperty(key)->AppendIfNotPresent( |
| 435 new base::StringValue(profile_path))) { | 441 new base::StringValue(profile_path))) { |
| 436 CallNotifyObserversPropertyChanged(key, 0); | 442 CallNotifyObserversPropertyChanged(key, 0); |
| 437 } | 443 } |
| 438 } | 444 } |
| 439 | 445 |
| 440 void ShillManagerClientStub::AddServiceToWatchList( | 446 void ShillManagerClientStub::AddServiceToWatchList( |
| 441 const std::string& service_path) { | 447 const std::string& service_path) { |
| 442 if (GetListProperty( | 448 // Remove and insert the service, moving it to the front of the watch list. |
| 443 flimflam::kServiceWatchListProperty)->AppendIfNotPresent( | 449 GetListProperty(flimflam::kServiceWatchListProperty)->Remove( |
| 444 base::Value::CreateStringValue(service_path))) { | 450 base::StringValue(service_path), NULL); |
| 445 CallNotifyObserversPropertyChanged( | 451 GetListProperty(flimflam::kServiceWatchListProperty)->Insert( |
| 446 flimflam::kServiceWatchListProperty, 0); | 452 0, base::Value::CreateStringValue(service_path)); |
| 447 } | 453 CallNotifyObserversPropertyChanged( |
| 454 flimflam::kServiceWatchListProperty, 0); |
| 448 } | 455 } |
| 449 | 456 |
| 450 void ShillManagerClientStub::SetDefaultProperties() { | 457 void ShillManagerClientStub::SetDefaultProperties() { |
| 451 // Stub Technologies. | 458 // Stub Technologies. |
| 452 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 459 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 453 chromeos::switches::kDisableStubEthernet)) { | 460 chromeos::switches::kDisableStubEthernet)) { |
| 454 AddTechnology(flimflam::kTypeEthernet, true); | 461 AddTechnology(flimflam::kTypeEthernet, true); |
| 455 } | 462 } |
| 456 AddTechnology(flimflam::kTypeWifi, true); | 463 AddTechnology(flimflam::kTypeWifi, true); |
| 457 AddTechnology(flimflam::kTypeCellular, true); | 464 AddTechnology(flimflam::kTypeCellular, true); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 472 } | 479 } |
| 473 | 480 |
| 474 void ShillManagerClientStub::PassStubGeoNetworks( | 481 void ShillManagerClientStub::PassStubGeoNetworks( |
| 475 const DictionaryValueCallback& callback) const { | 482 const DictionaryValueCallback& callback) const { |
| 476 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); | 483 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); |
| 477 } | 484 } |
| 478 | 485 |
| 479 void ShillManagerClientStub::CallNotifyObserversPropertyChanged( | 486 void ShillManagerClientStub::CallNotifyObserversPropertyChanged( |
| 480 const std::string& property, | 487 const std::string& property, |
| 481 int delay_ms) { | 488 int delay_ms) { |
| 482 // Don't actually delay unless we're interactive. | |
| 483 if (!CommandLine::ForCurrentProcess()->HasSwitch( | |
| 484 chromeos::switches::kEnableStubInteractive)) { | |
| 485 delay_ms = 0; | |
| 486 } | |
| 487 | |
| 488 // Avoid unnecessary delayed task if we have no observers (e.g. during | 489 // Avoid unnecessary delayed task if we have no observers (e.g. during |
| 489 // initial setup). | 490 // initial setup). |
| 490 if (observer_list_.size() == 0) | 491 if (observer_list_.size() == 0) |
| 491 return; | 492 return; |
| 492 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 493 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
| 493 chromeos::switches::kEnableStubInteractive)) { | 494 chromeos::switches::kEnableStubInteractive)) { |
| 494 delay_ms = 0; | 495 delay_ms = 0; |
| 495 } | 496 } |
| 496 MessageLoop::current()->PostDelayedTask( | 497 MessageLoop::current()->PostDelayedTask( |
| 497 FROM_HERE, | 498 FROM_HERE, |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 base::FundamentalValue(false)); | 606 base::FundamentalValue(false)); |
| 606 } | 607 } |
| 607 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); | 608 CallNotifyObserversPropertyChanged(flimflam::kServicesProperty, 0); |
| 608 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, | 609 CallNotifyObserversPropertyChanged(flimflam::kServiceWatchListProperty, |
| 609 0); | 610 0); |
| 610 if (!callback.is_null()) | 611 if (!callback.is_null()) |
| 611 MessageLoop::current()->PostTask(FROM_HERE, callback); | 612 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 612 } | 613 } |
| 613 | 614 |
| 614 } // namespace chromeos | 615 } // namespace chromeos |
| OLD | NEW |