| 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 if (wifi_network_state->tether_guid().empty() && |
| 628 tether_network->set_tether_guid(std::string()); | 629 tether_network_state->tether_guid().empty()) { |
| 630 return true; |
| 631 } |
| 629 | 632 |
| 630 NotifyNetworkListChanged(); | 633 wifi_network_state->set_tether_guid(std::string()); |
| 634 tether_network_state->set_tether_guid(std::string()); |
| 635 |
| 636 NotifyNetworkPropertiesUpdated(wifi_network_state); |
| 637 NotifyNetworkPropertiesUpdated(tether_network_state); |
| 631 | 638 |
| 632 return true; | 639 return true; |
| 633 } | 640 } |
| 634 | 641 |
| 635 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( | 642 bool NetworkStateHandler::AssociateTetherNetworkStateWithWifiNetwork( |
| 636 const std::string& tether_network_guid, | 643 const std::string& tether_network_guid, |
| 637 const std::string& wifi_network_guid) { | 644 const std::string& wifi_network_guid) { |
| 638 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { | 645 if (tether_technology_state_ != TECHNOLOGY_ENABLED) { |
| 639 NET_LOG(ERROR) << "AssociateTetherNetworkStateWithWifiNetwork() called " | 646 NET_LOG(ERROR) << "AssociateTetherNetworkStateWithWifiNetwork() called " |
| 640 << "when Tether networks are not enabled. Cannot " | 647 << "when Tether networks are not enabled. Cannot " |
| 641 << "associate."; | 648 << "associate."; |
| 642 return false; | 649 return false; |
| 643 } | 650 } |
| 644 | 651 |
| 645 NetworkState* tether_network = | 652 NetworkState* tether_network_state = |
| 646 GetModifiableNetworkStateFromGuid(tether_network_guid); | 653 GetModifiableNetworkStateFromGuid(tether_network_guid); |
| 647 if (!tether_network) { | 654 if (!tether_network_state) { |
| 648 NET_LOG(ERROR) << "Tether network does not exist: " << tether_network_guid; | 655 NET_LOG(ERROR) << "Tether network does not exist: " << tether_network_guid; |
| 649 return false; | 656 return false; |
| 650 } | 657 } |
| 651 if (!NetworkTypePattern::Tether().MatchesType(tether_network->type())) { | 658 if (!NetworkTypePattern::Tether().MatchesType(tether_network_state->type())) { |
| 652 NET_LOG(ERROR) << "Network is not a Tether network: " | 659 NET_LOG(ERROR) << "Network is not a Tether network: " |
| 653 << tether_network_guid; | 660 << tether_network_guid; |
| 654 return false; | 661 return false; |
| 655 } | 662 } |
| 656 | 663 |
| 657 NetworkState* wifi_network = | 664 NetworkState* wifi_network_state = |
| 658 GetModifiableNetworkStateFromGuid(wifi_network_guid); | 665 GetModifiableNetworkStateFromGuid(wifi_network_guid); |
| 659 if (!wifi_network) { | 666 if (!wifi_network_state) { |
| 660 NET_LOG(ERROR) << "Wi-Fi Network does not exist: " << wifi_network_guid; | 667 NET_LOG(ERROR) << "Wi-Fi Network does not exist: " << wifi_network_guid; |
| 661 return false; | 668 return false; |
| 662 } | 669 } |
| 663 if (!NetworkTypePattern::WiFi().MatchesType(wifi_network->type())) { | 670 if (!NetworkTypePattern::WiFi().MatchesType(wifi_network_state->type())) { |
| 664 NET_LOG(ERROR) << "Network is not a W-Fi network: " << wifi_network_guid; | 671 NET_LOG(ERROR) << "Network is not a W-Fi network: " << wifi_network_guid; |
| 665 return false; | 672 return false; |
| 666 } | 673 } |
| 667 | 674 |
| 668 tether_network->set_tether_guid(wifi_network_guid); | 675 if (wifi_network_state->tether_guid() == tether_network_guid && |
| 669 wifi_network->set_tether_guid(tether_network_guid); | 676 tether_network_state->tether_guid() == wifi_network_guid) { |
| 670 NotifyNetworkListChanged(); | 677 return true; |
| 678 } |
| 679 |
| 680 tether_network_state->set_tether_guid(wifi_network_guid); |
| 681 wifi_network_state->set_tether_guid(tether_network_guid); |
| 682 |
| 683 NotifyNetworkPropertiesUpdated(wifi_network_state); |
| 684 NotifyNetworkPropertiesUpdated(tether_network_state); |
| 685 |
| 671 return true; | 686 return true; |
| 672 } | 687 } |
| 673 | 688 |
| 674 void NetworkStateHandler::SetTetherNetworkStateDisconnected( | 689 void NetworkStateHandler::SetTetherNetworkStateDisconnected( |
| 675 const std::string& guid) { | 690 const std::string& guid) { |
| 676 // TODO(khorimoto): Remove the Tether network as the default network, and | 691 // TODO(khorimoto): Remove the Tether network as the default network. |
| 677 // send a connection status change. | |
| 678 SetTetherNetworkStateConnectionState(guid, shill::kStateDisconnect); | 692 SetTetherNetworkStateConnectionState(guid, shill::kStateDisconnect); |
| 679 } | 693 } |
| 680 | 694 |
| 681 void NetworkStateHandler::SetTetherNetworkStateConnecting( | 695 void NetworkStateHandler::SetTetherNetworkStateConnecting( |
| 682 const std::string& guid) { | 696 const std::string& guid) { |
| 683 // TODO(khorimoto): Set the Tether network as the default network, and send | 697 // TODO(khorimoto): Set the Tether network as the default network. |
| 684 // a connection status change. | |
| 685 SetTetherNetworkStateConnectionState(guid, shill::kStateConfiguration); | 698 SetTetherNetworkStateConnectionState(guid, shill::kStateConfiguration); |
| 686 } | 699 } |
| 687 | 700 |
| 688 void NetworkStateHandler::SetTetherNetworkStateConnected( | 701 void NetworkStateHandler::SetTetherNetworkStateConnected( |
| 689 const std::string& guid) { | 702 const std::string& guid) { |
| 690 // Being connected implies that AssociateTetherNetworkStateWithWifiNetwork() | 703 // Being connected implies that AssociateTetherNetworkStateWithWifiNetwork() |
| 691 // was already called, so ensure that the association is still intact. | 704 // was already called, so ensure that the association is still intact. |
| 692 DCHECK(GetNetworkStateFromGuid(GetNetworkStateFromGuid(guid)->tether_guid()) | 705 DCHECK(GetNetworkStateFromGuid(GetNetworkStateFromGuid(guid)->tether_guid()) |
| 693 ->tether_guid() == guid); | 706 ->tether_guid() == guid); |
| 694 | 707 |
| 695 // TODO(khorimoto): Send a connection status change. | |
| 696 SetTetherNetworkStateConnectionState(guid, shill::kStateOnline); | 708 SetTetherNetworkStateConnectionState(guid, shill::kStateOnline); |
| 697 } | 709 } |
| 698 | 710 |
| 699 void NetworkStateHandler::SetTetherNetworkStateConnectionState( | 711 void NetworkStateHandler::SetTetherNetworkStateConnectionState( |
| 700 const std::string& guid, | 712 const std::string& guid, |
| 701 const std::string& connection_state) { | 713 const std::string& connection_state) { |
| 702 NetworkState* tether_network = GetModifiableNetworkStateFromGuid(guid); | 714 NetworkState* tether_network_state = GetModifiableNetworkStateFromGuid(guid); |
| 703 if (!tether_network) { | 715 if (!tether_network_state) { |
| 704 NET_LOG(ERROR) << "SetTetherNetworkStateConnectionState: Tether network " | 716 NET_LOG(ERROR) << "SetTetherNetworkStateConnectionState: Tether network " |
| 705 << "not found: " << guid; | 717 << "not found: " << guid; |
| 706 return; | 718 return; |
| 707 } | 719 } |
| 708 | 720 |
| 709 DCHECK(NetworkTypePattern::Tether().MatchesType(tether_network->type())); | 721 DCHECK( |
| 722 NetworkTypePattern::Tether().MatchesType(tether_network_state->type())); |
| 710 | 723 |
| 711 tether_network->set_connection_state(connection_state); | 724 std::string prev_connection_state = tether_network_state->connection_state(); |
| 712 NotifyNetworkListChanged(); | 725 tether_network_state->set_connection_state(connection_state); |
| 726 DCHECK(!tether_network_state->is_captive_portal()); |
| 727 |
| 728 if (ConnectionStateChanged(tether_network_state, prev_connection_state, |
| 729 false /* prev_is_captive_portal */)) { |
| 730 NET_LOG(EVENT) << "Changing connection state for Tether network with GUID " |
| 731 << guid << ". Old state: " << prev_connection_state << ", " |
| 732 << "New state: " << connection_state; |
| 733 |
| 734 OnNetworkConnectionStateChanged(tether_network_state); |
| 735 NotifyNetworkPropertiesUpdated(tether_network_state); |
| 736 } |
| 713 } | 737 } |
| 714 | 738 |
| 715 void NetworkStateHandler::EnsureTetherDeviceState() { | 739 void NetworkStateHandler::EnsureTetherDeviceState() { |
| 716 bool should_be_present = | 740 bool should_be_present = |
| 717 tether_technology_state_ != TechnologyState::TECHNOLOGY_UNAVAILABLE; | 741 tether_technology_state_ != TechnologyState::TECHNOLOGY_UNAVAILABLE; |
| 718 | 742 |
| 719 for (auto it = device_list_.begin(); it < device_list_.end(); ++it) { | 743 for (auto it = device_list_.begin(); it < device_list_.end(); ++it) { |
| 720 std::string path = (*it)->path(); | 744 std::string path = (*it)->path(); |
| 721 if (path == kTetherDevicePath) { | 745 if (path == kTetherDevicePath) { |
| 722 // If the Tether DeviceState is in the list and it should not be, remove | 746 // 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)) | 1506 if (type.MatchesType(shill::kTypeVPN)) |
| 1483 technologies.emplace_back(shill::kTypeVPN); | 1507 technologies.emplace_back(shill::kTypeVPN); |
| 1484 if (type.MatchesType(kTypeTether)) | 1508 if (type.MatchesType(kTypeTether)) |
| 1485 technologies.emplace_back(kTypeTether); | 1509 technologies.emplace_back(kTypeTether); |
| 1486 | 1510 |
| 1487 CHECK_GT(technologies.size(), 0ul); | 1511 CHECK_GT(technologies.size(), 0ul); |
| 1488 return technologies; | 1512 return technologies; |
| 1489 } | 1513 } |
| 1490 | 1514 |
| 1491 } // namespace chromeos | 1515 } // namespace chromeos |
| OLD | NEW |