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" |
| 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) { | |
|
stevenjb
2014/07/08 00:24:53
*info
zqiu1
2014/07/08 20:47:53
Done.
| |
| 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) { | |
|
stevenjb
2014/07/08 00:24:53
Verify that service_path == service_path_, since t
zqiu1
2014/07/08 20:47:53
Done.
| |
| 132 net::NetworkChangeNotifier::WifiApInfo info; | |
| 133 | |
| 134 // Parse security info. | |
| 135 std::string security; | |
| 136 properties.GetStringWithoutPathExpansion( | |
| 137 shill::kSecurityProperty, &security); | |
| 138 info.security = WIFI_SECURITY_UNKNOWN; | |
| 139 if (security == shill::kSecurityWpa) | |
| 140 info.security = WIFI_SECURITY_WPA; | |
| 141 else if (security == shill::kSecurityWep) | |
| 142 info.security = WIFI_SECURITY_WEP; | |
| 143 else if (security == shill::kSecurityRsn) | |
| 144 info.security = WIFI_SECURITY_RSN; | |
| 145 else if (security == shill::kSecurity8021x) | |
| 146 info.security = WIFI_SECURITY_802_1X; | |
| 147 else if (security == shill::kSecurityPsk) | |
| 148 info.security = WIFI_SECURITY_PSK; | |
| 149 else if (security == shill::kSecurityNone) | |
| 150 info.security = WIFI_SECURITY_NONE; | |
| 151 | |
| 152 properties.GetStringWithoutPathExpansion( | |
| 153 shill::kWifiBSsid, &info.bssid); | |
| 154 const base::DictionaryValue* vendor_dict = NULL; | |
| 155 if (properties.GetDictionaryWithoutPathExpansion( | |
| 156 shill::kWifiVendorInformationProperty, | |
| 157 &vendor_dict)) { | |
| 158 vendor_dict->GetStringWithoutPathExpansion( | |
| 159 shill::kVendorWPSModelNumberProperty, | |
| 160 &info.model_number); | |
| 161 vendor_dict->GetStringWithoutPathExpansion( | |
| 162 shill::kVendorWPSModelNameProperty, | |
| 163 &info.model_name); | |
| 164 vendor_dict->GetStringWithoutPathExpansion( | |
| 165 shill::kVendorWPSDeviceNameProperty, | |
| 166 &info.device_name); | |
| 167 vendor_dict->GetStringWithoutPathExpansion(shill::kVendorOUIListProperty, | |
| 168 &info.oui_list); | |
| 169 } | |
| 170 wifi_ap_info_ = info; | |
|
stevenjb
2014/07/08 00:24:53
Why copy this instead of updating wifi_ap_info_ di
zqiu1
2014/07/08 20:47:53
The original intent was to make sure the fields in
| |
| 108 } | 171 } |
| 109 | 172 |
| 110 void NetworkChangeNotifierChromeos::UpdateState( | 173 void NetworkChangeNotifierChromeos::UpdateState( |
| 111 const chromeos::NetworkState* default_network, | 174 const chromeos::NetworkState* default_network, |
| 112 bool* connection_type_changed, | 175 bool* connection_type_changed, |
| 113 bool* ip_address_changed, | 176 bool* ip_address_changed, |
| 114 bool* dns_changed) { | 177 bool* dns_changed) { |
| 115 *connection_type_changed = false; | 178 *connection_type_changed = false; |
| 116 *ip_address_changed = false; | 179 *ip_address_changed = false; |
| 117 *dns_changed = false; | 180 *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. | 294 // produce a single signal when switching between network connections. |
| 232 params.ip_address_offline_delay_ = base::TimeDelta::FromMilliseconds(4000); | 295 params.ip_address_offline_delay_ = base::TimeDelta::FromMilliseconds(4000); |
| 233 params.ip_address_online_delay_ = base::TimeDelta::FromMilliseconds(1000); | 296 params.ip_address_online_delay_ = base::TimeDelta::FromMilliseconds(1000); |
| 234 params.connection_type_offline_delay_ = | 297 params.connection_type_offline_delay_ = |
| 235 base::TimeDelta::FromMilliseconds(500); | 298 base::TimeDelta::FromMilliseconds(500); |
| 236 params.connection_type_online_delay_ = base::TimeDelta::FromMilliseconds(500); | 299 params.connection_type_online_delay_ = base::TimeDelta::FromMilliseconds(500); |
| 237 return params; | 300 return params; |
| 238 } | 301 } |
| 239 | 302 |
| 240 } // namespace chromeos | 303 } // namespace chromeos |
| OLD | NEW |