Chromium Code Reviews| 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/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 if (add_to_visible_list && | 446 if (add_to_visible_list && |
| 447 GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( | 447 GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( |
| 448 base::Value::CreateStringValue(service_path))) { | 448 base::Value::CreateStringValue(service_path))) { |
| 449 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | 449 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 450 } | 450 } |
| 451 if (add_to_watch_list) | 451 if (add_to_watch_list) |
| 452 AddServiceToWatchList(service_path); | 452 AddServiceToWatchList(service_path); |
| 453 } | 453 } |
| 454 | 454 |
| 455 void FakeShillManagerClient::RemoveManagerService( | 455 void FakeShillManagerClient::RemoveManagerService( |
| 456 const std::string& service_path) { | 456 const std::string& service_path, |
| 457 bool remove_from_complete_list) { | |
| 457 base::StringValue service_path_value(service_path); | 458 base::StringValue service_path_value(service_path); |
| 459 if (remove_from_complete_list && | |
| 460 GetListProperty(shill::kServiceCompleteListProperty)->Remove( | |
| 461 service_path_value, NULL)) { | |
| 462 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); | |
|
pneubeck (no reviews)
2014/05/16 13:18:55
I think the reason for this notification missing w
stevenjb
2014/05/16 17:35:23
Ah, you are correct, I'll remove these. Done.
| |
| 463 } | |
| 458 if (GetListProperty(shill::kServicesProperty)->Remove( | 464 if (GetListProperty(shill::kServicesProperty)->Remove( |
| 459 service_path_value, NULL)) { | 465 service_path_value, NULL)) { |
| 460 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | 466 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 461 } | 467 } |
| 462 GetListProperty(shill::kServiceCompleteListProperty)->Remove( | |
| 463 service_path_value, NULL); | |
| 464 if (GetListProperty(shill::kServiceWatchListProperty)->Remove( | 468 if (GetListProperty(shill::kServiceWatchListProperty)->Remove( |
| 465 service_path_value, NULL)) { | 469 service_path_value, NULL)) { |
| 466 CallNotifyObserversPropertyChanged( | 470 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| 467 shill::kServiceWatchListProperty); | |
| 468 } | 471 } |
| 469 } | 472 } |
| 470 | 473 |
| 471 void FakeShillManagerClient::ClearManagerServices() { | 474 void FakeShillManagerClient::ClearManagerServices() { |
| 475 GetListProperty(shill::kServiceCompleteListProperty)->Clear(); | |
| 472 GetListProperty(shill::kServicesProperty)->Clear(); | 476 GetListProperty(shill::kServicesProperty)->Clear(); |
| 473 GetListProperty(shill::kServiceCompleteListProperty)->Clear(); | |
| 474 GetListProperty(shill::kServiceWatchListProperty)->Clear(); | 477 GetListProperty(shill::kServiceWatchListProperty)->Clear(); |
| 478 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); | |
|
pneubeck (no reviews)
2014/05/16 13:18:55
ditto
stevenjb
2014/05/16 17:35:23
Done.
| |
| 475 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | 479 CallNotifyObserversPropertyChanged(shill::kServicesProperty); |
| 476 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); | 480 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); |
| 477 } | 481 } |
| 478 | 482 |
| 479 void FakeShillManagerClient::ServiceStateChanged( | 483 void FakeShillManagerClient::ServiceStateChanged( |
| 480 const std::string& service_path, | 484 const std::string& service_path, |
| 481 const std::string& state) { | 485 const std::string& state) { |
| 482 if (service_path == default_service_ && !IsConnectedState(state)) { | 486 if (service_path == default_service_ && !IsConnectedState(state)) { |
| 483 // Default service is no longer connected; clear. | 487 // Default service is no longer connected; clear. |
| 484 default_service_.clear(); | 488 default_service_.clear(); |
| 485 base::StringValue default_service_value(default_service_); | 489 base::StringValue default_service_value(default_service_); |
| 486 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); | 490 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); |
| 487 } | 491 } |
| 488 } | 492 } |
| 489 | 493 |
| 490 void FakeShillManagerClient::SortManagerServices() { | 494 void FakeShillManagerClient::SortManagerServices() { |
| 495 SortServiceList(shill::kServicesProperty); | |
| 496 SortServiceList(shill::kServiceCompleteListProperty); | |
| 497 } | |
| 498 | |
| 499 void FakeShillManagerClient::SortServiceList(const std::string& property) { | |
| 491 static const char* ordered_types[] = { | 500 static const char* ordered_types[] = { |
| 492 shill::kTypeEthernet, | 501 shill::kTypeEthernet, |
| 493 shill::kTypeWifi, | 502 shill::kTypeWifi, |
| 494 shill::kTypeCellular, | 503 shill::kTypeCellular, |
| 495 shill::kTypeWimax, | 504 shill::kTypeWimax, |
| 496 shill::kTypeVPN | 505 shill::kTypeVPN |
| 497 }; | 506 }; |
| 498 base::ListValue* service_list = GetListProperty(shill::kServicesProperty); | 507 |
| 499 if (!service_list || service_list->empty()) { | 508 base::ListValue* service_list = GetListProperty(property); |
| 500 if (!default_service_.empty()) { | |
| 501 default_service_.clear(); | |
| 502 base::StringValue empty_value(""); | |
| 503 SetManagerProperty(shill::kDefaultServiceProperty, empty_value); | |
| 504 } | |
| 505 return; | |
| 506 } | |
| 507 std::vector<std::string> active_services; | 509 std::vector<std::string> active_services; |
| 508 std::vector<std::string> inactive_services; | 510 std::vector<std::string> inactive_services; |
| 509 for (size_t i = 0; i < arraysize(ordered_types); ++i) { | 511 if (service_list && !service_list->empty()) { |
| 510 AppendServicesForType(service_list, ordered_types[i], | 512 for (size_t i = 0; i < arraysize(ordered_types); ++i) { |
| 513 AppendServicesForType(service_list, ordered_types[i], | |
| 511 &active_services, &inactive_services); | 514 &active_services, &inactive_services); |
| 515 } | |
| 516 service_list->Clear(); | |
| 517 for (size_t i = 0; i < active_services.size(); ++i) | |
| 518 service_list->AppendString(active_services[i]); | |
| 519 for (size_t i = 0; i < inactive_services.size(); ++i) | |
| 520 service_list->AppendString(inactive_services[i]); | |
| 521 | |
| 522 CallNotifyObserversPropertyChanged(property); | |
| 512 } | 523 } |
| 513 service_list->Clear(); | |
| 514 for (size_t i = 0; i < active_services.size(); ++i) | |
| 515 service_list->AppendString(active_services[i]); | |
| 516 for (size_t i = 0; i < inactive_services.size(); ++i) | |
| 517 service_list->AppendString(inactive_services[i]); | |
| 518 | 524 |
| 519 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | 525 if (property != shill::kServicesProperty) |
| 526 return; | |
| 520 | 527 |
| 521 // Set the first active service as the Default service. | 528 // Set the first active service as the Default service. |
| 522 std::string new_default_service; | 529 std::string new_default_service; |
| 523 if (!active_services.empty()) { | 530 if (!active_services.empty()) { |
| 524 ShillServiceClient::TestInterface* service_client = | 531 ShillServiceClient::TestInterface* service_client = |
| 525 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 532 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 526 std::string service_path = active_services[0]; | 533 std::string service_path = active_services[0]; |
| 527 const base::DictionaryValue* properties = | 534 const base::DictionaryValue* properties = |
| 528 service_client->GetServiceProperties(service_path); | 535 service_client->GetServiceProperties(service_path); |
| 529 if (!properties) { | 536 if (!properties) { |
| 530 LOG(ERROR) << "Properties not found for service: " << service_path; | 537 LOG(ERROR) << "Properties not found for service: " << service_path; |
| 531 } else { | 538 } else { |
| 532 std::string state; | 539 std::string state; |
| 533 properties->GetString(shill::kStateProperty, &state); | 540 properties->GetString(shill::kStateProperty, &state); |
| 534 if (IsConnectedState(state)) | 541 if (IsConnectedState(state)) |
| 535 new_default_service = service_path; | 542 new_default_service = service_path; |
| 536 } | 543 } |
| 537 } | 544 } |
| 538 if (default_service_ != new_default_service) { | 545 if (default_service_ != new_default_service) { |
| 539 default_service_ = new_default_service; | 546 default_service_ = new_default_service; |
| 540 base::StringValue default_service_value(default_service_); | 547 base::StringValue default_service_value(default_service_); |
| 541 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); | 548 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); |
| 542 } | 549 } |
| 550 | |
| 551 return; | |
| 543 } | 552 } |
| 544 | 553 |
| 545 | 554 |
| 546 int FakeShillManagerClient::GetInteractiveDelay() const { | 555 int FakeShillManagerClient::GetInteractiveDelay() const { |
| 547 return interactive_delay_; | 556 return interactive_delay_; |
| 548 } | 557 } |
| 549 | 558 |
| 550 void FakeShillManagerClient::SetupDefaultEnvironment() { | 559 void FakeShillManagerClient::SetupDefaultEnvironment() { |
| 551 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); | 560 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); |
| 552 ShillServiceClient::TestInterface* services = | 561 ShillServiceClient::TestInterface* services = |
| (...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1031 *enabled = true; | 1040 *enabled = true; |
| 1032 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || | 1041 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || |
| 1033 (state == kNetworkActivated && type != shill::kTypeCellular)) { | 1042 (state == kNetworkActivated && type != shill::kTypeCellular)) { |
| 1034 LOG(WARNING) << "Invalid state: " << state << " for " << type; | 1043 LOG(WARNING) << "Invalid state: " << state << " for " << type; |
| 1035 return shill::kStateIdle; | 1044 return shill::kStateIdle; |
| 1036 } | 1045 } |
| 1037 return state; | 1046 return state; |
| 1038 } | 1047 } |
| 1039 | 1048 |
| 1040 } // namespace chromeos | 1049 } // namespace chromeos |
| OLD | NEW |