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 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
757 | 757 |
758 void NetworkStateHandler::DefaultNetworkServiceChanged( | 758 void NetworkStateHandler::DefaultNetworkServiceChanged( |
759 const std::string& service_path) { | 759 const std::string& service_path) { |
760 // Shill uses '/' for empty service path values; check explicitly for that. | 760 // Shill uses '/' for empty service path values; check explicitly for that. |
761 const char* kEmptyServicePath = "/"; | 761 const char* kEmptyServicePath = "/"; |
762 std::string new_service_path = | 762 std::string new_service_path = |
763 (service_path != kEmptyServicePath) ? service_path : ""; | 763 (service_path != kEmptyServicePath) ? service_path : ""; |
764 if (new_service_path == default_network_path_) | 764 if (new_service_path == default_network_path_) |
765 return; | 765 return; |
766 | 766 |
767 default_network_path_ = service_path; | 767 default_network_path_ = service_path; |
pneubeck (no reviews)
2015/03/12 09:57:48
Not that it is affecting this CL, but just a remin
stevenjb
2015/03/12 16:42:28
Yes, that is true. I've limited the notifications
| |
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: " |
pneubeck (no reviews)
2015/03/12 09:57:48
missing '<<' after NET_LOG(EVENT) ?
how can this
stevenjb
2015/03/12 16:42:28
It doesn't. Last second change to use the same LOG
| |
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 NET_LOG(EVENT) << "DefaultNetwork is not connected: " << GetLogName(network) |
782 "DefaultNetwork is not connected: " + network->connection_state(), | 782 << ": " << network->connection_state(); |
783 network->path()); | 783 // Do not notify observers here, the notification will occur when the |
pneubeck (no reviews)
2015/03/12 09:57:48
is it worth logging an error here if the state is
stevenjb
2015/03/12 16:42:28
Yes, done.
| |
784 // connection state changes. | |
Paul Stewart
2015/03/11 23:29:03
Awesome. This might fix some page load attempts b
stevenjb
2015/03/12 16:42:28
I hope so!
| |
785 return; | |
784 } | 786 } |
785 NotifyDefaultNetworkChanged(network); | 787 NotifyDefaultNetworkChanged(network); |
786 } | 788 } |
787 | 789 |
788 //------------------------------------------------------------------------------ | 790 //------------------------------------------------------------------------------ |
789 // Private methods | 791 // Private methods |
790 | 792 |
791 void NetworkStateHandler::UpdateGuid(NetworkState* network) { | 793 void NetworkStateHandler::UpdateGuid(NetworkState* network) { |
792 std::string specifier = network->GetSpecifier(); | 794 std::string specifier = network->GetSpecifier(); |
793 DCHECK(!specifier.empty()); | 795 DCHECK(!specifier.empty()); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
860 return &device_list_; | 862 return &device_list_; |
861 } | 863 } |
862 NOTREACHED(); | 864 NOTREACHED(); |
863 return nullptr; | 865 return nullptr; |
864 } | 866 } |
865 | 867 |
866 void NetworkStateHandler::OnNetworkConnectionStateChanged( | 868 void NetworkStateHandler::OnNetworkConnectionStateChanged( |
867 NetworkState* network) { | 869 NetworkState* network) { |
868 SCOPED_NET_LOG_IF_SLOW(); | 870 SCOPED_NET_LOG_IF_SLOW(); |
869 DCHECK(network); | 871 DCHECK(network); |
870 std::string event = "NetworkConnectionStateChanged"; | 872 bool notify_default = false; |
871 if (network->path() == default_network_path_) { | 873 if (network->path() == default_network_path_) { |
872 event = "Default" + event; | 874 if (network->IsConnectedState()) { |
873 if (!network->IsConnectedState()) { | 875 notify_default = true; |
874 NET_LOG_EVENT( | 876 } else if (network->IsConnectingState()) { |
875 "DefaultNetwork is not connected: " + network->connection_state(), | 877 // Wait until the network is actually connected to notify that the default |
876 network->path()); | 878 // network changed. |
879 NET_LOG(EVENT) << "Default network is not connected: " | |
880 << GetLogName(network) | |
881 << "State: " << network->connection_state(); | |
882 } else { | |
883 NET_LOG(ERROR) << "Default network in unexpected state: " | |
884 << GetLogName(network) | |
885 << "State: " << network->connection_state(); | |
877 default_network_path_.clear(); | 886 default_network_path_.clear(); |
878 SortNetworkList(); | 887 SortNetworkList(); |
879 NotifyDefaultNetworkChanged(nullptr); | 888 NotifyDefaultNetworkChanged(nullptr); |
880 } | 889 } |
881 } | 890 } |
882 NET_LOG_EVENT("NOTIFY:" + event + ": " + network->connection_state(), | 891 std::string desc = "NetworkConnectionStateChanged"; |
883 GetLogName(network)); | 892 if (notify_default) |
pneubeck (no reviews)
2015/03/12 09:57:48
the log message should always use the prefix 'Defa
stevenjb
2015/03/12 16:42:28
My intention is to have the log match the *notific
pneubeck (no reviews)
2015/03/12 19:40:09
ok, makes sense.
| |
893 desc = "Default" + desc; | |
894 NET_LOG(EVENT) << "NOTIFY: " << desc << ": " << GetLogName(network) << ": " | |
895 << network->connection_state(); | |
884 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 896 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
885 NetworkConnectionStateChanged(network)); | 897 NetworkConnectionStateChanged(network)); |
886 if (network->path() == default_network_path_) | 898 if (notify_default) |
887 NotifyDefaultNetworkChanged(network); | 899 NotifyDefaultNetworkChanged(network); |
888 } | 900 } |
889 | 901 |
890 void NetworkStateHandler::NotifyDefaultNetworkChanged( | 902 void NetworkStateHandler::NotifyDefaultNetworkChanged( |
891 const NetworkState* default_network) { | 903 const NetworkState* default_network) { |
892 SCOPED_NET_LOG_IF_SLOW(); | 904 SCOPED_NET_LOG_IF_SLOW(); |
893 NET_LOG_EVENT("NOTIFY:DefaultNetworkChanged", GetLogName(default_network)); | 905 NET_LOG_EVENT("NOTIFY:DefaultNetworkChanged", GetLogName(default_network)); |
894 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, | 906 FOR_EACH_OBSERVER(NetworkStateHandlerObserver, observers_, |
895 DefaultNetworkChanged(default_network)); | 907 DefaultNetworkChanged(default_network)); |
896 } | 908 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
956 if (type.MatchesType(shill::kTypeBluetooth)) | 968 if (type.MatchesType(shill::kTypeBluetooth)) |
957 technologies.push_back(new std::string(shill::kTypeBluetooth)); | 969 technologies.push_back(new std::string(shill::kTypeBluetooth)); |
958 if (type.MatchesType(shill::kTypeVPN)) | 970 if (type.MatchesType(shill::kTypeVPN)) |
959 technologies.push_back(new std::string(shill::kTypeVPN)); | 971 technologies.push_back(new std::string(shill::kTypeVPN)); |
960 | 972 |
961 CHECK_GT(technologies.size(), 0ul); | 973 CHECK_GT(technologies.size(), 0ul); |
962 return technologies.Pass(); | 974 return technologies.Pass(); |
963 } | 975 } |
964 | 976 |
965 } // namespace chromeos | 977 } // namespace chromeos |
OLD | NEW |