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

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 nonchromeos 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
« no previous file with comments | « chromeos/dbus/fake_shill_manager_client.h ('k') | chromeos/dbus/fake_shill_service_client.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 if (add_to_visible_list && 453 if (add_to_visible_list &&
454 GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( 454 GetListProperty(shill::kServicesProperty)->AppendIfNotPresent(
455 base::Value::CreateStringValue(service_path))) { 455 base::Value::CreateStringValue(service_path))) {
456 CallNotifyObserversPropertyChanged(shill::kServicesProperty); 456 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
457 } 457 }
458 if (add_to_watch_list) 458 if (add_to_watch_list)
459 AddServiceToWatchList(service_path); 459 AddServiceToWatchList(service_path);
460 } 460 }
461 461
462 void FakeShillManagerClient::RemoveManagerService( 462 void FakeShillManagerClient::RemoveManagerService(
463 const std::string& service_path) { 463 const std::string& service_path,
464 bool remove_from_complete_list) {
464 base::StringValue service_path_value(service_path); 465 base::StringValue service_path_value(service_path);
466 if (remove_from_complete_list) {
467 GetListProperty(shill::kServiceCompleteListProperty)->Remove(
468 service_path_value, NULL);
469 }
465 if (GetListProperty(shill::kServicesProperty)->Remove( 470 if (GetListProperty(shill::kServicesProperty)->Remove(
466 service_path_value, NULL)) { 471 service_path_value, NULL)) {
467 CallNotifyObserversPropertyChanged(shill::kServicesProperty); 472 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
468 } 473 }
469 GetListProperty(shill::kServiceCompleteListProperty)->Remove(
470 service_path_value, NULL);
471 if (GetListProperty(shill::kServiceWatchListProperty)->Remove( 474 if (GetListProperty(shill::kServiceWatchListProperty)->Remove(
472 service_path_value, NULL)) { 475 service_path_value, NULL)) {
473 CallNotifyObserversPropertyChanged( 476 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty);
474 shill::kServiceWatchListProperty);
475 } 477 }
476 } 478 }
477 479
478 void FakeShillManagerClient::ClearManagerServices() { 480 void FakeShillManagerClient::ClearManagerServices() {
481 GetListProperty(shill::kServiceCompleteListProperty)->Clear();
479 GetListProperty(shill::kServicesProperty)->Clear(); 482 GetListProperty(shill::kServicesProperty)->Clear();
480 GetListProperty(shill::kServiceCompleteListProperty)->Clear();
481 GetListProperty(shill::kServiceWatchListProperty)->Clear(); 483 GetListProperty(shill::kServiceWatchListProperty)->Clear();
482 CallNotifyObserversPropertyChanged(shill::kServicesProperty); 484 CallNotifyObserversPropertyChanged(shill::kServicesProperty);
483 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty); 485 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty);
484 } 486 }
485 487
486 void FakeShillManagerClient::ServiceStateChanged( 488 void FakeShillManagerClient::ServiceStateChanged(
487 const std::string& service_path, 489 const std::string& service_path,
488 const std::string& state) { 490 const std::string& state) {
489 if (service_path == default_service_ && !IsConnectedState(state)) { 491 if (service_path == default_service_ && !IsConnectedState(state)) {
490 // Default service is no longer connected; clear. 492 // Default service is no longer connected; clear.
491 default_service_.clear(); 493 default_service_.clear();
492 base::StringValue default_service_value(default_service_); 494 base::StringValue default_service_value(default_service_);
493 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); 495 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value);
494 } 496 }
495 } 497 }
496 498
497 void FakeShillManagerClient::SortManagerServices() { 499 void FakeShillManagerClient::SortManagerServices() {
500 SortServiceList(shill::kServicesProperty);
501 SortServiceList(shill::kServiceCompleteListProperty);
502 }
503
504 void FakeShillManagerClient::SortServiceList(const std::string& property) {
498 static const char* ordered_types[] = { 505 static const char* ordered_types[] = {
499 shill::kTypeEthernet, 506 shill::kTypeEthernet,
500 shill::kTypeWifi, 507 shill::kTypeWifi,
501 shill::kTypeCellular, 508 shill::kTypeCellular,
502 shill::kTypeWimax, 509 shill::kTypeWimax,
503 shill::kTypeVPN 510 shill::kTypeVPN
504 }; 511 };
505 base::ListValue* service_list = GetListProperty(shill::kServicesProperty); 512
506 if (!service_list || service_list->empty()) { 513 base::ListValue* service_list = GetListProperty(property);
507 if (!default_service_.empty()) {
508 default_service_.clear();
509 base::StringValue empty_value("");
510 SetManagerProperty(shill::kDefaultServiceProperty, empty_value);
511 }
512 return;
513 }
514 std::vector<std::string> active_services; 514 std::vector<std::string> active_services;
515 std::vector<std::string> inactive_services; 515 std::vector<std::string> inactive_services;
516 for (size_t i = 0; i < arraysize(ordered_types); ++i) { 516 if (service_list && !service_list->empty()) {
517 AppendServicesForType(service_list, ordered_types[i], 517 for (size_t i = 0; i < arraysize(ordered_types); ++i) {
518 &active_services, &inactive_services); 518 AppendServicesForType(service_list, ordered_types[i],
519 &active_services, &inactive_services);
520 }
521 service_list->Clear();
522 for (size_t i = 0; i < active_services.size(); ++i)
523 service_list->AppendString(active_services[i]);
524 for (size_t i = 0; i < inactive_services.size(); ++i)
525 service_list->AppendString(inactive_services[i]);
519 } 526 }
520 service_list->Clear();
521 for (size_t i = 0; i < active_services.size(); ++i)
522 service_list->AppendString(active_services[i]);
523 for (size_t i = 0; i < inactive_services.size(); ++i)
524 service_list->AppendString(inactive_services[i]);
525 527
526 CallNotifyObserversPropertyChanged(shill::kServicesProperty); 528 if (property != shill::kServicesProperty)
529 return;
530
531 CallNotifyObserversPropertyChanged(property);
527 532
528 // Set the first active service as the Default service. 533 // Set the first active service as the Default service.
529 std::string new_default_service; 534 std::string new_default_service;
530 if (!active_services.empty()) { 535 if (!active_services.empty()) {
531 ShillServiceClient::TestInterface* service_client = 536 ShillServiceClient::TestInterface* service_client =
532 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); 537 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface();
533 std::string service_path = active_services[0]; 538 std::string service_path = active_services[0];
534 const base::DictionaryValue* properties = 539 const base::DictionaryValue* properties =
535 service_client->GetServiceProperties(service_path); 540 service_client->GetServiceProperties(service_path);
536 if (!properties) { 541 if (!properties) {
537 LOG(ERROR) << "Properties not found for service: " << service_path; 542 LOG(ERROR) << "Properties not found for service: " << service_path;
538 } else { 543 } else {
539 std::string state; 544 std::string state;
540 properties->GetString(shill::kStateProperty, &state); 545 properties->GetString(shill::kStateProperty, &state);
541 if (IsConnectedState(state)) 546 if (IsConnectedState(state))
542 new_default_service = service_path; 547 new_default_service = service_path;
543 } 548 }
544 } 549 }
545 if (default_service_ != new_default_service) { 550 if (default_service_ != new_default_service) {
546 default_service_ = new_default_service; 551 default_service_ = new_default_service;
547 base::StringValue default_service_value(default_service_); 552 base::StringValue default_service_value(default_service_);
548 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); 553 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value);
549 } 554 }
550 } 555 }
551 556
552
553 int FakeShillManagerClient::GetInteractiveDelay() const { 557 int FakeShillManagerClient::GetInteractiveDelay() const {
554 return interactive_delay_; 558 return interactive_delay_;
555 } 559 }
556 560
557 void FakeShillManagerClient::SetBestServiceToConnect( 561 void FakeShillManagerClient::SetBestServiceToConnect(
558 const std::string& service_path) { 562 const std::string& service_path) {
559 best_service_ = service_path; 563 best_service_ = service_path;
560 } 564 }
561 565
562 void FakeShillManagerClient::SetupDefaultEnvironment() { 566 void FakeShillManagerClient::SetupDefaultEnvironment() {
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
1041 *enabled = true; 1045 *enabled = true;
1042 if ((state == shill::kStatePortal && type != shill::kTypeWifi) || 1046 if ((state == shill::kStatePortal && type != shill::kTypeWifi) ||
1043 (state == kNetworkActivated && type != shill::kTypeCellular)) { 1047 (state == kNetworkActivated && type != shill::kTypeCellular)) {
1044 LOG(WARNING) << "Invalid state: " << state << " for " << type; 1048 LOG(WARNING) << "Invalid state: " << state << " for " << type;
1045 return shill::kStateIdle; 1049 return shill::kStateIdle;
1046 } 1050 }
1047 return state; 1051 return state;
1048 } 1052 }
1049 1053
1050 } // namespace chromeos 1054 } // namespace chromeos
OLDNEW
« no previous file with comments | « chromeos/dbus/fake_shill_manager_client.h ('k') | chromeos/dbus/fake_shill_service_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698