| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/fake_shill_manager_client.h" | 5 #include "chromeos/dbus/fake_shill_manager_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 state == shill::kStateConfiguration || | 66 state == shill::kStateConfiguration || |
| 67 state == shill::kStatePortal || | 67 state == shill::kStatePortal || |
| 68 state == shill::kStateReady) { | 68 state == shill::kStateReady) { |
| 69 active_service_list_out->push_back(service_path); | 69 active_service_list_out->push_back(service_path); |
| 70 } else { | 70 } else { |
| 71 inactive_service_list_out->push_back(service_path); | 71 inactive_service_list_out->push_back(service_path); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 void LogErrorCallback(const std::string& error_name, |
| 77 const std::string& error_message) { |
| 78 LOG(ERROR) << error_name << ": " << error_message; |
| 79 } |
| 80 |
| 81 bool IsConnectedState(const std::string& state) { |
| 82 return state == shill::kStateOnline || state == shill::kStatePortal || |
| 83 state == shill::kStateReady; |
| 84 } |
| 85 |
| 76 } // namespace | 86 } // namespace |
| 77 | 87 |
| 78 FakeShillManagerClient::FakeShillManagerClient() | 88 FakeShillManagerClient::FakeShillManagerClient() |
| 79 : weak_ptr_factory_(this) { | 89 : weak_ptr_factory_(this) { |
| 80 } | 90 } |
| 81 | 91 |
| 82 FakeShillManagerClient::~FakeShillManagerClient() {} | 92 FakeShillManagerClient::~FakeShillManagerClient() {} |
| 83 | 93 |
| 84 // ShillManagerClient overrides. | 94 // ShillManagerClient overrides. |
| 85 | 95 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 111 &FakeShillManagerClient::PassStubGeoNetworks, | 121 &FakeShillManagerClient::PassStubGeoNetworks, |
| 112 weak_ptr_factory_.GetWeakPtr(), | 122 weak_ptr_factory_.GetWeakPtr(), |
| 113 callback)); | 123 callback)); |
| 114 } | 124 } |
| 115 | 125 |
| 116 void FakeShillManagerClient::SetProperty(const std::string& name, | 126 void FakeShillManagerClient::SetProperty(const std::string& name, |
| 117 const base::Value& value, | 127 const base::Value& value, |
| 118 const base::Closure& callback, | 128 const base::Closure& callback, |
| 119 const ErrorCallback& error_callback) { | 129 const ErrorCallback& error_callback) { |
| 120 stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy()); | 130 stub_properties_.SetWithoutPathExpansion(name, value.DeepCopy()); |
| 121 CallNotifyObserversPropertyChanged(name, 0); | 131 CallNotifyObserversPropertyChanged(name); |
| 122 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 132 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 123 } | 133 } |
| 124 | 134 |
| 125 void FakeShillManagerClient::RequestScan(const std::string& type, | 135 void FakeShillManagerClient::RequestScan(const std::string& type, |
| 126 const base::Closure& callback, | 136 const base::Closure& callback, |
| 127 const ErrorCallback& error_callback) { | 137 const ErrorCallback& error_callback) { |
| 128 // For Stub purposes, default to a Wifi scan. | 138 // For Stub purposes, default to a Wifi scan. |
| 129 std::string device_type = shill::kTypeWifi; | 139 std::string device_type = shill::kTypeWifi; |
| 130 if (!type.empty()) | 140 if (!type.empty()) |
| 131 device_type = type; | 141 device_type = type; |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 | 327 |
| 318 ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() { | 328 ShillManagerClient::TestInterface* FakeShillManagerClient::GetTestInterface() { |
| 319 return this; | 329 return this; |
| 320 } | 330 } |
| 321 | 331 |
| 322 // ShillManagerClient::TestInterface overrides. | 332 // ShillManagerClient::TestInterface overrides. |
| 323 | 333 |
| 324 void FakeShillManagerClient::AddDevice(const std::string& device_path) { | 334 void FakeShillManagerClient::AddDevice(const std::string& device_path) { |
| 325 if (GetListProperty(shill::kDevicesProperty)->AppendIfNotPresent( | 335 if (GetListProperty(shill::kDevicesProperty)->AppendIfNotPresent( |
| 326 base::Value::CreateStringValue(device_path))) { | 336 base::Value::CreateStringValue(device_path))) { |
| 327 CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); | 337 CallNotifyObserversPropertyChanged(shill::kDevicesProperty); |
| 328 } | 338 } |
| 329 } | 339 } |
| 330 | 340 |
| 331 void FakeShillManagerClient::RemoveDevice(const std::string& device_path) { | 341 void FakeShillManagerClient::RemoveDevice(const std::string& device_path) { |
| 332 base::StringValue device_path_value(device_path); | 342 base::StringValue device_path_value(device_path); |
| 333 if (GetListProperty(shill::kDevicesProperty)->Remove( | 343 if (GetListProperty(shill::kDevicesProperty)->Remove( |
| 334 device_path_value, NULL)) { | 344 device_path_value, NULL)) { |
| 335 CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); | 345 CallNotifyObserversPropertyChanged(shill::kDevicesProperty); |
| 336 } | 346 } |
| 337 } | 347 } |
| 338 | 348 |
| 339 void FakeShillManagerClient::ClearDevices() { | 349 void FakeShillManagerClient::ClearDevices() { |
| 340 GetListProperty(shill::kDevicesProperty)->Clear(); | 350 GetListProperty(shill::kDevicesProperty)->Clear(); |
| 341 CallNotifyObserversPropertyChanged(shill::kDevicesProperty, 0); | 351 CallNotifyObserversPropertyChanged(shill::kDevicesProperty); |
| 342 } | 352 } |
| 343 | 353 |
| 344 void FakeShillManagerClient::AddTechnology(const std::string& type, | 354 void FakeShillManagerClient::AddTechnology(const std::string& type, |
| 345 bool enabled) { | 355 bool enabled) { |
| 346 if (GetListProperty(shill::kAvailableTechnologiesProperty)-> | 356 if (GetListProperty(shill::kAvailableTechnologiesProperty)-> |
| 347 AppendIfNotPresent(base::Value::CreateStringValue(type))) { | 357 AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| 348 CallNotifyObserversPropertyChanged( | 358 CallNotifyObserversPropertyChanged( |
| 349 shill::kAvailableTechnologiesProperty, 0); | 359 shill::kAvailableTechnologiesProperty); |
| 350 } | 360 } |
| 351 if (enabled && | 361 if (enabled && |
| 352 GetListProperty(shill::kEnabledTechnologiesProperty)-> | 362 GetListProperty(shill::kEnabledTechnologiesProperty)-> |
| 353 AppendIfNotPresent(base::Value::CreateStringValue(type))) { | 363 AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| 354 CallNotifyObserversPropertyChanged( | 364 CallNotifyObserversPropertyChanged( |
| 355 shill::kEnabledTechnologiesProperty, 0); | 365 shill::kEnabledTechnologiesProperty); |
| 356 } | 366 } |
| 357 } | 367 } |
| 358 | 368 |
| 359 void FakeShillManagerClient::RemoveTechnology(const std::string& type) { | 369 void FakeShillManagerClient::RemoveTechnology(const std::string& type) { |
| 360 base::StringValue type_value(type); | 370 base::StringValue type_value(type); |
| 361 if (GetListProperty(shill::kAvailableTechnologiesProperty)->Remove( | 371 if (GetListProperty(shill::kAvailableTechnologiesProperty)->Remove( |
| 362 type_value, NULL)) { | 372 type_value, NULL)) { |
| 363 CallNotifyObserversPropertyChanged( | 373 CallNotifyObserversPropertyChanged( |
| 364 shill::kAvailableTechnologiesProperty, 0); | 374 shill::kAvailableTechnologiesProperty); |
| 365 } | 375 } |
| 366 if (GetListProperty(shill::kEnabledTechnologiesProperty)->Remove( | 376 if (GetListProperty(shill::kEnabledTechnologiesProperty)->Remove( |
| 367 type_value, NULL)) { | 377 type_value, NULL)) { |
| 368 CallNotifyObserversPropertyChanged( | 378 CallNotifyObserversPropertyChanged( |
| 369 shill::kEnabledTechnologiesProperty, 0); | 379 shill::kEnabledTechnologiesProperty); |
| 370 } | 380 } |
| 371 } | 381 } |
| 372 | 382 |
| 373 void FakeShillManagerClient::SetTechnologyInitializing(const std::string& type, | 383 void FakeShillManagerClient::SetTechnologyInitializing(const std::string& type, |
| 374 bool initializing) { | 384 bool initializing) { |
| 375 if (initializing) { | 385 if (initializing) { |
| 376 if (GetListProperty(shill::kUninitializedTechnologiesProperty)-> | 386 if (GetListProperty(shill::kUninitializedTechnologiesProperty)-> |
| 377 AppendIfNotPresent(base::Value::CreateStringValue(type))) { | 387 AppendIfNotPresent(base::Value::CreateStringValue(type))) { |
| 378 CallNotifyObserversPropertyChanged( | 388 CallNotifyObserversPropertyChanged( |
| 379 shill::kUninitializedTechnologiesProperty, 0); | 389 shill::kUninitializedTechnologiesProperty); |
| 380 } | 390 } |
| 381 } else { | 391 } else { |
| 382 if (GetListProperty(shill::kUninitializedTechnologiesProperty)->Remove( | 392 if (GetListProperty(shill::kUninitializedTechnologiesProperty)->Remove( |
| 383 base::StringValue(type), NULL)) { | 393 base::StringValue(type), NULL)) { |
| 384 CallNotifyObserversPropertyChanged( | 394 CallNotifyObserversPropertyChanged( |
| 385 shill::kUninitializedTechnologiesProperty, 0); | 395 shill::kUninitializedTechnologiesProperty); |
| 386 } | 396 } |
| 387 } | 397 } |
| 388 } | 398 } |
| 389 | 399 |
| 390 void FakeShillManagerClient::ClearProperties() { | 400 void FakeShillManagerClient::ClearProperties() { |
| 391 stub_properties_.Clear(); | 401 stub_properties_.Clear(); |
| 392 } | 402 } |
| 393 | 403 |
| 404 void FakeShillManagerClient::SetManagerProperty(const std::string& key, |
| 405 const base::Value& value) { |
| 406 SetProperty(key, value, |
| 407 base::Bind(&base::DoNothing), base::Bind(&LogErrorCallback)); |
| 408 } |
| 409 |
| 394 void FakeShillManagerClient::AddManagerService(const std::string& service_path, | 410 void FakeShillManagerClient::AddManagerService(const std::string& service_path, |
| 395 bool add_to_visible_list, | 411 bool add_to_visible_list, |
| 396 bool add_to_watch_list) { | 412 bool add_to_watch_list) { |
| 397 // Always add to ServiceCompleteListProperty. | 413 // Always add to ServiceCompleteListProperty. |
| 398 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent( | 414 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent( |
| 399 base::Value::CreateStringValue(service_path)); | 415 base::Value::CreateStringValue(service_path)); |
| 400 // If visible, add to Services and notify if new. | 416 // If visible, add to Services and notify if new. |
| 401 if (add_to_visible_list && | 417 if (add_to_visible_list && |
| 402 GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( | 418 GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( |
| 403 base::Value::CreateStringValue(service_path))) { | 419 base::Value::CreateStringValue(service_path))) { |
| 404 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 420 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 405 } | 421 } |
| 406 if (add_to_watch_list) | 422 if (add_to_watch_list) |
| 407 AddServiceToWatchList(service_path); | 423 AddServiceToWatchList(service_path); |
| 408 } | 424 } |
| 409 | 425 |
| 410 void FakeShillManagerClient::RemoveManagerService( | 426 void FakeShillManagerClient::RemoveManagerService( |
| 411 const std::string& service_path) { | 427 const std::string& service_path) { |
| 412 base::StringValue service_path_value(service_path); | 428 base::StringValue service_path_value(service_path); |
| 413 if (GetListProperty(shill::kServicesProperty)->Remove( | 429 if (GetListProperty(shill::kServicesProperty)->Remove( |
| 414 service_path_value, NULL)) { | 430 service_path_value, NULL)) { |
| 415 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 431 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 416 } | 432 } |
| 417 GetListProperty(shill::kServiceCompleteListProperty)->Remove( | 433 GetListProperty(shill::kServiceCompleteListProperty)->Remove( |
| 418 service_path_value, NULL); | 434 service_path_value, NULL); |
| 419 if (GetListProperty(shill::kServiceWatchListProperty)->Remove( | 435 if (GetListProperty(shill::kServiceWatchListProperty)->Remove( |
| 420 service_path_value, NULL)) { | 436 service_path_value, NULL)) { |
| 421 CallNotifyObserversPropertyChanged( | 437 CallNotifyObserversPropertyChanged( |
| 422 shill::kServiceWatchListProperty, 0); | 438 shill::kServiceWatchListProperty); |
| 423 } | 439 } |
| 424 } | 440 } |
| 425 | 441 |
| 426 void FakeShillManagerClient::ClearManagerServices() { | 442 void FakeShillManagerClient::ClearManagerServices() { |
| 427 GetListProperty(shill::kServicesProperty)->Clear(); | 443 GetListProperty(shill::kServicesProperty)->Clear(); |
| 428 GetListProperty(shill::kServiceCompleteListProperty)->Clear(); | 444 GetListProperty(shill::kServiceCompleteListProperty)->Clear(); |
| 429 GetListProperty(shill::kServiceWatchListProperty)->Clear(); | 445 GetListProperty(shill::kServiceWatchListProperty)->Clear(); |
| 430 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 446 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 431 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); | 447 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| 448 } |
| 449 |
| 450 void FakeShillManagerClient::ServiceStateChanged( |
| 451 const std::string& service_path, |
| 452 const std::string& state) { |
| 453 if (service_path == default_service_ && !IsConnectedState(state)) { |
| 454 // Default service is no longer connected; clear. |
| 455 default_service_.clear(); |
| 456 base::StringValue default_service_value(default_service_); |
| 457 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); |
| 458 } |
| 432 } | 459 } |
| 433 | 460 |
| 434 void FakeShillManagerClient::SortManagerServices() { | 461 void FakeShillManagerClient::SortManagerServices() { |
| 435 static const char* ordered_types[] = { | 462 static const char* ordered_types[] = { |
| 436 shill::kTypeEthernet, | 463 shill::kTypeEthernet, |
| 437 shill::kTypeWifi, | 464 shill::kTypeWifi, |
| 438 shill::kTypeCellular, | 465 shill::kTypeCellular, |
| 439 shill::kTypeWimax, | 466 shill::kTypeWimax, |
| 440 shill::kTypeVPN | 467 shill::kTypeVPN |
| 441 }; | 468 }; |
| 442 base::ListValue* service_list = GetListProperty(shill::kServicesProperty); | 469 base::ListValue* service_list = GetListProperty(shill::kServicesProperty); |
| 443 if (!service_list || service_list->empty()) | 470 if (!service_list || service_list->empty()) { |
| 471 if (!default_service_.empty()) { |
| 472 default_service_.clear(); |
| 473 base::StringValue empty_value(""); |
| 474 SetManagerProperty(shill::kDefaultServiceProperty, empty_value); |
| 475 } |
| 444 return; | 476 return; |
| 477 } |
| 445 std::vector<std::string> active_services; | 478 std::vector<std::string> active_services; |
| 446 std::vector<std::string> inactive_services; | 479 std::vector<std::string> inactive_services; |
| 447 for (size_t i = 0; i < arraysize(ordered_types); ++i) { | 480 for (size_t i = 0; i < arraysize(ordered_types); ++i) { |
| 448 AppendServicesForType(service_list, ordered_types[i], | 481 AppendServicesForType(service_list, ordered_types[i], |
| 449 &active_services, &inactive_services); | 482 &active_services, &inactive_services); |
| 450 } | 483 } |
| 451 service_list->Clear(); | 484 service_list->Clear(); |
| 452 for (size_t i = 0; i < active_services.size(); ++i) | 485 for (size_t i = 0; i < active_services.size(); ++i) |
| 453 service_list->AppendString(active_services[i]); | 486 service_list->AppendString(active_services[i]); |
| 454 for (size_t i = 0; i < inactive_services.size(); ++i) | 487 for (size_t i = 0; i < inactive_services.size(); ++i) |
| 455 service_list->AppendString(inactive_services[i]); | 488 service_list->AppendString(inactive_services[i]); |
| 456 | 489 |
| 457 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 490 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 491 |
| 492 // Set the first active service as the Default service. |
| 493 std::string new_default_service; |
| 494 if (!active_services.empty()) { |
| 495 ShillServiceClient::TestInterface* service_client = |
| 496 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 497 std::string service_path = active_services[0]; |
| 498 const base::DictionaryValue* properties = |
| 499 service_client->GetServiceProperties(service_path); |
| 500 if (!properties) { |
| 501 LOG(ERROR) << "Properties not found for service: " << service_path; |
| 502 } else { |
| 503 std::string state; |
| 504 properties->GetString(shill::kStateProperty, &state); |
| 505 if (IsConnectedState(state)) |
| 506 new_default_service = service_path; |
| 507 } |
| 508 } |
| 509 if (default_service_ != new_default_service) { |
| 510 default_service_ = new_default_service; |
| 511 base::StringValue default_service_value(default_service_); |
| 512 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); |
| 513 } |
| 458 } | 514 } |
| 459 | 515 |
| 460 void FakeShillManagerClient::AddGeoNetwork( | 516 void FakeShillManagerClient::AddGeoNetwork( |
| 461 const std::string& technology, | 517 const std::string& technology, |
| 462 const base::DictionaryValue& network) { | 518 const base::DictionaryValue& network) { |
| 463 base::ListValue* list_value = NULL; | 519 base::ListValue* list_value = NULL; |
| 464 if (!stub_geo_networks_.GetListWithoutPathExpansion( | 520 if (!stub_geo_networks_.GetListWithoutPathExpansion( |
| 465 technology, &list_value)) { | 521 technology, &list_value)) { |
| 466 list_value = new base::ListValue; | 522 list_value = new base::ListValue; |
| 467 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); | 523 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); |
| 468 } | 524 } |
| 469 list_value->Append(network.DeepCopy()); | 525 list_value->Append(network.DeepCopy()); |
| 470 } | 526 } |
| 471 | 527 |
| 472 void FakeShillManagerClient::AddProfile(const std::string& profile_path) { | 528 void FakeShillManagerClient::AddProfile(const std::string& profile_path) { |
| 473 const char* key = shill::kProfilesProperty; | 529 const char* key = shill::kProfilesProperty; |
| 474 if (GetListProperty(key)->AppendIfNotPresent( | 530 if (GetListProperty(key)->AppendIfNotPresent( |
| 475 new base::StringValue(profile_path))) { | 531 new base::StringValue(profile_path))) { |
| 476 CallNotifyObserversPropertyChanged(key, 0); | 532 CallNotifyObserversPropertyChanged(key); |
| 477 } | 533 } |
| 478 } | 534 } |
| 479 | 535 |
| 480 void FakeShillManagerClient::AddServiceToWatchList( | 536 void FakeShillManagerClient::AddServiceToWatchList( |
| 481 const std::string& service_path) { | 537 const std::string& service_path) { |
| 482 // Remove and insert the service, moving it to the front of the watch list. | 538 // Remove and insert the service, moving it to the front of the watch list. |
| 483 GetListProperty(shill::kServiceWatchListProperty)->Remove( | 539 GetListProperty(shill::kServiceWatchListProperty)->Remove( |
| 484 base::StringValue(service_path), NULL); | 540 base::StringValue(service_path), NULL); |
| 485 GetListProperty(shill::kServiceWatchListProperty)->Insert( | 541 GetListProperty(shill::kServiceWatchListProperty)->Insert( |
| 486 0, base::Value::CreateStringValue(service_path)); | 542 0, base::Value::CreateStringValue(service_path)); |
| 487 CallNotifyObserversPropertyChanged( | 543 CallNotifyObserversPropertyChanged( |
| 488 shill::kServiceWatchListProperty, 0); | 544 shill::kServiceWatchListProperty); |
| 489 } | 545 } |
| 490 | 546 |
| 491 void FakeShillManagerClient::PassStubProperties( | 547 void FakeShillManagerClient::PassStubProperties( |
| 492 const DictionaryValueCallback& callback) const { | 548 const DictionaryValueCallback& callback) const { |
| 493 scoped_ptr<base::DictionaryValue> stub_properties( | 549 scoped_ptr<base::DictionaryValue> stub_properties( |
| 494 stub_properties_.DeepCopy()); | 550 stub_properties_.DeepCopy()); |
| 495 // Remove disabled services from the list. | 551 // Remove disabled services from the list. |
| 496 stub_properties->SetWithoutPathExpansion( | 552 stub_properties->SetWithoutPathExpansion( |
| 497 shill::kServicesProperty, | 553 shill::kServicesProperty, |
| 498 GetEnabledServiceList(shill::kServicesProperty)); | 554 GetEnabledServiceList(shill::kServicesProperty)); |
| 499 stub_properties->SetWithoutPathExpansion( | 555 stub_properties->SetWithoutPathExpansion( |
| 500 shill::kServiceWatchListProperty, | 556 shill::kServiceWatchListProperty, |
| 501 GetEnabledServiceList(shill::kServiceWatchListProperty)); | 557 GetEnabledServiceList(shill::kServiceWatchListProperty)); |
| 502 callback.Run(DBUS_METHOD_CALL_SUCCESS, *stub_properties); | 558 callback.Run(DBUS_METHOD_CALL_SUCCESS, *stub_properties); |
| 503 } | 559 } |
| 504 | 560 |
| 505 void FakeShillManagerClient::PassStubGeoNetworks( | 561 void FakeShillManagerClient::PassStubGeoNetworks( |
| 506 const DictionaryValueCallback& callback) const { | 562 const DictionaryValueCallback& callback) const { |
| 507 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); | 563 callback.Run(DBUS_METHOD_CALL_SUCCESS, stub_geo_networks_); |
| 508 } | 564 } |
| 509 | 565 |
| 510 void FakeShillManagerClient::CallNotifyObserversPropertyChanged( | 566 void FakeShillManagerClient::CallNotifyObserversPropertyChanged( |
| 511 const std::string& property, | 567 const std::string& property) { |
| 512 int delay_ms) { | |
| 513 // Avoid unnecessary delayed task if we have no observers (e.g. during | 568 // Avoid unnecessary delayed task if we have no observers (e.g. during |
| 514 // initial setup). | 569 // initial setup). |
| 515 if (!observer_list_.might_have_observers()) | 570 if (!observer_list_.might_have_observers()) |
| 516 return; | 571 return; |
| 517 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 572 base::MessageLoop::current()->PostTask( |
| 518 chromeos::switches::kEnableStubInteractive)) { | |
| 519 delay_ms = 0; | |
| 520 } | |
| 521 base::MessageLoop::current()->PostDelayedTask( | |
| 522 FROM_HERE, | 573 FROM_HERE, |
| 523 base::Bind(&FakeShillManagerClient::NotifyObserversPropertyChanged, | 574 base::Bind(&FakeShillManagerClient::NotifyObserversPropertyChanged, |
| 524 weak_ptr_factory_.GetWeakPtr(), | 575 weak_ptr_factory_.GetWeakPtr(), |
| 525 property), | 576 property)); |
| 526 base::TimeDelta::FromMilliseconds(delay_ms)); | |
| 527 } | 577 } |
| 528 | 578 |
| 529 void FakeShillManagerClient::NotifyObserversPropertyChanged( | 579 void FakeShillManagerClient::NotifyObserversPropertyChanged( |
| 530 const std::string& property) { | 580 const std::string& property) { |
| 531 if (property == shill::kServicesProperty || | 581 if (property == shill::kServicesProperty || |
| 532 property == shill::kServiceWatchListProperty) { | 582 property == shill::kServiceWatchListProperty) { |
| 533 scoped_ptr<base::ListValue> services(GetEnabledServiceList(property)); | 583 scoped_ptr<base::ListValue> services(GetEnabledServiceList(property)); |
| 534 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, | 584 FOR_EACH_OBSERVER(ShillPropertyChangedObserver, |
| 535 observer_list_, | 585 observer_list_, |
| 536 OnPropertyChanged(property, *(services.get()))); | 586 OnPropertyChanged(property, *(services.get()))); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 bool enabled) { | 637 bool enabled) { |
| 588 base::ListValue* enabled_list = NULL; | 638 base::ListValue* enabled_list = NULL; |
| 589 stub_properties_.GetListWithoutPathExpansion( | 639 stub_properties_.GetListWithoutPathExpansion( |
| 590 shill::kEnabledTechnologiesProperty, &enabled_list); | 640 shill::kEnabledTechnologiesProperty, &enabled_list); |
| 591 DCHECK(enabled_list); | 641 DCHECK(enabled_list); |
| 592 if (enabled) | 642 if (enabled) |
| 593 enabled_list->AppendIfNotPresent(new base::StringValue(type)); | 643 enabled_list->AppendIfNotPresent(new base::StringValue(type)); |
| 594 else | 644 else |
| 595 enabled_list->Remove(base::StringValue(type), NULL); | 645 enabled_list->Remove(base::StringValue(type), NULL); |
| 596 CallNotifyObserversPropertyChanged( | 646 CallNotifyObserversPropertyChanged( |
| 597 shill::kEnabledTechnologiesProperty, 0 /* already delayed */); | 647 shill::kEnabledTechnologiesProperty); |
| 598 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 648 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 599 // May affect available services | 649 // May affect available services |
| 600 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 650 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 601 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); | 651 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| 602 } | 652 } |
| 603 | 653 |
| 604 base::ListValue* FakeShillManagerClient::GetEnabledServiceList( | 654 base::ListValue* FakeShillManagerClient::GetEnabledServiceList( |
| 605 const std::string& property) const { | 655 const std::string& property) const { |
| 606 base::ListValue* new_service_list = new base::ListValue; | 656 base::ListValue* new_service_list = new base::ListValue; |
| 607 const base::ListValue* service_list; | 657 const base::ListValue* service_list; |
| 608 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { | 658 if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) { |
| 609 ShillServiceClient::TestInterface* service_client = | 659 ShillServiceClient::TestInterface* service_client = |
| 610 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 660 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 611 for (base::ListValue::const_iterator iter = service_list->begin(); | 661 for (base::ListValue::const_iterator iter = service_list->begin(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 631 } | 681 } |
| 632 | 682 |
| 633 void FakeShillManagerClient::ScanCompleted(const std::string& device_path, | 683 void FakeShillManagerClient::ScanCompleted(const std::string& device_path, |
| 634 const base::Closure& callback) { | 684 const base::Closure& callback) { |
| 635 if (!device_path.empty()) { | 685 if (!device_path.empty()) { |
| 636 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> | 686 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> |
| 637 SetDeviceProperty(device_path, | 687 SetDeviceProperty(device_path, |
| 638 shill::kScanningProperty, | 688 shill::kScanningProperty, |
| 639 base::FundamentalValue(false)); | 689 base::FundamentalValue(false)); |
| 640 } | 690 } |
| 641 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 691 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 642 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); | 692 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| 643 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 693 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 644 } | 694 } |
| 645 | 695 |
| 646 } // namespace chromeos | 696 } // namespace chromeos |
| OLD | NEW |