Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/network/network_state_handler.h" | 5 #include "chromeos/network/network_state_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 if (!tether_network_state) { | 554 if (!tether_network_state) { |
| 555 NET_LOG(ERROR) << "UpdateTetherNetworkProperties(): No NetworkState for " | 555 NET_LOG(ERROR) << "UpdateTetherNetworkProperties(): No NetworkState for " |
| 556 << "Tether network with GUID \"" << guid << "\"."; | 556 << "Tether network with GUID \"" << guid << "\"."; |
| 557 return false; | 557 return false; |
| 558 } | 558 } |
| 559 | 559 |
| 560 tether_network_state->set_carrier(carrier); | 560 tether_network_state->set_carrier(carrier); |
| 561 tether_network_state->set_battery_percentage(battery_percentage); | 561 tether_network_state->set_battery_percentage(battery_percentage); |
| 562 tether_network_state->set_signal_strength(signal_strength); | 562 tether_network_state->set_signal_strength(signal_strength); |
| 563 | 563 |
| 564 NotifyNetworkListChanged(); | 564 NotifyNetworkPropertiesUpdated(tether_network_state); |
| 565 return true; | 565 return true; |
| 566 } | 566 } |
| 567 | 567 |
| 568 bool NetworkStateHandler::SetTetherNetworkHasConnectedToHost( | 568 bool NetworkStateHandler::SetTetherNetworkHasConnectedToHost( |
| 569 const std::string& guid) { | 569 const std::string& guid) { |
| 570 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid); | 570 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid); |
| 571 if (!tether_network_state) { | 571 if (!tether_network_state) { |
| 572 NET_LOG(ERROR) << "SetTetherNetworkHasConnectedToHost(): No NetworkState " | 572 NET_LOG(ERROR) << "SetTetherNetworkHasConnectedToHost(): No NetworkState " |
| 573 << "for Tether network with GUID \"" << guid << "\"."; | 573 << "for Tether network with GUID \"" << guid << "\"."; |
| 574 return false; | 574 return false; |
| 575 } | 575 } |
| 576 | 576 |
| 577 if (tether_network_state->tether_has_connected_to_host()) { | 577 if (tether_network_state->tether_has_connected_to_host()) { |
| 578 return false; | 578 return false; |
| 579 } | 579 } |
| 580 | 580 |
| 581 tether_network_state->set_tether_has_connected_to_host(true); | 581 tether_network_state->set_tether_has_connected_to_host(true); |
| 582 NotifyNetworkListChanged(); | 582 |
| 583 NotifyNetworkPropertiesUpdated(tether_network_state); | |
| 583 return true; | 584 return true; |
| 584 } | 585 } |
| 585 | 586 |
| 586 bool NetworkStateHandler::RemoveTetherNetworkState(const std::string& guid) { | 587 bool NetworkStateHandler::RemoveTetherNetworkState(const std::string& guid) { |
| 587 for (auto iter = tether_network_list_.begin(); | 588 for (auto iter = tether_network_list_.begin(); |
| 588 iter != tether_network_list_.end(); ++iter) { | 589 iter != tether_network_list_.end(); ++iter) { |
| 589 if (iter->get()->AsNetworkState()->guid() == guid) { | 590 if (iter->get()->AsNetworkState()->guid() == guid) { |
| 590 NetworkState* wifi_network = GetModifiableNetworkStateFromGuid( | 591 NetworkState* wifi_network = GetModifiableNetworkStateFromGuid( |
| 591 iter->get()->AsNetworkState()->tether_guid()); | 592 iter->get()->AsNetworkState()->tether_guid()); |
| 592 if (wifi_network) | 593 if (wifi_network) |
| 593 wifi_network->set_tether_guid(std::string()); | 594 wifi_network->set_tether_guid(std::string()); |
| 594 | 595 |
| 595 tether_network_list_.erase(iter); | 596 tether_network_list_.erase(iter); |
| 596 NotifyNetworkListChanged(); | 597 NotifyNetworkListChanged(); |
| 597 | 598 |
| 598 return true; | 599 return true; |
| 599 } | 600 } |
| 600 } | 601 } |
| 601 return false; | 602 return false; |
| 602 } | 603 } |
| 603 | 604 |
| 604 bool NetworkStateHandler::DisassociateTetherNetworkStateFromWifiNetwork( | 605 bool NetworkStateHandler::DisassociateTetherNetworkStateFromWifiNetwork( |
| 605 const std::string& tether_network_guid) { | 606 const std::string& tether_network_guid) { |
| 606 NetworkState* tether_network = | 607 NetworkState* tether_network_state = |
| 607 GetModifiableNetworkStateFromGuid(tether_network_guid); | 608 GetModifiableNetworkStateFromGuid(tether_network_guid); |
| 608 | 609 |
| 609 if (!tether_network) { | 610 if (!tether_network_state) { |
| 610 NET_LOG(ERROR) << "DisassociateTetherNetworkStateWithWifiNetwork(): Tether " | 611 NET_LOG(ERROR) << "DisassociateTetherNetworkStateWithWifiNetwork(): Tether " |
| 611 << "network with ID " << tether_network_guid | 612 << "network with ID " << tether_network_guid |
| 612 << " not registered; could not remove association."; | 613 << " not registered; could not remove association."; |
| 613 return false; | 614 return false; |
| 614 } | 615 } |
| 615 | 616 |
| 616 std::string wifi_network_guid = tether_network->tether_guid(); | 617 std::string wifi_network_guid = tether_network_state->tether_guid(); |
| 617 NetworkState* wifi_network = | 618 NetworkState* wifi_network_state = |
| 618 GetModifiableNetworkStateFromGuid(wifi_network_guid); | 619 GetModifiableNetworkStateFromGuid(wifi_network_guid); |
| 619 | 620 |
| 620 if (!wifi_network) { | 621 if (!wifi_network_state) { |
| 621 NET_LOG(ERROR) << "DisassociateTetherNetworkStateWithWifiNetwork(): Wi-Fi " | 622 NET_LOG(ERROR) << "DisassociateTetherNetworkStateWithWifiNetwork(): Wi-Fi " |
| 622 << "network with ID " << wifi_network_guid | 623 << "network with ID " << wifi_network_guid |
| 623 << " not registered; could not remove association."; | 624 << " not registered; could not remove association."; |
| 624 return false; | 625 return false; |
| 625 } | 626 } |
| 626 | 627 |
| 627 wifi_network->set_tether_guid(std::string()); | 628 const std::string old_wifi_network_tether_guid = |
| 628 tether_network->set_tether_guid(std::string()); | 629 wifi_network_state->tether_guid(); |
| 630 const std::string old_tether_network_tether_guid = | |
| 631 tether_network_state->tether_guid(); | |
| 629 | 632 |
| 630 NotifyNetworkListChanged(); | 633 wifi_network_state->set_tether_guid(std::string()); |
| 634 tether_network_state->set_tether_guid(std::string()); | |
| 635 | |
| 636 if (!old_wifi_network_tether_guid.empty()) | |
| 637 NotifyNetworkPropertiesUpdated(wifi_network_state); | |
| 638 if (!old_tether_network_tether_guid.empty()) | |
| 639 NotifyNetworkPropertiesUpdated(tether_network_state); | |
|
stevenjb
2017/06/09 15:39:31
Can't all of this just be:
if (wifi_network_state
Kyle Horimoto
2017/06/09 17:18:34
Done.
| |
| 631 | 640 |
| 632 return true; | 641 return true; |
| 633 } | 642 } |
| 634 | 643 |
| 635 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( | 644 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( |
| 636 const std::string& tether_network_guid, | 645 const std::string& tether_network_guid, |
| 637 const std::string& wifi_network_guid) { | 646 const std::string& wifi_network_guid) { |
| 638 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { | 647 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { |
| 639 NET_LOG(ERROR) << "AssociateTetherNetworkStateWithWifiNetwork() called " | 648 NET_LOG(ERROR) << "AssociateTetherNetworkStateWithWifiNetwork() called " |
| 640 << "when Tether networks are not enabled. Cannot " | 649 << "when Tether networks are not enabled. Cannot " |
| 641 << "associate."; | 650 << "associate."; |
| 642 return false; | 651 return false; |
| 643 } | 652 } |
| 644 | 653 |
| 645 NetworkState* tether_network = | 654 NetworkState* tether_network_state = |
| 646 GetModifiableNetworkStateFromGuid(tether_network_guid); | 655 GetModifiableNetworkStateFromGuid(tether_network_guid); |
| 647 if (!tether_network) { | 656 if (!tether_network_state) { |
| 648 NET_LOG(ERROR) << "Tether network does not exist: " << tether_network_guid; | 657 NET_LOG(ERROR) << "Tether network does not exist: " << tether_network_guid; |
| 649 return false; | 658 return false; |
| 650 } | 659 } |
| 651 if (!NetworkTypePattern::Tether().MatchesType(tether_network->type())) { | 660 if (!NetworkTypePattern::Tether().MatchesType(tether_network_state->type())) { |
| 652 NET_LOG(ERROR) << "Network is not a Tether network: " | 661 NET_LOG(ERROR) << "Network is not a Tether network: " |
| 653 << tether_network_guid; | 662 << tether_network_guid; |
| 654 return false; | 663 return false; |
| 655 } | 664 } |
| 656 | 665 |
| 657 NetworkState* wifi_network = | 666 NetworkState* wifi_network_state = |
| 658 GetModifiableNetworkStateFromGuid(wifi_network_guid); | 667 GetModifiableNetworkStateFromGuid(wifi_network_guid); |
| 659 if (!wifi_network) { | 668 if (!wifi_network_state) { |
| 660 NET_LOG(ERROR) << "Wi-Fi Network does not exist: " << wifi_network_guid; | 669 NET_LOG(ERROR) << "Wi-Fi Network does not exist: " << wifi_network_guid; |
| 661 return false; | 670 return false; |
| 662 } | 671 } |
| 663 if (!NetworkTypePattern::WiFi().MatchesType(wifi_network->type())) { | 672 if (!NetworkTypePattern::WiFi().MatchesType(wifi_network_state->type())) { |
| 664 NET_LOG(ERROR) << "Network is not a W-Fi network: " << wifi_network_guid; | 673 NET_LOG(ERROR) << "Network is not a W-Fi network: " << wifi_network_guid; |
| 665 return false; | 674 return false; |
| 666 } | 675 } |
| 667 | 676 |
| 668 tether_network->set_tether_guid(wifi_network_guid); | 677 const std::string old_wifi_network_tether_guid = |
| 669 wifi_network->set_tether_guid(tether_network_guid); | 678 wifi_network_state->tether_guid(); |
| 670 NotifyNetworkListChanged(); | 679 const std::string old_tether_network_tether_guid = |
| 680 tether_network_state->tether_guid(); | |
| 681 | |
| 682 tether_network_state->set_tether_guid(wifi_network_guid); | |
| 683 wifi_network_state->set_tether_guid(tether_network_guid); | |
| 684 | |
| 685 if (old_wifi_network_tether_guid != tether_network_guid) | |
| 686 NotifyNetworkPropertiesUpdated(wifi_network_state); | |
| 687 if (old_tether_network_tether_guid != wifi_network_guid) | |
| 688 NotifyNetworkPropertiesUpdated(tether_network_state); | |
|
stevenjb
2017/06/09 15:39:31
Same here? Alternately this logic could be moved t
Kyle Horimoto
2017/06/09 17:18:34
Done, but I didn't create a shared function since
| |
| 689 | |
| 671 return true; | 690 return true; |
| 672 } | 691 } |
| 673 | 692 |
| 674 void NetworkStateHandler::SetTetherNetworkStateDisconnected( | 693 void NetworkStateHandler::SetTetherNetworkStateDisconnected( |
| 675 const std::string& guid) { | 694 const std::string& guid) { |
| 676 // TODO(khorimoto): Remove the Tether network as the default network, and | 695 // TODO(khorimoto): Remove the Tether network as the default network. |
| 677 // send a connection status change. | |
| 678 SetTetherNetworkStateConnectionState(guid, shill::kStateDisconnect); | 696 SetTetherNetworkStateConnectionState(guid, shill::kStateDisconnect); |
| 679 } | 697 } |
| 680 | 698 |
| 681 void NetworkStateHandler::SetTetherNetworkStateConnecting( | 699 void NetworkStateHandler::SetTetherNetworkStateConnecting( |
| 682 const std::string& guid) { | 700 const std::string& guid) { |
| 683 // TODO(khorimoto): Set the Tether network as the default network, and send | 701 // TODO(khorimoto): Set the Tether network as the default network. |
| 684 // a connection status change. | |
| 685 SetTetherNetworkStateConnectionState(guid, shill::kStateConfiguration); | 702 SetTetherNetworkStateConnectionState(guid, shill::kStateConfiguration); |
| 686 } | 703 } |
| 687 | 704 |
| 688 void NetworkStateHandler::SetTetherNetworkStateConnected( | 705 void NetworkStateHandler::SetTetherNetworkStateConnected( |
| 689 const std::string& guid) { | 706 const std::string& guid) { |
| 690 // Being connected implies that AssociateTetherNetworkStateWithWifiNetwork() | 707 // Being connected implies that AssociateTetherNetworkStateWithWifiNetwork() |
| 691 // was already called, so ensure that the association is still intact. | 708 // was already called, so ensure that the association is still intact. |
| 692 DCHECK(GetNetworkStateFromGuid(GetNetworkStateFromGuid(guid)->tether_guid()) | 709 DCHECK(GetNetworkStateFromGuid(GetNetworkStateFromGuid(guid)->tether_guid()) |
| 693 ->tether_guid() == guid); | 710 ->tether_guid() == guid); |
| 694 | 711 |
| 695 // TODO(khorimoto): Send a connection status change. | |
| 696 SetTetherNetworkStateConnectionState(guid, shill::kStateOnline); | 712 SetTetherNetworkStateConnectionState(guid, shill::kStateOnline); |
| 697 } | 713 } |
| 698 | 714 |
| 699 void NetworkStateHandler::SetTetherNetworkStateConnectionState( | 715 void NetworkStateHandler::SetTetherNetworkStateConnectionState( |
| 700 const std::string& guid, | 716 const std::string& guid, |
| 701 const std::string& connection_state) { | 717 const std::string& connection_state) { |
| 702 NetworkState* tether_network = GetModifiableNetworkStateFromGuid(guid); | 718 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid); |
| 703 if (!tether_network) { | 719 if (!tether_network_state) { |
| 704 NET_LOG(ERROR) << "SetTetherNetworkStateConnectionState: Tether network " | 720 NET_LOG(ERROR) << "SetTetherNetworkStateConnectionState: Tether network " |
| 705 << "not found: " << guid; | 721 << "not found: " << guid; |
| 706 return; | 722 return; |
| 707 } | 723 } |
| 708 | 724 |
| 709 DCHECK(NetworkTypePattern::Tether().MatchesType(tether_network->type())); | 725 DCHECK( |
| 726 NetworkTypePattern::Tether().MatchesType(tether_network_state->type())); | |
| 710 | 727 |
| 711 tether_network->set_connection_state(connection_state); | 728 std::string prev_connection_state = tether_network_state->connection_state(); |
| 712 NotifyNetworkListChanged(); | 729 tether_network_state->set_connection_state(connection_state); |
| 730 DCHECK(!tether_network_state->is_captive_portal()); | |
| 731 | |
| 732 if (ConnectionStateChanged(tether_network_state, prev_connection_state, | |
| 733 false /* prev_is_captive_portal */)) { | |
| 734 NET_LOG(EVENT) << "Changing connection state for Tether network with GUID " | |
| 735 << guid << ". Old state: " << prev_connection_state << ", " | |
| 736 << "New state: " << connection_state; | |
| 737 | |
| 738 OnNetworkConnectionStateChanged(tether_network_state); | |
| 739 NotifyNetworkPropertiesUpdated(tether_network_state); | |
| 740 } | |
| 713 } | 741 } |
| 714 | 742 |
| 715 void NetworkStateHandler::EnsureTetherDeviceState() { | 743 void NetworkStateHandler::EnsureTetherDeviceState() { |
| 716 bool should_be_present = | 744 bool should_be_present = |
| 717 tether_technology_state_ != TechnologyState::TECHNOLOGY_UNAVAILABLE; | 745 tether_technology_state_ != TechnologyState::TECHNOLOGY_UNAVAILABLE; |
| 718 | 746 |
| 719 for (auto it = device_list_.begin(); it < device_list_.end(); ++it) { | 747 for (auto it = device_list_.begin(); it < device_list_.end(); ++it) { |
| 720 std::string path = (*it)->path(); | 748 std::string path = (*it)->path(); |
| 721 if (path == kTetherDevicePath) { | 749 if (path == kTetherDevicePath) { |
| 722 // If the Tether DeviceState is in the list and it should not be, remove | 750 // If the Tether DeviceState is in the list and it should not be, remove |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1482 if (type.MatchesType(shill::kTypeVPN)) | 1510 if (type.MatchesType(shill::kTypeVPN)) |
| 1483 technologies.emplace_back(shill::kTypeVPN); | 1511 technologies.emplace_back(shill::kTypeVPN); |
| 1484 if (type.MatchesType(kTypeTether)) | 1512 if (type.MatchesType(kTypeTether)) |
| 1485 technologies.emplace_back(kTypeTether); | 1513 technologies.emplace_back(kTypeTether); |
| 1486 | 1514 |
| 1487 CHECK_GT(technologies.size(), 0ul); | 1515 CHECK_GT(technologies.size(), 0ul); |
| 1488 return technologies; | 1516 return technologies; |
| 1489 } | 1517 } |
| 1490 | 1518 |
| 1491 } // namespace chromeos | 1519 } // namespace chromeos |
| OLD | NEW |