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 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
461 base::Bind(&base::DoNothing), base::Bind(&LogErrorCallback)); | 461 base::Bind(&base::DoNothing), base::Bind(&LogErrorCallback)); |
462 } | 462 } |
463 | 463 |
464 void FakeShillManagerClient::AddManagerService( | 464 void FakeShillManagerClient::AddManagerService( |
465 const std::string& service_path) { | 465 const std::string& service_path) { |
466 DVLOG(2) << "AddManagerService: " << service_path; | 466 DVLOG(2) << "AddManagerService: " << service_path; |
467 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent( | 467 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent( |
468 base::Value::CreateStringValue(service_path)); | 468 base::Value::CreateStringValue(service_path)); |
469 SortManagerServices(false); | 469 SortManagerServices(false); |
470 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); | 470 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); |
471 // SortManagerServices will add the service to Services if it is visible. | |
472 const base::ListValue* services = GetListProperty(shill::kServicesProperty); | |
473 if (services->Find(base::StringValue(service_path)) != services->end()) | |
474 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | |
475 } | 471 } |
476 | 472 |
477 void FakeShillManagerClient::RemoveManagerService( | 473 void FakeShillManagerClient::RemoveManagerService( |
478 const std::string& service_path) { | 474 const std::string& service_path) { |
479 DVLOG(2) << "RemoveManagerService: " << service_path; | 475 DVLOG(2) << "RemoveManagerService: " << service_path; |
480 base::StringValue service_path_value(service_path); | 476 base::StringValue service_path_value(service_path); |
481 GetListProperty(shill::kServiceCompleteListProperty)->Remove( | 477 GetListProperty(shill::kServiceCompleteListProperty)->Remove( |
482 service_path_value, NULL); | 478 service_path_value, NULL); |
483 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); | 479 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); |
484 if (GetListProperty(shill::kServicesProperty)->Remove( | |
485 service_path_value, NULL)) { | |
486 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | |
487 } | |
488 } | 480 } |
489 | 481 |
490 void FakeShillManagerClient::ClearManagerServices() { | 482 void FakeShillManagerClient::ClearManagerServices() { |
491 DVLOG(1) << "ClearManagerServices"; | 483 DVLOG(1) << "ClearManagerServices"; |
492 GetListProperty(shill::kServiceCompleteListProperty)->Clear(); | 484 GetListProperty(shill::kServiceCompleteListProperty)->Clear(); |
493 GetListProperty(shill::kServicesProperty)->Clear(); | |
494 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); | 485 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); |
495 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | |
496 } | 486 } |
497 | 487 |
498 void FakeShillManagerClient::ServiceStateChanged( | 488 void FakeShillManagerClient::ServiceStateChanged( |
499 const std::string& service_path, | 489 const std::string& service_path, |
500 const std::string& state) { | 490 const std::string& state) { |
501 if (service_path == default_service_ && !IsConnectedState(state)) { | 491 if (service_path == default_service_ && !IsConnectedState(state)) { |
502 // Default service is no longer connected; clear. | 492 // Default service is no longer connected; clear. |
503 default_service_.clear(); | 493 default_service_.clear(); |
504 base::StringValue default_service_value(default_service_); | 494 base::StringValue default_service_value(default_service_); |
505 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); | 495 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); |
506 } | 496 } |
507 } | 497 } |
508 | 498 |
509 void FakeShillManagerClient::SortManagerServices(bool notify) { | 499 void FakeShillManagerClient::SortManagerServices(bool notify) { |
510 DVLOG(1) << "SortManagerServices"; | 500 DVLOG(1) << "SortManagerServices"; |
511 static const char* ordered_types[] = {shill::kTypeEthernet, | 501 static const char* ordered_types[] = {shill::kTypeEthernet, |
512 shill::kTypeWifi, | 502 shill::kTypeWifi, |
513 shill::kTypeCellular, | 503 shill::kTypeCellular, |
514 shill::kTypeWimax, | 504 shill::kTypeWimax, |
515 shill::kTypeVPN}; | 505 shill::kTypeVPN}; |
516 | 506 |
517 base::ListValue* service_list = GetListProperty(shill::kServicesProperty); | |
518 scoped_ptr<base::ListValue> prev_service_list(service_list->DeepCopy()); | |
519 base::ListValue* complete_list = | 507 base::ListValue* complete_list = |
520 GetListProperty(shill::kServiceCompleteListProperty); | 508 GetListProperty(shill::kServiceCompleteListProperty); |
521 if (complete_list->empty()) | 509 if (complete_list->empty()) |
522 return; | 510 return; |
523 scoped_ptr<base::ListValue> prev_complete_list(complete_list->DeepCopy()); | 511 scoped_ptr<base::ListValue> prev_complete_list(complete_list->DeepCopy()); |
524 | 512 |
525 std::vector<std::string> active_services; | 513 std::vector<std::string> active_services; |
526 std::vector<std::string> inactive_services; | 514 std::vector<std::string> inactive_services; |
527 std::vector<std::string> disabled_services; | 515 std::vector<std::string> disabled_services; |
528 for (size_t i = 0; i < arraysize(ordered_types); ++i) { | 516 for (size_t i = 0; i < arraysize(ordered_types); ++i) { |
529 AppendServicesForType(complete_list, | 517 AppendServicesForType(complete_list, |
530 ordered_types[i], | 518 ordered_types[i], |
531 TechnologyEnabled(ordered_types[i]), | 519 TechnologyEnabled(ordered_types[i]), |
532 &active_services, | 520 &active_services, |
533 &inactive_services, | 521 &inactive_services, |
534 &disabled_services); | 522 &disabled_services); |
535 } | 523 } |
536 service_list->Clear(); | |
537 complete_list->Clear(); | 524 complete_list->Clear(); |
538 for (size_t i = 0; i < active_services.size(); ++i) { | 525 for (size_t i = 0; i < active_services.size(); ++i) |
539 complete_list->AppendString(active_services[i]); | 526 complete_list->AppendString(active_services[i]); |
540 service_list->AppendString(active_services[i]); | 527 for (size_t i = 0; i < inactive_services.size(); ++i) |
541 } | |
542 for (size_t i = 0; i < inactive_services.size(); ++i) { | |
543 complete_list->AppendString(inactive_services[i]); | 528 complete_list->AppendString(inactive_services[i]); |
544 service_list->AppendString(inactive_services[i]); | 529 for (size_t i = 0; i < disabled_services.size(); ++i) |
545 } | |
546 for (size_t i = 0; i < disabled_services.size(); ++i) { | |
547 complete_list->AppendString(disabled_services[i]); | 530 complete_list->AppendString(disabled_services[i]); |
548 } | |
549 | 531 |
550 if (notify) { | 532 if (notify && !complete_list->Equals(prev_complete_list.get())) |
551 if (!service_list->Equals(prev_service_list.get())) | 533 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); |
552 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | |
553 if (!complete_list->Equals(prev_complete_list.get())) | |
554 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); | |
555 } | |
556 | 534 |
557 // Set the first active service as the Default service. | 535 // Set the first active service as the Default service. |
558 std::string new_default_service; | 536 std::string new_default_service; |
559 if (!active_services.empty()) { | 537 if (!active_services.empty()) { |
560 ShillServiceClient::TestInterface* service_client = | 538 ShillServiceClient::TestInterface* service_client = |
561 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); | 539 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
562 std::string service_path = active_services[0]; | 540 std::string service_path = active_services[0]; |
563 const base::DictionaryValue* properties = | 541 const base::DictionaryValue* properties = |
564 service_client->GetServiceProperties(service_path); | 542 service_client->GetServiceProperties(service_path); |
565 if (!properties) { | 543 if (!properties) { |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
894 void FakeShillManagerClient::ScanCompleted(const std::string& device_path, | 872 void FakeShillManagerClient::ScanCompleted(const std::string& device_path, |
895 const base::Closure& callback) { | 873 const base::Closure& callback) { |
896 if (!device_path.empty()) { | 874 if (!device_path.empty()) { |
897 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> | 875 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> |
898 SetDeviceProperty(device_path, | 876 SetDeviceProperty(device_path, |
899 shill::kScanningProperty, | 877 shill::kScanningProperty, |
900 base::FundamentalValue(false)); | 878 base::FundamentalValue(false)); |
901 } | 879 } |
902 DVLOG(2) << "ScanCompleted"; | 880 DVLOG(2) << "ScanCompleted"; |
903 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); | 881 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); |
904 CallNotifyObserversPropertyChanged(shill::kServicesProperty); | |
905 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 882 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
906 } | 883 } |
907 | 884 |
908 void FakeShillManagerClient::ParseCommandLineSwitch() { | 885 void FakeShillManagerClient::ParseCommandLineSwitch() { |
909 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 886 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
910 if (command_line->HasSwitch(switches::kShillStub)) { | 887 if (command_line->HasSwitch(switches::kShillStub)) { |
911 std::string option_str = | 888 std::string option_str = |
912 command_line->GetSwitchValueASCII(switches::kShillStub); | 889 command_line->GetSwitchValueASCII(switches::kShillStub); |
913 base::StringPairs string_pairs; | 890 base::StringPairs string_pairs; |
914 base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs); | 891 base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 *enabled = true; | 991 *enabled = true; |
1015 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || | 992 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || |
1016 (state == kNetworkActivated && type != shill::kTypeCellular)) { | 993 (state == kNetworkActivated && type != shill::kTypeCellular)) { |
1017 LOG(WARNING) << "Invalid state: " << state << " for " << type; | 994 LOG(WARNING) << "Invalid state: " << state << " for " << type; |
1018 return shill::kStateIdle; | 995 return shill::kStateIdle; |
1019 } | 996 } |
1020 return state; | 997 return state; |
1021 } | 998 } |
1022 | 999 |
1023 } // namespace chromeos | 1000 } // namespace chromeos |
OLD | NEW |