OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/cros/network_library_impl_cros.h" | 5 #include "chrome/browser/chromeos/cros/network_library_impl_cros.h" |
6 | 6 |
7 #include <dbus/dbus-glib.h> | 7 #include <dbus/dbus-glib.h> |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/json/json_writer.h" // for debug output only. | 9 #include "base/json/json_writer.h" // for debug output only. |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // static callback | 116 // static callback |
117 void NetworkLibraryImplCros::NetworkStatusChangedHandler( | 117 void NetworkLibraryImplCros::NetworkStatusChangedHandler( |
118 void* object, | 118 void* object, |
119 const std::string& path, | 119 const std::string& path, |
120 const std::string& key, | 120 const std::string& key, |
121 const Value& value) { | 121 const Value& value) { |
122 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 122 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
123 NetworkLibraryImplCros* networklib = | 123 NetworkLibraryImplCros* networklib = |
124 static_cast<NetworkLibraryImplCros*>(object); | 124 static_cast<NetworkLibraryImplCros*>(object); |
125 DCHECK(networklib); | 125 DCHECK(networklib); |
126 networklib->UpdateNetworkStatus(std::string(path), std::string(key), value); | 126 networklib->UpdateNetworkStatus(path, key, value); |
127 } | 127 } |
128 | 128 |
129 void NetworkLibraryImplCros::UpdateNetworkStatus( | 129 void NetworkLibraryImplCros::UpdateNetworkStatus( |
130 const std::string& path, const std::string& key, const Value& value) { | 130 const std::string& path, const std::string& key, const Value& value) { |
131 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 131 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
132 Network* network = FindNetworkByPath(path); | 132 Network* network = FindNetworkByPath(path); |
133 if (network) { | 133 if (network) { |
134 VLOG(2) << "UpdateNetworkStatus: " << network->name() << "." << key; | 134 VLOG(2) << "UpdateNetworkStatus: " << network->name() << "." << key; |
135 bool prev_connected = network->connected(); | 135 bool prev_connected = network->connected(); |
136 if (!network->UpdateStatus(key, value, NULL)) { | 136 if (!network->UpdateStatus(key, value, NULL)) { |
(...skipping 12 matching lines...) Expand all Loading... |
149 // static callback | 149 // static callback |
150 void NetworkLibraryImplCros::NetworkDevicePropertyChangedHandler( | 150 void NetworkLibraryImplCros::NetworkDevicePropertyChangedHandler( |
151 void* object, | 151 void* object, |
152 const std::string& path, | 152 const std::string& path, |
153 const std::string& key, | 153 const std::string& key, |
154 const Value& value) { | 154 const Value& value) { |
155 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 155 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
156 NetworkLibraryImplCros* networklib = | 156 NetworkLibraryImplCros* networklib = |
157 static_cast<NetworkLibraryImplCros*>(object); | 157 static_cast<NetworkLibraryImplCros*>(object); |
158 DCHECK(networklib); | 158 DCHECK(networklib); |
159 networklib->UpdateNetworkDeviceStatus(std::string(path), | 159 networklib->UpdateNetworkDeviceStatus(path, key, value); |
160 std::string(key), | |
161 value); | |
162 } | 160 } |
163 | 161 |
164 void NetworkLibraryImplCros::UpdateNetworkDeviceStatus( | 162 void NetworkLibraryImplCros::UpdateNetworkDeviceStatus( |
165 const std::string& path, const std::string& key, const Value& value) { | 163 const std::string& path, const std::string& key, const Value& value) { |
166 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 164 CHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
167 NetworkDevice* device = FindNetworkDeviceByPath(path); | 165 NetworkDevice* device = FindNetworkDeviceByPath(path); |
168 if (device) { | 166 if (device) { |
169 VLOG(2) << "UpdateNetworkDeviceStatus: " << device->name() << "." << key; | 167 VLOG(2) << "UpdateNetworkDeviceStatus: " << device->name() << "." << key; |
170 PropertyIndex index = PROPERTY_INDEX_UNKNOWN; | 168 PropertyIndex index = PROPERTY_INDEX_UNKNOWN; |
171 if (device->UpdateStatus(key, value, &index)) { | 169 if (device->UpdateStatus(key, value, &index)) { |
172 if (device->type() == TYPE_CELLULAR) { | 170 if (device->type() == TYPE_CELLULAR) { |
173 if (!UpdateCellularDeviceStatus(device, index)) | 171 if (!UpdateCellularDeviceStatus(device, index)) |
174 return; // Update aborted, skip notify. | 172 return; // Update aborted, skip notify. |
175 } | 173 } |
176 } else { | 174 } else { |
177 VLOG(1) << "UpdateNetworkDeviceStatus: Failed to update: " | 175 VLOG(1) << "UpdateNetworkDeviceStatus: Failed to update: " |
178 << path << "." << key; | 176 << path << "." << key; |
179 } | 177 } |
180 // Notify only observers on device property change. | 178 // Notify only observers on device property change. |
181 NotifyNetworkDeviceChanged(device, index); | 179 NotifyNetworkDeviceChanged(device, index); |
182 // If a device's power state changes, new properties may become defined. | 180 // If a device's power state changes, new properties may become defined. |
183 if (index == PROPERTY_INDEX_POWERED) { | 181 if (index == PROPERTY_INDEX_POWERED) { |
184 CrosRequestNetworkDeviceProperties(path.c_str(), | 182 CrosRequestNetworkDeviceProperties(path, |
185 base::Bind(&NetworkDeviceUpdate, | 183 base::Bind(&NetworkDeviceUpdate, |
186 this)); | 184 this)); |
187 } | 185 } |
188 } | 186 } |
189 } | 187 } |
190 | 188 |
191 bool NetworkLibraryImplCros::UpdateCellularDeviceStatus( | 189 bool NetworkLibraryImplCros::UpdateCellularDeviceStatus( |
192 NetworkDevice* device, PropertyIndex index) { | 190 NetworkDevice* device, PropertyIndex index) { |
193 if (index == PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING) { | 191 if (index == PROPERTY_INDEX_CELLULAR_ALLOW_ROAMING) { |
194 if (!device->data_roaming_allowed() && IsCellularAlwaysInRoaming()) { | 192 if (!device->data_roaming_allowed() && IsCellularAlwaysInRoaming()) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 << " Error: " << error << " Message: " << error_message; | 233 << " Error: " << error << " Message: " << error_message; |
236 if (error_message && | 234 if (error_message && |
237 strcmp(error_message, flimflam::kErrorPassphraseRequiredMsg) == 0) { | 235 strcmp(error_message, flimflam::kErrorPassphraseRequiredMsg) == 0) { |
238 status = CONNECT_BAD_PASSPHRASE; | 236 status = CONNECT_BAD_PASSPHRASE; |
239 } else { | 237 } else { |
240 status = CONNECT_FAILED; | 238 status = CONNECT_FAILED; |
241 } | 239 } |
242 } | 240 } |
243 NetworkLibraryImplCros* networklib = | 241 NetworkLibraryImplCros* networklib = |
244 static_cast<NetworkLibraryImplCros*>(object); | 242 static_cast<NetworkLibraryImplCros*>(object); |
245 Network* network = networklib->FindNetworkByPath(std::string(service_path)); | 243 Network* network = networklib->FindNetworkByPath(service_path); |
246 if (!network) { | 244 if (!network) { |
247 LOG(ERROR) << "No network for path: " << service_path; | 245 LOG(ERROR) << "No network for path: " << service_path; |
248 return; | 246 return; |
249 } | 247 } |
250 networklib->NetworkConnectCompleted(network, status); | 248 networklib->NetworkConnectCompleted(network, status); |
251 } | 249 } |
252 | 250 |
253 void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) { | 251 void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) { |
254 DCHECK(network); | 252 DCHECK(network); |
255 CrosRequestNetworkServiceConnect(network->service_path().c_str(), | 253 CrosRequestNetworkServiceConnect(network->service_path(), |
256 NetworkConnectCallback, this); | 254 NetworkConnectCallback, this); |
257 } | 255 } |
258 | 256 |
259 // static callback | 257 // static callback |
260 void NetworkLibraryImplCros::WifiServiceUpdateAndConnect( | 258 void NetworkLibraryImplCros::WifiServiceUpdateAndConnect( |
261 void* object, | 259 void* object, |
262 const char* service_path, | 260 const std::string& service_path, |
263 const base::DictionaryValue* properties) { | 261 const base::DictionaryValue* properties) { |
264 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 262 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
265 NetworkLibraryImplCros* networklib = | 263 NetworkLibraryImplCros* networklib = |
266 static_cast<NetworkLibraryImplCros*>(object); | 264 static_cast<NetworkLibraryImplCros*>(object); |
267 DCHECK(networklib); | 265 DCHECK(networklib); |
268 if (service_path && properties) { | 266 if (properties) { |
269 Network* network = | 267 Network* network = networklib->ParseNetwork(service_path, *properties); |
270 networklib->ParseNetwork(std::string(service_path), *properties); | |
271 DCHECK_EQ(network->type(), TYPE_WIFI); | 268 DCHECK_EQ(network->type(), TYPE_WIFI); |
272 networklib->ConnectToWifiNetworkUsingConnectData( | 269 networklib->ConnectToWifiNetworkUsingConnectData( |
273 static_cast<WifiNetwork*>(network)); | 270 static_cast<WifiNetwork*>(network)); |
274 } | 271 } |
275 } | 272 } |
276 | 273 |
277 void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect( | 274 void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect( |
278 const std::string& ssid, ConnectionSecurity security) { | 275 const std::string& ssid, ConnectionSecurity security) { |
279 // Asynchronously request service properties and call | 276 // Asynchronously request service properties and call |
280 // WifiServiceUpdateAndConnect. | 277 // WifiServiceUpdateAndConnect. |
281 CrosRequestHiddenWifiNetworkProperties( | 278 CrosRequestHiddenWifiNetworkProperties( |
282 ssid.c_str(), | 279 ssid, |
283 SecurityToString(security), | 280 SecurityToString(security), |
284 base::Bind(&WifiServiceUpdateAndConnect, this)); | 281 base::Bind(&WifiServiceUpdateAndConnect, this)); |
285 } | 282 } |
286 | 283 |
287 // static callback | 284 // static callback |
288 void NetworkLibraryImplCros::VPNServiceUpdateAndConnect( | 285 void NetworkLibraryImplCros::VPNServiceUpdateAndConnect( |
289 void* object, | 286 void* object, |
290 const char* service_path, | 287 const std::string& service_path, |
291 const base::DictionaryValue* properties) { | 288 const base::DictionaryValue* properties) { |
292 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 289 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
293 NetworkLibraryImplCros* networklib = | 290 NetworkLibraryImplCros* networklib = |
294 static_cast<NetworkLibraryImplCros*>(object); | 291 static_cast<NetworkLibraryImplCros*>(object); |
295 DCHECK(networklib); | 292 DCHECK(networklib); |
296 if (service_path && properties) { | 293 if (properties) { |
297 VLOG(1) << "Connecting to new VPN Service: " << service_path; | 294 VLOG(1) << "Connecting to new VPN Service: " << service_path; |
298 Network* network = | 295 Network* network = networklib->ParseNetwork(service_path, *properties); |
299 networklib->ParseNetwork(std::string(service_path), *properties); | |
300 DCHECK_EQ(network->type(), TYPE_VPN); | 296 DCHECK_EQ(network->type(), TYPE_VPN); |
301 networklib->ConnectToVirtualNetworkUsingConnectData( | 297 networklib->ConnectToVirtualNetworkUsingConnectData( |
302 static_cast<VirtualNetwork*>(network)); | 298 static_cast<VirtualNetwork*>(network)); |
303 } else { | 299 } else { |
304 LOG(WARNING) << "Unable to create VPN Service: " << service_path; | 300 LOG(WARNING) << "Unable to create VPN Service: " << service_path; |
305 } | 301 } |
306 } | 302 } |
307 | 303 |
308 void NetworkLibraryImplCros::CallRequestVirtualNetworkAndConnect( | 304 void NetworkLibraryImplCros::CallRequestVirtualNetworkAndConnect( |
309 const std::string& service_name, | 305 const std::string& service_name, |
310 const std::string& server_hostname, | 306 const std::string& server_hostname, |
311 ProviderType provider_type) { | 307 ProviderType provider_type) { |
312 CrosRequestVirtualNetworkProperties( | 308 CrosRequestVirtualNetworkProperties( |
313 service_name.c_str(), | 309 service_name, |
314 server_hostname.c_str(), | 310 server_hostname, |
315 ProviderTypeToString(provider_type), | 311 ProviderTypeToString(provider_type), |
316 base::Bind(&VPNServiceUpdateAndConnect, this)); | 312 base::Bind(&VPNServiceUpdateAndConnect, this)); |
317 } | 313 } |
318 | 314 |
319 void NetworkLibraryImplCros::CallDeleteRememberedNetwork( | 315 void NetworkLibraryImplCros::CallDeleteRememberedNetwork( |
320 const std::string& profile_path, | 316 const std::string& profile_path, |
321 const std::string& service_path) { | 317 const std::string& service_path) { |
322 CrosDeleteServiceFromProfile( | 318 CrosDeleteServiceFromProfile(profile_path, service_path); |
323 profile_path.c_str(), service_path.c_str()); | |
324 } | 319 } |
325 | 320 |
326 ////////////////////////////////////////////////////////////////////////////// | 321 ////////////////////////////////////////////////////////////////////////////// |
327 // NetworkLibrary implementation. | 322 // NetworkLibrary implementation. |
328 | 323 |
329 void NetworkLibraryImplCros::SetCheckPortalList( | 324 void NetworkLibraryImplCros::SetCheckPortalList( |
330 const std::string& check_portal_list) { | 325 const std::string& check_portal_list) { |
331 base::StringValue value(check_portal_list); | 326 base::StringValue value(check_portal_list); |
332 CrosSetNetworkManagerProperty(flimflam::kCheckPortalListProperty, value); | 327 CrosSetNetworkManagerProperty(flimflam::kCheckPortalListProperty, value); |
333 } | 328 } |
334 | 329 |
335 void NetworkLibraryImplCros::SetDefaultCheckPortalList() { | 330 void NetworkLibraryImplCros::SetDefaultCheckPortalList() { |
336 SetCheckPortalList(kDefaultCheckPortalList); | 331 SetCheckPortalList(kDefaultCheckPortalList); |
337 } | 332 } |
338 | 333 |
339 void NetworkLibraryImplCros::ChangePin(const std::string& old_pin, | 334 void NetworkLibraryImplCros::ChangePin(const std::string& old_pin, |
340 const std::string& new_pin) { | 335 const std::string& new_pin) { |
341 const NetworkDevice* cellular = FindCellularDevice(); | 336 const NetworkDevice* cellular = FindCellularDevice(); |
342 if (!cellular) { | 337 if (!cellular) { |
343 NOTREACHED() << "Calling ChangePin method w/o cellular device."; | 338 NOTREACHED() << "Calling ChangePin method w/o cellular device."; |
344 return; | 339 return; |
345 } | 340 } |
346 sim_operation_ = SIM_OPERATION_CHANGE_PIN; | 341 sim_operation_ = SIM_OPERATION_CHANGE_PIN; |
347 CrosRequestChangePin(cellular->device_path().c_str(), | 342 CrosRequestChangePin(cellular->device_path(), old_pin, new_pin, |
348 old_pin.c_str(), new_pin.c_str(), | |
349 PinOperationCallback, this); | 343 PinOperationCallback, this); |
350 } | 344 } |
351 | 345 |
352 void NetworkLibraryImplCros::ChangeRequirePin(bool require_pin, | 346 void NetworkLibraryImplCros::ChangeRequirePin(bool require_pin, |
353 const std::string& pin) { | 347 const std::string& pin) { |
354 VLOG(1) << "ChangeRequirePin require_pin: " << require_pin | 348 VLOG(1) << "ChangeRequirePin require_pin: " << require_pin |
355 << " pin: " << pin; | 349 << " pin: " << pin; |
356 const NetworkDevice* cellular = FindCellularDevice(); | 350 const NetworkDevice* cellular = FindCellularDevice(); |
357 if (!cellular) { | 351 if (!cellular) { |
358 NOTREACHED() << "Calling ChangeRequirePin method w/o cellular device."; | 352 NOTREACHED() << "Calling ChangeRequirePin method w/o cellular device."; |
359 return; | 353 return; |
360 } | 354 } |
361 sim_operation_ = SIM_OPERATION_CHANGE_REQUIRE_PIN; | 355 sim_operation_ = SIM_OPERATION_CHANGE_REQUIRE_PIN; |
362 CrosRequestRequirePin(cellular->device_path().c_str(), | 356 CrosRequestRequirePin(cellular->device_path(), pin, require_pin, |
363 pin.c_str(), require_pin, | |
364 PinOperationCallback, this); | 357 PinOperationCallback, this); |
365 } | 358 } |
366 | 359 |
367 void NetworkLibraryImplCros::EnterPin(const std::string& pin) { | 360 void NetworkLibraryImplCros::EnterPin(const std::string& pin) { |
368 const NetworkDevice* cellular = FindCellularDevice(); | 361 const NetworkDevice* cellular = FindCellularDevice(); |
369 if (!cellular) { | 362 if (!cellular) { |
370 NOTREACHED() << "Calling EnterPin method w/o cellular device."; | 363 NOTREACHED() << "Calling EnterPin method w/o cellular device."; |
371 return; | 364 return; |
372 } | 365 } |
373 sim_operation_ = SIM_OPERATION_ENTER_PIN; | 366 sim_operation_ = SIM_OPERATION_ENTER_PIN; |
374 CrosRequestEnterPin(cellular->device_path().c_str(), | 367 CrosRequestEnterPin(cellular->device_path(), pin, PinOperationCallback, this); |
375 pin.c_str(), | |
376 PinOperationCallback, this); | |
377 } | 368 } |
378 | 369 |
379 void NetworkLibraryImplCros::UnblockPin(const std::string& puk, | 370 void NetworkLibraryImplCros::UnblockPin(const std::string& puk, |
380 const std::string& new_pin) { | 371 const std::string& new_pin) { |
381 const NetworkDevice* cellular = FindCellularDevice(); | 372 const NetworkDevice* cellular = FindCellularDevice(); |
382 if (!cellular) { | 373 if (!cellular) { |
383 NOTREACHED() << "Calling UnblockPin method w/o cellular device."; | 374 NOTREACHED() << "Calling UnblockPin method w/o cellular device."; |
384 return; | 375 return; |
385 } | 376 } |
386 sim_operation_ = SIM_OPERATION_UNBLOCK_PIN; | 377 sim_operation_ = SIM_OPERATION_UNBLOCK_PIN; |
387 CrosRequestUnblockPin(cellular->device_path().c_str(), | 378 CrosRequestUnblockPin(cellular->device_path(), puk, new_pin, |
388 puk.c_str(), new_pin.c_str(), | |
389 PinOperationCallback, this); | 379 PinOperationCallback, this); |
390 } | 380 } |
391 | 381 |
392 // static callback | 382 // static callback |
393 void NetworkLibraryImplCros::PinOperationCallback( | 383 void NetworkLibraryImplCros::PinOperationCallback( |
394 void* object, | 384 void* object, |
395 const char* path, | 385 const char* path, |
396 NetworkMethodErrorType error, | 386 NetworkMethodErrorType error, |
397 const char* error_message) { | 387 const char* error_message) { |
398 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 388 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
(...skipping 21 matching lines...) Expand all Loading... |
420 } | 410 } |
421 networklib->NotifyPinOperationCompleted(pin_error); | 411 networklib->NotifyPinOperationCompleted(pin_error); |
422 } | 412 } |
423 | 413 |
424 void NetworkLibraryImplCros::RequestCellularScan() { | 414 void NetworkLibraryImplCros::RequestCellularScan() { |
425 const NetworkDevice* cellular = FindCellularDevice(); | 415 const NetworkDevice* cellular = FindCellularDevice(); |
426 if (!cellular) { | 416 if (!cellular) { |
427 NOTREACHED() << "Calling RequestCellularScan method w/o cellular device."; | 417 NOTREACHED() << "Calling RequestCellularScan method w/o cellular device."; |
428 return; | 418 return; |
429 } | 419 } |
430 CrosProposeScan(cellular->device_path().c_str()); | 420 CrosProposeScan(cellular->device_path()); |
431 } | 421 } |
432 | 422 |
433 void NetworkLibraryImplCros::RequestCellularRegister( | 423 void NetworkLibraryImplCros::RequestCellularRegister( |
434 const std::string& network_id) { | 424 const std::string& network_id) { |
435 const NetworkDevice* cellular = FindCellularDevice(); | 425 const NetworkDevice* cellular = FindCellularDevice(); |
436 if (!cellular) { | 426 if (!cellular) { |
437 NOTREACHED() << "Calling CellularRegister method w/o cellular device."; | 427 NOTREACHED() << "Calling CellularRegister method w/o cellular device."; |
438 return; | 428 return; |
439 } | 429 } |
440 CrosRequestCellularRegister(cellular->device_path().c_str(), | 430 CrosRequestCellularRegister( |
441 network_id.c_str(), | 431 cellular->device_path(), network_id, CellularRegisterCallback, this); |
442 CellularRegisterCallback, | |
443 this); | |
444 } | 432 } |
445 | 433 |
446 // static callback | 434 // static callback |
447 void NetworkLibraryImplCros::CellularRegisterCallback( | 435 void NetworkLibraryImplCros::CellularRegisterCallback( |
448 void* object, | 436 void* object, |
449 const char* path, | 437 const char* path, |
450 NetworkMethodErrorType error, | 438 NetworkMethodErrorType error, |
451 const char* error_message) { | 439 const char* error_message) { |
452 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 440 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
453 NetworkLibraryImplCros* networklib = | 441 NetworkLibraryImplCros* networklib = |
454 static_cast<NetworkLibraryImplCros*>(object); | 442 static_cast<NetworkLibraryImplCros*>(object); |
455 DCHECK(networklib); | 443 DCHECK(networklib); |
456 // TODO(dpolukhin): Notify observers about network registration status | 444 // TODO(dpolukhin): Notify observers about network registration status |
457 // but not UI doesn't assume such notification so just ignore result. | 445 // but not UI doesn't assume such notification so just ignore result. |
458 } | 446 } |
459 | 447 |
460 void NetworkLibraryImplCros::SetCellularDataRoamingAllowed(bool new_value) { | 448 void NetworkLibraryImplCros::SetCellularDataRoamingAllowed(bool new_value) { |
461 const NetworkDevice* cellular = FindCellularDevice(); | 449 const NetworkDevice* cellular = FindCellularDevice(); |
462 if (!cellular) { | 450 if (!cellular) { |
463 NOTREACHED() << "Calling SetCellularDataRoamingAllowed method " | 451 NOTREACHED() << "Calling SetCellularDataRoamingAllowed method " |
464 "w/o cellular device."; | 452 "w/o cellular device."; |
465 return; | 453 return; |
466 } | 454 } |
467 base::FundamentalValue value(new_value); | 455 base::FundamentalValue value(new_value); |
468 CrosSetNetworkDeviceProperty(cellular->device_path().c_str(), | 456 CrosSetNetworkDeviceProperty(cellular->device_path(), |
469 flimflam::kCellularAllowRoamingProperty, | 457 flimflam::kCellularAllowRoamingProperty, |
470 value); | 458 value); |
471 } | 459 } |
472 | 460 |
473 bool NetworkLibraryImplCros::IsCellularAlwaysInRoaming() { | 461 bool NetworkLibraryImplCros::IsCellularAlwaysInRoaming() { |
474 const NetworkDevice* cellular = FindCellularDevice(); | 462 const NetworkDevice* cellular = FindCellularDevice(); |
475 if (!cellular) { | 463 if (!cellular) { |
476 NOTREACHED() << "Calling IsCellularAlwaysInRoaming method " | 464 NOTREACHED() << "Calling IsCellularAlwaysInRoaming method " |
477 "w/o cellular device."; | 465 "w/o cellular device."; |
478 return false; | 466 return false; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 result->push_back(ap); | 507 result->push_back(ap); |
520 } | 508 } |
521 CrosFreeDeviceNetworkList(network_list); | 509 CrosFreeDeviceNetworkList(network_list); |
522 return true; | 510 return true; |
523 } | 511 } |
524 | 512 |
525 void NetworkLibraryImplCros::DisconnectFromNetwork(const Network* network) { | 513 void NetworkLibraryImplCros::DisconnectFromNetwork(const Network* network) { |
526 DCHECK(network); | 514 DCHECK(network); |
527 // Asynchronous disconnect request. Network state will be updated through | 515 // Asynchronous disconnect request. Network state will be updated through |
528 // the network manager once disconnect completes. | 516 // the network manager once disconnect completes. |
529 CrosRequestNetworkServiceDisconnect(network->service_path().c_str()); | 517 CrosRequestNetworkServiceDisconnect(network->service_path()); |
530 } | 518 } |
531 | 519 |
532 void NetworkLibraryImplCros::CallEnableNetworkDeviceType( | 520 void NetworkLibraryImplCros::CallEnableNetworkDeviceType( |
533 ConnectionType device, bool enable) { | 521 ConnectionType device, bool enable) { |
534 busy_devices_ |= 1 << device; | 522 busy_devices_ |= 1 << device; |
535 CrosRequestNetworkDeviceEnable( | 523 CrosRequestNetworkDeviceEnable(ConnectionTypeToString(device), enable); |
536 ConnectionTypeToString(device), enable); | |
537 } | 524 } |
538 | 525 |
539 void NetworkLibraryImplCros::CallRemoveNetwork(const Network* network) { | 526 void NetworkLibraryImplCros::CallRemoveNetwork(const Network* network) { |
540 const char* service_path = network->service_path().c_str(); | 527 const std::string& service_path = network->service_path(); |
541 if (network->connected()) | 528 if (network->connected()) |
542 CrosRequestNetworkServiceDisconnect(service_path); | 529 CrosRequestNetworkServiceDisconnect(service_path); |
543 CrosRequestRemoveNetworkService(service_path); | 530 CrosRequestRemoveNetworkService(service_path); |
544 } | 531 } |
545 | 532 |
546 void NetworkLibraryImplCros::EnableOfflineMode(bool enable) { | 533 void NetworkLibraryImplCros::EnableOfflineMode(bool enable) { |
547 // If network device is already enabled/disabled, then don't do anything. | 534 // If network device is already enabled/disabled, then don't do anything. |
548 if (CrosSetOfflineMode(enable)) | 535 if (CrosSetOfflineMode(enable)) |
549 offline_mode_ = enable; | 536 offline_mode_ = enable; |
550 } | 537 } |
551 | 538 |
552 NetworkIPConfigVector NetworkLibraryImplCros::GetIPConfigs( | 539 NetworkIPConfigVector NetworkLibraryImplCros::GetIPConfigs( |
553 const std::string& device_path, | 540 const std::string& device_path, |
554 std::string* hardware_address, | 541 std::string* hardware_address, |
555 HardwareAddressFormat format) { | 542 HardwareAddressFormat format) { |
556 DCHECK(hardware_address); | 543 DCHECK(hardware_address); |
557 hardware_address->clear(); | 544 hardware_address->clear(); |
558 NetworkIPConfigVector ipconfig_vector; | 545 NetworkIPConfigVector ipconfig_vector; |
559 if (!device_path.empty()) { | 546 if (!device_path.empty()) { |
560 IPConfigStatus* ipconfig_status = CrosListIPConfigs(device_path.c_str()); | 547 IPConfigStatus* ipconfig_status = CrosListIPConfigs(device_path); |
561 if (ipconfig_status) { | 548 if (ipconfig_status) { |
562 for (int i = 0; i < ipconfig_status->size; ++i) { | 549 for (int i = 0; i < ipconfig_status->size; ++i) { |
563 IPConfig ipconfig = ipconfig_status->ips[i]; | 550 IPConfig ipconfig = ipconfig_status->ips[i]; |
564 ipconfig_vector.push_back( | 551 ipconfig_vector.push_back( |
565 NetworkIPConfig(device_path, ipconfig.type, ipconfig.address, | 552 NetworkIPConfig(device_path, ipconfig.type, ipconfig.address, |
566 ipconfig.netmask, ipconfig.gateway, | 553 ipconfig.netmask, ipconfig.gateway, |
567 ipconfig.name_servers)); | 554 ipconfig.name_servers)); |
568 } | 555 } |
569 *hardware_address = ipconfig_status->hardware_address; | 556 *hardware_address = ipconfig_status->hardware_address; |
570 CrosFreeIPConfigStatus(ipconfig_status); | 557 CrosFreeIPConfigStatus(ipconfig_status); |
(...skipping 19 matching lines...) Expand all Loading... |
590 } | 577 } |
591 | 578 |
592 void NetworkLibraryImplCros::SetIPConfig(const NetworkIPConfig& ipconfig) { | 579 void NetworkLibraryImplCros::SetIPConfig(const NetworkIPConfig& ipconfig) { |
593 if (ipconfig.device_path.empty()) | 580 if (ipconfig.device_path.empty()) |
594 return; | 581 return; |
595 | 582 |
596 IPConfig* ipconfig_dhcp = NULL; | 583 IPConfig* ipconfig_dhcp = NULL; |
597 IPConfig* ipconfig_static = NULL; | 584 IPConfig* ipconfig_static = NULL; |
598 | 585 |
599 IPConfigStatus* ipconfig_status = | 586 IPConfigStatus* ipconfig_status = |
600 CrosListIPConfigs(ipconfig.device_path.c_str()); | 587 CrosListIPConfigs(ipconfig.device_path); |
601 if (ipconfig_status) { | 588 if (ipconfig_status) { |
602 for (int i = 0; i < ipconfig_status->size; ++i) { | 589 for (int i = 0; i < ipconfig_status->size; ++i) { |
603 if (ipconfig_status->ips[i].type == chromeos::IPCONFIG_TYPE_DHCP) | 590 if (ipconfig_status->ips[i].type == chromeos::IPCONFIG_TYPE_DHCP) |
604 ipconfig_dhcp = &ipconfig_status->ips[i]; | 591 ipconfig_dhcp = &ipconfig_status->ips[i]; |
605 else if (ipconfig_status->ips[i].type == chromeos::IPCONFIG_TYPE_IPV4) | 592 else if (ipconfig_status->ips[i].type == chromeos::IPCONFIG_TYPE_IPV4) |
606 ipconfig_static = &ipconfig_status->ips[i]; | 593 ipconfig_static = &ipconfig_status->ips[i]; |
607 } | 594 } |
608 } | 595 } |
609 | 596 |
610 IPConfigStatus* ipconfig_status2 = NULL; | 597 IPConfigStatus* ipconfig_status2 = NULL; |
611 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) { | 598 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) { |
612 // If switching from static to dhcp, create new dhcp ip config. | 599 // If switching from static to dhcp, create new dhcp ip config. |
613 if (!ipconfig_dhcp) | 600 if (!ipconfig_dhcp) |
614 CrosAddIPConfig(ipconfig.device_path.c_str(), | 601 CrosAddIPConfig(ipconfig.device_path, chromeos::IPCONFIG_TYPE_DHCP); |
615 chromeos::IPCONFIG_TYPE_DHCP); | |
616 // User wants DHCP now. So delete the static ip config. | 602 // User wants DHCP now. So delete the static ip config. |
617 if (ipconfig_static) | 603 if (ipconfig_static) |
618 CrosRemoveIPConfig(ipconfig_static); | 604 CrosRemoveIPConfig(ipconfig_static); |
619 } else if (ipconfig.type == chromeos::IPCONFIG_TYPE_IPV4) { | 605 } else if (ipconfig.type == chromeos::IPCONFIG_TYPE_IPV4) { |
620 // If switching from dhcp to static, create new static ip config. | 606 // If switching from dhcp to static, create new static ip config. |
621 if (!ipconfig_static) { | 607 if (!ipconfig_static) { |
622 CrosAddIPConfig(ipconfig.device_path.c_str(), | 608 CrosAddIPConfig(ipconfig.device_path, chromeos::IPCONFIG_TYPE_IPV4); |
623 chromeos::IPCONFIG_TYPE_IPV4); | |
624 // Now find the newly created IP config. | 609 // Now find the newly created IP config. |
625 ipconfig_status2 = | 610 ipconfig_status2 = |
626 CrosListIPConfigs(ipconfig.device_path.c_str()); | 611 CrosListIPConfigs(ipconfig.device_path); |
627 if (ipconfig_status2) { | 612 if (ipconfig_status2) { |
628 for (int i = 0; i < ipconfig_status2->size; ++i) { | 613 for (int i = 0; i < ipconfig_status2->size; ++i) { |
629 if (ipconfig_status2->ips[i].type == chromeos::IPCONFIG_TYPE_IPV4) | 614 if (ipconfig_status2->ips[i].type == chromeos::IPCONFIG_TYPE_IPV4) |
630 ipconfig_static = &ipconfig_status2->ips[i]; | 615 ipconfig_static = &ipconfig_status2->ips[i]; |
631 } | 616 } |
632 } | 617 } |
633 } | 618 } |
634 if (ipconfig_static) { | 619 if (ipconfig_static) { |
635 // Save any changed details. | 620 // Save any changed details. |
636 if (ipconfig.address != ipconfig_static->address) { | 621 if (ipconfig.address != ipconfig_static->address) { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 } | 761 } |
777 base::TimeDelta delta = base::TimeTicks::Now() - start; | 762 base::TimeDelta delta = base::TimeTicks::Now() - start; |
778 VLOG(2) << "NetworkManagerStatusChanged: time: " | 763 VLOG(2) << "NetworkManagerStatusChanged: time: " |
779 << delta.InMilliseconds() << " ms."; | 764 << delta.InMilliseconds() << " ms."; |
780 HISTOGRAM_TIMES("CROS_NETWORK_UPDATE", delta); | 765 HISTOGRAM_TIMES("CROS_NETWORK_UPDATE", delta); |
781 } | 766 } |
782 | 767 |
783 // static | 768 // static |
784 void NetworkLibraryImplCros::NetworkManagerUpdate( | 769 void NetworkLibraryImplCros::NetworkManagerUpdate( |
785 void* object, | 770 void* object, |
786 const char* manager_path, | 771 const std::string& manager_path, |
787 const base::DictionaryValue* properties) { | 772 const base::DictionaryValue* properties) { |
788 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 773 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
789 NetworkLibraryImplCros* networklib = | 774 NetworkLibraryImplCros* networklib = |
790 static_cast<NetworkLibraryImplCros*>(object); | 775 static_cast<NetworkLibraryImplCros*>(object); |
791 DCHECK(networklib); | 776 DCHECK(networklib); |
792 if (!properties) { | 777 if (!properties) { |
793 LOG(ERROR) << "Error retrieving manager properties: " << manager_path; | 778 LOG(ERROR) << "Error retrieving manager properties: " << manager_path; |
794 return; | 779 return; |
795 } | 780 } |
796 VLOG(1) << "Received NetworkManagerUpdate."; | 781 VLOG(1) << "Received NetworkManagerUpdate."; |
797 networklib->ParseNetworkManager(*properties); | 782 networklib->ParseNetworkManager(*properties); |
798 } | 783 } |
799 | 784 |
800 void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue& dict) { | 785 void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue& dict) { |
801 for (DictionaryValue::key_iterator iter = dict.begin_keys(); | 786 for (DictionaryValue::key_iterator iter = dict.begin_keys(); |
802 iter != dict.end_keys(); ++iter) { | 787 iter != dict.end_keys(); ++iter) { |
803 const std::string& key = *iter; | 788 const std::string& key = *iter; |
804 Value* value; | 789 Value* value; |
805 bool res = dict.GetWithoutPathExpansion(key, &value); | 790 bool res = dict.GetWithoutPathExpansion(key, &value); |
806 CHECK(res); | 791 CHECK(res); |
807 NetworkManagerStatusChanged(key.c_str(), value); | 792 NetworkManagerStatusChanged(key, value); |
808 } | 793 } |
809 // If there is no Profiles entry, request remembered networks here. | 794 // If there is no Profiles entry, request remembered networks here. |
810 if (!dict.HasKey(flimflam::kProfilesProperty)) | 795 if (!dict.HasKey(flimflam::kProfilesProperty)) |
811 RequestRememberedNetworksUpdate(); | 796 RequestRememberedNetworksUpdate(); |
812 } | 797 } |
813 | 798 |
814 // static | 799 // static |
815 void NetworkLibraryImplCros::DataPlanUpdateHandler( | 800 void NetworkLibraryImplCros::DataPlanUpdateHandler( |
816 void* object, | 801 void* object, |
817 const char* modem_service_path, | 802 const char* modem_service_path, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
913 AddNetwork(found->second); | 898 AddNetwork(found->second); |
914 old_network_map.erase(found); | 899 old_network_map.erase(found); |
915 } | 900 } |
916 // Always request network updates. | 901 // Always request network updates. |
917 // TODO(stevenjb): Investigate why we are missing updates then | 902 // TODO(stevenjb): Investigate why we are missing updates then |
918 // rely on watched network updates and only request updates here for | 903 // rely on watched network updates and only request updates here for |
919 // new networks. | 904 // new networks. |
920 // Use update_request map to store network priority. | 905 // Use update_request map to store network priority. |
921 network_update_requests_[service_path] = network_priority_order++; | 906 network_update_requests_[service_path] = network_priority_order++; |
922 wifi_scanning_ = true; | 907 wifi_scanning_ = true; |
923 CrosRequestNetworkServiceProperties(service_path.c_str(), | 908 CrosRequestNetworkServiceProperties(service_path, |
924 base::Bind(&NetworkServiceUpdate, | 909 base::Bind(&NetworkServiceUpdate, |
925 this)); | 910 this)); |
926 } | 911 } |
927 } | 912 } |
928 // Iterate through list of remaining networks that are no longer in the | 913 // Iterate through list of remaining networks that are no longer in the |
929 // list and delete them or update their status and re-add them to the list. | 914 // list and delete them or update their status and re-add them to the list. |
930 for (NetworkMap::iterator iter = old_network_map.begin(); | 915 for (NetworkMap::iterator iter = old_network_map.begin(); |
931 iter != old_network_map.end(); ++iter) { | 916 iter != old_network_map.end(); ++iter) { |
932 Network* network = iter->second; | 917 Network* network = iter->second; |
933 VLOG(2) << "Delete Network: " << network->name() | 918 VLOG(2) << "Delete Network: " << network->name() |
(...skipping 25 matching lines...) Expand all Loading... |
959 // in this list, but if there are they will be added appropriately. | 944 // in this list, but if there are they will be added appropriately. |
960 void NetworkLibraryImplCros::UpdateWatchedNetworkServiceList( | 945 void NetworkLibraryImplCros::UpdateWatchedNetworkServiceList( |
961 const ListValue* services) { | 946 const ListValue* services) { |
962 for (ListValue::const_iterator iter = services->begin(); | 947 for (ListValue::const_iterator iter = services->begin(); |
963 iter != services->end(); ++iter) { | 948 iter != services->end(); ++iter) { |
964 std::string service_path; | 949 std::string service_path; |
965 (*iter)->GetAsString(&service_path); | 950 (*iter)->GetAsString(&service_path); |
966 if (!service_path.empty()) { | 951 if (!service_path.empty()) { |
967 VLOG(1) << "Watched Service: " << service_path; | 952 VLOG(1) << "Watched Service: " << service_path; |
968 CrosRequestNetworkServiceProperties( | 953 CrosRequestNetworkServiceProperties( |
969 service_path.c_str(), | 954 service_path, |
970 base::Bind(&NetworkServiceUpdate, this)); | 955 base::Bind(&NetworkServiceUpdate, this)); |
971 } | 956 } |
972 } | 957 } |
973 } | 958 } |
974 | 959 |
975 // static | 960 // static |
976 void NetworkLibraryImplCros::NetworkServiceUpdate( | 961 void NetworkLibraryImplCros::NetworkServiceUpdate( |
977 void* object, | 962 void* object, |
978 const char* service_path, | 963 const std::string& service_path, |
979 const base::DictionaryValue* properties) { | 964 const base::DictionaryValue* properties) { |
980 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 965 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
981 NetworkLibraryImplCros* networklib = | 966 NetworkLibraryImplCros* networklib = |
982 static_cast<NetworkLibraryImplCros*>(object); | 967 static_cast<NetworkLibraryImplCros*>(object); |
983 DCHECK(networklib); | 968 DCHECK(networklib); |
984 if (service_path) { | 969 if (!properties) |
985 if (!properties) | 970 return; // Network no longer in visible list, ignore. |
986 return; // Network no longer in visible list, ignore. | 971 networklib->ParseNetwork(service_path, *properties); |
987 networklib->ParseNetwork(std::string(service_path), *properties); | |
988 } | |
989 } | 972 } |
990 | 973 |
991 // Called from NetworkServiceUpdate and WifiServiceUpdateAndConnect. | 974 // Called from NetworkServiceUpdate and WifiServiceUpdateAndConnect. |
992 Network* NetworkLibraryImplCros::ParseNetwork( | 975 Network* NetworkLibraryImplCros::ParseNetwork( |
993 const std::string& service_path, const DictionaryValue& info) { | 976 const std::string& service_path, const DictionaryValue& info) { |
994 Network* network = FindNetworkByPath(service_path); | 977 Network* network = FindNetworkByPath(service_path); |
995 if (!network) { | 978 if (!network) { |
996 NativeNetworkParser parser; | 979 NativeNetworkParser parser; |
997 network = parser.CreateNetworkFromInfo(service_path, info); | 980 network = parser.CreateNetworkFromInfo(service_path, info); |
998 AddNetwork(network); | 981 AddNetwork(network); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1077 // remembered networks. This list updates infrequently. | 1060 // remembered networks. This list updates infrequently. |
1078 DeleteRememberedNetworks(); | 1061 DeleteRememberedNetworks(); |
1079 // Request remembered networks from each profile. Later entries will | 1062 // Request remembered networks from each profile. Later entries will |
1080 // override earlier entries, so default/local entries will override | 1063 // override earlier entries, so default/local entries will override |
1081 // user entries (as desired). | 1064 // user entries (as desired). |
1082 for (NetworkProfileList::iterator iter = profile_list_.begin(); | 1065 for (NetworkProfileList::iterator iter = profile_list_.begin(); |
1083 iter != profile_list_.end(); ++iter) { | 1066 iter != profile_list_.end(); ++iter) { |
1084 NetworkProfile& profile = *iter; | 1067 NetworkProfile& profile = *iter; |
1085 VLOG(1) << " Requesting Profile: " << profile.path; | 1068 VLOG(1) << " Requesting Profile: " << profile.path; |
1086 CrosRequestNetworkProfileProperties( | 1069 CrosRequestNetworkProfileProperties( |
1087 profile.path.c_str(), base::Bind(&ProfileUpdate, this)); | 1070 profile.path, base::Bind(&ProfileUpdate, this)); |
1088 } | 1071 } |
1089 } | 1072 } |
1090 | 1073 |
1091 // static | 1074 // static |
1092 void NetworkLibraryImplCros::ProfileUpdate( | 1075 void NetworkLibraryImplCros::ProfileUpdate( |
1093 void* object, | 1076 void* object, |
1094 const char* profile_path, | 1077 const std::string& profile_path, |
1095 const base::DictionaryValue* properties) { | 1078 const base::DictionaryValue* properties) { |
1096 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 1079 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
1097 NetworkLibraryImplCros* networklib = | 1080 NetworkLibraryImplCros* networklib = |
1098 static_cast<NetworkLibraryImplCros*>(object); | 1081 static_cast<NetworkLibraryImplCros*>(object); |
1099 DCHECK(networklib); | 1082 DCHECK(networklib); |
1100 if (!properties) { | 1083 if (!properties) { |
1101 LOG(ERROR) << "Error retrieving profile: " << profile_path; | 1084 LOG(ERROR) << "Error retrieving profile: " << profile_path; |
1102 return; | 1085 return; |
1103 } | 1086 } |
1104 VLOG(1) << "Received ProfileUpdate for: " << profile_path; | 1087 VLOG(1) << "Received ProfileUpdate for: " << profile_path; |
1105 ListValue* entries(NULL); | 1088 ListValue* entries(NULL); |
1106 properties->GetList(flimflam::kEntriesProperty, &entries); | 1089 properties->GetList(flimflam::kEntriesProperty, &entries); |
1107 DCHECK(entries); | 1090 DCHECK(entries); |
1108 networklib->UpdateRememberedServiceList(profile_path, entries); | 1091 networklib->UpdateRememberedServiceList(profile_path, entries); |
1109 } | 1092 } |
1110 | 1093 |
1111 void NetworkLibraryImplCros::UpdateRememberedServiceList( | 1094 void NetworkLibraryImplCros::UpdateRememberedServiceList( |
1112 const char* profile_path, const ListValue* profile_entries) { | 1095 const std::string& profile_path, const ListValue* profile_entries) { |
1113 DCHECK(profile_path); | |
1114 VLOG(1) << "UpdateRememberedServiceList for path: " << profile_path; | 1096 VLOG(1) << "UpdateRememberedServiceList for path: " << profile_path; |
1115 NetworkProfileList::iterator iter1; | 1097 NetworkProfileList::iterator iter1; |
1116 for (iter1 = profile_list_.begin(); iter1 != profile_list_.end(); ++iter1) { | 1098 for (iter1 = profile_list_.begin(); iter1 != profile_list_.end(); ++iter1) { |
1117 if (iter1->path == profile_path) | 1099 if (iter1->path == profile_path) |
1118 break; | 1100 break; |
1119 } | 1101 } |
1120 if (iter1 == profile_list_.end()) { | 1102 if (iter1 == profile_list_.end()) { |
1121 // This can happen if flimflam gets restarted while Chrome is running. | 1103 // This can happen if flimflam gets restarted while Chrome is running. |
1122 LOG(WARNING) << "Profile not in list: " << profile_path; | 1104 LOG(WARNING) << "Profile not in list: " << profile_path; |
1123 return; | 1105 return; |
1124 } | 1106 } |
1125 NetworkProfile& profile = *iter1; | 1107 NetworkProfile& profile = *iter1; |
1126 // |profile_entries| is a list of remembered networks from |profile_path|. | 1108 // |profile_entries| is a list of remembered networks from |profile_path|. |
1127 profile.services.clear(); | 1109 profile.services.clear(); |
1128 for (ListValue::const_iterator iter2 = profile_entries->begin(); | 1110 for (ListValue::const_iterator iter2 = profile_entries->begin(); |
1129 iter2 != profile_entries->end(); ++iter2) { | 1111 iter2 != profile_entries->end(); ++iter2) { |
1130 std::string service_path; | 1112 std::string service_path; |
1131 (*iter2)->GetAsString(&service_path); | 1113 (*iter2)->GetAsString(&service_path); |
1132 if (service_path.empty()) { | 1114 if (service_path.empty()) { |
1133 LOG(WARNING) << "Empty service path in profile."; | 1115 LOG(WARNING) << "Empty service path in profile."; |
1134 continue; | 1116 continue; |
1135 } | 1117 } |
1136 VLOG(1) << " Remembered service: " << service_path; | 1118 VLOG(1) << " Remembered service: " << service_path; |
1137 // Add service to profile list. | 1119 // Add service to profile list. |
1138 profile.services.insert(service_path); | 1120 profile.services.insert(service_path); |
1139 // Request update for remembered network. | 1121 // Request update for remembered network. |
1140 CrosRequestNetworkProfileEntryProperties( | 1122 CrosRequestNetworkProfileEntryProperties( |
1141 profile_path, | 1123 profile_path, |
1142 service_path.c_str(), | 1124 service_path, |
1143 base::Bind(&RememberedNetworkServiceUpdate, this)); | 1125 base::Bind(&RememberedNetworkServiceUpdate, this)); |
1144 } | 1126 } |
1145 } | 1127 } |
1146 | 1128 |
1147 // static | 1129 // static |
1148 void NetworkLibraryImplCros::RememberedNetworkServiceUpdate( | 1130 void NetworkLibraryImplCros::RememberedNetworkServiceUpdate( |
1149 void* object, | 1131 void* object, |
1150 const char* service_path, | 1132 const std::string& service_path, |
1151 const base::DictionaryValue* properties) { | 1133 const base::DictionaryValue* properties) { |
1152 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 1134 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
1153 NetworkLibraryImplCros* networklib = | 1135 NetworkLibraryImplCros* networklib = |
1154 static_cast<NetworkLibraryImplCros*>(object); | 1136 static_cast<NetworkLibraryImplCros*>(object); |
1155 DCHECK(networklib); | 1137 DCHECK(networklib); |
1156 if (service_path) { | 1138 if (!properties) { |
1157 if (!properties) { | 1139 // Remembered network no longer exists. |
1158 // Remembered network no longer exists. | 1140 networklib->DeleteRememberedNetwork(service_path); |
1159 networklib->DeleteRememberedNetwork(std::string(service_path)); | 1141 } else { |
1160 } else { | 1142 networklib->ParseRememberedNetwork(service_path, *properties); |
1161 networklib->ParseRememberedNetwork( | |
1162 std::string(service_path), *properties); | |
1163 } | |
1164 } | 1143 } |
1165 } | 1144 } |
1166 | 1145 |
1167 // Returns NULL if |service_path| refers to a network that is not a | 1146 // Returns NULL if |service_path| refers to a network that is not a |
1168 // remembered type. Called from RememberedNetworkServiceUpdate. | 1147 // remembered type. Called from RememberedNetworkServiceUpdate. |
1169 Network* NetworkLibraryImplCros::ParseRememberedNetwork( | 1148 Network* NetworkLibraryImplCros::ParseRememberedNetwork( |
1170 const std::string& service_path, const DictionaryValue& info) { | 1149 const std::string& service_path, const DictionaryValue& info) { |
1171 Network* remembered; | 1150 Network* remembered; |
1172 NetworkMap::iterator found = remembered_network_map_.find(service_path); | 1151 NetworkMap::iterator found = remembered_network_map_.find(service_path); |
1173 if (found != remembered_network_map_.end()) { | 1152 if (found != remembered_network_map_.end()) { |
(...skipping 30 matching lines...) Expand all Loading... |
1204 if (remembered->type() == TYPE_VPN) { | 1183 if (remembered->type() == TYPE_VPN) { |
1205 // VPNs are only stored in profiles. If we don't have a network for it, | 1184 // VPNs are only stored in profiles. If we don't have a network for it, |
1206 // request one. | 1185 // request one. |
1207 if (!FindNetworkByUniqueId(remembered->unique_id())) { | 1186 if (!FindNetworkByUniqueId(remembered->unique_id())) { |
1208 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(remembered); | 1187 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(remembered); |
1209 std::string provider_type = ProviderTypeToString(vpn->provider_type()); | 1188 std::string provider_type = ProviderTypeToString(vpn->provider_type()); |
1210 VLOG(1) << "Requesting VPN: " << vpn->name() | 1189 VLOG(1) << "Requesting VPN: " << vpn->name() |
1211 << " Server: " << vpn->server_hostname() | 1190 << " Server: " << vpn->server_hostname() |
1212 << " Type: " << provider_type; | 1191 << " Type: " << provider_type; |
1213 CrosRequestVirtualNetworkProperties( | 1192 CrosRequestVirtualNetworkProperties( |
1214 vpn->name().c_str(), | 1193 vpn->name(), |
1215 vpn->server_hostname().c_str(), | 1194 vpn->server_hostname(), |
1216 provider_type.c_str(), | 1195 provider_type, |
1217 base::Bind(&NetworkServiceUpdate, this)); | 1196 base::Bind(&NetworkServiceUpdate, this)); |
1218 } | 1197 } |
1219 } | 1198 } |
1220 | 1199 |
1221 return remembered; | 1200 return remembered; |
1222 } | 1201 } |
1223 | 1202 |
1224 //////////////////////////////////////////////////////////////////////////// | 1203 //////////////////////////////////////////////////////////////////////////// |
1225 // NetworkDevice list management functions. | 1204 // NetworkDevice list management functions. |
1226 | 1205 |
1227 // Update device list, and request associated device updates. | 1206 // Update device list, and request associated device updates. |
1228 // |devices| represents a complete list of devices. | 1207 // |devices| represents a complete list of devices. |
1229 void NetworkLibraryImplCros::UpdateNetworkDeviceList(const ListValue* devices) { | 1208 void NetworkLibraryImplCros::UpdateNetworkDeviceList(const ListValue* devices) { |
1230 NetworkDeviceMap old_device_map = device_map_; | 1209 NetworkDeviceMap old_device_map = device_map_; |
1231 device_map_.clear(); | 1210 device_map_.clear(); |
1232 VLOG(2) << "Updating Device List."; | 1211 VLOG(2) << "Updating Device List."; |
1233 for (ListValue::const_iterator iter = devices->begin(); | 1212 for (ListValue::const_iterator iter = devices->begin(); |
1234 iter != devices->end(); ++iter) { | 1213 iter != devices->end(); ++iter) { |
1235 std::string device_path; | 1214 std::string device_path; |
1236 (*iter)->GetAsString(&device_path); | 1215 (*iter)->GetAsString(&device_path); |
1237 if (!device_path.empty()) { | 1216 if (!device_path.empty()) { |
1238 NetworkDeviceMap::iterator found = old_device_map.find(device_path); | 1217 NetworkDeviceMap::iterator found = old_device_map.find(device_path); |
1239 if (found != old_device_map.end()) { | 1218 if (found != old_device_map.end()) { |
1240 VLOG(2) << " Adding existing device: " << device_path; | 1219 VLOG(2) << " Adding existing device: " << device_path; |
1241 CHECK(found->second) << "Attempted to add NULL device pointer"; | 1220 CHECK(found->second) << "Attempted to add NULL device pointer"; |
1242 device_map_[device_path] = found->second; | 1221 device_map_[device_path] = found->second; |
1243 old_device_map.erase(found); | 1222 old_device_map.erase(found); |
1244 } | 1223 } |
1245 CrosRequestNetworkDeviceProperties( | 1224 CrosRequestNetworkDeviceProperties( |
1246 device_path.c_str(), | 1225 device_path, |
1247 base::Bind(&NetworkDeviceUpdate, this)); | 1226 base::Bind(&NetworkDeviceUpdate, this)); |
1248 } | 1227 } |
1249 } | 1228 } |
1250 // Delete any old devices that no longer exist. | 1229 // Delete any old devices that no longer exist. |
1251 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); | 1230 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); |
1252 iter != old_device_map.end(); ++iter) { | 1231 iter != old_device_map.end(); ++iter) { |
1253 DeleteDeviceFromDeviceObserversMap(iter->first); | 1232 DeleteDeviceFromDeviceObserversMap(iter->first); |
1254 // Delete device. | 1233 // Delete device. |
1255 delete iter->second; | 1234 delete iter->second; |
1256 } | 1235 } |
1257 } | 1236 } |
1258 | 1237 |
1259 // static | 1238 // static |
1260 void NetworkLibraryImplCros::NetworkDeviceUpdate( | 1239 void NetworkLibraryImplCros::NetworkDeviceUpdate( |
1261 void* object, | 1240 void* object, |
1262 const char* device_path, | 1241 const std::string& device_path, |
1263 const base::DictionaryValue* properties) { | 1242 const base::DictionaryValue* properties) { |
1264 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 1243 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
1265 NetworkLibraryImplCros* networklib = | 1244 NetworkLibraryImplCros* networklib = |
1266 static_cast<NetworkLibraryImplCros*>(object); | 1245 static_cast<NetworkLibraryImplCros*>(object); |
1267 DCHECK(networklib); | 1246 DCHECK(networklib); |
1268 if (device_path) { | 1247 if (!properties) { |
1269 if (!properties) { | 1248 // device no longer exists. |
1270 // device no longer exists. | 1249 networklib->DeleteDevice(device_path); |
1271 networklib->DeleteDevice(std::string(device_path)); | 1250 } else { |
1272 } else { | 1251 networklib->ParseNetworkDevice(device_path, *properties); |
1273 networklib->ParseNetworkDevice(std::string(device_path), *properties); | |
1274 } | |
1275 } | 1252 } |
1276 } | 1253 } |
1277 | 1254 |
1278 void NetworkLibraryImplCros::ParseNetworkDevice(const std::string& device_path, | 1255 void NetworkLibraryImplCros::ParseNetworkDevice(const std::string& device_path, |
1279 const DictionaryValue& info) { | 1256 const DictionaryValue& info) { |
1280 NetworkDeviceMap::iterator found = device_map_.find(device_path); | 1257 NetworkDeviceMap::iterator found = device_map_.find(device_path); |
1281 NetworkDevice* device; | 1258 NetworkDevice* device; |
1282 if (found != device_map_.end()) { | 1259 if (found != device_map_.end()) { |
1283 device = found->second; | 1260 device = found->second; |
1284 device->device_parser()->UpdateDeviceFromInfo(info, device); | 1261 device->device_parser()->UpdateDeviceFromInfo(info, device); |
(...skipping 18 matching lines...) Expand all Loading... |
1303 // Switch back to signed settings value. | 1280 // Switch back to signed settings value. |
1304 SetCellularDataRoamingAllowed(settings_value); | 1281 SetCellularDataRoamingAllowed(settings_value); |
1305 } | 1282 } |
1306 } | 1283 } |
1307 } | 1284 } |
1308 NotifyNetworkManagerChanged(false); // Not forced. | 1285 NotifyNetworkManagerChanged(false); // Not forced. |
1309 AddNetworkDeviceObserver(device_path, network_device_observer_.get()); | 1286 AddNetworkDeviceObserver(device_path, network_device_observer_.get()); |
1310 } | 1287 } |
1311 | 1288 |
1312 } // namespace chromeos | 1289 } // namespace chromeos |
OLD | NEW |