OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/cros/network_library.h" | 5 #include "chrome/browser/chromeos/cros/network_library.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/i18n/icu_encoding_detection.h" | 11 #include "base/i18n/icu_encoding_detection.h" |
12 #include "base/i18n/icu_string_conversions.h" | 12 #include "base/i18n/icu_string_conversions.h" |
13 #include "base/i18n/time_formatting.h" | 13 #include "base/i18n/time_formatting.h" |
14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
17 #include "base/string_tokenizer.h" | 17 #include "base/string_tokenizer.h" |
18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
19 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
21 #include "base/utf_string_conversion_utils.h" | 21 #include "base/utf_string_conversion_utils.h" |
22 #include "base/values.h" | 22 #include "base/values.h" |
23 #include "chrome/browser/chromeos/cros/cros_library.h" | 23 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 24 #include "chrome/browser/chromeos/cros/native_network_constants.h" |
| 25 #include "chrome/browser/chromeos/cros/native_network_parser.h" |
24 #include "chrome/browser/chromeos/login/user_manager.h" | 26 #include "chrome/browser/chromeos/login/user_manager.h" |
25 #include "chrome/browser/chromeos/network_login_observer.h" | 27 #include "chrome/browser/chromeos/network_login_observer.h" |
26 #include "chrome/browser/chromeos/user_cros_settings_provider.h" | 28 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
27 #include "chrome/common/time_format.h" | 29 #include "chrome/common/time_format.h" |
28 #include "content/browser/browser_thread.h" | 30 #include "content/browser/browser_thread.h" |
29 #include "crypto/nss_util.h" // crypto::GetTPMTokenInfo() for 802.1X and VPN. | 31 #include "crypto/nss_util.h" // crypto::GetTPMTokenInfo() for 802.1X and VPN. |
30 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
31 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
32 #include "ui/base/text/bytes_formatting.h" | 34 #include "ui/base/text/bytes_formatting.h" |
33 | 35 |
34 //////////////////////////////////////////////////////////////////////////////// | 36 //////////////////////////////////////////////////////////////////////////////// |
35 // Implementation notes. | 37 // Implementation notes. |
36 // NetworkLibraryImpl manages a series of classes that describe network devices | 38 // NetworkLibraryImpl manages a series of classes that describe network devices |
37 // and services: | 39 // and services: |
38 // | 40 // |
39 // NetworkDevice: e.g. ethernet, wifi modem, cellular modem | 41 // NetworkDevice: e.g. ethernet, wifi modem, cellular modem |
40 // device_map_: canonical map<path,NetworkDevice*> for devices | 42 // device_map_: canonical map<path, NetworkDevice*> for devices |
41 // | 43 // |
42 // Network: a network service ("network"). | 44 // Network: a network service ("network"). |
43 // network_map_: canonical map<path,Network*> for all visible networks. | 45 // network_map_: canonical map<path, Network*> for all visible networks. |
44 // EthernetNetwork | 46 // EthernetNetwork |
45 // ethernet_: EthernetNetwork* to the active ethernet network in network_map_. | 47 // ethernet_: EthernetNetwork* to the active ethernet network in network_map_. |
46 // WirelessNetwork: a WiFi or Cellular Network. | 48 // WirelessNetwork: a WiFi or Cellular Network. |
47 // WifiNetwork | 49 // WifiNetwork |
48 // active_wifi_: WifiNetwork* to the active wifi network in network_map_. | 50 // active_wifi_: WifiNetwork* to the active wifi network in network_map_. |
49 // wifi_networks_: ordered vector of WifiNetwork* entries in network_map_, | 51 // wifi_networks_: ordered vector of WifiNetwork* entries in network_map_, |
50 // in descending order of importance. | 52 // in descending order of importance. |
51 // CellularNetwork | 53 // CellularNetwork |
52 // active_cellular_: Cellular version of wifi_. | 54 // active_cellular_: Cellular version of wifi_. |
53 // cellular_networks_: Cellular version of wifi_. | 55 // cellular_networks_: Cellular version of wifi_. |
54 // network_unique_id_map_: map<unique_id,Network*> for visible networks. | 56 // network_unique_id_map_: map<unique_id, Network*> for visible networks. |
55 // remembered_network_map_: a canonical map<path,Network*> for all networks | 57 // remembered_network_map_: a canonical map<path, Network*> for all networks |
56 // remembered in the active Profile ("favorites"). | 58 // remembered in the active Profile ("favorites"). |
57 // remembered_wifi_networks_: ordered vector of WifiNetwork* entries in | 59 // remembered_wifi_networks_: ordered vector of WifiNetwork* entries in |
58 // remembered_network_map_, in descending order of preference. | 60 // remembered_network_map_, in descending order of preference. |
59 // remembered_virtual_networks_: ordered vector of VirtualNetwork* entries in | 61 // remembered_virtual_networks_: ordered vector of VirtualNetwork* entries in |
60 // remembered_network_map_, in descending order of preference. | 62 // remembered_network_map_, in descending order of preference. |
61 // | 63 // |
62 // network_manager_monitor_: a handle to the libcros network Manager handler. | 64 // network_manager_monitor_: a handle to the libcros network Manager handler. |
63 // NetworkManagerStatusChanged: This handles all messages from the Manager. | 65 // NetworkManagerStatusChanged: This handles all messages from the Manager. |
64 // Messages are parsed here and the appropriate updates are then requested. | 66 // Messages are parsed here and the appropriate updates are then requested. |
65 // | 67 // |
(...skipping 28 matching lines...) Expand all Loading... |
94 const int kNetworkNotifyDelayMs = 50; | 96 const int kNetworkNotifyDelayMs = 50; |
95 | 97 |
96 // How long we should remember that cellular plan payment was received. | 98 // How long we should remember that cellular plan payment was received. |
97 const int kRecentPlanPaymentHours = 6; | 99 const int kRecentPlanPaymentHours = 6; |
98 | 100 |
99 // Default value of the SIM unlock retries count. It is updated to the real | 101 // Default value of the SIM unlock retries count. It is updated to the real |
100 // retries count once cellular device with SIM card is initialized. | 102 // retries count once cellular device with SIM card is initialized. |
101 // If cellular device doesn't have SIM card, then retries are never used. | 103 // If cellular device doesn't have SIM card, then retries are never used. |
102 const int kDefaultSimUnlockRetriesCount = 999; | 104 const int kDefaultSimUnlockRetriesCount = 999; |
103 | 105 |
104 // Format of the Carrier ID: <carrier name> (<carrier country>). | |
105 const char kCarrierIdFormat[] = "%s (%s)"; | |
106 | |
107 // Path of the default (shared) flimflam profile. | |
108 const char kSharedProfilePath[] = "/profile/default"; | |
109 | |
110 // Type of a pending SIM operation. | |
111 enum SimOperationType { | |
112 SIM_OPERATION_NONE = 0, | |
113 SIM_OPERATION_CHANGE_PIN = 1, | |
114 SIM_OPERATION_CHANGE_REQUIRE_PIN = 2, | |
115 SIM_OPERATION_ENTER_PIN = 3, | |
116 SIM_OPERATION_UNBLOCK_PIN = 4, | |
117 }; | |
118 | |
119 // D-Bus interface string constants. | |
120 | |
121 // Flimflam manager properties. | |
122 const char kAvailableTechnologiesProperty[] = "AvailableTechnologies"; | |
123 const char kEnabledTechnologiesProperty[] = "EnabledTechnologies"; | |
124 const char kConnectedTechnologiesProperty[] = "ConnectedTechnologies"; | |
125 const char kDefaultTechnologyProperty[] = "DefaultTechnology"; | |
126 const char kOfflineModeProperty[] = "OfflineMode"; | |
127 const char kActiveProfileProperty[] = "ActiveProfile"; | |
128 const char kProfilesProperty[] = "Profiles"; | |
129 const char kServicesProperty[] = "Services"; | |
130 const char kServiceWatchListProperty[] = "ServiceWatchList"; | |
131 const char kDevicesProperty[] = "Devices"; | |
132 const char kPortalURLProperty[] = "PortalURL"; | |
133 const char kCheckPortalListProperty[] = "CheckPortalList"; | |
134 | |
135 // Flimflam service properties. | |
136 const char kSecurityProperty[] = "Security"; | |
137 const char kPassphraseProperty[] = "Passphrase"; | |
138 const char kIdentityProperty[] = "Identity"; | |
139 const char kPassphraseRequiredProperty[] = "PassphraseRequired"; | |
140 const char kSaveCredentialsProperty[] = "SaveCredentials"; | |
141 const char kSignalStrengthProperty[] = "Strength"; | |
142 const char kNameProperty[] = "Name"; | |
143 const char kStateProperty[] = "State"; | |
144 const char kTypeProperty[] = "Type"; | |
145 const char kDeviceProperty[] = "Device"; | |
146 const char kProfileProperty[] = "Profile"; | |
147 const char kTechnologyFamilyProperty[] = "Cellular.Family"; | |
148 const char kActivationStateProperty[] = "Cellular.ActivationState"; | |
149 const char kNetworkTechnologyProperty[] = "Cellular.NetworkTechnology"; | |
150 const char kRoamingStateProperty[] = "Cellular.RoamingState"; | |
151 const char kOperatorNameProperty[] = "Cellular.OperatorName"; | |
152 const char kOperatorCodeProperty[] = "Cellular.OperatorCode"; | |
153 const char kServingOperatorProperty[] = "Cellular.ServingOperator"; | |
154 const char kPaymentURLProperty[] = "Cellular.OlpUrl"; | |
155 const char kUsageURLProperty[] = "Cellular.UsageUrl"; | |
156 const char kCellularApnProperty[] = "Cellular.APN"; | |
157 const char kCellularLastGoodApnProperty[] = "Cellular.LastGoodAPN"; | |
158 const char kCellularApnListProperty[] = "Cellular.APNList"; | |
159 const char kWifiHexSsid[] = "WiFi.HexSSID"; | |
160 const char kWifiFrequency[] = "WiFi.Frequency"; | |
161 const char kWifiHiddenSsid[] = "WiFi.HiddenSSID"; | |
162 const char kWifiPhyMode[] = "WiFi.PhyMode"; | |
163 const char kWifiAuthMode[] = "WiFi.AuthMode"; | |
164 const char kFavoriteProperty[] = "Favorite"; | |
165 const char kConnectableProperty[] = "Connectable"; | |
166 const char kPriorityProperty[] = "Priority"; | |
167 const char kAutoConnectProperty[] = "AutoConnect"; | |
168 const char kIsActiveProperty[] = "IsActive"; | |
169 const char kModeProperty[] = "Mode"; | |
170 const char kErrorProperty[] = "Error"; | |
171 const char kEntriesProperty[] = "Entries"; | |
172 const char kProviderProperty[] = "Provider"; | |
173 const char kHostProperty[] = "Host"; | |
174 const char kProxyConfigProperty[] = "ProxyConfig"; | |
175 | |
176 // Flimflam property names for SIMLock status. | |
177 const char kSIMLockStatusProperty[] = "Cellular.SIMLockStatus"; | |
178 const char kSIMLockTypeProperty[] = "LockType"; | |
179 const char kSIMLockRetriesLeftProperty[] = "RetriesLeft"; | |
180 | |
181 // Flimflam property names for Cellular.FoundNetworks. | |
182 const char kLongNameProperty[] = "long_name"; | |
183 const char kStatusProperty[] = "status"; | |
184 const char kShortNameProperty[] = "short_name"; | |
185 const char kTechnologyProperty[] = "technology"; | |
186 const char kNetworkIdProperty[] = "network_id"; | |
187 | |
188 // Flimflam SIMLock status types. | |
189 const char kSIMLockPin[] = "sim-pin"; | |
190 const char kSIMLockPuk[] = "sim-puk"; | |
191 | |
192 // APN info property names. | |
193 const char kApnProperty[] = "apn"; | |
194 const char kApnNetworkIdProperty[] = "network_id"; | |
195 const char kApnUsernameProperty[] = "username"; | |
196 const char kApnPasswordProperty[] = "password"; | |
197 const char kApnNameProperty[] = "name"; | |
198 const char kApnLocalizedNameProperty[] = "localized_name"; | |
199 const char kApnLanguageProperty[] = "language"; | |
200 | |
201 // Operator info property names. | |
202 const char kOperatorNameKey[] = "name"; | |
203 const char kOperatorCodeKey[] = "code"; | |
204 const char kOperatorCountryKey[] = "country"; | |
205 | |
206 // Flimflam device info property names. | |
207 const char kScanningProperty[] = "Scanning"; | |
208 const char kPoweredProperty[] = "Powered"; | |
209 const char kNetworksProperty[] = "Networks"; | |
210 const char kCarrierProperty[] = "Cellular.Carrier"; | |
211 const char kCellularAllowRoamingProperty[] = "Cellular.AllowRoaming"; | |
212 const char kHomeProviderProperty[] = "Cellular.HomeProvider"; | |
213 const char kMeidProperty[] = "Cellular.MEID"; | |
214 const char kImeiProperty[] = "Cellular.IMEI"; | |
215 const char kImsiProperty[] = "Cellular.IMSI"; | |
216 const char kEsnProperty[] = "Cellular.ESN"; | |
217 const char kMdnProperty[] = "Cellular.MDN"; | |
218 const char kMinProperty[] = "Cellular.MIN"; | |
219 const char kModelIDProperty[] = "Cellular.ModelID"; | |
220 const char kManufacturerProperty[] = "Cellular.Manufacturer"; | |
221 const char kFirmwareRevisionProperty[] = "Cellular.FirmwareRevision"; | |
222 const char kHardwareRevisionProperty[] = "Cellular.HardwareRevision"; | |
223 const char kPRLVersionProperty[] = "Cellular.PRLVersion"; // (INT16) | |
224 const char kSelectedNetworkProperty[] = "Cellular.SelectedNetwork"; | |
225 const char kSupportNetworkScanProperty[] = "Cellular.SupportNetworkScan"; | |
226 const char kFoundNetworksProperty[] = "Cellular.FoundNetworks"; | |
227 | |
228 // Flimflam ip config property names. | |
229 const char kAddressProperty[] = "Address"; | |
230 const char kPrefixlenProperty[] = "Prefixlen"; | |
231 const char kGatewayProperty[] = "Gateway"; | |
232 const char kNameServersProperty[] = "NameServers"; | |
233 | |
234 // Flimflam type options. | |
235 const char kTypeEthernet[] = "ethernet"; | |
236 const char kTypeWifi[] = "wifi"; | |
237 const char kTypeWimax[] = "wimax"; | |
238 const char kTypeBluetooth[] = "bluetooth"; | |
239 const char kTypeCellular[] = "cellular"; | |
240 const char kTypeVPN[] = "vpn"; | |
241 | |
242 // Flimflam mode options. | |
243 const char kModeManaged[] = "managed"; | |
244 const char kModeAdhoc[] = "adhoc"; | |
245 | |
246 // Flimflam security options. | |
247 const char kSecurityWpa[] = "wpa"; | |
248 const char kSecurityWep[] = "wep"; | |
249 const char kSecurityRsn[] = "rsn"; | |
250 const char kSecurity8021x[] = "802_1x"; | |
251 const char kSecurityPsk[] = "psk"; | |
252 const char kSecurityNone[] = "none"; | |
253 | |
254 // Flimflam L2TPIPsec property names. | |
255 const char kL2TPIPSecCACertNSSProperty[] = "L2TPIPsec.CACertNSS"; | |
256 const char kL2TPIPSecClientCertIDProperty[] = "L2TPIPsec.ClientCertID"; | |
257 const char kL2TPIPSecClientCertSlotProp[] = "L2TPIPsec.ClientCertSlot"; | |
258 const char kL2TPIPSecPINProperty[] = "L2TPIPsec.PIN"; | |
259 const char kL2TPIPSecPSKProperty[] = "L2TPIPsec.PSK"; | |
260 const char kL2TPIPSecUserProperty[] = "L2TPIPsec.User"; | |
261 const char kL2TPIPSecPasswordProperty[] = "L2TPIPsec.Password"; | |
262 | |
263 // Flimflam EAP property names. | |
264 // See src/third_party/flimflam/doc/service-api.txt. | |
265 const char kEapIdentityProperty[] = "EAP.Identity"; | |
266 const char kEapMethodProperty[] = "EAP.EAP"; | |
267 const char kEapPhase2AuthProperty[] = "EAP.InnerEAP"; | |
268 const char kEapAnonymousIdentityProperty[] = "EAP.AnonymousIdentity"; | |
269 const char kEapClientCertProperty[] = "EAP.ClientCert"; // path | |
270 const char kEapCertIDProperty[] = "EAP.CertID"; // PKCS#11 ID | |
271 const char kEapClientCertNssProperty[] = "EAP.ClientCertNSS"; // NSS nickname | |
272 const char kEapPrivateKeyProperty[] = "EAP.PrivateKey"; | |
273 const char kEapPrivateKeyPasswordProperty[] = "EAP.PrivateKeyPassword"; | |
274 const char kEapKeyIDProperty[] = "EAP.KeyID"; | |
275 const char kEapCaCertProperty[] = "EAP.CACert"; // server CA cert path | |
276 const char kEapCaCertIDProperty[] = "EAP.CACertID"; // server CA PKCS#11 ID | |
277 const char kEapCaCertNssProperty[] = "EAP.CACertNSS"; // server CA NSS nickname | |
278 const char kEapUseSystemCAsProperty[] = "EAP.UseSystemCAs"; | |
279 const char kEapPinProperty[] = "EAP.PIN"; | |
280 const char kEapPasswordProperty[] = "EAP.Password"; | |
281 const char kEapKeyMgmtProperty[] = "EAP.KeyMgmt"; | |
282 | |
283 // Flimflam EAP method options. | |
284 const char kEapMethodPEAP[] = "PEAP"; | |
285 const char kEapMethodTLS[] = "TLS"; | |
286 const char kEapMethodTTLS[] = "TTLS"; | |
287 const char kEapMethodLEAP[] = "LEAP"; | |
288 | |
289 // Flimflam EAP phase 2 auth options. | |
290 const char kEapPhase2AuthPEAPMD5[] = "auth=MD5"; | |
291 const char kEapPhase2AuthPEAPMSCHAPV2[] = "auth=MSCHAPV2"; | |
292 const char kEapPhase2AuthTTLSMD5[] = "autheap=MD5"; | |
293 const char kEapPhase2AuthTTLSMSCHAPV2[] = "autheap=MSCHAPV2"; | |
294 const char kEapPhase2AuthTTLSMSCHAP[] = "autheap=MSCHAP"; | |
295 const char kEapPhase2AuthTTLSPAP[] = "autheap=PAP"; | |
296 const char kEapPhase2AuthTTLSCHAP[] = "autheap=CHAP"; | |
297 | |
298 // Flimflam VPN provider types. | |
299 const char kProviderL2tpIpsec[] = "l2tpipsec"; | |
300 const char kProviderOpenVpn[] = "openvpn"; | |
301 | |
302 | |
303 // Flimflam state options. | |
304 const char kStateIdle[] = "idle"; | |
305 const char kStateCarrier[] = "carrier"; | |
306 const char kStateAssociation[] = "association"; | |
307 const char kStateConfiguration[] = "configuration"; | |
308 const char kStateReady[] = "ready"; | |
309 const char kStatePortal[] = "portal"; | |
310 const char kStateOnline[] = "online"; | |
311 const char kStateDisconnect[] = "disconnect"; | |
312 const char kStateFailure[] = "failure"; | |
313 const char kStateActivationFailure[] = "activation-failure"; | |
314 | |
315 // Flimflam network technology options. | |
316 const char kNetworkTechnology1Xrtt[] = "1xRTT"; | |
317 const char kNetworkTechnologyEvdo[] = "EVDO"; | |
318 const char kNetworkTechnologyGprs[] = "GPRS"; | |
319 const char kNetworkTechnologyEdge[] = "EDGE"; | |
320 const char kNetworkTechnologyUmts[] = "UMTS"; | |
321 const char kNetworkTechnologyHspa[] = "HSPA"; | |
322 const char kNetworkTechnologyHspaPlus[] = "HSPA+"; | |
323 const char kNetworkTechnologyLte[] = "LTE"; | |
324 const char kNetworkTechnologyLteAdvanced[] = "LTE Advanced"; | |
325 const char kNetworkTechnologyGsm[] = "GSM"; | |
326 | |
327 // Flimflam roaming state options | |
328 const char kRoamingStateHome[] = "home"; | |
329 const char kRoamingStateRoaming[] = "roaming"; | |
330 const char kRoamingStateUnknown[] = "unknown"; | |
331 | |
332 // Flimflam activation state options | |
333 const char kActivationStateActivated[] = "activated"; | |
334 const char kActivationStateActivating[] = "activating"; | |
335 const char kActivationStateNotActivated[] = "not-activated"; | |
336 const char kActivationStatePartiallyActivated[] = "partially-activated"; | |
337 const char kActivationStateUnknown[] = "unknown"; | |
338 | |
339 // FlimFlam technology family options | |
340 const char kTechnologyFamilyCdma[] = "CDMA"; | |
341 const char kTechnologyFamilyGsm[] = "GSM"; | |
342 | |
343 // Flimflam error options. | |
344 const char kErrorOutOfRange[] = "out-of-range"; | |
345 const char kErrorPinMissing[] = "pin-missing"; | |
346 const char kErrorDhcpFailed[] = "dhcp-failed"; | |
347 const char kErrorConnectFailed[] = "connect-failed"; | |
348 const char kErrorBadPassphrase[] = "bad-passphrase"; | |
349 const char kErrorBadWEPKey[] = "bad-wepkey"; | |
350 const char kErrorActivationFailed[] = "activation-failed"; | |
351 const char kErrorNeedEvdo[] = "need-evdo"; | |
352 const char kErrorNeedHomeNetwork[] = "need-home-network"; | |
353 const char kErrorOtaspFailed[] = "otasp-failed"; | |
354 const char kErrorAaaFailed[] = "aaa-failed"; | |
355 const char kErrorInternal[] = "internal-error"; | |
356 const char kErrorDNSLookupFailed[] = "dns-lookup-failed"; | |
357 const char kErrorHTTPGetFailed[] = "http-get-failed"; | |
358 | |
359 // Flimflam error messages. | |
360 const char kErrorPassphraseRequiredMsg[] = "Passphrase required"; | |
361 const char kErrorIncorrectPinMsg[] = "org.chromium.flimflam.Error.IncorrectPin"; | |
362 const char kErrorPinBlockedMsg[] = "org.chromium.flimflam.Error.PinBlocked"; | |
363 const char kErrorPinRequiredMsg[] = "org.chromium.flimflam.Error.PinRequired"; | |
364 | |
365 const char kUnknownString[] = "UNKNOWN"; | |
366 | |
367 //////////////////////////////////////////////////////////////////////////// | |
368 | |
369 static const char* ConnectionTypeToString(ConnectionType type) { | |
370 switch (type) { | |
371 case TYPE_UNKNOWN: | |
372 break; | |
373 case TYPE_ETHERNET: | |
374 return kTypeEthernet; | |
375 case TYPE_WIFI: | |
376 return kTypeWifi; | |
377 case TYPE_WIMAX: | |
378 return kTypeWimax; | |
379 case TYPE_BLUETOOTH: | |
380 return kTypeBluetooth; | |
381 case TYPE_CELLULAR: | |
382 return kTypeCellular; | |
383 case TYPE_VPN: | |
384 return kTypeVPN; | |
385 } | |
386 LOG(ERROR) << "ConnectionTypeToString called with unknown type: " << type; | |
387 return kUnknownString; | |
388 } | |
389 | |
390 static const char* SecurityToString(ConnectionSecurity security) { | |
391 switch (security) { | |
392 case SECURITY_NONE: | |
393 return kSecurityNone; | |
394 case SECURITY_WEP: | |
395 return kSecurityWep; | |
396 case SECURITY_WPA: | |
397 return kSecurityWpa; | |
398 case SECURITY_RSN: | |
399 return kSecurityRsn; | |
400 case SECURITY_8021X: | |
401 return kSecurity8021x; | |
402 case SECURITY_PSK: | |
403 return kSecurityPsk; | |
404 case SECURITY_UNKNOWN: | |
405 break; | |
406 } | |
407 LOG(ERROR) << "SecurityToString called with unknown type: " << security; | |
408 return kUnknownString; | |
409 } | |
410 | |
411 static const char* ProviderTypeToString(VirtualNetwork::ProviderType type) { | |
412 switch (type) { | |
413 case VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_PSK: | |
414 case VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT: | |
415 return kProviderL2tpIpsec; | |
416 case VirtualNetwork::PROVIDER_TYPE_OPEN_VPN: | |
417 return kProviderOpenVpn; | |
418 case VirtualNetwork::PROVIDER_TYPE_MAX: | |
419 break; | |
420 } | |
421 LOG(ERROR) << "ProviderTypeToString called with unknown type: " << type; | |
422 return kUnknownString; | |
423 } | |
424 | |
425 //////////////////////////////////////////////////////////////////////////// | |
426 | |
427 // Helper class to cache maps of strings to enums. | |
428 template <typename Type> | |
429 class StringToEnum { | |
430 public: | |
431 struct Pair { | |
432 const char* key; | |
433 const Type value; | |
434 }; | |
435 | |
436 StringToEnum(const Pair* list, size_t num_entries, Type unknown) | |
437 : unknown_value_(unknown) { | |
438 for (size_t i = 0; i < num_entries; ++i, ++list) | |
439 enum_map_[list->key] = list->value; | |
440 } | |
441 | |
442 Type Get(const std::string& type) const { | |
443 EnumMapConstIter iter = enum_map_.find(type); | |
444 if (iter != enum_map_.end()) | |
445 return iter->second; | |
446 return unknown_value_; | |
447 } | |
448 | |
449 private: | |
450 typedef typename std::map<std::string, Type> EnumMap; | |
451 typedef typename std::map<std::string, Type>::const_iterator EnumMapConstIter; | |
452 EnumMap enum_map_; | |
453 Type unknown_value_; | |
454 DISALLOW_COPY_AND_ASSIGN(StringToEnum); | |
455 }; | |
456 | |
457 //////////////////////////////////////////////////////////////////////////// | |
458 | |
459 enum PropertyIndex { | |
460 PROPERTY_INDEX_ACTIVATION_STATE, | |
461 PROPERTY_INDEX_ACTIVE_PROFILE, | |
462 PROPERTY_INDEX_AUTO_CONNECT, | |
463 PROPERTY_INDEX_AVAILABLE_TECHNOLOGIES, | |
464 PROPERTY_INDEX_CARRIER, | |
465 PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING, | |
466 PROPERTY_INDEX_CELLULAR_APN, | |
467 PROPERTY_INDEX_CELLULAR_APN_LIST, | |
468 PROPERTY_INDEX_CELLULAR_LAST_GOOD_APN, | |
469 PROPERTY_INDEX_CHECK_PORTAL_LIST, | |
470 PROPERTY_INDEX_CONNECTABLE, | |
471 PROPERTY_INDEX_CONNECTED_TECHNOLOGIES, | |
472 PROPERTY_INDEX_CONNECTIVITY_STATE, | |
473 PROPERTY_INDEX_DEFAULT_TECHNOLOGY, | |
474 PROPERTY_INDEX_DEVICE, | |
475 PROPERTY_INDEX_DEVICES, | |
476 PROPERTY_INDEX_EAP_ANONYMOUS_IDENTITY, | |
477 PROPERTY_INDEX_EAP_CA_CERT, | |
478 PROPERTY_INDEX_EAP_CA_CERT_ID, | |
479 PROPERTY_INDEX_EAP_CA_CERT_NSS, | |
480 PROPERTY_INDEX_EAP_CERT_ID, | |
481 PROPERTY_INDEX_EAP_CLIENT_CERT, | |
482 PROPERTY_INDEX_EAP_CLIENT_CERT_NSS, | |
483 PROPERTY_INDEX_EAP_IDENTITY, | |
484 PROPERTY_INDEX_EAP_KEY_ID, | |
485 PROPERTY_INDEX_EAP_KEY_MGMT, | |
486 PROPERTY_INDEX_EAP_METHOD, | |
487 PROPERTY_INDEX_EAP_PASSWORD, | |
488 PROPERTY_INDEX_EAP_PHASE_2_AUTH, | |
489 PROPERTY_INDEX_EAP_PIN, | |
490 PROPERTY_INDEX_EAP_PRIVATE_KEY, | |
491 PROPERTY_INDEX_EAP_PRIVATE_KEY_PASSWORD, | |
492 PROPERTY_INDEX_EAP_USE_SYSTEM_CAS, | |
493 PROPERTY_INDEX_ENABLED_TECHNOLOGIES, | |
494 PROPERTY_INDEX_ERROR, | |
495 PROPERTY_INDEX_ESN, | |
496 PROPERTY_INDEX_FAVORITE, | |
497 PROPERTY_INDEX_FIRMWARE_REVISION, | |
498 PROPERTY_INDEX_FOUND_NETWORKS, | |
499 PROPERTY_INDEX_HARDWARE_REVISION, | |
500 PROPERTY_INDEX_HOME_PROVIDER, | |
501 PROPERTY_INDEX_HOST, | |
502 PROPERTY_INDEX_IDENTITY, | |
503 PROPERTY_INDEX_IMEI, | |
504 PROPERTY_INDEX_IMSI, | |
505 PROPERTY_INDEX_IS_ACTIVE, | |
506 PROPERTY_INDEX_L2TPIPSEC_CA_CERT_NSS, | |
507 PROPERTY_INDEX_L2TPIPSEC_CLIENT_CERT_ID, | |
508 PROPERTY_INDEX_L2TPIPSEC_CLIENT_CERT_SLOT, | |
509 PROPERTY_INDEX_L2TPIPSEC_PASSWORD, | |
510 PROPERTY_INDEX_L2TPIPSEC_PIN, | |
511 PROPERTY_INDEX_L2TPIPSEC_PSK, | |
512 PROPERTY_INDEX_L2TPIPSEC_USER, | |
513 PROPERTY_INDEX_MANUFACTURER, | |
514 PROPERTY_INDEX_MDN, | |
515 PROPERTY_INDEX_MEID, | |
516 PROPERTY_INDEX_MIN, | |
517 PROPERTY_INDEX_MODE, | |
518 PROPERTY_INDEX_MODEL_ID, | |
519 PROPERTY_INDEX_NAME, | |
520 PROPERTY_INDEX_NETWORKS, | |
521 PROPERTY_INDEX_NETWORK_TECHNOLOGY, | |
522 PROPERTY_INDEX_OFFLINE_MODE, | |
523 PROPERTY_INDEX_OPERATOR_CODE, | |
524 PROPERTY_INDEX_OPERATOR_NAME, | |
525 PROPERTY_INDEX_PASSPHRASE, | |
526 PROPERTY_INDEX_PASSPHRASE_REQUIRED, | |
527 PROPERTY_INDEX_PAYMENT_URL, | |
528 PROPERTY_INDEX_PORTAL_URL, | |
529 PROPERTY_INDEX_POWERED, | |
530 PROPERTY_INDEX_PRIORITY, | |
531 PROPERTY_INDEX_PRL_VERSION, | |
532 PROPERTY_INDEX_PROFILE, | |
533 PROPERTY_INDEX_PROFILES, | |
534 PROPERTY_INDEX_PROVIDER, | |
535 PROPERTY_INDEX_PROXY_CONFIG, | |
536 PROPERTY_INDEX_ROAMING_STATE, | |
537 PROPERTY_INDEX_SAVE_CREDENTIALS, | |
538 PROPERTY_INDEX_SCANNING, | |
539 PROPERTY_INDEX_SECURITY, | |
540 PROPERTY_INDEX_SELECTED_NETWORK, | |
541 PROPERTY_INDEX_SERVICES, | |
542 PROPERTY_INDEX_SERVICE_WATCH_LIST, | |
543 PROPERTY_INDEX_SERVING_OPERATOR, | |
544 PROPERTY_INDEX_SIGNAL_STRENGTH, | |
545 PROPERTY_INDEX_SIM_LOCK, | |
546 PROPERTY_INDEX_STATE, | |
547 PROPERTY_INDEX_SUPPORT_NETWORK_SCAN, | |
548 PROPERTY_INDEX_TECHNOLOGY_FAMILY, | |
549 PROPERTY_INDEX_TYPE, | |
550 PROPERTY_INDEX_UNKNOWN, | |
551 PROPERTY_INDEX_USAGE_URL, | |
552 PROPERTY_INDEX_WIFI_AUTH_MODE, | |
553 PROPERTY_INDEX_WIFI_FREQUENCY, | |
554 PROPERTY_INDEX_WIFI_HEX_SSID, | |
555 PROPERTY_INDEX_WIFI_HIDDEN_SSID, | |
556 PROPERTY_INDEX_WIFI_PHY_MODE, | |
557 }; | |
558 | |
559 StringToEnum<PropertyIndex>::Pair property_index_table[] = { | |
560 { kActivationStateProperty, PROPERTY_INDEX_ACTIVATION_STATE }, | |
561 { kActiveProfileProperty, PROPERTY_INDEX_ACTIVE_PROFILE }, | |
562 { kAutoConnectProperty, PROPERTY_INDEX_AUTO_CONNECT }, | |
563 { kAvailableTechnologiesProperty, PROPERTY_INDEX_AVAILABLE_TECHNOLOGIES }, | |
564 { kCarrierProperty, PROPERTY_INDEX_CARRIER }, | |
565 { kCellularAllowRoamingProperty, PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING }, | |
566 { kCellularApnListProperty, PROPERTY_INDEX_CELLULAR_APN_LIST }, | |
567 { kCellularApnProperty, PROPERTY_INDEX_CELLULAR_APN }, | |
568 { kCellularLastGoodApnProperty, PROPERTY_INDEX_CELLULAR_LAST_GOOD_APN }, | |
569 { kCheckPortalListProperty, PROPERTY_INDEX_CHECK_PORTAL_LIST }, | |
570 { kConnectableProperty, PROPERTY_INDEX_CONNECTABLE }, | |
571 { kConnectedTechnologiesProperty, PROPERTY_INDEX_CONNECTED_TECHNOLOGIES }, | |
572 { kDefaultTechnologyProperty, PROPERTY_INDEX_DEFAULT_TECHNOLOGY }, | |
573 { kDeviceProperty, PROPERTY_INDEX_DEVICE }, | |
574 { kDevicesProperty, PROPERTY_INDEX_DEVICES }, | |
575 { kEapAnonymousIdentityProperty, PROPERTY_INDEX_EAP_ANONYMOUS_IDENTITY }, | |
576 { kEapCaCertIDProperty, PROPERTY_INDEX_EAP_CA_CERT_ID }, | |
577 { kEapCaCertNssProperty, PROPERTY_INDEX_EAP_CA_CERT_NSS }, | |
578 { kEapCaCertProperty, PROPERTY_INDEX_EAP_CA_CERT }, | |
579 { kEapCertIDProperty, PROPERTY_INDEX_EAP_CERT_ID }, | |
580 { kEapClientCertNssProperty, PROPERTY_INDEX_EAP_CLIENT_CERT_NSS }, | |
581 { kEapClientCertProperty, PROPERTY_INDEX_EAP_CLIENT_CERT }, | |
582 { kEapIdentityProperty, PROPERTY_INDEX_EAP_IDENTITY }, | |
583 { kEapKeyIDProperty, PROPERTY_INDEX_EAP_KEY_ID }, | |
584 { kEapKeyMgmtProperty, PROPERTY_INDEX_EAP_KEY_MGMT }, | |
585 { kEapMethodProperty, PROPERTY_INDEX_EAP_METHOD }, | |
586 { kEapPasswordProperty, PROPERTY_INDEX_EAP_PASSWORD }, | |
587 { kEapPhase2AuthProperty, PROPERTY_INDEX_EAP_PHASE_2_AUTH }, | |
588 { kEapPinProperty, PROPERTY_INDEX_EAP_PIN }, | |
589 { kEapPrivateKeyPasswordProperty, PROPERTY_INDEX_EAP_PRIVATE_KEY_PASSWORD }, | |
590 { kEapPrivateKeyProperty, PROPERTY_INDEX_EAP_PRIVATE_KEY }, | |
591 { kEapUseSystemCAsProperty, PROPERTY_INDEX_EAP_USE_SYSTEM_CAS }, | |
592 { kEnabledTechnologiesProperty, PROPERTY_INDEX_ENABLED_TECHNOLOGIES }, | |
593 { kErrorProperty, PROPERTY_INDEX_ERROR }, | |
594 { kEsnProperty, PROPERTY_INDEX_ESN }, | |
595 { kFavoriteProperty, PROPERTY_INDEX_FAVORITE }, | |
596 { kFirmwareRevisionProperty, PROPERTY_INDEX_FIRMWARE_REVISION }, | |
597 { kFoundNetworksProperty, PROPERTY_INDEX_FOUND_NETWORKS }, | |
598 { kHardwareRevisionProperty, PROPERTY_INDEX_HARDWARE_REVISION }, | |
599 { kHomeProviderProperty, PROPERTY_INDEX_HOME_PROVIDER }, | |
600 { kHostProperty, PROPERTY_INDEX_HOST }, | |
601 { kIdentityProperty, PROPERTY_INDEX_IDENTITY }, | |
602 { kImeiProperty, PROPERTY_INDEX_IMEI }, | |
603 { kImsiProperty, PROPERTY_INDEX_IMSI }, | |
604 { kIsActiveProperty, PROPERTY_INDEX_IS_ACTIVE }, | |
605 { kL2TPIPSecCACertNSSProperty, PROPERTY_INDEX_L2TPIPSEC_CA_CERT_NSS }, | |
606 { kL2TPIPSecClientCertIDProperty, PROPERTY_INDEX_L2TPIPSEC_CLIENT_CERT_ID }, | |
607 { kL2TPIPSecClientCertSlotProp, PROPERTY_INDEX_L2TPIPSEC_CLIENT_CERT_SLOT }, | |
608 { kL2TPIPSecPasswordProperty, PROPERTY_INDEX_L2TPIPSEC_PASSWORD }, | |
609 { kL2TPIPSecPINProperty, PROPERTY_INDEX_L2TPIPSEC_PIN }, | |
610 { kL2TPIPSecPSKProperty, PROPERTY_INDEX_L2TPIPSEC_PSK }, | |
611 { kL2TPIPSecUserProperty, PROPERTY_INDEX_L2TPIPSEC_USER }, | |
612 { kManufacturerProperty, PROPERTY_INDEX_MANUFACTURER }, | |
613 { kMdnProperty, PROPERTY_INDEX_MDN }, | |
614 { kMeidProperty, PROPERTY_INDEX_MEID }, | |
615 { kMinProperty, PROPERTY_INDEX_MIN }, | |
616 { kModeProperty, PROPERTY_INDEX_MODE }, | |
617 { kModelIDProperty, PROPERTY_INDEX_MODEL_ID }, | |
618 { kNameProperty, PROPERTY_INDEX_NAME }, | |
619 { kNetworkTechnologyProperty, PROPERTY_INDEX_NETWORK_TECHNOLOGY }, | |
620 { kNetworksProperty, PROPERTY_INDEX_NETWORKS }, | |
621 { kOfflineModeProperty, PROPERTY_INDEX_OFFLINE_MODE }, | |
622 { kOperatorCodeProperty, PROPERTY_INDEX_OPERATOR_CODE }, | |
623 { kOperatorNameProperty, PROPERTY_INDEX_OPERATOR_NAME }, | |
624 { kPRLVersionProperty, PROPERTY_INDEX_PRL_VERSION }, | |
625 { kPassphraseProperty, PROPERTY_INDEX_PASSPHRASE }, | |
626 { kPassphraseRequiredProperty, PROPERTY_INDEX_PASSPHRASE_REQUIRED }, | |
627 { kPaymentURLProperty, PROPERTY_INDEX_PAYMENT_URL }, | |
628 { kPortalURLProperty, PROPERTY_INDEX_PORTAL_URL }, | |
629 { kPoweredProperty, PROPERTY_INDEX_POWERED }, | |
630 { kPriorityProperty, PROPERTY_INDEX_PRIORITY }, | |
631 { kProfileProperty, PROPERTY_INDEX_PROFILE }, | |
632 { kProfilesProperty, PROPERTY_INDEX_PROFILES }, | |
633 { kProviderProperty, PROPERTY_INDEX_PROVIDER }, | |
634 { kProxyConfigProperty, PROPERTY_INDEX_PROXY_CONFIG }, | |
635 { kRoamingStateProperty, PROPERTY_INDEX_ROAMING_STATE }, | |
636 { kSIMLockStatusProperty, PROPERTY_INDEX_SIM_LOCK }, | |
637 { kSaveCredentialsProperty, PROPERTY_INDEX_SAVE_CREDENTIALS }, | |
638 { kScanningProperty, PROPERTY_INDEX_SCANNING }, | |
639 { kSecurityProperty, PROPERTY_INDEX_SECURITY }, | |
640 { kSelectedNetworkProperty, PROPERTY_INDEX_SELECTED_NETWORK }, | |
641 { kServiceWatchListProperty, PROPERTY_INDEX_SERVICE_WATCH_LIST }, | |
642 { kServicesProperty, PROPERTY_INDEX_SERVICES }, | |
643 { kServingOperatorProperty, PROPERTY_INDEX_SERVING_OPERATOR }, | |
644 { kSignalStrengthProperty, PROPERTY_INDEX_SIGNAL_STRENGTH }, | |
645 { kStateProperty, PROPERTY_INDEX_STATE }, | |
646 { kSupportNetworkScanProperty, PROPERTY_INDEX_SUPPORT_NETWORK_SCAN }, | |
647 { kTechnologyFamilyProperty, PROPERTY_INDEX_TECHNOLOGY_FAMILY }, | |
648 { kTypeProperty, PROPERTY_INDEX_TYPE }, | |
649 { kUsageURLProperty, PROPERTY_INDEX_USAGE_URL }, | |
650 { kWifiAuthMode, PROPERTY_INDEX_WIFI_AUTH_MODE }, | |
651 { kWifiFrequency, PROPERTY_INDEX_WIFI_FREQUENCY }, | |
652 { kWifiHexSsid, PROPERTY_INDEX_WIFI_HEX_SSID }, | |
653 { kWifiHiddenSsid, PROPERTY_INDEX_WIFI_HIDDEN_SSID }, | |
654 { kWifiPhyMode, PROPERTY_INDEX_WIFI_PHY_MODE }, | |
655 }; | |
656 | |
657 StringToEnum<PropertyIndex>& property_index_parser() { | |
658 static StringToEnum<PropertyIndex> parser(property_index_table, | |
659 arraysize(property_index_table), | |
660 PROPERTY_INDEX_UNKNOWN); | |
661 return parser; | |
662 } | |
663 | |
664 //////////////////////////////////////////////////////////////////////////// | |
665 // Parse strings from libcros. | |
666 | |
667 // Network. | |
668 static ConnectionType ParseType(const std::string& type) { | |
669 static StringToEnum<ConnectionType>::Pair table[] = { | |
670 { kTypeEthernet, TYPE_ETHERNET }, | |
671 { kTypeWifi, TYPE_WIFI }, | |
672 { kTypeWimax, TYPE_WIMAX }, | |
673 { kTypeBluetooth, TYPE_BLUETOOTH }, | |
674 { kTypeCellular, TYPE_CELLULAR }, | |
675 { kTypeVPN, TYPE_VPN }, | |
676 }; | |
677 static StringToEnum<ConnectionType> parser( | |
678 table, arraysize(table), TYPE_UNKNOWN); | |
679 return parser.Get(type); | |
680 } | |
681 | |
682 ConnectionType ParseTypeFromDictionary(const DictionaryValue* info) { | |
683 std::string type_string; | |
684 info->GetString(kTypeProperty, &type_string); | |
685 return ParseType(type_string); | |
686 } | |
687 | |
688 static ConnectionMode ParseMode(const std::string& mode) { | |
689 static StringToEnum<ConnectionMode>::Pair table[] = { | |
690 { kModeManaged, MODE_MANAGED }, | |
691 { kModeAdhoc, MODE_ADHOC }, | |
692 }; | |
693 static StringToEnum<ConnectionMode> parser( | |
694 table, arraysize(table), MODE_UNKNOWN); | |
695 return parser.Get(mode); | |
696 } | |
697 | |
698 static ConnectionState ParseState(const std::string& state) { | |
699 static StringToEnum<ConnectionState>::Pair table[] = { | |
700 { kStateIdle, STATE_IDLE }, | |
701 { kStateCarrier, STATE_CARRIER }, | |
702 { kStateAssociation, STATE_ASSOCIATION }, | |
703 { kStateConfiguration, STATE_CONFIGURATION }, | |
704 { kStateReady, STATE_READY }, | |
705 { kStateDisconnect, STATE_DISCONNECT }, | |
706 { kStateFailure, STATE_FAILURE }, | |
707 { kStateActivationFailure, STATE_ACTIVATION_FAILURE }, | |
708 { kStatePortal, STATE_PORTAL }, | |
709 { kStateOnline, STATE_ONLINE }, | |
710 }; | |
711 static StringToEnum<ConnectionState> parser( | |
712 table, arraysize(table), STATE_UNKNOWN); | |
713 return parser.Get(state); | |
714 } | |
715 | |
716 static ConnectionError ParseError(const std::string& error) { | |
717 static StringToEnum<ConnectionError>::Pair table[] = { | |
718 { kErrorOutOfRange, ERROR_OUT_OF_RANGE }, | |
719 { kErrorPinMissing, ERROR_PIN_MISSING }, | |
720 { kErrorDhcpFailed, ERROR_DHCP_FAILED }, | |
721 { kErrorConnectFailed, ERROR_CONNECT_FAILED }, | |
722 { kErrorBadPassphrase, ERROR_BAD_PASSPHRASE }, | |
723 { kErrorBadWEPKey, ERROR_BAD_WEPKEY }, | |
724 { kErrorActivationFailed, ERROR_ACTIVATION_FAILED }, | |
725 { kErrorNeedEvdo, ERROR_NEED_EVDO }, | |
726 { kErrorNeedHomeNetwork, ERROR_NEED_HOME_NETWORK }, | |
727 { kErrorOtaspFailed, ERROR_OTASP_FAILED }, | |
728 { kErrorAaaFailed, ERROR_AAA_FAILED }, | |
729 { kErrorInternal, ERROR_INTERNAL }, | |
730 { kErrorDNSLookupFailed, ERROR_DNS_LOOKUP_FAILED }, | |
731 { kErrorHTTPGetFailed, ERROR_HTTP_GET_FAILED }, | |
732 }; | |
733 static StringToEnum<ConnectionError> parser( | |
734 table, arraysize(table), ERROR_NO_ERROR); | |
735 return parser.Get(error); | |
736 } | |
737 | |
738 // VirtualNetwork | |
739 static VirtualNetwork::ProviderType ParseProviderType(const std::string& mode) { | |
740 static StringToEnum<VirtualNetwork::ProviderType>::Pair table[] = { | |
741 { kProviderL2tpIpsec, VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_PSK }, | |
742 { kProviderOpenVpn, VirtualNetwork::PROVIDER_TYPE_OPEN_VPN }, | |
743 }; | |
744 static StringToEnum<VirtualNetwork::ProviderType> parser( | |
745 table, arraysize(table), VirtualNetwork::PROVIDER_TYPE_MAX); | |
746 return parser.Get(mode); | |
747 } | |
748 | |
749 // CellularNetwork. | |
750 static ActivationState ParseActivationState(const std::string& state) { | |
751 static StringToEnum<ActivationState>::Pair table[] = { | |
752 { kActivationStateActivated, ACTIVATION_STATE_ACTIVATED }, | |
753 { kActivationStateActivating, ACTIVATION_STATE_ACTIVATING }, | |
754 { kActivationStateNotActivated, ACTIVATION_STATE_NOT_ACTIVATED }, | |
755 { kActivationStatePartiallyActivated, ACTIVATION_STATE_PARTIALLY_ACTIVATED}, | |
756 { kActivationStateUnknown, ACTIVATION_STATE_UNKNOWN}, | |
757 }; | |
758 static StringToEnum<ActivationState> parser( | |
759 table, arraysize(table), ACTIVATION_STATE_UNKNOWN); | |
760 return parser.Get(state); | |
761 } | |
762 | |
763 static NetworkTechnology ParseNetworkTechnology(const std::string& technology) { | |
764 static StringToEnum<NetworkTechnology>::Pair table[] = { | |
765 { kNetworkTechnology1Xrtt, NETWORK_TECHNOLOGY_1XRTT }, | |
766 { kNetworkTechnologyEvdo, NETWORK_TECHNOLOGY_EVDO }, | |
767 { kNetworkTechnologyGprs, NETWORK_TECHNOLOGY_GPRS }, | |
768 { kNetworkTechnologyEdge, NETWORK_TECHNOLOGY_EDGE }, | |
769 { kNetworkTechnologyUmts, NETWORK_TECHNOLOGY_UMTS }, | |
770 { kNetworkTechnologyHspa, NETWORK_TECHNOLOGY_HSPA }, | |
771 { kNetworkTechnologyHspaPlus, NETWORK_TECHNOLOGY_HSPA_PLUS }, | |
772 { kNetworkTechnologyLte, NETWORK_TECHNOLOGY_LTE }, | |
773 { kNetworkTechnologyLteAdvanced, NETWORK_TECHNOLOGY_LTE_ADVANCED }, | |
774 { kNetworkTechnologyGsm, NETWORK_TECHNOLOGY_GSM }, | |
775 }; | |
776 static StringToEnum<NetworkTechnology> parser( | |
777 table, arraysize(table), NETWORK_TECHNOLOGY_UNKNOWN); | |
778 return parser.Get(technology); | |
779 } | |
780 | |
781 static SIMLockState ParseSimLockState(const std::string& state) { | |
782 static StringToEnum<SIMLockState>::Pair table[] = { | |
783 { "", SIM_UNLOCKED }, | |
784 { kSIMLockPin, SIM_LOCKED_PIN }, | |
785 { kSIMLockPuk, SIM_LOCKED_PUK }, | |
786 }; | |
787 static StringToEnum<SIMLockState> parser( | |
788 table, arraysize(table), SIM_UNKNOWN); | |
789 SIMLockState parsed_state = parser.Get(state); | |
790 DCHECK_NE(parsed_state, SIM_UNKNOWN) << "Unknown SIMLock state encountered"; | |
791 return parsed_state; | |
792 } | |
793 | |
794 static bool ParseSimLockStateFromDictionary(const DictionaryValue* info, | |
795 SIMLockState* out_state, | |
796 int* out_retries) { | |
797 std::string state_string; | |
798 if (!info->GetString(kSIMLockTypeProperty, &state_string) || | |
799 !info->GetInteger(kSIMLockRetriesLeftProperty, out_retries)) { | |
800 LOG(ERROR) << "Error parsing SIMLock state"; | |
801 return false; | |
802 } | |
803 *out_state = ParseSimLockState(state_string); | |
804 return true; | |
805 } | |
806 | |
807 static bool ParseFoundNetworksFromList(const ListValue* list, | |
808 CellularNetworkList* found_networks_) { | |
809 found_networks_->clear(); | |
810 found_networks_->reserve(list->GetSize()); | |
811 for (ListValue::const_iterator it = list->begin(); it != list->end(); ++it) { | |
812 if ((*it)->IsType(Value::TYPE_DICTIONARY)) { | |
813 found_networks_->resize(found_networks_->size() + 1); | |
814 const DictionaryValue* dict = static_cast<const DictionaryValue*>(*it); | |
815 dict->GetStringWithoutPathExpansion( | |
816 kStatusProperty, &found_networks_->back().status); | |
817 dict->GetStringWithoutPathExpansion( | |
818 kNetworkIdProperty, &found_networks_->back().network_id); | |
819 dict->GetStringWithoutPathExpansion( | |
820 kShortNameProperty, &found_networks_->back().short_name); | |
821 dict->GetStringWithoutPathExpansion( | |
822 kLongNameProperty, &found_networks_->back().long_name); | |
823 dict->GetStringWithoutPathExpansion( | |
824 kTechnologyProperty, &found_networks_->back().technology); | |
825 } else { | |
826 return false; | |
827 } | |
828 } | |
829 return true; | |
830 } | |
831 | |
832 static bool ParseApnList(const ListValue* list, | |
833 CellularApnList* apn_list) { | |
834 apn_list->clear(); | |
835 apn_list->reserve(list->GetSize()); | |
836 for (ListValue::const_iterator it = list->begin(); it != list->end(); ++it) { | |
837 if ((*it)->IsType(Value::TYPE_DICTIONARY)) { | |
838 apn_list->resize(apn_list->size() + 1); | |
839 apn_list->back().Set(*static_cast<const DictionaryValue*>(*it)); | |
840 } else { | |
841 return false; | |
842 } | |
843 } | |
844 return true; | |
845 } | |
846 | |
847 static NetworkRoamingState ParseRoamingState(const std::string& roaming_state) { | |
848 static StringToEnum<NetworkRoamingState>::Pair table[] = { | |
849 { kRoamingStateHome, ROAMING_STATE_HOME }, | |
850 { kRoamingStateRoaming, ROAMING_STATE_ROAMING }, | |
851 { kRoamingStateUnknown, ROAMING_STATE_UNKNOWN }, | |
852 }; | |
853 static StringToEnum<NetworkRoamingState> parser( | |
854 table, arraysize(table), ROAMING_STATE_UNKNOWN); | |
855 return parser.Get(roaming_state); | |
856 } | |
857 | |
858 // WifiNetwork | |
859 static ConnectionSecurity ParseSecurity(const std::string& security) { | |
860 static StringToEnum<ConnectionSecurity>::Pair table[] = { | |
861 { kSecurityNone, SECURITY_NONE }, | |
862 { kSecurityWep, SECURITY_WEP }, | |
863 { kSecurityWpa, SECURITY_WPA }, | |
864 { kSecurityRsn, SECURITY_RSN }, | |
865 { kSecurityPsk, SECURITY_PSK }, | |
866 { kSecurity8021x, SECURITY_8021X }, | |
867 }; | |
868 static StringToEnum<ConnectionSecurity> parser( | |
869 table, arraysize(table), SECURITY_UNKNOWN); | |
870 return parser.Get(security); | |
871 } | |
872 | |
873 static EAPMethod ParseEAPMethod(const std::string& method) { | |
874 static StringToEnum<EAPMethod>::Pair table[] = { | |
875 { kEapMethodPEAP, EAP_METHOD_PEAP }, | |
876 { kEapMethodTLS, EAP_METHOD_TLS }, | |
877 { kEapMethodTTLS, EAP_METHOD_TTLS }, | |
878 { kEapMethodLEAP, EAP_METHOD_LEAP }, | |
879 }; | |
880 static StringToEnum<EAPMethod> parser( | |
881 table, arraysize(table), EAP_METHOD_UNKNOWN); | |
882 return parser.Get(method); | |
883 } | |
884 | |
885 static EAPPhase2Auth ParseEAPPhase2Auth(const std::string& auth) { | |
886 static StringToEnum<EAPPhase2Auth>::Pair table[] = { | |
887 { kEapPhase2AuthPEAPMD5, EAP_PHASE_2_AUTH_MD5 }, | |
888 { kEapPhase2AuthPEAPMSCHAPV2, EAP_PHASE_2_AUTH_MSCHAPV2 }, | |
889 { kEapPhase2AuthTTLSMD5, EAP_PHASE_2_AUTH_MD5 }, | |
890 { kEapPhase2AuthTTLSMSCHAPV2, EAP_PHASE_2_AUTH_MSCHAPV2 }, | |
891 { kEapPhase2AuthTTLSMSCHAP, EAP_PHASE_2_AUTH_MSCHAP }, | |
892 { kEapPhase2AuthTTLSPAP, EAP_PHASE_2_AUTH_PAP }, | |
893 { kEapPhase2AuthTTLSCHAP, EAP_PHASE_2_AUTH_CHAP }, | |
894 }; | |
895 static StringToEnum<EAPPhase2Auth> parser( | |
896 table, arraysize(table), EAP_PHASE_2_AUTH_AUTO); | |
897 return parser.Get(auth); | |
898 } | |
899 | |
900 // NetworkDevice | |
901 static TechnologyFamily ParseTechnologyFamily(const std::string& family) { | |
902 static StringToEnum<TechnologyFamily>::Pair table[] = { | |
903 { kTechnologyFamilyCdma, TECHNOLOGY_FAMILY_CDMA }, | |
904 { kTechnologyFamilyGsm, TECHNOLOGY_FAMILY_GSM }, | |
905 }; | |
906 static StringToEnum<TechnologyFamily> parser( | |
907 table, arraysize(table), TECHNOLOGY_FAMILY_UNKNOWN); | |
908 return parser.Get(family); | |
909 } | |
910 | |
911 //////////////////////////////////////////////////////////////////////////////// | 106 //////////////////////////////////////////////////////////////////////////////// |
912 // Misc. | 107 // Misc. |
913 | 108 |
914 // Safe string constructor since we can't rely on non NULL pointers | 109 // Safe string constructor since we can't rely on non NULL pointers |
915 // for string values from libcros. | 110 // for string values from libcros. |
916 static std::string SafeString(const char* s) { | 111 static std::string SafeString(const char* s) { |
917 return s ? std::string(s) : std::string(); | 112 return s ? std::string(s) : std::string(); |
918 } | 113 } |
919 | 114 |
920 // Erase the memory used by a string, then clear it. | 115 // Erase the memory used by a string, then clear it. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 //////////////////////////////////////////////////////////////////////////////// | 156 //////////////////////////////////////////////////////////////////////////////// |
962 // NetworkDevice | 157 // NetworkDevice |
963 | 158 |
964 NetworkDevice::NetworkDevice(const std::string& device_path) | 159 NetworkDevice::NetworkDevice(const std::string& device_path) |
965 : device_path_(device_path), | 160 : device_path_(device_path), |
966 type_(TYPE_UNKNOWN), | 161 type_(TYPE_UNKNOWN), |
967 scanning_(false), | 162 scanning_(false), |
968 sim_lock_state_(SIM_UNKNOWN), | 163 sim_lock_state_(SIM_UNKNOWN), |
969 sim_retries_left_(kDefaultSimUnlockRetriesCount), | 164 sim_retries_left_(kDefaultSimUnlockRetriesCount), |
970 sim_pin_required_(SIM_PIN_REQUIRE_UNKNOWN), | 165 sim_pin_required_(SIM_PIN_REQUIRE_UNKNOWN), |
971 PRL_version_(0), | 166 prl_version_(0), |
972 data_roaming_allowed_(false), | 167 data_roaming_allowed_(false), |
973 support_network_scan_(false) { | 168 support_network_scan_(false), |
| 169 device_parser_(new NativeNetworkDeviceParser) { |
974 } | 170 } |
975 | 171 |
976 NetworkDevice::~NetworkDevice() {} | 172 NetworkDevice::~NetworkDevice() {} |
977 | 173 |
978 bool NetworkDevice::ParseValue(int index, const Value* value) { | 174 void NetworkDevice::ParseInfo(const DictionaryValue& info) { |
979 switch (index) { | 175 if (device_parser_.get()) |
980 case PROPERTY_INDEX_TYPE: { | 176 device_parser_->UpdateDeviceFromInfo(info, this); |
981 std::string type_string; | |
982 if (value->GetAsString(&type_string)) { | |
983 type_ = ParseType(type_string); | |
984 return true; | |
985 } | |
986 break; | |
987 } | |
988 case PROPERTY_INDEX_NAME: | |
989 return value->GetAsString(&name_); | |
990 case PROPERTY_INDEX_CARRIER: | |
991 return value->GetAsString(&carrier_); | |
992 case PROPERTY_INDEX_SCANNING: | |
993 return value->GetAsBoolean(&scanning_); | |
994 case PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING: | |
995 return value->GetAsBoolean(&data_roaming_allowed_); | |
996 case PROPERTY_INDEX_CELLULAR_APN_LIST: | |
997 if (value->IsType(Value::TYPE_LIST)) { | |
998 return ParseApnList(static_cast<const ListValue*>(value), | |
999 &provider_apn_list_); | |
1000 } | |
1001 break; | |
1002 case PROPERTY_INDEX_NETWORKS: | |
1003 if (value->IsType(Value::TYPE_LIST)) { | |
1004 // Ignored. | |
1005 return true; | |
1006 } | |
1007 break; | |
1008 case PROPERTY_INDEX_FOUND_NETWORKS: | |
1009 if (value->IsType(Value::TYPE_LIST)) { | |
1010 return ParseFoundNetworksFromList( | |
1011 static_cast<const ListValue*>(value), | |
1012 &found_cellular_networks_); | |
1013 } | |
1014 break; | |
1015 case PROPERTY_INDEX_HOME_PROVIDER: { | |
1016 if (value->IsType(Value::TYPE_DICTIONARY)) { | |
1017 const DictionaryValue* dict = | |
1018 static_cast<const DictionaryValue*>(value); | |
1019 home_provider_code_.clear(); | |
1020 home_provider_country_.clear(); | |
1021 home_provider_name_.clear(); | |
1022 dict->GetStringWithoutPathExpansion(kOperatorCodeKey, | |
1023 &home_provider_code_); | |
1024 dict->GetStringWithoutPathExpansion(kOperatorCountryKey, | |
1025 &home_provider_country_); | |
1026 dict->GetStringWithoutPathExpansion(kOperatorNameKey, | |
1027 &home_provider_name_); | |
1028 if (!home_provider_name_.empty() && !home_provider_country_.empty()) { | |
1029 home_provider_id_ = base::StringPrintf( | |
1030 kCarrierIdFormat, | |
1031 home_provider_name_.c_str(), | |
1032 home_provider_country_.c_str()); | |
1033 } else { | |
1034 home_provider_id_ = home_provider_code_; | |
1035 LOG(WARNING) << "Carrier ID not defined, using code instead: " | |
1036 << home_provider_id_; | |
1037 } | |
1038 return true; | |
1039 } | |
1040 break; | |
1041 } | |
1042 case PROPERTY_INDEX_MEID: | |
1043 return value->GetAsString(&MEID_); | |
1044 case PROPERTY_INDEX_IMEI: | |
1045 return value->GetAsString(&IMEI_); | |
1046 case PROPERTY_INDEX_IMSI: | |
1047 return value->GetAsString(&IMSI_); | |
1048 case PROPERTY_INDEX_ESN: | |
1049 return value->GetAsString(&ESN_); | |
1050 case PROPERTY_INDEX_MDN: | |
1051 return value->GetAsString(&MDN_); | |
1052 case PROPERTY_INDEX_MIN: | |
1053 return value->GetAsString(&MIN_); | |
1054 case PROPERTY_INDEX_MODEL_ID: | |
1055 return value->GetAsString(&model_id_); | |
1056 case PROPERTY_INDEX_MANUFACTURER: | |
1057 return value->GetAsString(&manufacturer_); | |
1058 case PROPERTY_INDEX_SIM_LOCK: | |
1059 if (value->IsType(Value::TYPE_DICTIONARY)) { | |
1060 bool result = ParseSimLockStateFromDictionary( | |
1061 static_cast<const DictionaryValue*>(value), | |
1062 &sim_lock_state_, | |
1063 &sim_retries_left_); | |
1064 // Initialize PinRequired value only once. | |
1065 // See SIMPinRequire enum comments. | |
1066 if (sim_pin_required_ == SIM_PIN_REQUIRE_UNKNOWN) { | |
1067 if (sim_lock_state_ == SIM_UNLOCKED) { | |
1068 sim_pin_required_ = SIM_PIN_NOT_REQUIRED; | |
1069 } else if (sim_lock_state_ == SIM_LOCKED_PIN || | |
1070 sim_lock_state_ == SIM_LOCKED_PUK) { | |
1071 sim_pin_required_ = SIM_PIN_REQUIRED; | |
1072 } | |
1073 } | |
1074 return result; | |
1075 } | |
1076 break; | |
1077 case PROPERTY_INDEX_FIRMWARE_REVISION: | |
1078 return value->GetAsString(&firmware_revision_); | |
1079 case PROPERTY_INDEX_HARDWARE_REVISION: | |
1080 return value->GetAsString(&hardware_revision_); | |
1081 case PROPERTY_INDEX_POWERED: | |
1082 // we don't care about the value, just the fact that it changed | |
1083 return true; | |
1084 case PROPERTY_INDEX_PRL_VERSION: | |
1085 return value->GetAsInteger(&PRL_version_); | |
1086 case PROPERTY_INDEX_SELECTED_NETWORK: | |
1087 return value->GetAsString(&selected_cellular_network_); | |
1088 case PROPERTY_INDEX_SUPPORT_NETWORK_SCAN: | |
1089 return value->GetAsBoolean(&support_network_scan_); | |
1090 case PROPERTY_INDEX_TECHNOLOGY_FAMILY: { | |
1091 std::string technology_family_string; | |
1092 if (value->GetAsString(&technology_family_string)) { | |
1093 technology_family_ = ParseTechnologyFamily(technology_family_string); | |
1094 return true; | |
1095 } | |
1096 break; | |
1097 } | |
1098 default: | |
1099 break; | |
1100 } | |
1101 return false; | |
1102 } | 177 } |
1103 | 178 |
1104 void NetworkDevice::ParseInfo(const DictionaryValue* info) { | 179 bool NetworkDevice::UpdateStatus(const std::string& key, |
1105 for (DictionaryValue::key_iterator iter = info->begin_keys(); | 180 const Value& value, |
1106 iter != info->end_keys(); ++iter) { | 181 PropertyIndex* index) { |
1107 const std::string& key = *iter; | 182 if (device_parser_.get()) |
1108 Value* value; | 183 return device_parser_->UpdateStatus(key, value, this, index); |
1109 bool res = info->GetWithoutPathExpansion(key, &value); | 184 return false; |
1110 DCHECK(res); | |
1111 if (res) { | |
1112 int index = property_index_parser().Get(key); | |
1113 if (!ParseValue(index, value)) | |
1114 VLOG(1) << "NetworkDevice: Unhandled key: " << key; | |
1115 } | |
1116 } | |
1117 } | 185 } |
1118 | 186 |
1119 //////////////////////////////////////////////////////////////////////////////// | 187 //////////////////////////////////////////////////////////////////////////////// |
1120 // Network | 188 // Network |
1121 | 189 |
1122 Network::Network(const std::string& service_path, ConnectionType type) | 190 Network::Network(const std::string& service_path, |
| 191 ConnectionType type, |
| 192 NativeNetworkParser* parser) |
1123 : state_(STATE_UNKNOWN), | 193 : state_(STATE_UNKNOWN), |
1124 error_(ERROR_NO_ERROR), | 194 error_(ERROR_NO_ERROR), |
1125 connectable_(true), | 195 connectable_(true), |
1126 is_active_(false), | 196 is_active_(false), |
1127 priority_(kPriorityNotSet), | 197 priority_(kPriorityNotSet), |
1128 auto_connect_(false), | 198 auto_connect_(false), |
1129 save_credentials_(false), | 199 save_credentials_(false), |
1130 priority_order_(0), | 200 priority_order_(0), |
1131 added_(false), | 201 added_(false), |
1132 notify_failure_(false), | 202 notify_failure_(false), |
1133 profile_type_(PROFILE_NONE), | 203 profile_type_(PROFILE_NONE), |
1134 service_path_(service_path), | 204 service_path_(service_path), |
1135 type_(type) { | 205 type_(type), |
| 206 network_parser_(parser) { |
1136 } | 207 } |
1137 | 208 |
1138 Network::~Network() {} | 209 Network::~Network() {} |
1139 | 210 |
1140 void Network::SetState(ConnectionState new_state) { | 211 void Network::SetState(ConnectionState new_state) { |
1141 if (new_state == state_) | 212 if (new_state == state_) |
1142 return; | 213 return; |
1143 ConnectionState old_state = state_; | 214 ConnectionState old_state = state_; |
1144 state_ = new_state; | 215 state_ = new_state; |
1145 if (new_state == STATE_FAILURE) { | 216 if (new_state == STATE_FAILURE) { |
1146 if (old_state != STATE_UNKNOWN) { | 217 if (old_state != STATE_UNKNOWN) { |
1147 // New failure, the user needs to be notified. | 218 // New failure, the user needs to be notified. |
1148 notify_failure_ = true; | 219 notify_failure_ = true; |
1149 } | 220 } |
1150 } else { | 221 } else { |
1151 // State changed, so refresh IP address. | 222 // State changed, so refresh IP address. |
1152 // Note: blocking DBus call. TODO(stevenjb): refactor this. | 223 // Note: blocking DBus call. TODO(stevenjb): refactor this. |
1153 InitIPAddress(); | 224 InitIPAddress(); |
1154 } | 225 } |
1155 VLOG(1) << name() << ".State = " << GetStateString(); | 226 VLOG(1) << name() << ".State = " << GetStateString(); |
1156 } | 227 } |
1157 | 228 |
1158 void Network::SetName(const std::string& name) { | 229 void Network::SetName(const std::string& name) { |
1159 std::string name_utf8; | 230 std::string name_utf8; |
1160 ValidateUTF8(name, &name_utf8); | 231 ValidateUTF8(name, &name_utf8); |
1161 set_name(name_utf8); | 232 set_name(name_utf8); |
1162 } | 233 } |
1163 | 234 |
1164 bool Network::ParseValue(int index, const Value* value) { | 235 void Network::ParseInfo(const DictionaryValue& info) { |
1165 switch (index) { | 236 if (network_parser_.get()) |
1166 case PROPERTY_INDEX_TYPE: { | 237 network_parser_->UpdateNetworkFromInfo(info, this); |
1167 std::string type_string; | |
1168 if (value->GetAsString(&type_string)) { | |
1169 ConnectionType type = ParseType(type_string); | |
1170 LOG_IF(ERROR, type != type_) | |
1171 << "Network with mismatched type: " << service_path_ | |
1172 << " " << type << " != " << type_; | |
1173 return true; | |
1174 } | |
1175 break; | |
1176 } | |
1177 case PROPERTY_INDEX_DEVICE: | |
1178 return value->GetAsString(&device_path_); | |
1179 case PROPERTY_INDEX_NAME: { | |
1180 std::string name; | |
1181 if (value->GetAsString(&name)) { | |
1182 SetName(name); | |
1183 return true; | |
1184 } | |
1185 break; | |
1186 } | |
1187 case PROPERTY_INDEX_PROFILE: | |
1188 // Note: currently this is only provided for non remembered networks. | |
1189 return value->GetAsString(&profile_path_); | |
1190 case PROPERTY_INDEX_STATE: { | |
1191 std::string state_string; | |
1192 if (value->GetAsString(&state_string)) { | |
1193 SetState(ParseState(state_string)); | |
1194 return true; | |
1195 } | |
1196 break; | |
1197 } | |
1198 case PROPERTY_INDEX_MODE: { | |
1199 std::string mode_string; | |
1200 if (value->GetAsString(&mode_string)) { | |
1201 mode_ = ParseMode(mode_string); | |
1202 return true; | |
1203 } | |
1204 break; | |
1205 } | |
1206 case PROPERTY_INDEX_ERROR: { | |
1207 std::string error_string; | |
1208 if (value->GetAsString(&error_string)) { | |
1209 error_ = ParseError(error_string); | |
1210 return true; | |
1211 } | |
1212 break; | |
1213 } | |
1214 case PROPERTY_INDEX_CONNECTABLE: | |
1215 return value->GetAsBoolean(&connectable_); | |
1216 case PROPERTY_INDEX_IS_ACTIVE: | |
1217 return value->GetAsBoolean(&is_active_); | |
1218 case PROPERTY_INDEX_FAVORITE: | |
1219 // Not used currently. | |
1220 return true; | |
1221 case PROPERTY_INDEX_PRIORITY: | |
1222 return value->GetAsInteger(&priority_); | |
1223 case PROPERTY_INDEX_AUTO_CONNECT: | |
1224 return value->GetAsBoolean(&auto_connect_); | |
1225 case PROPERTY_INDEX_SAVE_CREDENTIALS: | |
1226 return value->GetAsBoolean(&save_credentials_); | |
1227 case PROPERTY_INDEX_PROXY_CONFIG: | |
1228 return value->GetAsString(&proxy_config_); | |
1229 default: | |
1230 break; | |
1231 } | |
1232 return false; | |
1233 } | |
1234 | |
1235 void Network::ParseInfo(const DictionaryValue* info) { | |
1236 // Set default values for properties that may not exist in the dictionary. | |
1237 priority_ = kPriorityNotSet; | |
1238 | |
1239 for (DictionaryValue::key_iterator iter = info->begin_keys(); | |
1240 iter != info->end_keys(); ++iter) { | |
1241 const std::string& key = *iter; | |
1242 Value* value; | |
1243 bool res = info->GetWithoutPathExpansion(key, &value); | |
1244 DCHECK(res); | |
1245 if (res) { | |
1246 int index = property_index_parser().Get(key); | |
1247 if (!ParseValue(index, value)) // virtual. | |
1248 VLOG(1) << "Network: " << name() | |
1249 << " Type: " << ConnectionTypeToString(type()) | |
1250 << " Unhandled key: " << key; | |
1251 } | |
1252 } | |
1253 CalculateUniqueId(); | |
1254 } | 238 } |
1255 | 239 |
1256 void Network::EraseCredentials() { | 240 void Network::EraseCredentials() { |
1257 } | 241 } |
1258 | 242 |
1259 void Network::CalculateUniqueId() { | 243 void Network::CalculateUniqueId() { |
1260 unique_id_ = name_; | 244 unique_id_ = name_; |
1261 } | 245 } |
1262 | 246 |
1263 bool Network::RequiresUserProfile() const { | 247 bool Network::RequiresUserProfile() const { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1429 if (strlen(ipconfig.address) > 0) { | 413 if (strlen(ipconfig.address) > 0) { |
1430 ip_address_ = ipconfig.address; | 414 ip_address_ = ipconfig.address; |
1431 break; | 415 break; |
1432 } | 416 } |
1433 } | 417 } |
1434 chromeos::FreeIPConfigStatus(ipconfig_status); | 418 chromeos::FreeIPConfigStatus(ipconfig_status); |
1435 } | 419 } |
1436 } | 420 } |
1437 } | 421 } |
1438 | 422 |
| 423 bool Network::UpdateStatus(const std::string& key, |
| 424 const Value& value, |
| 425 PropertyIndex* index) { |
| 426 if (network_parser_.get()) |
| 427 return network_parser_->UpdateStatus(key, value, this, index); |
| 428 return false; |
| 429 } |
| 430 |
| 431 //////////////////////////////////////////////////////////////////////////////// |
| 432 // EthernetNetwork |
| 433 |
| 434 EthernetNetwork::EthernetNetwork(const std::string& service_path) |
| 435 : Network(service_path, TYPE_ETHERNET, new NativeEthernetNetworkParser) { |
| 436 } |
| 437 |
1439 //////////////////////////////////////////////////////////////////////////////// | 438 //////////////////////////////////////////////////////////////////////////////// |
1440 // VirtualNetwork | 439 // VirtualNetwork |
1441 | 440 |
1442 VirtualNetwork::VirtualNetwork(const std::string& service_path) | 441 VirtualNetwork::VirtualNetwork(const std::string& service_path) |
1443 : Network(service_path, TYPE_VPN), | 442 : Network(service_path, TYPE_VPN, new NativeVirtualNetworkParser), |
1444 provider_type_(PROVIDER_TYPE_L2TP_IPSEC_PSK) { | 443 provider_type_(PROVIDER_TYPE_L2TP_IPSEC_PSK) { |
1445 } | 444 } |
1446 | 445 |
1447 VirtualNetwork::~VirtualNetwork() {} | 446 VirtualNetwork::~VirtualNetwork() {} |
1448 | 447 |
1449 bool VirtualNetwork::ParseProviderValue(int index, const Value* value) { | |
1450 switch (index) { | |
1451 case PROPERTY_INDEX_HOST: | |
1452 return value->GetAsString(&server_hostname_); | |
1453 case PROPERTY_INDEX_NAME: | |
1454 // Note: shadows Network::name_ property. | |
1455 return value->GetAsString(&name_); | |
1456 case PROPERTY_INDEX_TYPE: { | |
1457 std::string provider_type_string; | |
1458 if (value->GetAsString(&provider_type_string)) { | |
1459 provider_type_ = ParseProviderType(provider_type_string); | |
1460 return true; | |
1461 } | |
1462 break; | |
1463 } | |
1464 case PROPERTY_INDEX_L2TPIPSEC_CA_CERT_NSS: | |
1465 return value->GetAsString(&ca_cert_nss_); | |
1466 case PROPERTY_INDEX_L2TPIPSEC_PIN: | |
1467 // Ignore PIN property. | |
1468 return true; | |
1469 case PROPERTY_INDEX_L2TPIPSEC_PSK: | |
1470 return value->GetAsString(&psk_passphrase_); | |
1471 case PROPERTY_INDEX_L2TPIPSEC_CLIENT_CERT_ID: | |
1472 return value->GetAsString(&client_cert_id_); | |
1473 case PROPERTY_INDEX_L2TPIPSEC_CLIENT_CERT_SLOT: | |
1474 // Ignore ClientCertSlot property. | |
1475 return true; | |
1476 case PROPERTY_INDEX_L2TPIPSEC_USER: | |
1477 return value->GetAsString(&username_); | |
1478 case PROPERTY_INDEX_L2TPIPSEC_PASSWORD: | |
1479 return value->GetAsString(&user_passphrase_); | |
1480 default: | |
1481 break; | |
1482 } | |
1483 return false; | |
1484 } | |
1485 | |
1486 bool VirtualNetwork::ParseValue(int index, const Value* value) { | |
1487 switch (index) { | |
1488 case PROPERTY_INDEX_PROVIDER: { | |
1489 DCHECK_EQ(value->GetType(), Value::TYPE_DICTIONARY); | |
1490 const DictionaryValue* dict = static_cast<const DictionaryValue*>(value); | |
1491 for (DictionaryValue::key_iterator iter = dict->begin_keys(); | |
1492 iter != dict->end_keys(); ++iter) { | |
1493 const std::string& key = *iter; | |
1494 Value* v; | |
1495 bool res = dict->GetWithoutPathExpansion(key, &v); | |
1496 DCHECK(res); | |
1497 if (res) { | |
1498 int index = property_index_parser().Get(key); | |
1499 if (!ParseProviderValue(index, v)) | |
1500 VLOG(1) << name() << ": Provider unhandled key: " << key | |
1501 << " Type: " << v->GetType(); | |
1502 } | |
1503 } | |
1504 return true; | |
1505 } | |
1506 default: | |
1507 return Network::ParseValue(index, value); | |
1508 break; | |
1509 } | |
1510 return false; | |
1511 } | |
1512 | |
1513 void VirtualNetwork::ParseInfo(const DictionaryValue* info) { | |
1514 Network::ParseInfo(info); | |
1515 VLOG(1) << "VPN: " << name() | |
1516 << " Server: " << server_hostname() | |
1517 << " Type: " << ProviderTypeToString(provider_type()); | |
1518 if (provider_type_ == PROVIDER_TYPE_L2TP_IPSEC_PSK) { | |
1519 if (!client_cert_id_.empty()) | |
1520 provider_type_ = PROVIDER_TYPE_L2TP_IPSEC_USER_CERT; | |
1521 } | |
1522 } | |
1523 | |
1524 void VirtualNetwork::EraseCredentials() { | 448 void VirtualNetwork::EraseCredentials() { |
1525 WipeString(&ca_cert_nss_); | 449 WipeString(&ca_cert_nss_); |
1526 WipeString(&psk_passphrase_); | 450 WipeString(&psk_passphrase_); |
1527 WipeString(&client_cert_id_); | 451 WipeString(&client_cert_id_); |
1528 WipeString(&user_passphrase_); | 452 WipeString(&user_passphrase_); |
1529 } | 453 } |
1530 | 454 |
1531 void VirtualNetwork::CalculateUniqueId() { | 455 void VirtualNetwork::CalculateUniqueId() { |
1532 std::string provider_type(ProviderTypeToString(provider_type_)); | 456 std::string provider_type(ProviderTypeToString(provider_type_)); |
1533 unique_id_ = provider_type + "|" + server_hostname_; | 457 set_unique_id(provider_type + "|" + server_hostname_); |
1534 } | 458 } |
1535 | 459 |
1536 bool VirtualNetwork::RequiresUserProfile() const { | 460 bool VirtualNetwork::RequiresUserProfile() const { |
1537 return true; | 461 return true; |
1538 } | 462 } |
1539 | 463 |
1540 void VirtualNetwork::CopyCredentialsFromRemembered(Network* remembered) { | 464 void VirtualNetwork::CopyCredentialsFromRemembered(Network* remembered) { |
1541 DCHECK_EQ(remembered->type(), TYPE_VPN); | 465 DCHECK_EQ(remembered->type(), TYPE_VPN); |
1542 VirtualNetwork* remembered_vpn = static_cast<VirtualNetwork*>(remembered); | 466 VirtualNetwork* remembered_vpn = static_cast<VirtualNetwork*>(remembered); |
1543 VLOG(1) << "Copy VPN credentials: " << name() | 467 VLOG(1) << "Copy VPN credentials: " << name() |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1588 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_OPEN_VPN); | 512 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_OPEN_VPN); |
1589 break; | 513 break; |
1590 default: | 514 default: |
1591 return l10n_util::GetStringUTF8( | 515 return l10n_util::GetStringUTF8( |
1592 IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); | 516 IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); |
1593 break; | 517 break; |
1594 } | 518 } |
1595 } | 519 } |
1596 | 520 |
1597 void VirtualNetwork::SetCACertNSS(const std::string& ca_cert_nss) { | 521 void VirtualNetwork::SetCACertNSS(const std::string& ca_cert_nss) { |
1598 SetStringProperty(kL2TPIPSecCACertNSSProperty, ca_cert_nss, &ca_cert_nss_); | 522 SetStringProperty(kL2tpIpsecCaCertNssProperty, ca_cert_nss, &ca_cert_nss_); |
1599 } | 523 } |
1600 | 524 |
1601 void VirtualNetwork::SetPSKPassphrase(const std::string& psk_passphrase) { | 525 void VirtualNetwork::SetPSKPassphrase(const std::string& psk_passphrase) { |
1602 SetStringProperty(kL2TPIPSecPSKProperty, psk_passphrase, | 526 SetStringProperty(kL2tpIpsecPskProperty, psk_passphrase, |
1603 &psk_passphrase_); | 527 &psk_passphrase_); |
1604 } | 528 } |
1605 | 529 |
1606 void VirtualNetwork::SetClientCertID(const std::string& cert_id) { | 530 void VirtualNetwork::SetClientCertID(const std::string& cert_id) { |
1607 SetStringProperty(kL2TPIPSecClientCertIDProperty, cert_id, &client_cert_id_); | 531 SetStringProperty(kL2tpIpsecClientCertIdProperty, cert_id, &client_cert_id_); |
1608 } | 532 } |
1609 | 533 |
1610 void VirtualNetwork::SetUsername(const std::string& username) { | 534 void VirtualNetwork::SetUsername(const std::string& username) { |
1611 SetStringProperty(kL2TPIPSecUserProperty, username, &username_); | 535 SetStringProperty(kL2tpIpsecUserProperty, username, &username_); |
1612 } | 536 } |
1613 | 537 |
1614 void VirtualNetwork::SetUserPassphrase(const std::string& user_passphrase) { | 538 void VirtualNetwork::SetUserPassphrase(const std::string& user_passphrase) { |
1615 SetStringProperty(kL2TPIPSecPasswordProperty, user_passphrase, | 539 SetStringProperty(kL2tpIpsecPasswordProperty, user_passphrase, |
1616 &user_passphrase_); | 540 &user_passphrase_); |
1617 } | 541 } |
1618 | 542 |
1619 void VirtualNetwork::SetCertificateSlotAndPin( | 543 void VirtualNetwork::SetCertificateSlotAndPin( |
1620 const std::string& slot, const std::string& pin) { | 544 const std::string& slot, const std::string& pin) { |
1621 SetOrClearStringProperty(kL2TPIPSecClientCertSlotProp, slot, NULL); | 545 SetOrClearStringProperty(kL2tpIpsecClientCertSlotProp, slot, NULL); |
1622 SetOrClearStringProperty(kL2TPIPSecPINProperty, pin, NULL); | 546 SetOrClearStringProperty(kL2tpIpsecPinProperty, pin, NULL); |
1623 } | 547 } |
1624 | 548 |
1625 //////////////////////////////////////////////////////////////////////////////// | 549 //////////////////////////////////////////////////////////////////////////////// |
1626 // WirelessNetwork | 550 // WirelessNetwork |
1627 | 551 |
1628 bool WirelessNetwork::ParseValue(int index, const Value* value) { | |
1629 switch (index) { | |
1630 case PROPERTY_INDEX_SIGNAL_STRENGTH: | |
1631 return value->GetAsInteger(&strength_); | |
1632 default: | |
1633 return Network::ParseValue(index, value); | |
1634 break; | |
1635 } | |
1636 return false; | |
1637 } | |
1638 | |
1639 //////////////////////////////////////////////////////////////////////////////// | 552 //////////////////////////////////////////////////////////////////////////////// |
1640 // CellularDataPlan | 553 // CellularDataPlan |
1641 | 554 |
1642 CellularDataPlan::CellularDataPlan() | 555 CellularDataPlan::CellularDataPlan() |
1643 : plan_name("Unknown"), | 556 : plan_name("Unknown"), |
1644 plan_type(CELLULAR_DATA_PLAN_UNLIMITED), | 557 plan_type(CELLULAR_DATA_PLAN_UNLIMITED), |
1645 plan_data_bytes(0), | 558 plan_data_bytes(0), |
1646 data_bytes_used(0) { | 559 data_bytes_used(0) { |
1647 } | 560 } |
1648 | 561 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1876 &localized_name)) | 789 &localized_name)) |
1877 localized_name.clear(); | 790 localized_name.clear(); |
1878 if (!dict.GetStringWithoutPathExpansion(kApnLanguageProperty, &language)) | 791 if (!dict.GetStringWithoutPathExpansion(kApnLanguageProperty, &language)) |
1879 language.clear(); | 792 language.clear(); |
1880 } | 793 } |
1881 | 794 |
1882 //////////////////////////////////////////////////////////////////////////////// | 795 //////////////////////////////////////////////////////////////////////////////// |
1883 // CellularNetwork | 796 // CellularNetwork |
1884 | 797 |
1885 CellularNetwork::CellularNetwork(const std::string& service_path) | 798 CellularNetwork::CellularNetwork(const std::string& service_path) |
1886 : WirelessNetwork(service_path, TYPE_CELLULAR), | 799 : WirelessNetwork(service_path, TYPE_CELLULAR, |
| 800 new NativeCellularNetworkParser), |
1887 activation_state_(ACTIVATION_STATE_UNKNOWN), | 801 activation_state_(ACTIVATION_STATE_UNKNOWN), |
1888 network_technology_(NETWORK_TECHNOLOGY_UNKNOWN), | 802 network_technology_(NETWORK_TECHNOLOGY_UNKNOWN), |
1889 roaming_state_(ROAMING_STATE_UNKNOWN), | 803 roaming_state_(ROAMING_STATE_UNKNOWN), |
1890 data_left_(DATA_UNKNOWN) { | 804 data_left_(DATA_UNKNOWN) { |
1891 } | 805 } |
1892 | 806 |
1893 CellularNetwork::~CellularNetwork() { | 807 CellularNetwork::~CellularNetwork() { |
1894 } | 808 } |
1895 | 809 |
1896 bool CellularNetwork::ParseValue(int index, const Value* value) { | |
1897 switch (index) { | |
1898 case PROPERTY_INDEX_ACTIVATION_STATE: { | |
1899 std::string activation_state_string; | |
1900 if (value->GetAsString(&activation_state_string)) { | |
1901 ActivationState prev_state = activation_state_; | |
1902 activation_state_ = ParseActivationState(activation_state_string); | |
1903 if (activation_state_ != prev_state) | |
1904 RefreshDataPlansIfNeeded(); | |
1905 return true; | |
1906 } | |
1907 break; | |
1908 } | |
1909 case PROPERTY_INDEX_CELLULAR_APN: { | |
1910 if (value->IsType(Value::TYPE_DICTIONARY)) { | |
1911 apn_.Set(*static_cast<const DictionaryValue*>(value)); | |
1912 return true; | |
1913 } | |
1914 break; | |
1915 } | |
1916 case PROPERTY_INDEX_CELLULAR_LAST_GOOD_APN: { | |
1917 if (value->IsType(Value::TYPE_DICTIONARY)) { | |
1918 last_good_apn_.Set(*static_cast<const DictionaryValue*>(value)); | |
1919 return true; | |
1920 } | |
1921 break; | |
1922 } | |
1923 case PROPERTY_INDEX_NETWORK_TECHNOLOGY: { | |
1924 std::string network_technology_string; | |
1925 if (value->GetAsString(&network_technology_string)) { | |
1926 network_technology_ = ParseNetworkTechnology(network_technology_string); | |
1927 return true; | |
1928 } | |
1929 break; | |
1930 } | |
1931 case PROPERTY_INDEX_ROAMING_STATE: { | |
1932 std::string roaming_state_string; | |
1933 if (value->GetAsString(&roaming_state_string)) { | |
1934 roaming_state_ = ParseRoamingState(roaming_state_string); | |
1935 return true; | |
1936 } | |
1937 break; | |
1938 } | |
1939 case PROPERTY_INDEX_OPERATOR_NAME: | |
1940 return value->GetAsString(&operator_name_); | |
1941 case PROPERTY_INDEX_OPERATOR_CODE: | |
1942 return value->GetAsString(&operator_code_); | |
1943 case PROPERTY_INDEX_SERVING_OPERATOR: { | |
1944 if (value->IsType(Value::TYPE_DICTIONARY)) { | |
1945 const DictionaryValue* dict = | |
1946 static_cast<const DictionaryValue*>(value); | |
1947 operator_code_.clear(); | |
1948 operator_country_.clear(); | |
1949 operator_name_.clear(); | |
1950 dict->GetStringWithoutPathExpansion(kOperatorNameKey, | |
1951 &operator_name_); | |
1952 dict->GetStringWithoutPathExpansion(kOperatorCodeKey, | |
1953 &operator_code_); | |
1954 dict->GetStringWithoutPathExpansion(kOperatorCountryKey, | |
1955 &operator_country_); | |
1956 return true; | |
1957 } | |
1958 break; | |
1959 } | |
1960 case PROPERTY_INDEX_PAYMENT_URL: | |
1961 return value->GetAsString(&payment_url_); | |
1962 case PROPERTY_INDEX_USAGE_URL: | |
1963 return value->GetAsString(&usage_url_); | |
1964 case PROPERTY_INDEX_STATE: { | |
1965 // Save previous state before calling WirelessNetwork::ParseValue. | |
1966 ConnectionState prev_state = state_; | |
1967 if (WirelessNetwork::ParseValue(index, value)) { | |
1968 if (state_ != prev_state) | |
1969 RefreshDataPlansIfNeeded(); | |
1970 return true; | |
1971 } | |
1972 break; | |
1973 } | |
1974 default: | |
1975 return WirelessNetwork::ParseValue(index, value); | |
1976 } | |
1977 return false; | |
1978 } | |
1979 | |
1980 bool CellularNetwork::StartActivation() const { | 810 bool CellularNetwork::StartActivation() const { |
1981 if (!EnsureCrosLoaded()) | 811 if (!EnsureCrosLoaded()) |
1982 return false; | 812 return false; |
1983 return chromeos::ActivateCellularModem(service_path().c_str(), NULL); | 813 return chromeos::ActivateCellularModem(service_path().c_str(), NULL); |
1984 } | 814 } |
1985 | 815 |
1986 void CellularNetwork::RefreshDataPlansIfNeeded() const { | 816 void CellularNetwork::RefreshDataPlansIfNeeded() const { |
1987 if (!EnsureCrosLoaded()) | 817 if (!EnsureCrosLoaded()) |
1988 return; | 818 return; |
1989 if (connected() && activated()) | 819 if (connected() && activated()) |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2098 return l10n_util::GetStringUTF8( | 928 return l10n_util::GetStringUTF8( |
2099 IDS_CHROMEOS_NETWORK_ROAMING_STATE_UNKNOWN); | 929 IDS_CHROMEOS_NETWORK_ROAMING_STATE_UNKNOWN); |
2100 break; | 930 break; |
2101 } | 931 } |
2102 } | 932 } |
2103 | 933 |
2104 //////////////////////////////////////////////////////////////////////////////// | 934 //////////////////////////////////////////////////////////////////////////////// |
2105 // WifiNetwork | 935 // WifiNetwork |
2106 | 936 |
2107 WifiNetwork::WifiNetwork(const std::string& service_path) | 937 WifiNetwork::WifiNetwork(const std::string& service_path) |
2108 : WirelessNetwork(service_path, TYPE_WIFI), | 938 : WirelessNetwork(service_path, TYPE_WIFI, new NativeWifiNetworkParser), |
2109 encryption_(SECURITY_NONE), | 939 encryption_(SECURITY_NONE), |
2110 passphrase_required_(false), | 940 passphrase_required_(false), |
2111 eap_method_(EAP_METHOD_UNKNOWN), | 941 eap_method_(EAP_METHOD_UNKNOWN), |
2112 eap_phase_2_auth_(EAP_PHASE_2_AUTH_AUTO), | 942 eap_phase_2_auth_(EAP_PHASE_2_AUTH_AUTO), |
2113 eap_use_system_cas_(true) { | 943 eap_use_system_cas_(true) { |
2114 } | 944 } |
2115 | 945 |
2116 WifiNetwork::~WifiNetwork() {} | 946 WifiNetwork::~WifiNetwork() {} |
2117 | 947 |
2118 void WifiNetwork::CalculateUniqueId() { | 948 void WifiNetwork::CalculateUniqueId() { |
2119 ConnectionSecurity encryption = encryption_; | 949 ConnectionSecurity encryption = encryption_; |
2120 // Flimflam treats wpa and rsn as psk internally, so convert those types | 950 // Flimflam treats wpa and rsn as psk internally, so convert those types |
2121 // to psk for unique naming. | 951 // to psk for unique naming. |
2122 if (encryption == SECURITY_WPA || encryption == SECURITY_RSN) | 952 if (encryption == SECURITY_WPA || encryption == SECURITY_RSN) |
2123 encryption = SECURITY_PSK; | 953 encryption = SECURITY_PSK; |
2124 std::string security = std::string(SecurityToString(encryption)); | 954 std::string security = std::string(SecurityToString(encryption)); |
2125 unique_id_ = security + "|" + name_; | 955 set_unique_id(security + "|" + name()); |
2126 } | 956 } |
2127 | 957 |
2128 bool WifiNetwork::SetSsid(const std::string& ssid) { | 958 bool WifiNetwork::SetSsid(const std::string& ssid) { |
2129 // Detects encoding and convert to UTF-8. | 959 // Detects encoding and convert to UTF-8. |
2130 std::string ssid_utf8; | 960 std::string ssid_utf8; |
2131 if (!IsStringUTF8(ssid)) { | 961 if (!IsStringUTF8(ssid)) { |
2132 std::string encoding; | 962 std::string encoding; |
2133 if (base::DetectEncoding(ssid, &encoding)) { | 963 if (base::DetectEncoding(ssid, &encoding)) { |
2134 if (!base::ConvertToUtf8AndNormalize(ssid, encoding, &ssid_utf8)) { | 964 if (!base::ConvertToUtf8AndNormalize(ssid, encoding, &ssid_utf8)) { |
2135 ssid_utf8.clear(); | 965 ssid_utf8.clear(); |
(...skipping 14 matching lines...) Expand all Loading... |
2150 std::vector<uint8> ssid_raw; | 980 std::vector<uint8> ssid_raw; |
2151 if (!base::HexStringToBytes(ssid_hex, &ssid_raw)) { | 981 if (!base::HexStringToBytes(ssid_hex, &ssid_raw)) { |
2152 LOG(ERROR) << "Illegal hex char is found in WiFi.HexSSID."; | 982 LOG(ERROR) << "Illegal hex char is found in WiFi.HexSSID."; |
2153 ssid_raw.clear(); | 983 ssid_raw.clear(); |
2154 return false; | 984 return false; |
2155 } | 985 } |
2156 | 986 |
2157 return SetSsid(std::string(ssid_raw.begin(), ssid_raw.end())); | 987 return SetSsid(std::string(ssid_raw.begin(), ssid_raw.end())); |
2158 } | 988 } |
2159 | 989 |
2160 bool WifiNetwork::ParseValue(int index, const Value* value) { | |
2161 switch (index) { | |
2162 case PROPERTY_INDEX_WIFI_HEX_SSID: { | |
2163 std::string ssid_hex; | |
2164 if (!value->GetAsString(&ssid_hex)) | |
2165 return false; | |
2166 | |
2167 SetHexSsid(ssid_hex); | |
2168 return true; | |
2169 } | |
2170 case PROPERTY_INDEX_WIFI_AUTH_MODE: | |
2171 case PROPERTY_INDEX_WIFI_PHY_MODE: | |
2172 case PROPERTY_INDEX_WIFI_HIDDEN_SSID: | |
2173 case PROPERTY_INDEX_WIFI_FREQUENCY: | |
2174 // These properties are currently not used in the UI. | |
2175 return true; | |
2176 case PROPERTY_INDEX_NAME: { | |
2177 // Does not change network name when it was already set by WiFi.HexSSID. | |
2178 if (!name().empty()) | |
2179 return true; | |
2180 else | |
2181 return WirelessNetwork::ParseValue(index, value); | |
2182 } | |
2183 case PROPERTY_INDEX_SECURITY: { | |
2184 std::string security_string; | |
2185 if (value->GetAsString(&security_string)) { | |
2186 encryption_ = ParseSecurity(security_string); | |
2187 return true; | |
2188 } | |
2189 break; | |
2190 } | |
2191 case PROPERTY_INDEX_PASSPHRASE: { | |
2192 std::string passphrase; | |
2193 if (value->GetAsString(&passphrase)) { | |
2194 // Only store the passphrase if we are the owner. | |
2195 // TODO(stevenjb): Remove this when chromium-os:12948 is resolved. | |
2196 if (chromeos::UserManager::Get()->current_user_is_owner()) | |
2197 passphrase_ = passphrase; | |
2198 return true; | |
2199 } | |
2200 break; | |
2201 } | |
2202 case PROPERTY_INDEX_PASSPHRASE_REQUIRED: | |
2203 return value->GetAsBoolean(&passphrase_required_); | |
2204 case PROPERTY_INDEX_IDENTITY: | |
2205 return value->GetAsString(&identity_); | |
2206 case PROPERTY_INDEX_EAP_IDENTITY: | |
2207 return value->GetAsString(&eap_identity_); | |
2208 case PROPERTY_INDEX_EAP_METHOD: { | |
2209 std::string method; | |
2210 if (value->GetAsString(&method)) { | |
2211 eap_method_ = ParseEAPMethod(method); | |
2212 return true; | |
2213 } | |
2214 break; | |
2215 } | |
2216 case PROPERTY_INDEX_EAP_PHASE_2_AUTH: { | |
2217 std::string auth; | |
2218 if (value->GetAsString(&auth)) { | |
2219 eap_phase_2_auth_ = ParseEAPPhase2Auth(auth); | |
2220 return true; | |
2221 } | |
2222 break; | |
2223 } | |
2224 case PROPERTY_INDEX_EAP_ANONYMOUS_IDENTITY: | |
2225 return value->GetAsString(&eap_anonymous_identity_); | |
2226 case PROPERTY_INDEX_EAP_CERT_ID: | |
2227 return value->GetAsString(&eap_client_cert_pkcs11_id_); | |
2228 case PROPERTY_INDEX_EAP_CA_CERT_NSS: | |
2229 return value->GetAsString(&eap_server_ca_cert_nss_nickname_); | |
2230 case PROPERTY_INDEX_EAP_USE_SYSTEM_CAS: | |
2231 return value->GetAsBoolean(&eap_use_system_cas_); | |
2232 case PROPERTY_INDEX_EAP_PASSWORD: | |
2233 return value->GetAsString(&eap_passphrase_); | |
2234 case PROPERTY_INDEX_EAP_CLIENT_CERT: | |
2235 case PROPERTY_INDEX_EAP_CLIENT_CERT_NSS: | |
2236 case PROPERTY_INDEX_EAP_PRIVATE_KEY: | |
2237 case PROPERTY_INDEX_EAP_PRIVATE_KEY_PASSWORD: | |
2238 case PROPERTY_INDEX_EAP_KEY_ID: | |
2239 case PROPERTY_INDEX_EAP_CA_CERT: | |
2240 case PROPERTY_INDEX_EAP_CA_CERT_ID: | |
2241 case PROPERTY_INDEX_EAP_PIN: | |
2242 case PROPERTY_INDEX_EAP_KEY_MGMT: | |
2243 // These properties are currently not used in the UI. | |
2244 return true; | |
2245 default: | |
2246 return WirelessNetwork::ParseValue(index, value); | |
2247 } | |
2248 return false; | |
2249 } | |
2250 | |
2251 const std::string& WifiNetwork::GetPassphrase() const { | 990 const std::string& WifiNetwork::GetPassphrase() const { |
2252 if (!user_passphrase_.empty()) | 991 if (!user_passphrase_.empty()) |
2253 return user_passphrase_; | 992 return user_passphrase_; |
2254 return passphrase_; | 993 return passphrase_; |
2255 } | 994 } |
2256 | 995 |
2257 void WifiNetwork::SetPassphrase(const std::string& passphrase) { | 996 void WifiNetwork::SetPassphrase(const std::string& passphrase) { |
2258 // Set the user_passphrase_ only; passphrase_ stores the flimflam value. | 997 // Set the user_passphrase_ only; passphrase_ stores the flimflam value. |
2259 // If the user sets an empty passphrase, restore it to the passphrase | 998 // If the user sets an empty passphrase, restore it to the passphrase |
2260 // remembered by flimflam. | 999 // remembered by flimflam. |
(...skipping 20 matching lines...) Expand all Loading... |
2281 } | 1020 } |
2282 | 1021 |
2283 void WifiNetwork::SetIdentity(const std::string& identity) { | 1022 void WifiNetwork::SetIdentity(const std::string& identity) { |
2284 SetStringProperty(kIdentityProperty, identity, &identity_); | 1023 SetStringProperty(kIdentityProperty, identity, &identity_); |
2285 } | 1024 } |
2286 | 1025 |
2287 void WifiNetwork::SetEAPMethod(EAPMethod method) { | 1026 void WifiNetwork::SetEAPMethod(EAPMethod method) { |
2288 eap_method_ = method; | 1027 eap_method_ = method; |
2289 switch (method) { | 1028 switch (method) { |
2290 case EAP_METHOD_PEAP: | 1029 case EAP_METHOD_PEAP: |
2291 SetStringProperty(kEapMethodProperty, kEapMethodPEAP, NULL); | 1030 SetStringProperty(kEapMethodProperty, kEapMethodPeap, NULL); |
2292 break; | 1031 break; |
2293 case EAP_METHOD_TLS: | 1032 case EAP_METHOD_TLS: |
2294 SetStringProperty(kEapMethodProperty, kEapMethodTLS, NULL); | 1033 SetStringProperty(kEapMethodProperty, kEapMethodTls, NULL); |
2295 break; | 1034 break; |
2296 case EAP_METHOD_TTLS: | 1035 case EAP_METHOD_TTLS: |
2297 SetStringProperty(kEapMethodProperty, kEapMethodTTLS, NULL); | 1036 SetStringProperty(kEapMethodProperty, kEapMethodTtls, NULL); |
2298 break; | 1037 break; |
2299 case EAP_METHOD_LEAP: | 1038 case EAP_METHOD_LEAP: |
2300 SetStringProperty(kEapMethodProperty, kEapMethodLEAP, NULL); | 1039 SetStringProperty(kEapMethodProperty, kEapMethodLeap, NULL); |
2301 break; | 1040 break; |
2302 default: | 1041 default: |
2303 ClearProperty(kEapMethodProperty); | 1042 ClearProperty(kEapMethodProperty); |
2304 break; | 1043 break; |
2305 } | 1044 } |
2306 } | 1045 } |
2307 | 1046 |
2308 void WifiNetwork::SetEAPPhase2Auth(EAPPhase2Auth auth) { | 1047 void WifiNetwork::SetEAPPhase2Auth(EAPPhase2Auth auth) { |
2309 eap_phase_2_auth_ = auth; | 1048 eap_phase_2_auth_ = auth; |
2310 bool is_peap = (eap_method_ == EAP_METHOD_PEAP); | 1049 bool is_peap = (eap_method_ == EAP_METHOD_PEAP); |
2311 switch (auth) { | 1050 switch (auth) { |
2312 case EAP_PHASE_2_AUTH_AUTO: | 1051 case EAP_PHASE_2_AUTH_AUTO: |
2313 ClearProperty(kEapPhase2AuthProperty); | 1052 ClearProperty(kEapPhase2AuthProperty); |
2314 break; | 1053 break; |
2315 case EAP_PHASE_2_AUTH_MD5: | 1054 case EAP_PHASE_2_AUTH_MD5: |
2316 SetStringProperty(kEapPhase2AuthProperty, | 1055 SetStringProperty(kEapPhase2AuthProperty, |
2317 is_peap ? kEapPhase2AuthPEAPMD5 | 1056 is_peap ? kEapPhase2AuthPeapMd5 |
2318 : kEapPhase2AuthTTLSMD5, | 1057 : kEapPhase2AuthTtlsMd5, |
2319 NULL); | 1058 NULL); |
2320 break; | 1059 break; |
2321 case EAP_PHASE_2_AUTH_MSCHAPV2: | 1060 case EAP_PHASE_2_AUTH_MSCHAPV2: |
2322 SetStringProperty(kEapPhase2AuthProperty, | 1061 SetStringProperty(kEapPhase2AuthProperty, |
2323 is_peap ? kEapPhase2AuthPEAPMSCHAPV2 | 1062 is_peap ? kEapPhase2AuthPeapMschap2 |
2324 : kEapPhase2AuthTTLSMSCHAPV2, | 1063 : kEapPhase2AuthTtlsMschapV2, |
2325 NULL); | 1064 NULL); |
2326 break; | 1065 break; |
2327 case EAP_PHASE_2_AUTH_MSCHAP: | 1066 case EAP_PHASE_2_AUTH_MSCHAP: |
2328 SetStringProperty(kEapPhase2AuthProperty, kEapPhase2AuthTTLSMSCHAP, NULL); | 1067 SetStringProperty(kEapPhase2AuthProperty, kEapPhase2AuthTtlsMschap, NULL); |
2329 break; | 1068 break; |
2330 case EAP_PHASE_2_AUTH_PAP: | 1069 case EAP_PHASE_2_AUTH_PAP: |
2331 SetStringProperty(kEapPhase2AuthProperty, kEapPhase2AuthTTLSPAP, NULL); | 1070 SetStringProperty(kEapPhase2AuthProperty, kEapPhase2AuthTtlsPap, NULL); |
2332 break; | 1071 break; |
2333 case EAP_PHASE_2_AUTH_CHAP: | 1072 case EAP_PHASE_2_AUTH_CHAP: |
2334 SetStringProperty(kEapPhase2AuthProperty, kEapPhase2AuthTTLSCHAP, NULL); | 1073 SetStringProperty(kEapPhase2AuthProperty, kEapPhase2AuthTtlsChap, NULL); |
2335 break; | 1074 break; |
2336 } | 1075 } |
2337 } | 1076 } |
2338 | 1077 |
2339 void WifiNetwork::SetEAPServerCaCertNssNickname( | 1078 void WifiNetwork::SetEAPServerCaCertNssNickname( |
2340 const std::string& nss_nickname) { | 1079 const std::string& nss_nickname) { |
2341 VLOG(1) << "SetEAPServerCaCertNssNickname " << nss_nickname; | 1080 VLOG(1) << "SetEAPServerCaCertNssNickname " << nss_nickname; |
2342 SetOrClearStringProperty(kEapCaCertNssProperty, nss_nickname, | 1081 SetOrClearStringProperty(kEapCaCertNssProperty, nss_nickname, |
2343 &eap_server_ca_cert_nss_nickname_); | 1082 &eap_server_ca_cert_nss_nickname_); |
2344 } | 1083 } |
2345 | 1084 |
2346 void WifiNetwork::SetEAPClientCertPkcs11Id(const std::string& pkcs11_id) { | 1085 void WifiNetwork::SetEAPClientCertPkcs11Id(const std::string& pkcs11_id) { |
2347 VLOG(1) << "SetEAPClientCertPkcs11Id " << pkcs11_id; | 1086 VLOG(1) << "SetEAPClientCertPkcs11Id " << pkcs11_id; |
2348 SetOrClearStringProperty(kEapCertIDProperty, pkcs11_id, | 1087 SetOrClearStringProperty(kEapCertIdProperty, pkcs11_id, |
2349 &eap_client_cert_pkcs11_id_); | 1088 &eap_client_cert_pkcs11_id_); |
2350 // flimflam requires both CertID and KeyID for TLS connections, despite | 1089 // flimflam requires both CertID and KeyID for TLS connections, despite |
2351 // the fact that by convention they are the same ID. | 1090 // the fact that by convention they are the same ID. |
2352 SetOrClearStringProperty(kEapKeyIDProperty, pkcs11_id, NULL); | 1091 SetOrClearStringProperty(kEapKeyIdProperty, pkcs11_id, NULL); |
2353 } | 1092 } |
2354 | 1093 |
2355 void WifiNetwork::SetEAPUseSystemCAs(bool use_system_cas) { | 1094 void WifiNetwork::SetEAPUseSystemCAs(bool use_system_cas) { |
2356 SetBooleanProperty(kEapUseSystemCAsProperty, use_system_cas, | 1095 SetBooleanProperty(kEapUseSystemCasProperty, use_system_cas, |
2357 &eap_use_system_cas_); | 1096 &eap_use_system_cas_); |
2358 } | 1097 } |
2359 | 1098 |
2360 void WifiNetwork::SetEAPIdentity(const std::string& identity) { | 1099 void WifiNetwork::SetEAPIdentity(const std::string& identity) { |
2361 SetOrClearStringProperty(kEapIdentityProperty, identity, &eap_identity_); | 1100 SetOrClearStringProperty(kEapIdentityProperty, identity, &eap_identity_); |
2362 } | 1101 } |
2363 | 1102 |
2364 void WifiNetwork::SetEAPAnonymousIdentity(const std::string& identity) { | 1103 void WifiNetwork::SetEAPAnonymousIdentity(const std::string& identity) { |
2365 SetOrClearStringProperty(kEapAnonymousIdentityProperty, identity, | 1104 SetOrClearStringProperty(kEapAnonymousIdentityProperty, identity, |
2366 &eap_anonymous_identity_); | 1105 &eap_anonymous_identity_); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2404 } | 1143 } |
2405 case SECURITY_PSK: | 1144 case SECURITY_PSK: |
2406 return "PSK"; | 1145 return "PSK"; |
2407 } | 1146 } |
2408 return "Unknown"; | 1147 return "Unknown"; |
2409 } | 1148 } |
2410 | 1149 |
2411 bool WifiNetwork::IsPassphraseRequired() const { | 1150 bool WifiNetwork::IsPassphraseRequired() const { |
2412 // TODO(stevenjb): Remove error_ tests when fixed in flimflam | 1151 // TODO(stevenjb): Remove error_ tests when fixed in flimflam |
2413 // (http://crosbug.com/10135). | 1152 // (http://crosbug.com/10135). |
2414 if (error_ == ERROR_BAD_PASSPHRASE || error_ == ERROR_BAD_WEPKEY) | 1153 if (error() == ERROR_BAD_PASSPHRASE || error() == ERROR_BAD_WEPKEY) |
2415 return true; | 1154 return true; |
2416 // For 802.1x networks, configuration is required if connectable is false. | 1155 // For 802.1x networks, configuration is required if connectable is false. |
2417 if (encryption_ == SECURITY_8021X) | 1156 if (encryption_ == SECURITY_8021X) |
2418 return !connectable_; | 1157 return !connectable(); |
2419 return passphrase_required_; | 1158 return passphrase_required_; |
2420 } | 1159 } |
2421 | 1160 |
2422 bool WifiNetwork::RequiresUserProfile() const { | 1161 bool WifiNetwork::RequiresUserProfile() const { |
2423 // 8021X requires certificates which are only stored for individual users. | 1162 // 8021X requires certificates which are only stored for individual users. |
2424 if (encryption_ == SECURITY_8021X && | 1163 if (encryption_ == SECURITY_8021X && |
2425 (eap_method_ == EAP_METHOD_TLS || | 1164 (eap_method_ == EAP_METHOD_TLS || |
2426 !eap_client_cert_pkcs11_id().empty())) | 1165 !eap_client_cert_pkcs11_id().empty())) |
2427 return true; | 1166 return true; |
2428 return false; | 1167 return false; |
(...skipping 22 matching lines...) Expand all Loading... |
2451 | 1190 |
2452 // Called from ConnectToWifiNetwork. | 1191 // Called from ConnectToWifiNetwork. |
2453 // Calls ConnectToWifiNetworkUsingConnectData if network request succeeds. | 1192 // Calls ConnectToWifiNetworkUsingConnectData if network request succeeds. |
2454 virtual void CallRequestWifiNetworkAndConnect( | 1193 virtual void CallRequestWifiNetworkAndConnect( |
2455 const std::string& ssid, ConnectionSecurity security) = 0; | 1194 const std::string& ssid, ConnectionSecurity security) = 0; |
2456 // Called from ConnectToVirtualNetwork*. | 1195 // Called from ConnectToVirtualNetwork*. |
2457 // Calls ConnectToVirtualNetworkUsingConnectData if network request succeeds. | 1196 // Calls ConnectToVirtualNetworkUsingConnectData if network request succeeds. |
2458 virtual void CallRequestVirtualNetworkAndConnect( | 1197 virtual void CallRequestVirtualNetworkAndConnect( |
2459 const std::string& service_name, | 1198 const std::string& service_name, |
2460 const std::string& server_hostname, | 1199 const std::string& server_hostname, |
2461 VirtualNetwork::ProviderType provider_type) = 0; | 1200 ProviderType provider_type) = 0; |
2462 // Called from NetworkConnectStart. | 1201 // Called from NetworkConnectStart. |
2463 // Calls NetworkConnectCompleted when the connection attept completes. | 1202 // Calls NetworkConnectCompleted when the connection attept completes. |
2464 virtual void CallConnectToNetwork(Network* network) = 0; | 1203 virtual void CallConnectToNetwork(Network* network) = 0; |
2465 // Called from DeleteRememberedNetwork. | 1204 // Called from DeleteRememberedNetwork. |
2466 virtual void CallDeleteRememberedNetwork( | 1205 virtual void CallDeleteRememberedNetwork( |
2467 const std::string& profile_path, const std::string& service_path) = 0; | 1206 const std::string& profile_path, const std::string& service_path) = 0; |
2468 | 1207 |
2469 // Called from Enable*NetworkDevice. | 1208 // Called from Enable*NetworkDevice. |
2470 // Asynchronously enables or disables the specified device type. | 1209 // Asynchronously enables or disables the specified device type. |
2471 virtual void CallEnableNetworkDeviceType( | 1210 virtual void CallEnableNetworkDeviceType( |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2752 CellularNetwork::DataLeft GetDataLeft(CellularDataPlanVector* data_plans); | 1491 CellularNetwork::DataLeft GetDataLeft(CellularDataPlanVector* data_plans); |
2753 void UpdateCellularDataPlan(const std::string& service_path, | 1492 void UpdateCellularDataPlan(const std::string& service_path, |
2754 const CellularDataPlanList* data_plan_list); | 1493 const CellularDataPlanList* data_plan_list); |
2755 | 1494 |
2756 // Network list management functions. | 1495 // Network list management functions. |
2757 void UpdateActiveNetwork(Network* network); | 1496 void UpdateActiveNetwork(Network* network); |
2758 void AddNetwork(Network* network); | 1497 void AddNetwork(Network* network); |
2759 void DeleteNetwork(Network* network); | 1498 void DeleteNetwork(Network* network); |
2760 void AddRememberedNetwork(Network* network); | 1499 void AddRememberedNetwork(Network* network); |
2761 void DeleteRememberedNetwork(const std::string& service_path); | 1500 void DeleteRememberedNetwork(const std::string& service_path); |
2762 Network* CreateNewNetwork( | |
2763 ConnectionType type, const std::string& service_path); | |
2764 void ClearNetworks(); | 1501 void ClearNetworks(); |
2765 void ClearRememberedNetworks(); | 1502 void ClearRememberedNetworks(); |
2766 void DeleteNetworks(); | 1503 void DeleteNetworks(); |
2767 void DeleteRememberedNetworks(); | 1504 void DeleteRememberedNetworks(); |
2768 void DeleteDevice(const std::string& device_path); | 1505 void DeleteDevice(const std::string& device_path); |
2769 void DeleteDeviceFromDeviceObserversMap(const std::string& device_path); | 1506 void DeleteDeviceFromDeviceObserversMap(const std::string& device_path); |
2770 | 1507 |
2771 // Profile management functions. | 1508 // Profile management functions. |
2772 void SetProfileType(Network* network, NetworkProfileType type); | 1509 void SetProfileType(Network* network, NetworkProfileType type); |
2773 void SetProfileTypeFromPath(Network* network); | 1510 void SetProfileTypeFromPath(Network* network); |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3159 NetworkDeviceMap::iterator iter = device_map_.find(path); | 1896 NetworkDeviceMap::iterator iter = device_map_.find(path); |
3160 if (iter != device_map_.end()) | 1897 if (iter != device_map_.end()) |
3161 return iter->second; | 1898 return iter->second; |
3162 LOG(WARNING) << "Device path not found: " << path; | 1899 LOG(WARNING) << "Device path not found: " << path; |
3163 return NULL; | 1900 return NULL; |
3164 } | 1901 } |
3165 | 1902 |
3166 const NetworkDevice* NetworkLibraryImplBase::FindCellularDevice() const { | 1903 const NetworkDevice* NetworkLibraryImplBase::FindCellularDevice() const { |
3167 for (NetworkDeviceMap::const_iterator iter = device_map_.begin(); | 1904 for (NetworkDeviceMap::const_iterator iter = device_map_.begin(); |
3168 iter != device_map_.end(); ++iter) { | 1905 iter != device_map_.end(); ++iter) { |
3169 if (iter->second->type() == TYPE_CELLULAR) | 1906 if (iter->second && iter->second->type() == TYPE_CELLULAR) |
3170 return iter->second; | 1907 return iter->second; |
3171 } | 1908 } |
3172 return NULL; | 1909 return NULL; |
3173 } | 1910 } |
3174 | 1911 |
3175 const NetworkDevice* NetworkLibraryImplBase::FindEthernetDevice() const { | 1912 const NetworkDevice* NetworkLibraryImplBase::FindEthernetDevice() const { |
3176 for (NetworkDeviceMap::const_iterator iter = device_map_.begin(); | 1913 for (NetworkDeviceMap::const_iterator iter = device_map_.begin(); |
3177 iter != device_map_.end(); ++iter) { | 1914 iter != device_map_.end(); ++iter) { |
3178 if (iter->second->type() == TYPE_ETHERNET) | 1915 if (iter->second->type() == TYPE_ETHERNET) |
3179 return iter->second; | 1916 return iter->second; |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3605 const std::string& username, | 2342 const std::string& username, |
3606 const std::string& user_passphrase) { | 2343 const std::string& user_passphrase) { |
3607 // Store the connection data to be used by the callback. | 2344 // Store the connection data to be used by the callback. |
3608 connect_data_.service_name = service_name; | 2345 connect_data_.service_name = service_name; |
3609 connect_data_.psk_key = psk; | 2346 connect_data_.psk_key = psk; |
3610 connect_data_.server_hostname = server_hostname; | 2347 connect_data_.server_hostname = server_hostname; |
3611 connect_data_.psk_username = username; | 2348 connect_data_.psk_username = username; |
3612 connect_data_.passphrase = user_passphrase; | 2349 connect_data_.passphrase = user_passphrase; |
3613 CallRequestVirtualNetworkAndConnect( | 2350 CallRequestVirtualNetworkAndConnect( |
3614 service_name, server_hostname, | 2351 service_name, server_hostname, |
3615 VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_PSK); | 2352 PROVIDER_TYPE_L2TP_IPSEC_PSK); |
3616 } | 2353 } |
3617 | 2354 |
3618 // 1. Connect to a virtual network with a user cert. | 2355 // 1. Connect to a virtual network with a user cert. |
3619 void NetworkLibraryImplBase::ConnectToVirtualNetworkCert( | 2356 void NetworkLibraryImplBase::ConnectToVirtualNetworkCert( |
3620 const std::string& service_name, | 2357 const std::string& service_name, |
3621 const std::string& server_hostname, | 2358 const std::string& server_hostname, |
3622 const std::string& server_ca_cert_nss_nickname, | 2359 const std::string& server_ca_cert_nss_nickname, |
3623 const std::string& client_cert_pkcs11_id, | 2360 const std::string& client_cert_pkcs11_id, |
3624 const std::string& username, | 2361 const std::string& username, |
3625 const std::string& user_passphrase) { | 2362 const std::string& user_passphrase) { |
3626 // Store the connection data to be used by the callback. | 2363 // Store the connection data to be used by the callback. |
3627 connect_data_.service_name = service_name; | 2364 connect_data_.service_name = service_name; |
3628 connect_data_.server_hostname = server_hostname; | 2365 connect_data_.server_hostname = server_hostname; |
3629 connect_data_.server_ca_cert_nss_nickname = server_ca_cert_nss_nickname; | 2366 connect_data_.server_ca_cert_nss_nickname = server_ca_cert_nss_nickname; |
3630 connect_data_.client_cert_pkcs11_id = client_cert_pkcs11_id; | 2367 connect_data_.client_cert_pkcs11_id = client_cert_pkcs11_id; |
3631 connect_data_.psk_username = username; | 2368 connect_data_.psk_username = username; |
3632 connect_data_.passphrase = user_passphrase; | 2369 connect_data_.passphrase = user_passphrase; |
3633 CallRequestVirtualNetworkAndConnect( | 2370 CallRequestVirtualNetworkAndConnect( |
3634 service_name, server_hostname, | 2371 service_name, server_hostname, |
3635 VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT); | 2372 PROVIDER_TYPE_L2TP_IPSEC_USER_CERT); |
3636 } | 2373 } |
3637 | 2374 |
3638 // 2. Requests a WiFi Network by SSID and security. | 2375 // 2. Requests a WiFi Network by SSID and security. |
3639 // Calls ConnectToWifiNetworkUsingConnectData if network request succeeds. | 2376 // Calls ConnectToWifiNetworkUsingConnectData if network request succeeds. |
3640 // virtual void CallRequestWifiNetworkAndConnect( | 2377 // virtual void CallRequestWifiNetworkAndConnect( |
3641 // const std::string& ssid, ConnectionSecurity security) = 0; | 2378 // const std::string& ssid, ConnectionSecurity security) = 0; |
3642 | 2379 |
3643 // 2. Requests a Virtual Network by service name, etc. | 2380 // 2. Requests a Virtual Network by service name, etc. |
3644 // Calls ConnectToVirtualNetworkUsingConnectData if network request succeeds. | 2381 // Calls ConnectToVirtualNetworkUsingConnectData if network request succeeds. |
3645 // virtual void CallRequestVirtualNetworkAndConnect( | 2382 // virtual void CallRequestVirtualNetworkAndConnect( |
3646 // const std::string& service_name, | 2383 // const std::string& service_name, |
3647 // const std::string& server_hostname, | 2384 // const std::string& server_hostname, |
3648 // VirtualNetwork::ProviderType provider_type) = 0; | 2385 // ProviderType provider_type) = 0; |
3649 | 2386 |
3650 // 3. Sets network properties stored in ConnectData and calls | 2387 // 3. Sets network properties stored in ConnectData and calls |
3651 // NetworkConnectStart. | 2388 // NetworkConnectStart. |
3652 void NetworkLibraryImplBase::ConnectToWifiNetworkUsingConnectData( | 2389 void NetworkLibraryImplBase::ConnectToWifiNetworkUsingConnectData( |
3653 WifiNetwork* wifi) { | 2390 WifiNetwork* wifi) { |
3654 ConnectData& data = connect_data_; | 2391 ConnectData& data = connect_data_; |
3655 if (wifi->name() != data.service_name) { | 2392 if (wifi->name() != data.service_name) { |
3656 LOG(WARNING) << "WiFi network name does not match ConnectData: " | 2393 LOG(WARNING) << "WiFi network name does not match ConnectData: " |
3657 << wifi->name() << " != " << data.service_name; | 2394 << wifi->name() << " != " << data.service_name; |
3658 return; | 2395 return; |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3868 } | 2605 } |
3869 } | 2606 } |
3870 DCHECK(!network->profile_path().empty()) | 2607 DCHECK(!network->profile_path().empty()) |
3871 << "Service path not in any profile: " << network->service_path(); | 2608 << "Service path not in any profile: " << network->service_path(); |
3872 } | 2609 } |
3873 | 2610 |
3874 void NetworkLibraryImplBase::DeleteRememberedNetwork( | 2611 void NetworkLibraryImplBase::DeleteRememberedNetwork( |
3875 const std::string& service_path) { | 2612 const std::string& service_path) { |
3876 NetworkMap::iterator found = remembered_network_map_.find(service_path); | 2613 NetworkMap::iterator found = remembered_network_map_.find(service_path); |
3877 if (found == remembered_network_map_.end()) { | 2614 if (found == remembered_network_map_.end()) { |
3878 LOG(WARNING) << "Attempt to delete non-existant remembered network: " | 2615 LOG(WARNING) << "Attempt to delete non-existent remembered network: " |
3879 << service_path; | 2616 << service_path; |
3880 return; | 2617 return; |
3881 } | 2618 } |
3882 | 2619 |
3883 // Delete remembered network from lists. | 2620 // Delete remembered network from lists. |
3884 Network* remembered_network = found->second; | 2621 Network* remembered_network = found->second; |
3885 remembered_network_map_.erase(found); | 2622 remembered_network_map_.erase(found); |
3886 | 2623 |
3887 if (remembered_network->type() == TYPE_WIFI) { | 2624 if (remembered_network->type() == TYPE_WIFI) { |
3888 WifiNetworkVector::iterator iter = std::find( | 2625 WifiNetworkVector::iterator iter = std::find( |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3922 SetProfileType(network, PROFILE_NONE); | 2659 SetProfileType(network, PROFILE_NONE); |
3923 } else { | 2660 } else { |
3924 // Network is not in visible list. | 2661 // Network is not in visible list. |
3925 VLOG(2) << "Remembered Network not visible: " | 2662 VLOG(2) << "Remembered Network not visible: " |
3926 << remembered_network->unique_id(); | 2663 << remembered_network->unique_id(); |
3927 } | 2664 } |
3928 | 2665 |
3929 delete remembered_network; | 2666 delete remembered_network; |
3930 } | 2667 } |
3931 | 2668 |
3932 Network* NetworkLibraryImplBase::CreateNewNetwork( | |
3933 ConnectionType type, const std::string& service_path) { | |
3934 switch (type) { | |
3935 case TYPE_ETHERNET: { | |
3936 EthernetNetwork* ethernet = new EthernetNetwork(service_path); | |
3937 return ethernet; | |
3938 } | |
3939 case TYPE_WIFI: { | |
3940 WifiNetwork* wifi = new WifiNetwork(service_path); | |
3941 return wifi; | |
3942 } | |
3943 case TYPE_CELLULAR: { | |
3944 CellularNetwork* cellular = new CellularNetwork(service_path); | |
3945 return cellular; | |
3946 } | |
3947 case TYPE_VPN: { | |
3948 VirtualNetwork* vpn = new VirtualNetwork(service_path); | |
3949 return vpn; | |
3950 } | |
3951 default: { | |
3952 LOG(WARNING) << "Unknown service type: " << type; | |
3953 return new Network(service_path, type); | |
3954 } | |
3955 } | |
3956 } | |
3957 | |
3958 //////////////////////////////////////////////////////////////////////////// | 2669 //////////////////////////////////////////////////////////////////////////// |
3959 | 2670 |
3960 void NetworkLibraryImplBase::ClearNetworks() { | 2671 void NetworkLibraryImplBase::ClearNetworks() { |
3961 network_map_.clear(); | 2672 network_map_.clear(); |
3962 network_unique_id_map_.clear(); | 2673 network_unique_id_map_.clear(); |
3963 ethernet_ = NULL; | 2674 ethernet_ = NULL; |
3964 active_wifi_ = NULL; | 2675 active_wifi_ = NULL; |
3965 active_cellular_ = NULL; | 2676 active_cellular_ = NULL; |
3966 active_virtual_ = NULL; | 2677 active_virtual_ = NULL; |
3967 wifi_networks_.clear(); | 2678 wifi_networks_.clear(); |
(...skipping 13 matching lines...) Expand all Loading... |
3981 } | 2692 } |
3982 | 2693 |
3983 void NetworkLibraryImplBase::DeleteRememberedNetworks() { | 2694 void NetworkLibraryImplBase::DeleteRememberedNetworks() { |
3984 STLDeleteValues(&remembered_network_map_); | 2695 STLDeleteValues(&remembered_network_map_); |
3985 ClearRememberedNetworks(); | 2696 ClearRememberedNetworks(); |
3986 } | 2697 } |
3987 | 2698 |
3988 void NetworkLibraryImplBase::DeleteDevice(const std::string& device_path) { | 2699 void NetworkLibraryImplBase::DeleteDevice(const std::string& device_path) { |
3989 NetworkDeviceMap::iterator found = device_map_.find(device_path); | 2700 NetworkDeviceMap::iterator found = device_map_.find(device_path); |
3990 if (found == device_map_.end()) { | 2701 if (found == device_map_.end()) { |
3991 LOG(WARNING) << "Attempt to delete non-existant device: " | 2702 LOG(WARNING) << "Attempt to delete non-existent device: " |
3992 << device_path; | 2703 << device_path; |
3993 return; | 2704 return; |
3994 } | 2705 } |
3995 VLOG(2) << " Deleting device: " << device_path; | 2706 VLOG(2) << " Deleting device: " << device_path; |
3996 NetworkDevice* device = found->second; | 2707 NetworkDevice* device = found->second; |
3997 device_map_.erase(found); | 2708 device_map_.erase(found); |
3998 delete device; | 2709 delete device; |
3999 DeleteDeviceFromDeviceObserversMap(device_path); | 2710 DeleteDeviceFromDeviceObserversMap(device_path); |
4000 } | 2711 } |
4001 | 2712 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4206 const std::string& device_path) OVERRIDE; | 2917 const std::string& device_path) OVERRIDE; |
4207 virtual void MonitorNetworkDeviceStop( | 2918 virtual void MonitorNetworkDeviceStop( |
4208 const std::string& device_path) OVERRIDE; | 2919 const std::string& device_path) OVERRIDE; |
4209 | 2920 |
4210 virtual void CallConnectToNetwork(Network* network) OVERRIDE; | 2921 virtual void CallConnectToNetwork(Network* network) OVERRIDE; |
4211 virtual void CallRequestWifiNetworkAndConnect( | 2922 virtual void CallRequestWifiNetworkAndConnect( |
4212 const std::string& ssid, ConnectionSecurity security) OVERRIDE; | 2923 const std::string& ssid, ConnectionSecurity security) OVERRIDE; |
4213 virtual void CallRequestVirtualNetworkAndConnect( | 2924 virtual void CallRequestVirtualNetworkAndConnect( |
4214 const std::string& service_name, | 2925 const std::string& service_name, |
4215 const std::string& server_hostname, | 2926 const std::string& server_hostname, |
4216 VirtualNetwork::ProviderType provider_type) OVERRIDE; | 2927 ProviderType provider_type) OVERRIDE; |
4217 virtual void CallDeleteRememberedNetwork( | 2928 virtual void CallDeleteRememberedNetwork( |
4218 const std::string& profile_path, | 2929 const std::string& profile_path, |
4219 const std::string& service_path) OVERRIDE; | 2930 const std::string& service_path) OVERRIDE; |
4220 | 2931 |
4221 ////////////////////////////////////////////////////////////////////////////// | 2932 ////////////////////////////////////////////////////////////////////////////// |
4222 // NetworkLibrary implementation. | 2933 // NetworkLibrary implementation. |
4223 | 2934 |
4224 virtual void ChangePin(const std::string& old_pin, | 2935 virtual void ChangePin(const std::string& old_pin, |
4225 const std::string& new_pin) OVERRIDE; | 2936 const std::string& new_pin) OVERRIDE; |
4226 virtual void ChangeRequirePin(bool require_pin, | 2937 virtual void ChangeRequirePin(bool require_pin, |
(...skipping 16 matching lines...) Expand all Loading... |
4243 const std::string& device_path, | 2954 const std::string& device_path, |
4244 std::string* hardware_address, | 2955 std::string* hardware_address, |
4245 HardwareAddressFormat format) OVERRIDE; | 2956 HardwareAddressFormat format) OVERRIDE; |
4246 virtual void SetIPConfig(const NetworkIPConfig& ipconfig) OVERRIDE; | 2957 virtual void SetIPConfig(const NetworkIPConfig& ipconfig) OVERRIDE; |
4247 | 2958 |
4248 ////////////////////////////////////////////////////////////////////////////// | 2959 ////////////////////////////////////////////////////////////////////////////// |
4249 // Calbacks. | 2960 // Calbacks. |
4250 static void NetworkStatusChangedHandler( | 2961 static void NetworkStatusChangedHandler( |
4251 void* object, const char* path, const char* key, const Value* value); | 2962 void* object, const char* path, const char* key, const Value* value); |
4252 void UpdateNetworkStatus( | 2963 void UpdateNetworkStatus( |
4253 const char* path, const char* key, const Value* value); | 2964 const std::string& path, const std::string& key, const Value& value); |
4254 | 2965 |
4255 static void NetworkDevicePropertyChangedHandler( | 2966 static void NetworkDevicePropertyChangedHandler( |
4256 void* object, const char* path, const char* key, const Value* value); | 2967 void* object, const char* path, const char* key, const Value* value); |
4257 void UpdateNetworkDeviceStatus( | 2968 void UpdateNetworkDeviceStatus( |
4258 const char* path, const char* key, const Value* value); | 2969 const std::string& path, const std::string& key, const Value& value); |
4259 | 2970 |
4260 static void PinOperationCallback(void* object, | 2971 static void PinOperationCallback(void* object, |
4261 const char* path, | 2972 const char* path, |
4262 NetworkMethodErrorType error, | 2973 NetworkMethodErrorType error, |
4263 const char* error_message); | 2974 const char* error_message); |
4264 | 2975 |
4265 static void CellularRegisterCallback(void* object, | 2976 static void CellularRegisterCallback(void* object, |
4266 const char* path, | 2977 const char* path, |
4267 NetworkMethodErrorType error, | 2978 NetworkMethodErrorType error, |
4268 const char* error_message); | 2979 const char* error_message); |
(...skipping 22 matching lines...) Expand all Loading... |
4291 static void RememberedNetworkServiceUpdate( | 3002 static void RememberedNetworkServiceUpdate( |
4292 void* object, const char* service_path, const Value* info); | 3003 void* object, const char* service_path, const Value* info); |
4293 static void ProfileUpdate( | 3004 static void ProfileUpdate( |
4294 void* object, const char* profile_path, const Value* info); | 3005 void* object, const char* profile_path, const Value* info); |
4295 static void NetworkDeviceUpdate( | 3006 static void NetworkDeviceUpdate( |
4296 void* object, const char* device_path, const Value* info); | 3007 void* object, const char* device_path, const Value* info); |
4297 | 3008 |
4298 private: | 3009 private: |
4299 // This processes all Manager update messages. | 3010 // This processes all Manager update messages. |
4300 void NetworkManagerStatusChanged(const char* key, const Value* value); | 3011 void NetworkManagerStatusChanged(const char* key, const Value* value); |
4301 void ParseNetworkManager(const DictionaryValue* dict); | 3012 void ParseNetworkManager(const DictionaryValue& dict); |
4302 void UpdateTechnologies(const ListValue* technologies, int* bitfieldp); | 3013 void UpdateTechnologies(const ListValue* technologies, int* bitfieldp); |
4303 void UpdateAvailableTechnologies(const ListValue* technologies); | 3014 void UpdateAvailableTechnologies(const ListValue* technologies); |
4304 void UpdateEnabledTechnologies(const ListValue* technologies); | 3015 void UpdateEnabledTechnologies(const ListValue* technologies); |
4305 void UpdateConnectedTechnologies(const ListValue* technologies); | 3016 void UpdateConnectedTechnologies(const ListValue* technologies); |
4306 | 3017 |
4307 // Update network lists. | 3018 // Update network lists. |
4308 void UpdateNetworkServiceList(const ListValue* services); | 3019 void UpdateNetworkServiceList(const ListValue* services); |
4309 void UpdateWatchedNetworkServiceList(const ListValue* services); | 3020 void UpdateWatchedNetworkServiceList(const ListValue* services); |
4310 Network* ParseNetwork(const std::string& service_path, | 3021 Network* ParseNetwork(const std::string& service_path, |
4311 const DictionaryValue* info); | 3022 const DictionaryValue& info); |
4312 | 3023 |
4313 void UpdateRememberedNetworks(const ListValue* profiles); | 3024 void UpdateRememberedNetworks(const ListValue* profiles); |
4314 void RequestRememberedNetworksUpdate(); | 3025 void RequestRememberedNetworksUpdate(); |
4315 void UpdateRememberedServiceList(const char* profile_path, | 3026 void UpdateRememberedServiceList(const char* profile_path, |
4316 const ListValue* profile_entries); | 3027 const ListValue* profile_entries); |
4317 Network* ParseRememberedNetwork(const std::string& service_path, | 3028 Network* ParseRememberedNetwork(const std::string& service_path, |
4318 const DictionaryValue* info); | 3029 const DictionaryValue& info); |
4319 | 3030 |
4320 // NetworkDevice list management functions. | 3031 // NetworkDevice list management functions. |
4321 void UpdateNetworkDeviceList(const ListValue* devices); | 3032 void UpdateNetworkDeviceList(const ListValue* devices); |
4322 void ParseNetworkDevice(const std::string& device_path, | 3033 void ParseNetworkDevice(const std::string& device_path, |
4323 const DictionaryValue* info); | 3034 const DictionaryValue& info); |
4324 | 3035 |
4325 // Empty device observer to ensure that device property updates are received. | 3036 // Empty device observer to ensure that device property updates are received. |
4326 class NetworkLibraryDeviceObserver : public NetworkDeviceObserver { | 3037 class NetworkLibraryDeviceObserver : public NetworkDeviceObserver { |
4327 public: | 3038 public: |
4328 virtual ~NetworkLibraryDeviceObserver() {} | 3039 virtual ~NetworkLibraryDeviceObserver() {} |
4329 virtual void OnNetworkDeviceChanged( | 3040 virtual void OnNetworkDeviceChanged( |
4330 NetworkLibrary* cros, const NetworkDevice* device) OVERRIDE {} | 3041 NetworkLibrary* cros, const NetworkDevice* device) OVERRIDE {} |
4331 }; | 3042 }; |
4332 | 3043 |
4333 typedef std::map<std::string, chromeos::PropertyChangeMonitor> | 3044 typedef std::map<std::string, chromeos::PropertyChangeMonitor> |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4433 montitored_devices_.erase(iter); | 3144 montitored_devices_.erase(iter); |
4434 } | 3145 } |
4435 } | 3146 } |
4436 | 3147 |
4437 // static callback | 3148 // static callback |
4438 void NetworkLibraryImplCros::NetworkStatusChangedHandler( | 3149 void NetworkLibraryImplCros::NetworkStatusChangedHandler( |
4439 void* object, const char* path, const char* key, const Value* value) { | 3150 void* object, const char* path, const char* key, const Value* value) { |
4440 NetworkLibraryImplCros* networklib = | 3151 NetworkLibraryImplCros* networklib = |
4441 static_cast<NetworkLibraryImplCros*>(object); | 3152 static_cast<NetworkLibraryImplCros*>(object); |
4442 DCHECK(networklib); | 3153 DCHECK(networklib); |
4443 networklib->UpdateNetworkStatus(path, key, value); | 3154 if (key == NULL || value == NULL || path == NULL || object == NULL) |
| 3155 return; |
| 3156 networklib->UpdateNetworkStatus(std::string(path), std::string(key), *value); |
4444 } | 3157 } |
4445 | 3158 |
4446 void NetworkLibraryImplCros::UpdateNetworkStatus( | 3159 void NetworkLibraryImplCros::UpdateNetworkStatus( |
4447 const char* path, const char* key, const Value* value) { | 3160 const std::string& path, const std::string& key, const Value& value) { |
4448 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3161 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
4449 if (key == NULL || value == NULL) | |
4450 return; | |
4451 Network* network = FindNetworkByPath(path); | 3162 Network* network = FindNetworkByPath(path); |
4452 if (network) { | 3163 if (network) { |
4453 VLOG(2) << "UpdateNetworkStatus: " << network->name() << "." << key; | 3164 VLOG(2) << "UpdateNetworkStatus: " << network->name() << "." << key; |
4454 bool prev_connected = network->connected(); | 3165 bool prev_connected = network->connected(); |
4455 // Note: ParseValue is virtual. | 3166 if (!network->UpdateStatus(key, value, NULL)) { |
4456 int index = property_index_parser().Get(std::string(key)); | 3167 LOG(WARNING) << "UpdateNetworkStatus: Error updating: " |
4457 if (!network->ParseValue(index, value)) { | |
4458 LOG(WARNING) << "UpdateNetworkStatus: Error parsing: " | |
4459 << path << "." << key; | 3168 << path << "." << key; |
4460 } | 3169 } |
4461 // If we just connected, this may have been added to remembered list. | 3170 // If we just connected, this may have been added to remembered list. |
4462 if (!prev_connected && network->connected()) | 3171 if (!prev_connected && network->connected()) |
4463 RequestRememberedNetworksUpdate(); | 3172 RequestRememberedNetworksUpdate(); |
4464 NotifyNetworkChanged(network); | 3173 NotifyNetworkChanged(network); |
4465 // Anything observing the manager needs to know about any service change. | 3174 // Anything observing the manager needs to know about any service change. |
4466 NotifyNetworkManagerChanged(false); // Not forced. | 3175 NotifyNetworkManagerChanged(false); // Not forced. |
4467 } | 3176 } |
4468 } | 3177 } |
4469 | 3178 |
4470 // static callback | 3179 // static callback |
4471 void NetworkLibraryImplCros::NetworkDevicePropertyChangedHandler( | 3180 void NetworkLibraryImplCros::NetworkDevicePropertyChangedHandler( |
4472 void* object, const char* path, const char* key, const Value* value) { | 3181 void* object, const char* path, const char* key, const Value* value) { |
4473 NetworkLibraryImplCros* networklib = | 3182 NetworkLibraryImplCros* networklib = |
4474 static_cast<NetworkLibraryImplCros*>(object); | 3183 static_cast<NetworkLibraryImplCros*>(object); |
4475 DCHECK(networklib); | 3184 DCHECK(networklib); |
4476 networklib->UpdateNetworkDeviceStatus(path, key, value); | 3185 if (key == NULL || value == NULL || path == NULL || object == NULL) |
| 3186 return; |
| 3187 networklib->UpdateNetworkDeviceStatus(std::string(path), |
| 3188 std::string(key), |
| 3189 *value); |
4477 } | 3190 } |
4478 | 3191 |
4479 void NetworkLibraryImplCros::UpdateNetworkDeviceStatus( | 3192 void NetworkLibraryImplCros::UpdateNetworkDeviceStatus( |
4480 const char* path, const char* key, const Value* value) { | 3193 const std::string& path, const std::string& key, const Value& value) { |
4481 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3194 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
4482 if (key == NULL || value == NULL) | |
4483 return; | |
4484 NetworkDevice* device = FindNetworkDeviceByPath(path); | 3195 NetworkDevice* device = FindNetworkDeviceByPath(path); |
4485 if (device) { | 3196 if (device) { |
4486 VLOG(2) << "UpdateNetworkDeviceStatus: " << device->name() << "." << key; | 3197 VLOG(2) << "UpdateNetworkDeviceStatus: " << device->name() << "." << key; |
4487 PropertyIndex index = property_index_parser().Get(std::string(key)); | 3198 PropertyIndex index = PROPERTY_INDEX_UNKNOWN; |
4488 if (!device->ParseValue(index, value)) { | 3199 if (device->UpdateStatus(key, value, &index)) { |
4489 VLOG(1) << "UpdateNetworkDeviceStatus: Failed to parse: " | 3200 if (index == PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING) { |
| 3201 bool settings_value = |
| 3202 UserCrosSettingsProvider::cached_data_roaming_enabled(); |
| 3203 if (device->data_roaming_allowed() != settings_value) { |
| 3204 // Switch back to signed settings value. |
| 3205 SetCellularDataRoamingAllowed(settings_value); |
| 3206 return; |
| 3207 } |
| 3208 } |
| 3209 } else { |
| 3210 VLOG(1) << "UpdateNetworkDeviceStatus: Failed to update: " |
4490 << path << "." << key; | 3211 << path << "." << key; |
4491 } else if (index == PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING) { | |
4492 bool settings_value = | |
4493 UserCrosSettingsProvider::cached_data_roaming_enabled(); | |
4494 if (device->data_roaming_allowed() != settings_value) { | |
4495 // Switch back to signed settings value. | |
4496 SetCellularDataRoamingAllowed(settings_value); | |
4497 return; | |
4498 } | |
4499 } | 3212 } |
4500 // Notify only observers on device property change. | 3213 // Notify only observers on device property change. |
4501 NotifyNetworkDeviceChanged(device, index); | 3214 NotifyNetworkDeviceChanged(device, index); |
4502 // If a device's power state changes, new properties may become defined. | 3215 // If a device's power state changes, new properties may become defined. |
4503 if (index == PROPERTY_INDEX_POWERED) | 3216 if (index == PROPERTY_INDEX_POWERED) |
4504 chromeos::RequestNetworkDeviceInfo(path, &NetworkDeviceUpdate, this); | 3217 chromeos::RequestNetworkDeviceInfo(path.c_str(), |
| 3218 &NetworkDeviceUpdate, |
| 3219 this); |
4505 } | 3220 } |
4506 } | 3221 } |
4507 | 3222 |
4508 ///////////////////////////////////////////////////////////////////////////// | 3223 ///////////////////////////////////////////////////////////////////////////// |
4509 // NetworkLibraryImplBase connect implementation. | 3224 // NetworkLibraryImplBase connect implementation. |
4510 | 3225 |
4511 // static callback | 3226 // static callback |
4512 void NetworkLibraryImplCros::NetworkConnectCallback( | 3227 void NetworkLibraryImplCros::NetworkConnectCallback( |
4513 void* object, | 3228 void* object, |
4514 const char* service_path, | 3229 const char* service_path, |
4515 NetworkMethodErrorType error, | 3230 NetworkMethodErrorType error, |
4516 const char* error_message) { | 3231 const char* error_message) { |
4517 NetworkConnectStatus status; | 3232 NetworkConnectStatus status; |
4518 if (error == NETWORK_METHOD_ERROR_NONE) { | 3233 if (error == NETWORK_METHOD_ERROR_NONE) { |
4519 status = CONNECT_SUCCESS; | 3234 status = CONNECT_SUCCESS; |
4520 } else { | 3235 } else { |
4521 LOG(WARNING) << "Error from ServiceConnect callback for: " | 3236 LOG(WARNING) << "Error from ServiceConnect callback for: " |
4522 << service_path | 3237 << service_path |
4523 << " Error: " << error << " Message: " << error_message; | 3238 << " Error: " << error << " Message: " << error_message; |
4524 if (error_message && | 3239 if (error_message && |
4525 strcmp(error_message, kErrorPassphraseRequiredMsg) == 0) { | 3240 strcmp(error_message, kErrorPassphraseRequiredMsg) == 0) { |
4526 status = CONNECT_BAD_PASSPHRASE; | 3241 status = CONNECT_BAD_PASSPHRASE; |
4527 } else { | 3242 } else { |
4528 status = CONNECT_FAILED; | 3243 status = CONNECT_FAILED; |
4529 } | 3244 } |
4530 } | 3245 } |
4531 NetworkLibraryImplCros* networklib = | 3246 NetworkLibraryImplCros* networklib = |
4532 static_cast<NetworkLibraryImplCros*>(object); | 3247 static_cast<NetworkLibraryImplCros*>(object); |
4533 Network* network = networklib->FindNetworkByPath(service_path); | 3248 Network* network = networklib->FindNetworkByPath(std::string(service_path)); |
4534 if (!network) { | 3249 if (!network) { |
4535 LOG(ERROR) << "No network for path: " << service_path; | 3250 LOG(ERROR) << "No network for path: " << service_path; |
4536 return; | 3251 return; |
4537 } | 3252 } |
4538 networklib->NetworkConnectCompleted(network, status); | 3253 networklib->NetworkConnectCompleted(network, status); |
4539 } | 3254 } |
4540 | 3255 |
4541 void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) { | 3256 void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) { |
4542 DCHECK(network); | 3257 DCHECK(network); |
4543 chromeos::RequestNetworkServiceConnect(network->service_path().c_str(), | 3258 chromeos::RequestNetworkServiceConnect(network->service_path().c_str(), |
4544 NetworkConnectCallback, this); | 3259 NetworkConnectCallback, this); |
4545 } | 3260 } |
4546 | 3261 |
4547 // static callback | 3262 // static callback |
4548 void NetworkLibraryImplCros::WifiServiceUpdateAndConnect( | 3263 void NetworkLibraryImplCros::WifiServiceUpdateAndConnect( |
4549 void* object, const char* service_path, const Value* info) { | 3264 void* object, const char* service_path, const Value* info) { |
4550 NetworkLibraryImplCros* networklib = | 3265 NetworkLibraryImplCros* networklib = |
4551 static_cast<NetworkLibraryImplCros*>(object); | 3266 static_cast<NetworkLibraryImplCros*>(object); |
4552 DCHECK(networklib); | 3267 DCHECK(networklib); |
4553 if (service_path && info) { | 3268 if (service_path && info) { |
4554 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 3269 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); |
4555 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | 3270 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); |
4556 Network* network = | 3271 Network* network = |
4557 networklib->ParseNetwork(std::string(service_path), dict); | 3272 networklib->ParseNetwork(std::string(service_path), *dict); |
4558 DCHECK_EQ(network->type(), TYPE_WIFI); | 3273 DCHECK_EQ(network->type(), TYPE_WIFI); |
4559 networklib->ConnectToWifiNetworkUsingConnectData( | 3274 networklib->ConnectToWifiNetworkUsingConnectData( |
4560 static_cast<WifiNetwork*>(network)); | 3275 static_cast<WifiNetwork*>(network)); |
4561 } | 3276 } |
4562 } | 3277 } |
4563 | 3278 |
4564 void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect( | 3279 void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect( |
4565 const std::string& ssid, ConnectionSecurity security) { | 3280 const std::string& ssid, ConnectionSecurity security) { |
4566 // Asynchronously request service properties and call | 3281 // Asynchronously request service properties and call |
4567 // WifiServiceUpdateAndConnect. | 3282 // WifiServiceUpdateAndConnect. |
4568 chromeos::RequestHiddenWifiNetwork(ssid.c_str(), | 3283 chromeos::RequestHiddenWifiNetwork(ssid.c_str(), |
4569 SecurityToString(security), | 3284 SecurityToString(security), |
4570 WifiServiceUpdateAndConnect, | 3285 WifiServiceUpdateAndConnect, |
4571 this); | 3286 this); |
4572 } | 3287 } |
4573 | 3288 |
4574 // static callback | 3289 // static callback |
4575 void NetworkLibraryImplCros::VPNServiceUpdateAndConnect( | 3290 void NetworkLibraryImplCros::VPNServiceUpdateAndConnect( |
4576 void* object, const char* service_path, const Value* info) { | 3291 void* object, const char* service_path, const Value* info) { |
4577 NetworkLibraryImplCros* networklib = | 3292 NetworkLibraryImplCros* networklib = |
4578 static_cast<NetworkLibraryImplCros*>(object); | 3293 static_cast<NetworkLibraryImplCros*>(object); |
4579 DCHECK(networklib); | 3294 DCHECK(networklib); |
4580 if (service_path && info) { | 3295 if (service_path && info) { |
4581 VLOG(1) << "Connecting to new VPN Service: " << service_path; | 3296 VLOG(1) << "Connecting to new VPN Service: " << service_path; |
4582 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 3297 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); |
4583 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | 3298 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); |
4584 Network* network = | 3299 Network* network = |
4585 networklib->ParseNetwork(std::string(service_path), dict); | 3300 networklib->ParseNetwork(std::string(service_path), *dict); |
4586 DCHECK_EQ(network->type(), TYPE_VPN); | 3301 DCHECK_EQ(network->type(), TYPE_VPN); |
4587 networklib->ConnectToVirtualNetworkUsingConnectData( | 3302 networklib->ConnectToVirtualNetworkUsingConnectData( |
4588 static_cast<VirtualNetwork*>(network)); | 3303 static_cast<VirtualNetwork*>(network)); |
4589 } else { | 3304 } else { |
4590 LOG(WARNING) << "Unable to create VPN Service: " << service_path; | 3305 LOG(WARNING) << "Unable to create VPN Service: " << service_path; |
4591 } | 3306 } |
4592 } | 3307 } |
4593 | 3308 |
4594 void NetworkLibraryImplCros::CallRequestVirtualNetworkAndConnect( | 3309 void NetworkLibraryImplCros::CallRequestVirtualNetworkAndConnect( |
4595 const std::string& service_name, | 3310 const std::string& service_name, |
4596 const std::string& server_hostname, | 3311 const std::string& server_hostname, |
4597 VirtualNetwork::ProviderType provider_type) { | 3312 ProviderType provider_type) { |
4598 chromeos::RequestVirtualNetwork(service_name.c_str(), | 3313 chromeos::RequestVirtualNetwork(service_name.c_str(), |
4599 server_hostname.c_str(), | 3314 server_hostname.c_str(), |
4600 ProviderTypeToString(provider_type), | 3315 ProviderTypeToString(provider_type), |
4601 VPNServiceUpdateAndConnect, | 3316 VPNServiceUpdateAndConnect, |
4602 this); | 3317 this); |
4603 } | 3318 } |
4604 | 3319 |
4605 void NetworkLibraryImplCros::CallDeleteRememberedNetwork( | 3320 void NetworkLibraryImplCros::CallDeleteRememberedNetwork( |
4606 const std::string& profile_path, | 3321 const std::string& profile_path, |
4607 const std::string& service_path) { | 3322 const std::string& service_path) { |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4943 } | 3658 } |
4944 | 3659 |
4945 // This processes all Manager update messages. | 3660 // This processes all Manager update messages. |
4946 void NetworkLibraryImplCros::NetworkManagerStatusChanged( | 3661 void NetworkLibraryImplCros::NetworkManagerStatusChanged( |
4947 const char* key, const Value* value) { | 3662 const char* key, const Value* value) { |
4948 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 3663 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
4949 base::TimeTicks start = base::TimeTicks::Now(); | 3664 base::TimeTicks start = base::TimeTicks::Now(); |
4950 if (!key) | 3665 if (!key) |
4951 return; | 3666 return; |
4952 VLOG(1) << "NetworkManagerStatusChanged: KEY=" << key; | 3667 VLOG(1) << "NetworkManagerStatusChanged: KEY=" << key; |
4953 int index = property_index_parser().Get(std::string(key)); | 3668 int index = NativeNetworkParser::property_mapper()->Get(key); |
4954 switch (index) { | 3669 switch (index) { |
4955 case PROPERTY_INDEX_STATE: | 3670 case PROPERTY_INDEX_STATE: |
4956 // Currently we ignore the network manager state. | 3671 // Currently we ignore the network manager state. |
4957 break; | 3672 break; |
4958 case PROPERTY_INDEX_AVAILABLE_TECHNOLOGIES: { | 3673 case PROPERTY_INDEX_AVAILABLE_TECHNOLOGIES: { |
4959 DCHECK_EQ(value->GetType(), Value::TYPE_LIST); | 3674 DCHECK_EQ(value->GetType(), Value::TYPE_LIST); |
4960 const ListValue* vlist = static_cast<const ListValue*>(value); | 3675 const ListValue* vlist = static_cast<const ListValue*>(value); |
4961 UpdateAvailableTechnologies(vlist); | 3676 UpdateAvailableTechnologies(vlist); |
4962 break; | 3677 break; |
4963 } | 3678 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5013 } | 3728 } |
5014 case PROPERTY_INDEX_DEVICE: | 3729 case PROPERTY_INDEX_DEVICE: |
5015 case PROPERTY_INDEX_DEVICES: { | 3730 case PROPERTY_INDEX_DEVICES: { |
5016 DCHECK_EQ(value->GetType(), Value::TYPE_LIST); | 3731 DCHECK_EQ(value->GetType(), Value::TYPE_LIST); |
5017 const ListValue* vlist = static_cast<const ListValue*>(value); | 3732 const ListValue* vlist = static_cast<const ListValue*>(value); |
5018 UpdateNetworkDeviceList(vlist); | 3733 UpdateNetworkDeviceList(vlist); |
5019 break; | 3734 break; |
5020 } | 3735 } |
5021 case PROPERTY_INDEX_PORTAL_URL: | 3736 case PROPERTY_INDEX_PORTAL_URL: |
5022 case PROPERTY_INDEX_CHECK_PORTAL_LIST: | 3737 case PROPERTY_INDEX_CHECK_PORTAL_LIST: |
5023 // Currently we ignore PortalURL and CheckPortalList. | 3738 case PROPERTY_INDEX_ARP_GATEWAY: |
| 3739 // Currently we ignore PortalURL, CheckPortalList and ArpGateway. |
5024 break; | 3740 break; |
5025 default: | 3741 default: |
5026 LOG(WARNING) << "Manager: Unhandled key: " << key; | 3742 LOG(WARNING) << "Manager: Unhandled key: " << key; |
5027 break; | 3743 break; |
5028 } | 3744 } |
5029 base::TimeDelta delta = base::TimeTicks::Now() - start; | 3745 base::TimeDelta delta = base::TimeTicks::Now() - start; |
5030 VLOG(2) << "NetworkManagerStatusChanged: time: " | 3746 VLOG(2) << "NetworkManagerStatusChanged: time: " |
5031 << delta.InMilliseconds() << " ms."; | 3747 << delta.InMilliseconds() << " ms."; |
5032 HISTOGRAM_TIMES("CROS_NETWORK_UPDATE", delta); | 3748 HISTOGRAM_TIMES("CROS_NETWORK_UPDATE", delta); |
5033 } | 3749 } |
5034 | 3750 |
5035 // static | 3751 // static |
5036 void NetworkLibraryImplCros::NetworkManagerUpdate( | 3752 void NetworkLibraryImplCros::NetworkManagerUpdate( |
5037 void* object, const char* manager_path, const Value* info) { | 3753 void* object, const char* manager_path, const Value* info) { |
5038 NetworkLibraryImplCros* networklib = | 3754 NetworkLibraryImplCros* networklib = |
5039 static_cast<NetworkLibraryImplCros*>(object); | 3755 static_cast<NetworkLibraryImplCros*>(object); |
5040 DCHECK(networklib); | 3756 DCHECK(networklib); |
5041 if (!info) { | 3757 if (!info) { |
5042 LOG(ERROR) << "Error retrieving manager properties: " << manager_path; | 3758 LOG(ERROR) << "Error retrieving manager properties: " << manager_path; |
5043 return; | 3759 return; |
5044 } | 3760 } |
5045 VLOG(1) << "Received NetworkManagerUpdate."; | 3761 VLOG(1) << "Received NetworkManagerUpdate."; |
5046 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 3762 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); |
5047 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | 3763 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); |
5048 networklib->ParseNetworkManager(dict); | 3764 networklib->ParseNetworkManager(*dict); |
5049 } | 3765 } |
5050 | 3766 |
5051 void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue* dict) { | 3767 void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue& dict) { |
5052 for (DictionaryValue::key_iterator iter = dict->begin_keys(); | 3768 for (DictionaryValue::key_iterator iter = dict.begin_keys(); |
5053 iter != dict->end_keys(); ++iter) { | 3769 iter != dict.end_keys(); ++iter) { |
5054 const std::string& key = *iter; | 3770 const std::string& key = *iter; |
5055 Value* value; | 3771 Value* value; |
5056 bool res = dict->GetWithoutPathExpansion(key, &value); | 3772 bool res = dict.GetWithoutPathExpansion(key, &value); |
5057 CHECK(res); | 3773 CHECK(res); |
5058 NetworkManagerStatusChanged(key.c_str(), value); | 3774 NetworkManagerStatusChanged(key.c_str(), value); |
5059 } | 3775 } |
5060 // If there is no Profiles entry, request remembered networks here. | 3776 // If there is no Profiles entry, request remembered networks here. |
5061 if (!dict->HasKey(kProfilesProperty)) | 3777 if (!dict.HasKey(kProfilesProperty)) |
5062 RequestRememberedNetworksUpdate(); | 3778 RequestRememberedNetworksUpdate(); |
5063 } | 3779 } |
5064 | 3780 |
5065 // static | 3781 // static |
5066 void NetworkLibraryImplCros::DataPlanUpdateHandler( | 3782 void NetworkLibraryImplCros::DataPlanUpdateHandler( |
5067 void* object, | 3783 void* object, |
5068 const char* modem_service_path, | 3784 const char* modem_service_path, |
5069 const CellularDataPlanList* dataplan) { | 3785 const CellularDataPlanList* dataplan) { |
5070 NetworkLibraryImplCros* networklib = | 3786 NetworkLibraryImplCros* networklib = |
5071 static_cast<NetworkLibraryImplCros*>(object); | 3787 static_cast<NetworkLibraryImplCros*>(object); |
(...skipping 10 matching lines...) Expand all Loading... |
5082 const ListValue* technologies, int* bitfieldp) { | 3798 const ListValue* technologies, int* bitfieldp) { |
5083 DCHECK(bitfieldp); | 3799 DCHECK(bitfieldp); |
5084 if (!technologies) | 3800 if (!technologies) |
5085 return; | 3801 return; |
5086 int bitfield = 0; | 3802 int bitfield = 0; |
5087 for (ListValue::const_iterator iter = technologies->begin(); | 3803 for (ListValue::const_iterator iter = technologies->begin(); |
5088 iter != technologies->end(); ++iter) { | 3804 iter != technologies->end(); ++iter) { |
5089 std::string technology; | 3805 std::string technology; |
5090 (*iter)->GetAsString(&technology); | 3806 (*iter)->GetAsString(&technology); |
5091 if (!technology.empty()) { | 3807 if (!technology.empty()) { |
5092 ConnectionType type = ParseType(technology); | 3808 ConnectionType type = |
| 3809 NativeNetworkParser::ParseConnectionType(technology); |
5093 bitfield |= 1 << type; | 3810 bitfield |= 1 << type; |
5094 } | 3811 } |
5095 } | 3812 } |
5096 *bitfieldp = bitfield; | 3813 *bitfieldp = bitfield; |
5097 NotifyNetworkManagerChanged(false); // Not forced. | 3814 NotifyNetworkManagerChanged(false); // Not forced. |
5098 } | 3815 } |
5099 | 3816 |
5100 void NetworkLibraryImplCros::UpdateAvailableTechnologies( | 3817 void NetworkLibraryImplCros::UpdateAvailableTechnologies( |
5101 const ListValue* technologies) { | 3818 const ListValue* technologies) { |
5102 UpdateTechnologies(technologies, &available_devices_); | 3819 UpdateTechnologies(technologies, &available_devices_); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5168 iter != old_network_map.end(); ++iter) { | 3885 iter != old_network_map.end(); ++iter) { |
5169 Network* network = iter->second; | 3886 Network* network = iter->second; |
5170 if (network->failed() && network->notify_failure()) { | 3887 if (network->failed() && network->notify_failure()) { |
5171 // We have not notified observers of a connection failure yet. | 3888 // We have not notified observers of a connection failure yet. |
5172 AddNetwork(network); | 3889 AddNetwork(network); |
5173 } else if (network->connecting()) { | 3890 } else if (network->connecting()) { |
5174 // Network was in connecting state; set state to failed. | 3891 // Network was in connecting state; set state to failed. |
5175 network->SetState(STATE_FAILURE); | 3892 network->SetState(STATE_FAILURE); |
5176 AddNetwork(network); | 3893 AddNetwork(network); |
5177 } else { | 3894 } else { |
5178 VLOG(2) << "Deleting non-existant Network: " << network->name() | 3895 VLOG(2) << "Deleting non-existent Network: " << network->name() |
5179 << " State = " << network->GetStateString(); | 3896 << " State = " << network->GetStateString(); |
5180 DeleteNetwork(network); | 3897 DeleteNetwork(network); |
5181 } | 3898 } |
5182 } | 3899 } |
5183 // If the last network has disappeared, nothing else will | 3900 // If the last network has disappeared, nothing else will |
5184 // have notified observers, so do it now. | 3901 // have notified observers, so do it now. |
5185 if (services->empty()) | 3902 if (services->empty()) |
5186 NotifyNetworkManagerChanged(true); // Forced update | 3903 NotifyNetworkManagerChanged(true); // Forced update |
5187 } | 3904 } |
5188 | 3905 |
(...skipping 19 matching lines...) Expand all Loading... |
5208 void NetworkLibraryImplCros::NetworkServiceUpdate( | 3925 void NetworkLibraryImplCros::NetworkServiceUpdate( |
5209 void* object, const char* service_path, const Value* info) { | 3926 void* object, const char* service_path, const Value* info) { |
5210 NetworkLibraryImplCros* networklib = | 3927 NetworkLibraryImplCros* networklib = |
5211 static_cast<NetworkLibraryImplCros*>(object); | 3928 static_cast<NetworkLibraryImplCros*>(object); |
5212 DCHECK(networklib); | 3929 DCHECK(networklib); |
5213 if (service_path) { | 3930 if (service_path) { |
5214 if (!info) | 3931 if (!info) |
5215 return; // Network no longer in visible list, ignore. | 3932 return; // Network no longer in visible list, ignore. |
5216 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 3933 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); |
5217 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | 3934 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); |
5218 networklib->ParseNetwork(std::string(service_path), dict); | 3935 networklib->ParseNetwork(std::string(service_path), *dict); |
5219 } | 3936 } |
5220 } | 3937 } |
5221 | 3938 |
5222 // Called from NetworkServiceUpdate and WifiServiceUpdateAndConnect. | 3939 // Called from NetworkServiceUpdate and WifiServiceUpdateAndConnect. |
5223 Network* NetworkLibraryImplCros::ParseNetwork( | 3940 Network* NetworkLibraryImplCros::ParseNetwork( |
5224 const std::string& service_path, const DictionaryValue* info) { | 3941 const std::string& service_path, const DictionaryValue& info) { |
5225 Network* network = FindNetworkByPath(service_path); | 3942 Network* network = FindNetworkByPath(service_path); |
5226 if (!network) { | 3943 if (!network) { |
5227 ConnectionType type = ParseTypeFromDictionary(info); | 3944 NativeNetworkParser parser; |
5228 network = CreateNewNetwork(type, service_path); | 3945 network = parser.CreateNetworkFromInfo(service_path, info); |
5229 AddNetwork(network); | 3946 AddNetwork(network); |
| 3947 } else { |
| 3948 // Erase entry from network_unique_id_map_ in case unique id changes. |
| 3949 if (!network->unique_id().empty()) |
| 3950 network_unique_id_map_.erase(network->unique_id()); |
| 3951 network->network_parser()->UpdateNetworkFromInfo(info, network); |
5230 } | 3952 } |
5231 | 3953 |
5232 // Erase entry from network_unique_id_map_ in case unique id changes. | |
5233 if (!network->unique_id().empty()) | |
5234 network_unique_id_map_.erase(network->unique_id()); | |
5235 | |
5236 network->ParseInfo(info); // virtual. | |
5237 | |
5238 if (!network->unique_id().empty()) | 3954 if (!network->unique_id().empty()) |
5239 network_unique_id_map_[network->unique_id()] = network; | 3955 network_unique_id_map_[network->unique_id()] = network; |
5240 | 3956 |
5241 SetProfileTypeFromPath(network); | 3957 SetProfileTypeFromPath(network); |
5242 | 3958 |
5243 UpdateActiveNetwork(network); | 3959 UpdateActiveNetwork(network); |
5244 | 3960 |
5245 // Copy remembered credentials if required. | 3961 // Copy remembered credentials if required. |
5246 Network* remembered = FindRememberedFromNetwork(network); | 3962 Network* remembered = FindRememberedFromNetwork(network); |
5247 if (remembered) | 3963 if (remembered) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5386 NetworkLibraryImplCros* networklib = | 4102 NetworkLibraryImplCros* networklib = |
5387 static_cast<NetworkLibraryImplCros*>(object); | 4103 static_cast<NetworkLibraryImplCros*>(object); |
5388 DCHECK(networklib); | 4104 DCHECK(networklib); |
5389 if (service_path) { | 4105 if (service_path) { |
5390 if (!info) { | 4106 if (!info) { |
5391 // Remembered network no longer exists. | 4107 // Remembered network no longer exists. |
5392 networklib->DeleteRememberedNetwork(std::string(service_path)); | 4108 networklib->DeleteRememberedNetwork(std::string(service_path)); |
5393 } else { | 4109 } else { |
5394 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 4110 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); |
5395 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | 4111 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); |
5396 networklib->ParseRememberedNetwork(std::string(service_path), dict); | 4112 networklib->ParseRememberedNetwork(std::string(service_path), *dict); |
5397 } | 4113 } |
5398 } | 4114 } |
5399 } | 4115 } |
5400 | 4116 |
5401 // Returns NULL if |service_path| refers to a network that is not a | 4117 // Returns NULL if |service_path| refers to a network that is not a |
5402 // remembered type. Called from RememberedNetworkServiceUpdate. | 4118 // remembered type. Called from RememberedNetworkServiceUpdate. |
5403 Network* NetworkLibraryImplCros::ParseRememberedNetwork( | 4119 Network* NetworkLibraryImplCros::ParseRememberedNetwork( |
5404 const std::string& service_path, const DictionaryValue* info) { | 4120 const std::string& service_path, const DictionaryValue& info) { |
5405 Network* remembered; | 4121 Network* remembered; |
5406 NetworkMap::iterator found = remembered_network_map_.find(service_path); | 4122 NetworkMap::iterator found = remembered_network_map_.find(service_path); |
5407 if (found != remembered_network_map_.end()) { | 4123 if (found != remembered_network_map_.end()) { |
5408 remembered = found->second; | 4124 remembered = found->second; |
| 4125 remembered->network_parser()->UpdateNetworkFromInfo(info, remembered); |
5409 } else { | 4126 } else { |
5410 ConnectionType type = ParseTypeFromDictionary(info); | 4127 NativeNetworkParser parser; |
5411 if (type == TYPE_WIFI || type == TYPE_VPN) { | 4128 remembered = parser.CreateNetworkFromInfo(service_path, info); |
5412 remembered = CreateNewNetwork(type, service_path); | 4129 if (remembered->type() == TYPE_WIFI || remembered->type() == TYPE_VPN) { |
5413 AddRememberedNetwork(remembered); | 4130 AddRememberedNetwork(remembered); |
5414 } else { | 4131 } else { |
5415 VLOG(1) << "Ignoring remembered network: " << service_path | 4132 LOG(WARNING) << "Ignoring remembered network: " << service_path |
5416 << " Type: " << ConnectionTypeToString(type); | 4133 << " Type: " << ConnectionTypeToString(remembered->type()); |
| 4134 delete remembered; |
5417 return NULL; | 4135 return NULL; |
5418 } | 4136 } |
5419 } | 4137 } |
5420 remembered->ParseInfo(info); // virtual. | |
5421 | 4138 |
5422 SetProfileTypeFromPath(remembered); | 4139 SetProfileTypeFromPath(remembered); |
5423 | 4140 |
5424 VLOG(1) << "ParseRememberedNetwork: " << remembered->name() | 4141 VLOG(1) << "ParseRememberedNetwork: " << remembered->name() |
5425 << " path: " << remembered->service_path() | 4142 << " path: " << remembered->service_path() |
5426 << " profile: " << remembered->profile_path_; | 4143 << " profile: " << remembered->profile_path_; |
5427 NotifyNetworkManagerChanged(false); // Not forced. | 4144 NotifyNetworkManagerChanged(false); // Not forced. |
5428 | 4145 |
5429 if (remembered->type() == TYPE_VPN) { | 4146 if (remembered->type() == TYPE_VPN) { |
5430 // VPNs are only stored in profiles. If we don't have a network for it, | 4147 // VPNs are only stored in profiles. If we don't have a network for it, |
(...skipping 25 matching lines...) Expand all Loading... |
5456 device_map_.clear(); | 4173 device_map_.clear(); |
5457 VLOG(2) << "Updating Device List."; | 4174 VLOG(2) << "Updating Device List."; |
5458 for (ListValue::const_iterator iter = devices->begin(); | 4175 for (ListValue::const_iterator iter = devices->begin(); |
5459 iter != devices->end(); ++iter) { | 4176 iter != devices->end(); ++iter) { |
5460 std::string device_path; | 4177 std::string device_path; |
5461 (*iter)->GetAsString(&device_path); | 4178 (*iter)->GetAsString(&device_path); |
5462 if (!device_path.empty()) { | 4179 if (!device_path.empty()) { |
5463 NetworkDeviceMap::iterator found = old_device_map.find(device_path); | 4180 NetworkDeviceMap::iterator found = old_device_map.find(device_path); |
5464 if (found != old_device_map.end()) { | 4181 if (found != old_device_map.end()) { |
5465 VLOG(2) << " Adding existing device: " << device_path; | 4182 VLOG(2) << " Adding existing device: " << device_path; |
| 4183 CHECK(found->second) << "Attempted to add NULL device pointer"; |
5466 device_map_[device_path] = found->second; | 4184 device_map_[device_path] = found->second; |
5467 old_device_map.erase(found); | 4185 old_device_map.erase(found); |
5468 } | 4186 } |
5469 chromeos::RequestNetworkDeviceInfo(device_path.c_str(), | 4187 chromeos::RequestNetworkDeviceInfo(device_path.c_str(), |
5470 &NetworkDeviceUpdate, | 4188 &NetworkDeviceUpdate, |
5471 this); | 4189 this); |
5472 } | 4190 } |
5473 } | 4191 } |
5474 // Delete any old devices that no longer exist. | 4192 // Delete any old devices that no longer exist. |
5475 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); | 4193 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); |
(...skipping 10 matching lines...) Expand all Loading... |
5486 NetworkLibraryImplCros* networklib = | 4204 NetworkLibraryImplCros* networklib = |
5487 static_cast<NetworkLibraryImplCros*>(object); | 4205 static_cast<NetworkLibraryImplCros*>(object); |
5488 DCHECK(networklib); | 4206 DCHECK(networklib); |
5489 if (device_path) { | 4207 if (device_path) { |
5490 if (!info) { | 4208 if (!info) { |
5491 // device no longer exists. | 4209 // device no longer exists. |
5492 networklib->DeleteDevice(std::string(device_path)); | 4210 networklib->DeleteDevice(std::string(device_path)); |
5493 } else { | 4211 } else { |
5494 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); | 4212 DCHECK_EQ(info->GetType(), Value::TYPE_DICTIONARY); |
5495 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); | 4213 const DictionaryValue* dict = static_cast<const DictionaryValue*>(info); |
5496 networklib->ParseNetworkDevice(std::string(device_path), dict); | 4214 networklib->ParseNetworkDevice(std::string(device_path), *dict); |
5497 } | 4215 } |
5498 } | 4216 } |
5499 } | 4217 } |
5500 | 4218 |
5501 void NetworkLibraryImplCros::ParseNetworkDevice( | 4219 void NetworkLibraryImplCros::ParseNetworkDevice(const std::string& device_path, |
5502 const std::string& device_path, const DictionaryValue* info) { | 4220 const DictionaryValue& info) { |
5503 NetworkDeviceMap::iterator found = device_map_.find(device_path); | 4221 NetworkDeviceMap::iterator found = device_map_.find(device_path); |
5504 NetworkDevice* device; | 4222 NetworkDevice* device; |
5505 if (found != device_map_.end()) { | 4223 if (found != device_map_.end()) { |
5506 device = found->second; | 4224 device = found->second; |
| 4225 device->device_parser()->UpdateDeviceFromInfo(info, device); |
5507 } else { | 4226 } else { |
5508 device = new NetworkDevice(device_path); | 4227 NativeNetworkDeviceParser parser; |
| 4228 device = parser.CreateDeviceFromInfo(device_path, info); |
5509 VLOG(2) << " Adding device: " << device_path; | 4229 VLOG(2) << " Adding device: " << device_path; |
5510 device_map_[device_path] = device; | 4230 if (device) { |
| 4231 device_map_[device_path] = device; |
| 4232 } |
| 4233 CHECK(device) << "Attempted to add NULL device for path: " << device_path; |
5511 } | 4234 } |
5512 device->ParseInfo(info); | |
5513 VLOG(1) << "ParseNetworkDevice:" << device->name(); | 4235 VLOG(1) << "ParseNetworkDevice:" << device->name(); |
5514 NotifyNetworkManagerChanged(false); // Not forced. | 4236 NotifyNetworkManagerChanged(false); // Not forced. |
5515 AddNetworkDeviceObserver(device_path, network_device_observer_.get()); | 4237 AddNetworkDeviceObserver(device_path, network_device_observer_.get()); |
5516 } | 4238 } |
5517 | 4239 |
5518 //////////////////////////////////////////////////////////////////////////// | 4240 //////////////////////////////////////////////////////////////////////////// |
5519 | 4241 |
5520 class NetworkLibraryImplStub : public NetworkLibraryImplBase { | 4242 class NetworkLibraryImplStub : public NetworkLibraryImplBase { |
5521 public: | 4243 public: |
5522 NetworkLibraryImplStub(); | 4244 NetworkLibraryImplStub(); |
(...skipping 10 matching lines...) Expand all Loading... |
5533 const std::string& device_path) OVERRIDE {} | 4255 const std::string& device_path) OVERRIDE {} |
5534 virtual void MonitorNetworkDeviceStop( | 4256 virtual void MonitorNetworkDeviceStop( |
5535 const std::string& device_path) OVERRIDE {} | 4257 const std::string& device_path) OVERRIDE {} |
5536 | 4258 |
5537 virtual void CallConnectToNetwork(Network* network) OVERRIDE; | 4259 virtual void CallConnectToNetwork(Network* network) OVERRIDE; |
5538 virtual void CallRequestWifiNetworkAndConnect( | 4260 virtual void CallRequestWifiNetworkAndConnect( |
5539 const std::string& ssid, ConnectionSecurity security) OVERRIDE; | 4261 const std::string& ssid, ConnectionSecurity security) OVERRIDE; |
5540 virtual void CallRequestVirtualNetworkAndConnect( | 4262 virtual void CallRequestVirtualNetworkAndConnect( |
5541 const std::string& service_name, | 4263 const std::string& service_name, |
5542 const std::string& server_hostname, | 4264 const std::string& server_hostname, |
5543 VirtualNetwork::ProviderType provider_type) OVERRIDE; | 4265 ProviderType provider_type) OVERRIDE; |
5544 | 4266 |
5545 virtual void CallDeleteRememberedNetwork( | 4267 virtual void CallDeleteRememberedNetwork( |
5546 const std::string& profile_path, | 4268 const std::string& profile_path, |
5547 const std::string& service_path) OVERRIDE {} | 4269 const std::string& service_path) OVERRIDE {} |
5548 | 4270 |
5549 // NetworkLibrary implementation. | 4271 // NetworkLibrary implementation. |
5550 | 4272 |
5551 virtual void ChangePin(const std::string& old_pin, | 4273 virtual void ChangePin(const std::string& old_pin, |
5552 const std::string& new_pin) OVERRIDE; | 4274 const std::string& new_pin) OVERRIDE; |
5553 virtual void ChangeRequirePin(bool require_pin, | 4275 virtual void ChangeRequirePin(bool require_pin, |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5606 is_locked_ = false; | 4328 is_locked_ = false; |
5607 | 4329 |
5608 // Devices | 4330 // Devices |
5609 int devices = | 4331 int devices = |
5610 (1 << TYPE_ETHERNET) | (1 << TYPE_WIFI) | (1 << TYPE_CELLULAR); | 4332 (1 << TYPE_ETHERNET) | (1 << TYPE_WIFI) | (1 << TYPE_CELLULAR); |
5611 available_devices_ = devices; | 4333 available_devices_ = devices; |
5612 enabled_devices_ = devices; | 4334 enabled_devices_ = devices; |
5613 connected_devices_ = devices; | 4335 connected_devices_ = devices; |
5614 | 4336 |
5615 NetworkDevice* cellular = new NetworkDevice("cellular"); | 4337 NetworkDevice* cellular = new NetworkDevice("cellular"); |
5616 scoped_ptr<Value> cellular_type(Value::CreateStringValue(kTypeCellular)); | 4338 cellular->type_ = TYPE_CELLULAR; |
5617 cellular->ParseValue(PROPERTY_INDEX_TYPE, cellular_type.get()); | 4339 cellular->imsi_ = "123456789012345"; |
5618 cellular->IMSI_ = "123456789012345"; | |
5619 device_map_["cellular"] = cellular; | 4340 device_map_["cellular"] = cellular; |
5620 | 4341 |
5621 // Networks | 4342 // Networks |
5622 DeleteNetworks(); | 4343 DeleteNetworks(); |
5623 | 4344 |
5624 ethernet_ = new EthernetNetwork("eth1"); | 4345 ethernet_ = new EthernetNetwork("eth1"); |
5625 ethernet_->set_connected(true); | 4346 ethernet_->set_connected(true); |
5626 AddNetwork(ethernet_); | 4347 AddNetwork(ethernet_); |
5627 | 4348 |
5628 WifiNetwork* wifi1 = new WifiNetwork("fw1"); | 4349 WifiNetwork* wifi1 = new WifiNetwork("fw1"); |
5629 wifi1->set_name("Fake WiFi Connected"); | 4350 wifi1->set_name("Fake WiFi Connected"); |
5630 wifi1->set_strength(90); | 4351 wifi1->set_strength(90); |
5631 wifi1->set_connected(false); | 4352 wifi1->set_connected(false); |
5632 wifi1->set_connecting(true); | 4353 wifi1->set_connecting(true); |
5633 wifi1->set_active(true); | 4354 wifi1->set_is_active(true); |
5634 wifi1->set_encryption(SECURITY_NONE); | 4355 wifi1->set_encryption(SECURITY_NONE); |
5635 wifi1->set_profile_type(PROFILE_SHARED); | 4356 wifi1->set_profile_type(PROFILE_SHARED); |
5636 AddNetwork(wifi1); | 4357 AddNetwork(wifi1); |
5637 | 4358 |
5638 WifiNetwork* wifi2 = new WifiNetwork("fw2"); | 4359 WifiNetwork* wifi2 = new WifiNetwork("fw2"); |
5639 wifi2->set_name("Fake WiFi"); | 4360 wifi2->set_name("Fake WiFi"); |
5640 wifi2->set_strength(70); | 4361 wifi2->set_strength(70); |
5641 wifi2->set_connected(false); | 4362 wifi2->set_connected(false); |
5642 wifi2->set_encryption(SECURITY_NONE); | 4363 wifi2->set_encryption(SECURITY_NONE); |
5643 wifi2->set_profile_type(PROFILE_SHARED); | 4364 wifi2->set_profile_type(PROFILE_SHARED); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5677 wifi6->set_connected(false); | 4398 wifi6->set_connected(false); |
5678 AddNetwork(wifi6); | 4399 AddNetwork(wifi6); |
5679 | 4400 |
5680 active_wifi_ = wifi1; | 4401 active_wifi_ = wifi1; |
5681 | 4402 |
5682 CellularNetwork* cellular1 = new CellularNetwork("fc1"); | 4403 CellularNetwork* cellular1 = new CellularNetwork("fc1"); |
5683 cellular1->set_name("Fake Cellular"); | 4404 cellular1->set_name("Fake Cellular"); |
5684 cellular1->set_strength(70); | 4405 cellular1->set_strength(70); |
5685 cellular1->set_connected(false); | 4406 cellular1->set_connected(false); |
5686 cellular1->set_connecting(true); | 4407 cellular1->set_connecting(true); |
5687 cellular1->set_active(true); | 4408 cellular1->set_is_active(true); |
5688 cellular1->set_activation_state(ACTIVATION_STATE_ACTIVATED); | 4409 cellular1->set_activation_state(ACTIVATION_STATE_ACTIVATED); |
5689 cellular1->set_payment_url(std::string("http://www.google.com")); | 4410 cellular1->set_payment_url(std::string("http://www.google.com")); |
5690 cellular1->set_usage_url(std::string("http://www.google.com")); | 4411 cellular1->set_usage_url(std::string("http://www.google.com")); |
5691 cellular1->set_network_technology(NETWORK_TECHNOLOGY_EVDO); | 4412 cellular1->set_network_technology(NETWORK_TECHNOLOGY_EVDO); |
5692 cellular1->set_roaming_state(ROAMING_STATE_ROAMING); | 4413 cellular1->set_roaming_state(ROAMING_STATE_ROAMING); |
5693 | 4414 |
5694 CellularDataPlan* base_plan = new CellularDataPlan(); | 4415 CellularDataPlan* base_plan = new CellularDataPlan(); |
5695 base_plan->plan_name = "Base plan"; | 4416 base_plan->plan_name = "Base plan"; |
5696 base_plan->plan_type = CELLULAR_DATA_PLAN_METERED_BASE; | 4417 base_plan->plan_type = CELLULAR_DATA_PLAN_METERED_BASE; |
5697 base_plan->plan_data_bytes = 100ll * 1024 * 1024; | 4418 base_plan->plan_data_bytes = 100ll * 1024 * 1024; |
(...skipping 17 matching lines...) Expand all Loading... |
5715 cellular2->set_strength(70); | 4436 cellular2->set_strength(70); |
5716 cellular2->set_connected(true); | 4437 cellular2->set_connected(true); |
5717 cellular2->set_activation_state(ACTIVATION_STATE_ACTIVATED); | 4438 cellular2->set_activation_state(ACTIVATION_STATE_ACTIVATED); |
5718 cellular2->set_network_technology(NETWORK_TECHNOLOGY_UMTS); | 4439 cellular2->set_network_technology(NETWORK_TECHNOLOGY_UMTS); |
5719 AddNetwork(cellular2); | 4440 AddNetwork(cellular2); |
5720 | 4441 |
5721 // VPNs | 4442 // VPNs |
5722 VirtualNetwork* vpn1 = new VirtualNetwork("fv1"); | 4443 VirtualNetwork* vpn1 = new VirtualNetwork("fv1"); |
5723 vpn1->set_name("Fake VPN Provider 1"); | 4444 vpn1->set_name("Fake VPN Provider 1"); |
5724 vpn1->set_server_hostname("vpn1server.fake.com"); | 4445 vpn1->set_server_hostname("vpn1server.fake.com"); |
5725 vpn1->set_provider_type(VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_PSK); | 4446 vpn1->set_provider_type(PROVIDER_TYPE_L2TP_IPSEC_PSK); |
5726 vpn1->set_username("VPN User 1"); | 4447 vpn1->set_username("VPN User 1"); |
5727 vpn1->set_connected(false); | 4448 vpn1->set_connected(false); |
5728 AddNetwork(vpn1); | 4449 AddNetwork(vpn1); |
5729 | 4450 |
5730 VirtualNetwork* vpn2 = new VirtualNetwork("fv2"); | 4451 VirtualNetwork* vpn2 = new VirtualNetwork("fv2"); |
5731 vpn2->set_name("Fake VPN Provider 2"); | 4452 vpn2->set_name("Fake VPN Provider 2"); |
5732 vpn2->set_server_hostname("vpn2server.fake.com"); | 4453 vpn2->set_server_hostname("vpn2server.fake.com"); |
5733 vpn2->set_provider_type(VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT); | 4454 vpn2->set_provider_type(PROVIDER_TYPE_L2TP_IPSEC_USER_CERT); |
5734 vpn2->set_username("VPN User 2"); | 4455 vpn2->set_username("VPN User 2"); |
5735 vpn2->set_connected(true); | 4456 vpn2->set_connected(true); |
5736 AddNetwork(vpn2); | 4457 AddNetwork(vpn2); |
5737 | 4458 |
5738 VirtualNetwork* vpn3 = new VirtualNetwork("fv3"); | 4459 VirtualNetwork* vpn3 = new VirtualNetwork("fv3"); |
5739 vpn3->set_name("Fake VPN Provider 3"); | 4460 vpn3->set_name("Fake VPN Provider 3"); |
5740 vpn3->set_server_hostname("vpn3server.fake.com"); | 4461 vpn3->set_server_hostname("vpn3server.fake.com"); |
5741 vpn3->set_provider_type(VirtualNetwork::PROVIDER_TYPE_OPEN_VPN); | 4462 vpn3->set_provider_type(PROVIDER_TYPE_OPEN_VPN); |
5742 vpn3->set_connected(false); | 4463 vpn3->set_connected(false); |
5743 AddNetwork(vpn3); | 4464 AddNetwork(vpn3); |
5744 | 4465 |
5745 active_virtual_ = vpn2; | 4466 active_virtual_ = vpn2; |
5746 | 4467 |
5747 // Remembered Networks | 4468 // Remembered Networks |
5748 DeleteRememberedNetworks(); | 4469 DeleteRememberedNetworks(); |
5749 NetworkProfile profile("default", PROFILE_SHARED); | 4470 NetworkProfile profile("default", PROFILE_SHARED); |
5750 profile.services.insert("fw2"); | 4471 profile.services.insert("fw2"); |
5751 profile.services.insert("fv2"); | 4472 profile.services.insert("fv2"); |
5752 profile_list_.push_back(profile); | 4473 profile_list_.push_back(profile); |
5753 WifiNetwork* remembered_wifi2 = new WifiNetwork("fw2"); | 4474 WifiNetwork* remembered_wifi2 = new WifiNetwork("fw2"); |
5754 remembered_wifi2->set_name("Fake WiFi 2"); | 4475 remembered_wifi2->set_name("Fake WiFi 2"); |
5755 remembered_wifi2->set_encryption(SECURITY_WEP); | 4476 remembered_wifi2->set_encryption(SECURITY_WEP); |
5756 AddRememberedNetwork(remembered_wifi2); | 4477 AddRememberedNetwork(remembered_wifi2); |
5757 VirtualNetwork* remembered_vpn2 = new VirtualNetwork("fv2"); | 4478 VirtualNetwork* remembered_vpn2 = new VirtualNetwork("fv2"); |
5758 remembered_vpn2->set_name("Fake VPN Provider 2"); | 4479 remembered_vpn2->set_name("Fake VPN Provider 2"); |
5759 remembered_vpn2->set_server_hostname("vpn2server.fake.com"); | 4480 remembered_vpn2->set_server_hostname("vpn2server.fake.com"); |
5760 remembered_vpn2->set_provider_type( | 4481 remembered_vpn2->set_provider_type( |
5761 VirtualNetwork::PROVIDER_TYPE_L2TP_IPSEC_USER_CERT); | 4482 PROVIDER_TYPE_L2TP_IPSEC_USER_CERT); |
5762 remembered_vpn2->set_connected(true); | 4483 remembered_vpn2->set_connected(true); |
5763 AddRememberedNetwork(remembered_vpn2); | 4484 AddRememberedNetwork(remembered_vpn2); |
5764 | 4485 |
5765 wifi_scanning_ = false; | 4486 wifi_scanning_ = false; |
5766 offline_mode_ = false; | 4487 offline_mode_ = false; |
5767 } | 4488 } |
5768 | 4489 |
5769 ////////////////////////////////////////////////////////////////////////////// | 4490 ////////////////////////////////////////////////////////////////////////////// |
5770 // NetworkLibraryImplBase implementation. | 4491 // NetworkLibraryImplBase implementation. |
5771 | 4492 |
5772 void NetworkLibraryImplStub::CallConnectToNetwork(Network* network) { | 4493 void NetworkLibraryImplStub::CallConnectToNetwork(Network* network) { |
5773 NetworkConnectCompleted(network, CONNECT_SUCCESS); | 4494 NetworkConnectCompleted(network, CONNECT_SUCCESS); |
5774 } | 4495 } |
5775 | 4496 |
5776 void NetworkLibraryImplStub::CallRequestWifiNetworkAndConnect( | 4497 void NetworkLibraryImplStub::CallRequestWifiNetworkAndConnect( |
5777 const std::string& ssid, ConnectionSecurity security) { | 4498 const std::string& ssid, ConnectionSecurity security) { |
5778 WifiNetwork* wifi = new WifiNetwork(ssid); | 4499 WifiNetwork* wifi = new WifiNetwork(ssid); |
5779 wifi->set_encryption(security); | 4500 wifi->set_encryption(security); |
5780 AddNetwork(wifi); | 4501 AddNetwork(wifi); |
5781 ConnectToWifiNetworkUsingConnectData(wifi); | 4502 ConnectToWifiNetworkUsingConnectData(wifi); |
5782 } | 4503 } |
5783 | 4504 |
5784 void NetworkLibraryImplStub::CallRequestVirtualNetworkAndConnect( | 4505 void NetworkLibraryImplStub::CallRequestVirtualNetworkAndConnect( |
5785 const std::string& service_name, | 4506 const std::string& service_name, |
5786 const std::string& server_hostname, | 4507 const std::string& server_hostname, |
5787 VirtualNetwork::ProviderType provider_type) { | 4508 ProviderType provider_type) { |
5788 VirtualNetwork* vpn = new VirtualNetwork(service_name); | 4509 VirtualNetwork* vpn = new VirtualNetwork(service_name); |
5789 vpn->set_server_hostname(server_hostname); | 4510 vpn->set_server_hostname(server_hostname); |
5790 vpn->set_provider_type(provider_type); | 4511 vpn->set_provider_type(provider_type); |
5791 AddNetwork(vpn); | 4512 AddNetwork(vpn); |
5792 ConnectToVirtualNetworkUsingConnectData(vpn); | 4513 ConnectToVirtualNetworkUsingConnectData(vpn); |
5793 } | 4514 } |
5794 | 4515 |
5795 ///////////////////////////////////////////////////////////////////////////// | 4516 ///////////////////////////////////////////////////////////////////////////// |
5796 // NetworkLibrary implementation. | 4517 // NetworkLibrary implementation. |
5797 | 4518 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5873 return network_library; | 4594 return network_library; |
5874 } | 4595 } |
5875 | 4596 |
5876 ///////////////////////////////////////////////////////////////////////////// | 4597 ///////////////////////////////////////////////////////////////////////////// |
5877 | 4598 |
5878 } // namespace chromeos | 4599 } // namespace chromeos |
5879 | 4600 |
5880 // Allows InvokeLater without adding refcounting. This class is a Singleton and | 4601 // Allows InvokeLater without adding refcounting. This class is a Singleton and |
5881 // won't be deleted until it's last InvokeLater is run. | 4602 // won't be deleted until it's last InvokeLater is run. |
5882 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); | 4603 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::NetworkLibraryImplBase); |
OLD | NEW |