Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: chromeos/dbus/fake_shill_manager_client.cc

Issue 330833003: Rely on Service.Visible instead of Manager.Services (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sort services when updated, add test Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 stub_properties_.Clear(); 455 stub_properties_.Clear();
456 } 456 }
457 457
458 void FakeShillManagerClient::SetManagerProperty(const std::string& key, 458 void FakeShillManagerClient::SetManagerProperty(const std::string& key,
459 const base::Value& value) { 459 const base::Value& value) {
460 SetProperty(key, value, 460 SetProperty(key, value,
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 bool notify_observers) {
466 DVLOG(2) << "AddManagerService: " << service_path; 467 DVLOG(2) << "AddManagerService: " << service_path;
467 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent( 468 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent(
468 base::Value::CreateStringValue(service_path)); 469 base::Value::CreateStringValue(service_path));
469 SortManagerServices(false); 470 SortManagerServices(false);
470 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); 471 if (notify_observers)
471 // SortManagerServices will add the service to Services if it is visible. 472 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
472 const base::ListValue* services = GetListProperty(shill::kServicesProperty);
473 if (services->Find(base::StringValue(service_path)) != services->end())
474 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
475 } 473 }
476 474
477 void FakeShillManagerClient::RemoveManagerService( 475 void FakeShillManagerClient::RemoveManagerService(
478 const std::string& service_path) { 476 const std::string& service_path) {
479 DVLOG(2) << "RemoveManagerService: " << service_path; 477 DVLOG(2) << "RemoveManagerService: " << service_path;
480 base::StringValue service_path_value(service_path); 478 base::StringValue service_path_value(service_path);
481 GetListProperty(shill::kServiceCompleteListProperty)->Remove( 479 GetListProperty(shill::kServiceCompleteListProperty)->Remove(
482 service_path_value, NULL); 480 service_path_value, NULL);
483 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); 481 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
484 if (GetListProperty(shill::kServicesProperty)->Remove(
485 service_path_value, NULL)) {
486 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
487 }
488 } 482 }
489 483
490 void FakeShillManagerClient::ClearManagerServices() { 484 void FakeShillManagerClient::ClearManagerServices() {
491 DVLOG(1) << "ClearManagerServices"; 485 DVLOG(1) << "ClearManagerServices";
492 GetListProperty(shill::kServiceCompleteListProperty)->Clear(); 486 GetListProperty(shill::kServiceCompleteListProperty)->Clear();
493 GetListProperty(shill::kServicesProperty)->Clear();
494 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); 487 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
495 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
496 } 488 }
497 489
498 void FakeShillManagerClient::ServiceStateChanged( 490 void FakeShillManagerClient::ServiceStateChanged(
499 const std::string& service_path, 491 const std::string& service_path,
500 const std::string& state) { 492 const std::string& state) {
501 if (service_path == default_service_ && !IsConnectedState(state)) { 493 if (service_path == default_service_ && !IsConnectedState(state)) {
502 // Default service is no longer connected; clear. 494 // Default service is no longer connected; clear.
503 default_service_.clear(); 495 default_service_.clear();
504 base::StringValue default_service_value(default_service_); 496 base::StringValue default_service_value(default_service_);
505 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); 497 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value);
506 } 498 }
507 } 499 }
508 500
509 void FakeShillManagerClient::SortManagerServices(bool notify) { 501 void FakeShillManagerClient::SortManagerServices(bool notify) {
510 DVLOG(1) << "SortManagerServices"; 502 DVLOG(1) << "SortManagerServices";
511 static const char* ordered_types[] = {shill::kTypeEthernet, 503 static const char* ordered_types[] = {shill::kTypeEthernet,
512 shill::kTypeWifi, 504 shill::kTypeWifi,
513 shill::kTypeCellular, 505 shill::kTypeCellular,
514 shill::kTypeWimax, 506 shill::kTypeWimax,
515 shill::kTypeVPN}; 507 shill::kTypeVPN};
516 508
517 base::ListValue* service_list = GetListProperty(shill::kServicesProperty);
518 scoped_ptr<base::ListValue> prev_service_list(service_list->DeepCopy());
519 base::ListValue* complete_list = 509 base::ListValue* complete_list =
520 GetListProperty(shill::kServiceCompleteListProperty); 510 GetListProperty(shill::kServiceCompleteListProperty);
521 if (complete_list->empty()) 511 if (complete_list->empty())
522 return; 512 return;
523 scoped_ptr<base::ListValue> prev_complete_list(complete_list->DeepCopy()); 513 scoped_ptr<base::ListValue> prev_complete_list(complete_list->DeepCopy());
524 514
525 std::vector<std::string> active_services; 515 std::vector<std::string> active_services;
526 std::vector<std::string> inactive_services; 516 std::vector<std::string> inactive_services;
527 std::vector<std::string> disabled_services; 517 std::vector<std::string> disabled_services;
528 for (size_t i = 0; i < arraysize(ordered_types); ++i) { 518 for (size_t i = 0; i < arraysize(ordered_types); ++i) {
529 AppendServicesForType(complete_list, 519 AppendServicesForType(complete_list,
530 ordered_types[i], 520 ordered_types[i],
531 TechnologyEnabled(ordered_types[i]), 521 TechnologyEnabled(ordered_types[i]),
532 &active_services, 522 &active_services,
533 &inactive_services, 523 &inactive_services,
534 &disabled_services); 524 &disabled_services);
535 } 525 }
536 service_list->Clear();
537 complete_list->Clear(); 526 complete_list->Clear();
538 for (size_t i = 0; i < active_services.size(); ++i) { 527 for (size_t i = 0; i < active_services.size(); ++i)
539 complete_list->AppendString(active_services[i]); 528 complete_list->AppendString(active_services[i]);
540 service_list->AppendString(active_services[i]); 529 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]); 530 complete_list->AppendString(inactive_services[i]);
544 service_list->AppendString(inactive_services[i]); 531 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]); 532 complete_list->AppendString(disabled_services[i]);
548 }
549 533
550 if (notify) { 534 if (notify && !complete_list->Equals(prev_complete_list.get()))
551 if (!service_list->Equals(prev_service_list.get())) 535 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
552 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
553 if (!complete_list->Equals(prev_complete_list.get()))
554 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
555 }
556 536
557 // Set the first active service as the Default service. 537 // Set the first active service as the Default service.
558 std::string new_default_service; 538 std::string new_default_service;
559 if (!active_services.empty()) { 539 if (!active_services.empty()) {
560 ShillServiceClient::TestInterface* service_client = 540 ShillServiceClient::TestInterface* service_client =
561 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); 541 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
562 std::string service_path = active_services[0]; 542 std::string service_path = active_services[0];
563 const base::DictionaryValue* properties = 543 const base::DictionaryValue* properties =
564 service_client->GetServiceProperties(service_path); 544 service_client->GetServiceProperties(service_path);
565 if (!properties) { 545 if (!properties) {
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
894 void FakeShillManagerClient::ScanCompleted(const std::string& device_path, 874 void FakeShillManagerClient::ScanCompleted(const std::string& device_path,
895 const base::Closure& callback) { 875 const base::Closure& callback) {
896 if (!device_path.empty()) { 876 if (!device_path.empty()) {
897 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()-> 877 DBusThreadManager::Get()->GetShillDeviceClient()->GetTestInterface()->
898 SetDeviceProperty(device_path, 878 SetDeviceProperty(device_path,
899 shill::kScanningProperty, 879 shill::kScanningProperty,
900 base::FundamentalValue(false)); 880 base::FundamentalValue(false));
901 } 881 }
902 DVLOG(2) << "ScanCompleted"; 882 DVLOG(2) << "ScanCompleted";
903 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty); 883 CallNotifyObserversPropertyChanged(shill::kServiceCompleteListProperty);
904 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
905 base::MessageLoop::current()->PostTask(FROM_HERE, callback); 884 base::MessageLoop::current()->PostTask(FROM_HERE, callback);
906 } 885 }
907 886
908 void FakeShillManagerClient::ParseCommandLineSwitch() { 887 void FakeShillManagerClient::ParseCommandLineSwitch() {
909 CommandLine* command_line = CommandLine::ForCurrentProcess(); 888 CommandLine* command_line = CommandLine::ForCurrentProcess();
910 if (command_line->HasSwitch(switches::kShillStub)) { 889 if (command_line->HasSwitch(switches::kShillStub)) {
911 std::string option_str = 890 std::string option_str =
912 command_line->GetSwitchValueASCII(switches::kShillStub); 891 command_line->GetSwitchValueASCII(switches::kShillStub);
913 base::StringPairs string_pairs; 892 base::StringPairs string_pairs;
914 base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs); 893 base::SplitStringIntoKeyValuePairs(option_str, '=', ',', &string_pairs);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 *enabled = true; 993 *enabled = true;
1015 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || 994 if ((state == shill::kStatePortal && type != shill::kTypeWifi) ||
1016 (state == kNetworkActivated && type != shill::kTypeCellular)) { 995 (state == kNetworkActivated && type != shill::kTypeCellular)) {
1017 LOG(WARNING) << "Invalid state: " << state << " for " << type; 996 LOG(WARNING) << "Invalid state: " << state << " for " << type;
1018 return shill::kStateIdle; 997 return shill::kStateIdle;
1019 } 998 }
1020 return state; 999 return state;
1021 } 1000 }
1022 1001
1023 } // namespace chromeos 1002 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698