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 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 return; | 765 return; |
766 | 766 |
767 default_network_path_ = service_path; | 767 default_network_path_ = service_path; |
768 NET_LOG_EVENT("DefaultNetworkServiceChanged:", default_network_path_); | 768 NET_LOG_EVENT("DefaultNetworkServiceChanged:", default_network_path_); |
769 const NetworkState* network = nullptr; | 769 const NetworkState* network = nullptr; |
770 if (!default_network_path_.empty()) { | 770 if (!default_network_path_.empty()) { |
771 network = GetNetworkState(default_network_path_); | 771 network = GetNetworkState(default_network_path_); |
772 if (!network) { | 772 if (!network) { |
773 // If NetworkState is not available yet, do not notify observers here, | 773 // If NetworkState is not available yet, do not notify observers here, |
774 // they will be notified when the state is received. | 774 // they will be notified when the state is received. |
775 NET_LOG_DEBUG("Default NetworkState not available", | 775 NET_LOG(EVENT) << "Default NetworkState not available: " |
776 default_network_path_); | 776 << default_network_path_; |
777 return; | 777 return; |
778 } | 778 } |
779 } | 779 } |
780 if (network && !network->IsConnectedState()) { | 780 if (network && !network->IsConnectedState()) { |
781 NET_LOG_ERROR( | 781 if (network->IsConnectingState()) { |
782 "DefaultNetwork is not connected: " + network->connection_state(), | 782 NET_LOG(EVENT) << "DefaultNetwork is connecting: " << GetLogName(network) |
783 network->path()); | 783 << ": " << network->connection_state(); |
| 784 } else { |
| 785 NET_LOG(ERROR) << "DefaultNetwork in unexpected state: " |
| 786 << GetLogName(network) << ": " |
| 787 << network->connection_state(); |
| 788 } |
| 789 // Do not notify observers here, the notification will occur when the |
| 790 // connection state changes. |
| 791 return; |
784 } | 792 } |
785 NotifyDefaultNetworkChanged(network); | 793 NotifyDefaultNetworkChanged(network); |
786 } | 794 } |
787 | 795 |
788 //------------------------------------------------------------------------------ | 796 //------------------------------------------------------------------------------ |
789 // Private methods | 797 // Private methods |
790 | 798 |
791 void NetworkStateHandler::UpdateGuid(NetworkState* network) { | 799 void NetworkStateHandler::UpdateGuid(NetworkState* network) { |
792 std::string specifier = network->GetSpecifier(); | 800 std::string specifier = network->GetSpecifier(); |
793 DCHECK(!specifier.empty()); | 801 DCHECK(!specifier.empty()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 return &device_list_; | 868 return &device_list_; |
861 } | 869 } |
862 NOTREACHED(); | 870 NOTREACHED(); |
863 return nullptr; | 871 return nullptr; |
864 } | 872 } |
865 | 873 |
866 void NetworkStateHandler::OnNetworkConnectionStateChanged( | 874 void NetworkStateHandler::OnNetworkConnectionStateChanged( |
867 NetworkState* network) { | 875 NetworkState* network) { |
868 SCOPED_NET_LOG_IF_SLOW(); | 876 SCOPED_NET_LOG_IF_SLOW(); |
869 DCHECK(network); | 877 DCHECK(network); |
870 std::string event = "NetworkConnectionStateChanged"; | 878 bool notify_default = false; |
871 if (network->path() == default_network_path_) { | 879 if (network->path() == default_network_path_) { |
872 event = "Default" + event; | 880 if (network->IsConnectedState()) { |
873 if (!network->IsConnectedState()) { | 881 notify_default = true; |
874 NET_LOG_EVENT( | 882 } else if (network->IsConnectingState()) { |
875 "DefaultNetwork is not connected: " + network->connection_state(), | 883 // Wait until the network is actually connected to notify that the default |
876 network->path()); | 884 // network changed. |
| 885 NET_LOG(EVENT) << "Default network is not connected: " |
| 886 << GetLogName(network) |
| 887 << "State: " << network->connection_state(); |
| 888 } else { |
| 889 NET_LOG(ERROR) << "Default network in unexpected state: " |
| 890 << GetLogName(network) |
| 891 << "State: " << network->connection_state(); |
877 default_network_path_.clear(); | 892 default_network_path_.clear(); |
878 SortNetworkList(); | 893 SortNetworkList(); |
879 NotifyDefaultNetworkChanged(nullptr); | 894 NotifyDefaultNetworkChanged(nullptr); |
880 } | 895 } |
881 } | 896 } |
882 NET_LOG_EVENT("NOTIFY:" + event + ": " + network->connection_state(), | 897 std::string desc = "NetworkConnectionStateChanged"; |
883 GetLogName(network)); | 898 if (notify_default) |
| 899 desc = "Default" + desc; |
| 900 NET_LOG(EVENT) << "NOTIFY: " << desc << ": " << GetLogName(network) << ": " |
| 901 << network->connection_state(); |
884 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 902 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
885 NetworkConnectionStateChanged(network)); | 903 NetworkConnectionStateChanged(network)); |
886 if (network->path() == default_network_path_) | 904 if (notify_default) |
887 NotifyDefaultNetworkChanged(network); | 905 NotifyDefaultNetworkChanged(network); |
888 } | 906 } |
889 | 907 |
890 void NetworkStateHandler::NotifyDefaultNetworkChanged( | 908 void NetworkStateHandler::NotifyDefaultNetworkChanged( |
891 const NetworkState* default_network) { | 909 const NetworkState* default_network) { |
892 SCOPED_NET_LOG_IF_SLOW(); | 910 SCOPED_NET_LOG_IF_SLOW(); |
893 NET_LOG_EVENT("NOTIFY:DefaultNetworkChanged", GetLogName(default_network)); | 911 NET_LOG_EVENT("NOTIFY:DefaultNetworkChanged", GetLogName(default_network)); |
894 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 912 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
895 DefaultNetworkChanged(default_network)); | 913 DefaultNetworkChanged(default_network)); |
896 } | 914 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 if (type.MatchesType(shill::kTypeBluetooth)) | 974 if (type.MatchesType(shill::kTypeBluetooth)) |
957 technologies.push_back(new std::string(shill::kTypeBluetooth)); | 975 technologies.push_back(new std::string(shill::kTypeBluetooth)); |
958 if (type.MatchesType(shill::kTypeVPN)) | 976 if (type.MatchesType(shill::kTypeVPN)) |
959 technologies.push_back(new std::string(shill::kTypeVPN)); | 977 technologies.push_back(new std::string(shill::kTypeVPN)); |
960 | 978 |
961 CHECK_GT(technologies.size(), 0ul); | 979 CHECK_GT(technologies.size(), 0ul); |
962 return technologies.Pass(); | 980 return technologies.Pass(); |
963 } | 981 } |
964 | 982 |
965 } // namespace chromeos | 983 } // namespace chromeos |
OLD | NEW |