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/values.h" | 10 #include "base/values.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 state == shill::kStateConfiguration || | 66 state == shill::kStateConfiguration || |
67 state == shill::kStatePortal || | 67 state == shill::kStatePortal || |
68 state == shill::kStateReady) { | 68 state == shill::kStateReady) { |
69 active_service_list_out->push_back(service_path); | 69 active_service_list_out->push_back(service_path); |
70 } else { | 70 } else { |
71 inactive_service_list_out->push_back(service_path); | 71 inactive_service_list_out->push_back(service_path); |
72 } | 72 } |
73 } | 73 } |
74 } | 74 } |
75 | 75 |
| 76 void LogErrorCallback(const std::string& error_name, |
| 77 const std::string& error_message) { |
| 78 LOG(ERROR) << error_name << ": " << error_message; |
| 79 } |
| 80 |
76 } // namespace | 81 } // namespace |
77 | 82 |
78 FakeShillManagerClient::FakeShillManagerClient() | 83 FakeShillManagerClient::FakeShillManagerClient() |
79 : weak_ptr_factory_(this) { | 84 : weak_ptr_factory_(this) { |
80 } | 85 } |
81 | 86 |
82 FakeShillManagerClient::~FakeShillManagerClient() {} | 87 FakeShillManagerClient::~FakeShillManagerClient() {} |
83 | 88 |
84 // ShillManagerClient overrides. | 89 // ShillManagerClient overrides. |
85 | 90 |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 CallNotifyObserversPropertyChanged( | 389 CallNotifyObserversPropertyChanged( |
385 shill::kUninitializedTechnologiesProperty, 0); | 390 shill::kUninitializedTechnologiesProperty, 0); |
386 } | 391 } |
387 } | 392 } |
388 } | 393 } |
389 | 394 |
390 void FakeShillManagerClient::ClearProperties() { | 395 void FakeShillManagerClient::ClearProperties() { |
391 stub_properties_.Clear(); | 396 stub_properties_.Clear(); |
392 } | 397 } |
393 | 398 |
| 399 void FakeShillManagerClient::SetManagerProperty(const std::string& key, |
| 400 const base::Value& value) { |
| 401 SetProperty(key, value, |
| 402 base::Bind(&base::DoNothing), base::Bind(&LogErrorCallback)); |
| 403 } |
| 404 |
394 void FakeShillManagerClient::AddManagerService(const std::string& service_path, | 405 void FakeShillManagerClient::AddManagerService(const std::string& service_path, |
395 bool add_to_visible_list, | 406 bool add_to_visible_list, |
396 bool add_to_watch_list) { | 407 bool add_to_watch_list) { |
397 // Always add to ServiceCompleteListProperty. | 408 // Always add to ServiceCompleteListProperty. |
398 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent( | 409 GetListProperty(shill::kServiceCompleteListProperty)->AppendIfNotPresent( |
399 base::Value::CreateStringValue(service_path)); | 410 base::Value::CreateStringValue(service_path)); |
400 // If visible, add to Services and notify if new. | 411 // If visible, add to Services and notify if new. |
401 if (add_to_visible_list && | 412 if (add_to_visible_list && |
402 GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( | 413 GetListProperty(shill::kServicesProperty)->AppendIfNotPresent( |
403 base::Value::CreateStringValue(service_path))) { | 414 base::Value::CreateStringValue(service_path))) { |
(...skipping 29 matching lines...) Expand all Loading... |
433 | 444 |
434 void FakeShillManagerClient::SortManagerServices() { | 445 void FakeShillManagerClient::SortManagerServices() { |
435 static const char* ordered_types[] = { | 446 static const char* ordered_types[] = { |
436 shill::kTypeEthernet, | 447 shill::kTypeEthernet, |
437 shill::kTypeWifi, | 448 shill::kTypeWifi, |
438 shill::kTypeCellular, | 449 shill::kTypeCellular, |
439 shill::kTypeWimax, | 450 shill::kTypeWimax, |
440 shill::kTypeVPN | 451 shill::kTypeVPN |
441 }; | 452 }; |
442 base::ListValue* service_list = GetListProperty(shill::kServicesProperty); | 453 base::ListValue* service_list = GetListProperty(shill::kServicesProperty); |
443 if (!service_list || service_list->empty()) | 454 if (!service_list || service_list->empty()) { |
| 455 if (!default_service_.empty()) { |
| 456 default_service_.clear(); |
| 457 base::StringValue empty_value(""); |
| 458 SetManagerProperty(shill::kDefaultServiceProperty, empty_value); |
| 459 } |
444 return; | 460 return; |
| 461 } |
445 std::vector<std::string> active_services; | 462 std::vector<std::string> active_services; |
446 std::vector<std::string> inactive_services; | 463 std::vector<std::string> inactive_services; |
447 for (size_t i = 0; i < arraysize(ordered_types); ++i) { | 464 for (size_t i = 0; i < arraysize(ordered_types); ++i) { |
448 AppendServicesForType(service_list, ordered_types[i], | 465 AppendServicesForType(service_list, ordered_types[i], |
449 &active_services, &inactive_services); | 466 &active_services, &inactive_services); |
450 } | 467 } |
451 service_list->Clear(); | 468 service_list->Clear(); |
452 for (size_t i = 0; i < active_services.size(); ++i) | 469 for (size_t i = 0; i < active_services.size(); ++i) |
453 service_list->AppendString(active_services[i]); | 470 service_list->AppendString(active_services[i]); |
454 for (size_t i = 0; i < inactive_services.size(); ++i) | 471 for (size_t i = 0; i < inactive_services.size(); ++i) |
455 service_list->AppendString(inactive_services[i]); | 472 service_list->AppendString(inactive_services[i]); |
456 | 473 |
457 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 474 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
| 475 |
| 476 // Set the first active service as the Default service. |
| 477 std::string new_default_service; |
| 478 if (!active_services.empty()) { |
| 479 ShillServiceClient::TestInterface* service_client = |
| 480 DBusThreadManager::Get()->GetShillServiceClient()->GetTestInterface(); |
| 481 std::string service_path = active_services[0]; |
| 482 const base::DictionaryValue* properties = |
| 483 service_client->GetServiceProperties(service_path); |
| 484 if (!properties) { |
| 485 LOG(ERROR) << "Properties not found for service: " << service_path; |
| 486 } else { |
| 487 std::string state; |
| 488 properties->GetString(shill::kStateProperty, &state); |
| 489 if (state == shill::kStateOnline || |
| 490 state == shill::kStatePortal || |
| 491 state == shill::kStateReady) { |
| 492 new_default_service = service_path; |
| 493 } |
| 494 } |
| 495 } |
| 496 if (default_service_ != new_default_service) { |
| 497 default_service_ = new_default_service; |
| 498 base::StringValue default_service_value(default_service_); |
| 499 SetManagerProperty(shill::kDefaultServiceProperty, default_service_value); |
| 500 } |
458 } | 501 } |
459 | 502 |
460 void FakeShillManagerClient::AddGeoNetwork( | 503 void FakeShillManagerClient::AddGeoNetwork( |
461 const std::string& technology, | 504 const std::string& technology, |
462 const base::DictionaryValue& network) { | 505 const base::DictionaryValue& network) { |
463 base::ListValue* list_value = NULL; | 506 base::ListValue* list_value = NULL; |
464 if (!stub_geo_networks_.GetListWithoutPathExpansion( | 507 if (!stub_geo_networks_.GetListWithoutPathExpansion( |
465 technology, &list_value)) { | 508 technology, &list_value)) { |
466 list_value = new base::ListValue; | 509 list_value = new base::ListValue; |
467 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); | 510 stub_geo_networks_.SetWithoutPathExpansion(technology, list_value); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
637 SetDeviceProperty(device_path, | 680 SetDeviceProperty(device_path, |
638 shill::kScanningProperty, | 681 shill::kScanningProperty, |
639 base::FundamentalValue(false)); | 682 base::FundamentalValue(false)); |
640 } | 683 } |
641 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); | 684 CallNotifyObserversPropertyChanged(shill::kServicesProperty, 0); |
642 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); | 685 CallNotifyObserversPropertyChanged(shill::kServiceWatchListProperty, 0); |
643 base::MessageLoop::current()->PostTask(FROM_HERE, callback); | 686 base::MessageLoop::current()->PostTask(FROM_HERE, callback); |
644 } | 687 } |
645 | 688 |
646 } // namespace chromeos | 689 } // namespace chromeos |
OLD | NEW |