| 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" |
| 16 #include "net/base/network_change_notifier.h" | 17 #include "net/base/network_change_notifier.h" |
| 17 #include "net/dns/dns_config_service_posix.h" | 18 #include "net/dns/dns_config_service_posix.h" |
| 18 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 19 | 20 |
| 20 namespace chromeos { | 21 namespace chromeos { |
| 21 | 22 |
| 22 // DNS config services on Chrome OS are signalled by the network state handler | 23 // DNS config services on Chrome OS are signalled by the network state handler |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 NetworkHandler::Get()->network_state_handler()->RemoveObserver( | 77 NetworkHandler::Get()->network_state_handler()->RemoveObserver( |
| 77 this, FROM_HERE); | 78 this, FROM_HERE); |
| 78 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); | 79 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
| 79 } | 80 } |
| 80 | 81 |
| 81 net::NetworkChangeNotifier::ConnectionType | 82 net::NetworkChangeNotifier::ConnectionType |
| 82 NetworkChangeNotifierChromeos::GetCurrentConnectionType() const { | 83 NetworkChangeNotifierChromeos::GetCurrentConnectionType() const { |
| 83 return connection_type_; | 84 return connection_type_; |
| 84 } | 85 } |
| 85 | 86 |
| 87 bool NetworkChangeNotifierChromeos::GetCurrentWifiApInfo( |
| 88 net::NetworkChangeNotifier::WifiApInfo *info) { |
| 89 if (connection_type_ != CONNECTION_WIFI) |
| 90 return false; |
| 91 |
| 92 *info = wifi_ap_info_; |
| 93 return true; |
| 94 } |
| 95 |
| 86 void NetworkChangeNotifierChromeos::SuspendDone( | 96 void NetworkChangeNotifierChromeos::SuspendDone( |
| 87 const base::TimeDelta& sleep_duration) { | 97 const base::TimeDelta& sleep_duration) { |
| 88 // Force invalidation of network resources on resume. | 98 // Force invalidation of network resources on resume. |
| 89 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); | 99 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); |
| 90 } | 100 } |
| 91 | 101 |
| 92 | 102 |
| 93 void NetworkChangeNotifierChromeos::DefaultNetworkChanged( | 103 void NetworkChangeNotifierChromeos::DefaultNetworkChanged( |
| 94 const chromeos::NetworkState* default_network) { | 104 const chromeos::NetworkState* default_network) { |
| 95 bool connection_type_changed = false; | 105 bool connection_type_changed = false; |
| 96 bool ip_address_changed = false; | 106 bool ip_address_changed = false; |
| 97 bool dns_changed = false; | 107 bool dns_changed = false; |
| 98 | 108 |
| 99 UpdateState(default_network, &connection_type_changed, | 109 UpdateState(default_network, &connection_type_changed, |
| 100 &ip_address_changed, &dns_changed); | 110 &ip_address_changed, &dns_changed); |
| 101 | 111 |
| 102 if (connection_type_changed) | 112 if (connection_type_changed) |
| 103 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange(); | 113 NetworkChangeNotifier::NotifyObserversOfConnectionTypeChange(); |
| 104 if (ip_address_changed) | 114 if (ip_address_changed) |
| 105 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); | 115 NetworkChangeNotifier::NotifyObserversOfIPAddressChange(); |
| 106 if (dns_changed) | 116 if (dns_changed) |
| 107 dns_config_service_->OnNetworkChange(); | 117 dns_config_service_->OnNetworkChange(); |
| 118 |
| 119 // Retrieve AP info for wifi connection. |
| 120 if (connection_type_ == CONNECTION_WIFI) { |
| 121 NetworkHandler::Get()->network_configuration_handler()->GetProperties( |
| 122 default_network->path(), |
| 123 base::Bind(&NetworkChangeNotifierChromeos::ParseWifiApInfo, |
| 124 AsWeakPtr()), |
| 125 network_handler::ErrorCallback()); |
| 126 } |
| 127 } |
| 128 |
| 129 void NetworkChangeNotifierChromeos::ParseWifiApInfo( |
| 130 const std::string &service_path, |
| 131 const base::DictionaryValue& properties) { |
| 132 // Return if not the current service. |
| 133 if (service_path != service_path_) |
| 134 return; |
| 135 |
| 136 // Reset AP info. |
| 137 wifi_ap_info_ = net::NetworkChangeNotifier::WifiApInfo(); |
| 138 // Parse security info. |
| 139 std::string security; |
| 140 properties.GetStringWithoutPathExpansion( |
| 141 shill::kSecurityProperty, &security); |
| 142 wifi_ap_info_.security = WIFI_SECURITY_UNKNOWN; |
| 143 if (security == shill::kSecurityWpa) |
| 144 wifi_ap_info_.security = WIFI_SECURITY_WPA; |
| 145 else if (security == shill::kSecurityWep) |
| 146 wifi_ap_info_.security = WIFI_SECURITY_WEP; |
| 147 else if (security == shill::kSecurityRsn) |
| 148 wifi_ap_info_.security = WIFI_SECURITY_RSN; |
| 149 else if (security == shill::kSecurity8021x) |
| 150 wifi_ap_info_.security = WIFI_SECURITY_802_1X; |
| 151 else if (security == shill::kSecurityPsk) |
| 152 wifi_ap_info_.security = WIFI_SECURITY_PSK; |
| 153 else if (security == shill::kSecurityNone) |
| 154 wifi_ap_info_.security = WIFI_SECURITY_NONE; |
| 155 |
| 156 properties.GetStringWithoutPathExpansion( |
| 157 shill::kWifiBSsid, &wifi_ap_info_.bssid); |
| 158 const base::DictionaryValue* vendor_dict = NULL; |
| 159 if (properties.GetDictionaryWithoutPathExpansion( |
| 160 shill::kWifiVendorInformationProperty, |
| 161 &vendor_dict)) { |
| 162 vendor_dict->GetStringWithoutPathExpansion( |
| 163 shill::kVendorWPSModelNumberProperty, |
| 164 &wifi_ap_info_.model_number); |
| 165 vendor_dict->GetStringWithoutPathExpansion( |
| 166 shill::kVendorWPSModelNameProperty, |
| 167 &wifi_ap_info_.model_name); |
| 168 vendor_dict->GetStringWithoutPathExpansion( |
| 169 shill::kVendorWPSDeviceNameProperty, |
| 170 &wifi_ap_info_.device_name); |
| 171 vendor_dict->GetStringWithoutPathExpansion(shill::kVendorOUIListProperty, |
| 172 &wifi_ap_info_.oui_list); |
| 173 } |
| 108 } | 174 } |
| 109 | 175 |
| 110 void NetworkChangeNotifierChromeos::UpdateState( | 176 void NetworkChangeNotifierChromeos::UpdateState( |
| 111 const chromeos::NetworkState* default_network, | 177 const chromeos::NetworkState* default_network, |
| 112 bool* connection_type_changed, | 178 bool* connection_type_changed, |
| 113 bool* ip_address_changed, | 179 bool* ip_address_changed, |
| 114 bool* dns_changed) { | 180 bool* dns_changed) { |
| 115 *connection_type_changed = false; | 181 *connection_type_changed = false; |
| 116 *ip_address_changed = false; | 182 *ip_address_changed = false; |
| 117 *dns_changed = false; | 183 *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. | 297 // produce a single signal when switching between network connections. |
| 232 params.ip_address_offline_delay_ = base::TimeDelta::FromMilliseconds(4000); | 298 params.ip_address_offline_delay_ = base::TimeDelta::FromMilliseconds(4000); |
| 233 params.ip_address_online_delay_ = base::TimeDelta::FromMilliseconds(1000); | 299 params.ip_address_online_delay_ = base::TimeDelta::FromMilliseconds(1000); |
| 234 params.connection_type_offline_delay_ = | 300 params.connection_type_offline_delay_ = |
| 235 base::TimeDelta::FromMilliseconds(500); | 301 base::TimeDelta::FromMilliseconds(500); |
| 236 params.connection_type_online_delay_ = base::TimeDelta::FromMilliseconds(500); | 302 params.connection_type_online_delay_ = base::TimeDelta::FromMilliseconds(500); |
| 237 return params; | 303 return params; |
| 238 } | 304 } |
| 239 | 305 |
| 240 } // namespace chromeos | 306 } // namespace chromeos |
| OLD | NEW |