| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/guid.h" | 9 #include "base/guid.h" |
| 10 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
| (...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 OnNetworkConnectionStateChanged(network); | 535 OnNetworkConnectionStateChanged(network); |
| 536 NET_LOG_EVENT("NetworkPropertiesUpdated", GetLogName(network)); | 536 NET_LOG_EVENT("NetworkPropertiesUpdated", GetLogName(network)); |
| 537 NotifyNetworkPropertiesUpdated(network); | 537 NotifyNetworkPropertiesUpdated(network); |
| 538 } | 538 } |
| 539 } | 539 } |
| 540 | 540 |
| 541 void NetworkStateHandler::UpdateNetworkServiceProperty( | 541 void NetworkStateHandler::UpdateNetworkServiceProperty( |
| 542 const std::string& service_path, | 542 const std::string& service_path, |
| 543 const std::string& key, | 543 const std::string& key, |
| 544 const base::Value& value) { | 544 const base::Value& value) { |
| 545 SCOPED_NET_LOG_IF_SLOW(); |
| 545 bool changed = false; | 546 bool changed = false; |
| 546 NetworkState* network = GetModifiableNetworkState(service_path); | 547 NetworkState* network = GetModifiableNetworkState(service_path); |
| 547 if (!network) | 548 if (!network) |
| 548 return; | 549 return; |
| 549 std::string prev_connection_state = network->connection_state(); | 550 std::string prev_connection_state = network->connection_state(); |
| 550 std::string prev_profile_path = network->profile_path(); | 551 std::string prev_profile_path = network->profile_path(); |
| 551 changed |= network->PropertyChanged(key, value); | 552 changed |= network->PropertyChanged(key, value); |
| 552 if (!changed) | 553 if (!changed) |
| 553 return; | 554 return; |
| 554 | 555 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 | 595 |
| 595 // If added to a Profile, request a full update so that a NetworkState | 596 // If added to a Profile, request a full update so that a NetworkState |
| 596 // gets created. | 597 // gets created. |
| 597 if (prev_profile_path.empty() && !network->profile_path().empty()) | 598 if (prev_profile_path.empty() && !network->profile_path().empty()) |
| 598 RequestUpdateForNetwork(service_path); | 599 RequestUpdateForNetwork(service_path); |
| 599 } | 600 } |
| 600 | 601 |
| 601 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, | 602 void NetworkStateHandler::UpdateDeviceProperty(const std::string& device_path, |
| 602 const std::string& key, | 603 const std::string& key, |
| 603 const base::Value& value) { | 604 const base::Value& value) { |
| 605 SCOPED_NET_LOG_IF_SLOW(); |
| 604 DeviceState* device = GetModifiableDeviceState(device_path); | 606 DeviceState* device = GetModifiableDeviceState(device_path); |
| 605 if (!device) | 607 if (!device) |
| 606 return; | 608 return; |
| 607 if (!device->PropertyChanged(key, value)) | 609 if (!device->PropertyChanged(key, value)) |
| 608 return; | 610 return; |
| 609 | 611 |
| 610 std::string detail = device->name() + "." + key; | 612 std::string detail = device->name() + "." + key; |
| 611 detail += " = " + ValueAsString(value); | 613 detail += " = " + ValueAsString(value); |
| 612 NET_LOG_EVENT("DevicePropertyUpdated", detail); | 614 NET_LOG_EVENT("DevicePropertyUpdated", detail); |
| 613 | 615 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 } | 673 } |
| 672 | 674 |
| 673 void NetworkStateHandler::TechnologyListChanged() { | 675 void NetworkStateHandler::TechnologyListChanged() { |
| 674 // Eventually we would like to replace Technology state with Device state. | 676 // Eventually we would like to replace Technology state with Device state. |
| 675 // For now, treat technology state changes as device list changes. | 677 // For now, treat technology state changes as device list changes. |
| 676 NotifyDeviceListChanged(); | 678 NotifyDeviceListChanged(); |
| 677 } | 679 } |
| 678 | 680 |
| 679 void NetworkStateHandler::ManagedStateListChanged( | 681 void NetworkStateHandler::ManagedStateListChanged( |
| 680 ManagedState::ManagedType type) { | 682 ManagedState::ManagedType type) { |
| 683 SCOPED_NET_LOG_IF_SLOW(); |
| 681 if (type == ManagedState::MANAGED_TYPE_NETWORK) { | 684 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
| 682 SortNetworkList(); | 685 SortNetworkList(); |
| 683 UpdateNetworkStats(); | 686 UpdateNetworkStats(); |
| 684 // Notify observers that the list of networks has changed. | 687 // Notify observers that the list of networks has changed. |
| 685 NET_LOG_EVENT("NOTIFY:NetworkListChanged", | 688 NET_LOG_EVENT("NOTIFY:NetworkListChanged", |
| 686 base::StringPrintf("Size:%" PRIuS, network_list_.size())); | 689 base::StringPrintf("Size:%" PRIuS, network_list_.size())); |
| 687 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 690 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
| 688 NetworkListChanged()); | 691 NetworkListChanged()); |
| 689 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { | 692 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
| 690 std::string devices; | 693 std::string devices; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 if (iter != specifier_guid_map_.end()) { | 813 if (iter != specifier_guid_map_.end()) { |
| 811 guid = iter->second; | 814 guid = iter->second; |
| 812 } else { | 815 } else { |
| 813 guid = base::GenerateGUID(); | 816 guid = base::GenerateGUID(); |
| 814 specifier_guid_map_[specifier] = guid; | 817 specifier_guid_map_[specifier] = guid; |
| 815 } | 818 } |
| 816 network->SetGuid(guid); | 819 network->SetGuid(guid); |
| 817 } | 820 } |
| 818 | 821 |
| 819 void NetworkStateHandler::NotifyDeviceListChanged() { | 822 void NetworkStateHandler::NotifyDeviceListChanged() { |
| 823 SCOPED_NET_LOG_IF_SLOW(); |
| 820 NET_LOG_DEBUG("NOTIFY:DeviceListChanged", | 824 NET_LOG_DEBUG("NOTIFY:DeviceListChanged", |
| 821 base::StringPrintf("Size:%" PRIuS, device_list_.size())); | 825 base::StringPrintf("Size:%" PRIuS, device_list_.size())); |
| 822 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 826 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
| 823 DeviceListChanged()); | 827 DeviceListChanged()); |
| 824 } | 828 } |
| 825 | 829 |
| 826 DeviceState* NetworkStateHandler::GetModifiableDeviceState( | 830 DeviceState* NetworkStateHandler::GetModifiableDeviceState( |
| 827 const std::string& device_path) const { | 831 const std::string& device_path) const { |
| 828 ManagedState* managed = GetModifiableManagedState(&device_list_, device_path); | 832 ManagedState* managed = GetModifiableManagedState(&device_list_, device_path); |
| 829 if (!managed) | 833 if (!managed) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 859 return &network_list_; | 863 return &network_list_; |
| 860 case ManagedState::MANAGED_TYPE_DEVICE: | 864 case ManagedState::MANAGED_TYPE_DEVICE: |
| 861 return &device_list_; | 865 return &device_list_; |
| 862 } | 866 } |
| 863 NOTREACHED(); | 867 NOTREACHED(); |
| 864 return NULL; | 868 return NULL; |
| 865 } | 869 } |
| 866 | 870 |
| 867 void NetworkStateHandler::OnNetworkConnectionStateChanged( | 871 void NetworkStateHandler::OnNetworkConnectionStateChanged( |
| 868 NetworkState* network) { | 872 NetworkState* network) { |
| 873 SCOPED_NET_LOG_IF_SLOW(); |
| 869 DCHECK(network); | 874 DCHECK(network); |
| 870 std::string event = "NetworkConnectionStateChanged"; | 875 std::string event = "NetworkConnectionStateChanged"; |
| 871 if (network->path() == default_network_path_) { | 876 if (network->path() == default_network_path_) { |
| 872 event = "Default" + event; | 877 event = "Default" + event; |
| 873 if (!network->IsConnectedState()) { | 878 if (!network->IsConnectedState()) { |
| 874 NET_LOG_EVENT( | 879 NET_LOG_EVENT( |
| 875 "DefaultNetwork is not connected: " + network->connection_state(), | 880 "DefaultNetwork is not connected: " + network->connection_state(), |
| 876 network->path()); | 881 network->path()); |
| 877 default_network_path_.clear(); | 882 default_network_path_.clear(); |
| 878 SortNetworkList(); | 883 SortNetworkList(); |
| 879 NotifyDefaultNetworkChanged(NULL); | 884 NotifyDefaultNetworkChanged(NULL); |
| 880 } | 885 } |
| 881 } | 886 } |
| 882 NET_LOG_EVENT("NOTIFY:" + event + ": " + network->connection_state(), | 887 NET_LOG_EVENT("NOTIFY:" + event + ": " + network->connection_state(), |
| 883 GetLogName(network)); | 888 GetLogName(network)); |
| 884 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 889 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
| 885 NetworkConnectionStateChanged(network)); | 890 NetworkConnectionStateChanged(network)); |
| 886 if (network->path() == default_network_path_) | 891 if (network->path() == default_network_path_) |
| 887 NotifyDefaultNetworkChanged(network); | 892 NotifyDefaultNetworkChanged(network); |
| 888 } | 893 } |
| 889 | 894 |
| 890 void NetworkStateHandler::NotifyDefaultNetworkChanged( | 895 void NetworkStateHandler::NotifyDefaultNetworkChanged( |
| 891 const NetworkState* default_network) { | 896 const NetworkState* default_network) { |
| 897 SCOPED_NET_LOG_IF_SLOW(); |
| 892 NET_LOG_EVENT("NOTIFY:DefaultNetworkChanged", GetLogName(default_network)); | 898 NET_LOG_EVENT("NOTIFY:DefaultNetworkChanged", GetLogName(default_network)); |
| 893 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 899 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
| 894 DefaultNetworkChanged(default_network)); | 900 DefaultNetworkChanged(default_network)); |
| 895 } | 901 } |
| 896 | 902 |
| 897 void NetworkStateHandler::NotifyNetworkPropertiesUpdated( | 903 void NetworkStateHandler::NotifyNetworkPropertiesUpdated( |
| 898 const NetworkState* network) { | 904 const NetworkState* network) { |
| 905 SCOPED_NET_LOG_IF_SLOW(); |
| 899 NET_LOG_DEBUG("NOTIFY:NetworkPropertiesUpdated", GetLogName(network)); | 906 NET_LOG_DEBUG("NOTIFY:NetworkPropertiesUpdated", GetLogName(network)); |
| 900 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 907 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
| 901 NetworkPropertiesUpdated(network)); | 908 NetworkPropertiesUpdated(network)); |
| 902 } | 909 } |
| 903 | 910 |
| 904 void NetworkStateHandler::NotifyDevicePropertiesUpdated( | 911 void NetworkStateHandler::NotifyDevicePropertiesUpdated( |
| 905 const DeviceState* device) { | 912 const DeviceState* device) { |
| 913 SCOPED_NET_LOG_IF_SLOW(); |
| 906 NET_LOG_DEBUG("NOTIFY:DevicePropertiesUpdated", GetLogName(device)); | 914 NET_LOG_DEBUG("NOTIFY:DevicePropertiesUpdated", GetLogName(device)); |
| 907 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 915 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
| 908 DevicePropertiesUpdated(device)); | 916 DevicePropertiesUpdated(device)); |
| 909 } | 917 } |
| 910 | 918 |
| 911 void NetworkStateHandler::NotifyScanCompleted(const DeviceState* device) { | 919 void NetworkStateHandler::NotifyScanCompleted(const DeviceState* device) { |
| 920 SCOPED_NET_LOG_IF_SLOW(); |
| 912 NET_LOG_DEBUG("NOTIFY:ScanCompleted", GetLogName(device)); | 921 NET_LOG_DEBUG("NOTIFY:ScanCompleted", GetLogName(device)); |
| 913 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 922 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
| 914 ScanCompleted(device)); | 923 ScanCompleted(device)); |
| 915 } | 924 } |
| 916 | 925 |
| 917 std::string NetworkStateHandler::GetTechnologyForType( | 926 std::string NetworkStateHandler::GetTechnologyForType( |
| 918 const NetworkTypePattern& type) const { | 927 const NetworkTypePattern& type) const { |
| 919 if (type.MatchesType(shill::kTypeEthernet)) | 928 if (type.MatchesType(shill::kTypeEthernet)) |
| 920 return shill::kTypeEthernet; | 929 return shill::kTypeEthernet; |
| 921 | 930 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 952 if (type.MatchesType(shill::kTypeBluetooth)) | 961 if (type.MatchesType(shill::kTypeBluetooth)) |
| 953 technologies.push_back(new std::string(shill::kTypeBluetooth)); | 962 technologies.push_back(new std::string(shill::kTypeBluetooth)); |
| 954 if (type.MatchesType(shill::kTypeVPN)) | 963 if (type.MatchesType(shill::kTypeVPN)) |
| 955 technologies.push_back(new std::string(shill::kTypeVPN)); | 964 technologies.push_back(new std::string(shill::kTypeVPN)); |
| 956 | 965 |
| 957 CHECK_GT(technologies.size(), 0ul); | 966 CHECK_GT(technologies.size(), 0ul); |
| 958 return technologies.Pass(); | 967 return technologies.Pass(); |
| 959 } | 968 } |
| 960 | 969 |
| 961 } // namespace chromeos | 970 } // namespace chromeos |
| OLD | NEW |