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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
| 12 #include "chromeos/network/network_change_notifier_chromeos.h" | 12 #include "chromeos/network/network_change_notifier_chromeos.h" |
| 13 #include "chromeos/network/network_configuration_handler.h" | |
| 13 #include "chromeos/network/network_event_log.h" | 14 #include "chromeos/network/network_event_log.h" |
| 14 #include "chromeos/network/network_state.h" | 15 #include "chromeos/network/network_state.h" |
| 15 #include "chromeos/network/network_state_handler.h" | 16 #include "chromeos/network/network_state_handler.h" |
| 17 #include "chromeos/network/shill_property_util.h" | |
| 16 #include "net/base/network_change_notifier.h" | 18 #include "net/base/network_change_notifier.h" |
| 17 #include "net/dns/dns_config_service_posix.h" | 19 #include "net/dns/dns_config_service_posix.h" |
| 18 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 19 | 21 |
| 20 namespace chromeos { | 22 namespace chromeos { |
| 21 | 23 |
| 22 // DNS config services on Chrome OS are signalled by the network state handler | 24 // DNS config services on Chrome OS are signalled by the network state handler |
| 23 // rather than relying on watching files in /etc. | 25 // rather than relying on watching files in /etc. |
| 24 class NetworkChangeNotifierChromeos::DnsConfigService | 26 class NetworkChangeNotifierChromeos::DnsConfigService |
| 25 : public net::internal::DnsConfigServicePosix { | 27 : public net::internal::DnsConfigServicePosix { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 NetworkHandler::Get()->network_state_handler()->RemoveObserver( | 78 NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
| 77 this, FROM_HERE); | 79 this, FROM_HERE); |
| 78 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 80 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
| 79 } | 81 } |
| 80 | 82 |
| 81 net::NetworkChangeNotifier::ConnectionType | 83 net::NetworkChangeNotifier::ConnectionType |
| 82 NetworkChangeNotifierChromeos::GetCurrentConnectionType() const { | 84 NetworkChangeNotifierChromeos::GetCurrentConnectionType() const { |
| 83 return connection_type_; | 85 return connection_type_; |
| 84 } | 86 } |
| 85 | 87 |
| 88 bool NetworkChangeNotifierChromeos::GetCurrentWifiAccessPointInfo( | |
| 89 net::NetworkChangeNotifier::WifiAccessPointInfo* info) { | |
| 90 // Wifi access point information is not provided if the BSSID is empty. | |
| 91 // This assumes the BSSID is never empty when access point information exists. | |
| 92 if (wifi_ap_info_.bssid.empty()) | |
| 93 return false; | |
| 94 | |
| 95 *info = wifi_ap_info_; | |
| 96 return true; | |
| 97 } | |
| 98 | |
| 86 void NetworkChangeNotifierChromeos::SuspendDone( | 99 void NetworkChangeNotifierChromeos::SuspendDone( |
| 87 const base::TimeDelta& sleep_duration) { | 100 const base::TimeDelta& sleep_duration) { |
| 88 // Force invalidation of network resources on resume. | 101 // Force invalidation of network resources on resume. |
| 89 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); | 102 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); |
| 90 } | 103 } |
| 91 | 104 |
| 92 | 105 |
| 93 void NetworkChangeNotifierChromeos::DefaultNetworkChanged( | 106 void NetworkChangeNotifierChromeos::DefaultNetworkChanged( |
| 94 const chromeos::NetworkState* default_network) { | 107 const chromeos::NetworkState* default_network) { |
| 95 bool connection_type_changed = false; | 108 bool connection_type_changed = false; |
| 96 bool ip_address_changed = false; | 109 bool ip_address_changed = false; |
| 97 bool dns_changed = false; | 110 bool dns_changed = false; |
| 98 | 111 |
| 99 UpdateState(default_network, &connection_type_changed, | 112 UpdateState(default_network, &connection_type_changed, |
| 100 &ip_address_changed, &dns_changed); | 113 &ip_address_changed, &dns_changed); |
| 101 | 114 |
| 102 if (connection_type_changed) | 115 if (connection_type_changed) |
| 103 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange(); | 116 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange(); |
| 104 if (ip_address_changed) | 117 if (ip_address_changed) |
| 105 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); | 118 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); |
| 106 if (dns_changed) | 119 if (dns_changed) |
| 107 dns_config_service_->OnNetworkChange(); | 120 dns_config_service_->OnNetworkChange(); |
| 121 | |
| 122 // Reset access point info to prevent reporting of out-dated data. | |
| 123 wifi_ap_info_ = net::NetworkChangeNotifier::WifiAccessPointInfo(); | |
| 124 | |
| 125 // Retrieve access point info for wifi connection. | |
| 126 if (connection_type_ == CONNECTION_WIFI) { | |
| 127 NetworkHandler::Get()->network_configuration_handler()->GetProperties( | |
| 128 default_network->path(), | |
| 129 base::Bind(&NetworkChangeNotifierChromeos::ParseWifiAccessPointInfo, | |
| 130 AsWeakPtr()), | |
| 131 network_handler::ErrorCallback()); | |
| 132 } | |
| 133 } | |
| 134 | |
| 135 void NetworkChangeNotifierChromeos::ParseWifiAccessPointInfo( | |
| 136 const std::string &service_path, | |
| 137 const base::DictionaryValue& properties) { | |
| 138 // Return if not the current service. | |
| 139 if (service_path != service_path_) | |
| 140 return; | |
| 141 | |
| 142 // Skip services that contain "_nomap" in the SSID. | |
| 143 std::string ssid = shill_property_util::GetSSIDFromProperties( | |
| 144 properties, NULL); | |
| 145 if (ssid.find("_nomap", 0) != std::string::npos) | |
| 146 return; | |
| 147 | |
| 148 // Parse security info. | |
| 149 std::string security; | |
| 150 properties.GetStringWithoutPathExpansion( | |
| 151 shill::kSecurityProperty, &security); | |
| 152 wifi_ap_info_.security = WIFI_SECURITY_UNKNOWN; | |
| 153 if (security == shill::kSecurityWpa) | |
| 154 wifi_ap_info_.security = WIFI_SECURITY_WPA; | |
| 155 else if (security == shill::kSecurityWep) | |
| 156 wifi_ap_info_.security = WIFI_SECURITY_WEP; | |
| 157 else if (security == shill::kSecurityRsn) | |
| 158 wifi_ap_info_.security = WIFI_SECURITY_RSN; | |
| 159 else if (security == shill::kSecurity8021x) | |
| 160 wifi_ap_info_.security = WIFI_SECURITY_802_1X; | |
| 161 else if (security == shill::kSecurityPsk) | |
| 162 wifi_ap_info_.security = WIFI_SECURITY_PSK; | |
| 163 else if (security == shill::kSecurityNone) | |
| 164 wifi_ap_info_.security = WIFI_SECURITY_NONE; | |
| 165 | |
| 166 properties.GetStringWithoutPathExpansion( | |
| 167 shill::kWifiBSsid, &wifi_ap_info_.bssid); | |
| 168 const base::DictionaryValue* vendor_dict = NULL; | |
| 169 if (properties.GetDictionaryWithoutPathExpansion( | |
| 170 shill::kWifiVendorInformationProperty, | |
| 171 &vendor_dict)) { | |
|
stevenjb
2014/07/15 18:16:14
nit: early exit
zqiu1
2014/07/15 19:34:02
Done.
| |
| 172 vendor_dict->GetStringWithoutPathExpansion( | |
| 173 shill::kVendorWPSModelNumberProperty, | |
| 174 &wifi_ap_info_.model_number); | |
| 175 vendor_dict->GetStringWithoutPathExpansion( | |
| 176 shill::kVendorWPSModelNameProperty, | |
| 177 &wifi_ap_info_.model_name); | |
| 178 vendor_dict->GetStringWithoutPathExpansion( | |
| 179 shill::kVendorWPSDeviceNameProperty, | |
| 180 &wifi_ap_info_.device_name); | |
| 181 vendor_dict->GetStringWithoutPathExpansion(shill::kVendorOUIListProperty, | |
| 182 &wifi_ap_info_.oui_list); | |
| 183 } | |
| 108 } | 184 } |
| 109 | 185 |
| 110 void NetworkChangeNotifierChromeos::UpdateState( | 186 void NetworkChangeNotifierChromeos::UpdateState( |
| 111 const chromeos::NetworkState* default_network, | 187 const chromeos::NetworkState* default_network, |
| 112 bool* connection_type_changed, | 188 bool* connection_type_changed, |
| 113 bool* ip_address_changed, | 189 bool* ip_address_changed, |
| 114 bool* dns_changed) { | 190 bool* dns_changed) { |
| 115 *connection_type_changed = false; | 191 *connection_type_changed = false; |
| 116 *ip_address_changed = false; | 192 *ip_address_changed = false; |
| 117 *dns_changed = false; | 193 *dns_changed = false; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 // produce a single signal when switching between network connections. | 307 // produce a single signal when switching between network connections. |
| 232 params.ip_address_offline_delay_ = base::TimeDelta::FromMilliseconds(4000); | 308 params.ip_address_offline_delay_ = base::TimeDelta::FromMilliseconds(4000); |
| 233 params.ip_address_online_delay_ = base::TimeDelta::FromMilliseconds(1000); | 309 params.ip_address_online_delay_ = base::TimeDelta::FromMilliseconds(1000); |
| 234 params.connection_type_offline_delay_ = | 310 params.connection_type_offline_delay_ = |
| 235 base::TimeDelta::FromMilliseconds(500); | 311 base::TimeDelta::FromMilliseconds(500); |
| 236 params.connection_type_online_delay_ = base::TimeDelta::FromMilliseconds(500); | 312 params.connection_type_online_delay_ = base::TimeDelta::FromMilliseconds(500); |
| 237 return params; | 313 return params; |
| 238 } | 314 } |
| 239 | 315 |
| 240 } // namespace chromeos | 316 } // namespace chromeos |
| OLD | NEW |