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

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

Issue 280023003: Implement networkingPrivate.getNetworks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix tests (sort ServiceCompleteList) Created 6 years, 7 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 const std::string& state) { 481 const std::string& state) {
482 if (service_path == default_service_ && !IsConnectedState(state)) { 482 if (service_path == default_service_ && !IsConnectedState(state)) {
483 // Default service is no longer connected; clear. 483 // Default service is no longer connected; clear.
484 default_service_.clear(); 484 default_service_.clear();
485 base::StringValue default_service_value(default_service_); 485 base::StringValue default_service_value(default_service_);
486 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); 486 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value);
487 } 487 }
488 } 488 }
489 489
490 void FakeShillManagerClient::SortManagerServices() { 490 void FakeShillManagerClient::SortManagerServices() {
491 SortServiceList(shill::kServicesProperty);
492 SortServiceList(shill::kServiceCompleteListProperty);
493 }
494
495 void FakeShillManagerClient::SortServiceList(const std::string& property) {
491 static const char* ordered_types[] = { 496 static const char* ordered_types[] = {
492 shill::kTypeEthernet, 497 shill::kTypeEthernet,
493 shill::kTypeWifi, 498 shill::kTypeWifi,
494 shill::kTypeCellular, 499 shill::kTypeCellular,
495 shill::kTypeWimax, 500 shill::kTypeWimax,
496 shill::kTypeVPN 501 shill::kTypeVPN
497 }; 502 };
498 base::ListValue* service_list = GetListProperty(shill::kServicesProperty); 503
499 if (!service_list || service_list->empty()) { 504 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; 505 std::vector<std::string> active_services;
508 std::vector<std::string> inactive_services; 506 std::vector<std::string> inactive_services;
509 for (size_t i = 0; i < arraysize(ordered_types); ++i) { 507 if (service_list && !service_list->empty()) {
510 AppendServicesForType(service_list, ordered_types[i], 508 for (size_t i = 0; i < arraysize(ordered_types); ++i) {
509 AppendServicesForType(service_list, ordered_types[i],
511 &active_services, &inactive_services); 510 &active_services, &inactive_services);
pneubeck (no reviews) 2014/05/15 18:28:37 nit: format
stevenjb 2014/05/15 20:12:41 Done.
pneubeck (no reviews) 2014/05/16 13:18:55 not done? (I meant the indentation of the second a
511 }
512 service_list->Clear();
513 for (size_t i = 0; i < active_services.size(); ++i)
514 service_list->AppendString(active_services[i]);
515 for (size_t i = 0; i < inactive_services.size(); ++i)
516 service_list->AppendString(inactive_services[i]);
517
518 CallNotifyObserversPropertyChanged(property);
512 } 519 }
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 520
519 CallNotifyObserversPropertyChanged(shill::kServicesProperty); 521 if (property != shill::kServicesProperty)
522 return;
520 523
521 // Set the first active service as the Default service. 524 // Set the first active service as the Default service.
522 std::string new_default_service; 525 std::string new_default_service;
523 if (!active_services.empty()) { 526 if (!active_services.empty()) {
524 ShillServiceClient::TestInterface* service_client = 527 ShillServiceClient::TestInterface* service_client =
525 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); 528 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
526 std::string service_path = active_services[0]; 529 std::string service_path = active_services[0];
527 const base::DictionaryValue* properties = 530 const base::DictionaryValue* properties =
528 service_client->GetServiceProperties(service_path); 531 service_client->GetServiceProperties(service_path);
529 if (!properties) { 532 if (!properties) {
530 LOG(ERROR) << "Properties not found for service: " << service_path; 533 LOG(ERROR) << "Properties not found for service: " << service_path;
531 } else { 534 } else {
532 std::string state; 535 std::string state;
533 properties->GetString(shill::kStateProperty, &state); 536 properties->GetString(shill::kStateProperty, &state);
534 if (IsConnectedState(state)) 537 if (IsConnectedState(state))
535 new_default_service = service_path; 538 new_default_service = service_path;
536 } 539 }
537 } 540 }
538 if (default_service_ != new_default_service) { 541 if (default_service_ != new_default_service) {
539 default_service_ = new_default_service; 542 default_service_ = new_default_service;
540 base::StringValue default_service_value(default_service_); 543 base::StringValue default_service_value(default_service_);
541 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); 544 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value);
542 } 545 }
546
547 return;
pneubeck (no reviews) 2014/05/15 18:28:37 nit: remove
stevenjb 2014/05/15 20:12:41 Done.
pneubeck (no reviews) 2014/05/16 13:18:55 Not done?
543 } 548 }
544 549
545 550
546 int FakeShillManagerClient::GetInteractiveDelay() const { 551 int FakeShillManagerClient::GetInteractiveDelay() const {
547 return interactive_delay_; 552 return interactive_delay_;
548 } 553 }
549 554
550 void FakeShillManagerClient::SetupDefaultEnvironment() { 555 void FakeShillManagerClient::SetupDefaultEnvironment() {
551 DBusThreadManager* dbus_manager = DBusThreadManager::Get(); 556 DBusThreadManager* dbus_manager = DBusThreadManager::Get();
552 ShillServiceClient::TestInterface* services = 557 ShillServiceClient::TestInterface* services =
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 *enabled = true; 1036 *enabled = true;
1032 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || 1037 if ((state == shill::kStatePortal && type != shill::kTypeWifi) ||
1033 (state == kNetworkActivated && type != shill::kTypeCellular)) { 1038 (state == kNetworkActivated && type != shill::kTypeCellular)) {
1034 LOG(WARNING) << "Invalid state: " << state << " for " << type; 1039 LOG(WARNING) << "Invalid state: " << state << " for " << type;
1035 return shill::kStateIdle; 1040 return shill::kStateIdle;
1036 } 1041 }
1037 return state; 1042 return state;
1038 } 1043 }
1039 1044
1040 } // namespace chromeos 1045 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698