| 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 27 matching lines...) Expand all Loading... |
| 222 const char* error_message) { | 220 const char* error_message) { |
| 223 if (error != NETWORK_METHOD_ERROR_NONE) { | 221 if (error != NETWORK_METHOD_ERROR_NONE) { |
| 224 LOG(WARNING) << "Error from ConfigureService callback for: " | 222 LOG(WARNING) << "Error from ConfigureService callback for: " |
| 225 << service_path | 223 << service_path |
| 226 << " Error: " << error << " Message: " << error_message; | 224 << " Error: " << error << " Message: " << error_message; |
| 227 } | 225 } |
| 228 } | 226 } |
| 229 | 227 |
| 230 void NetworkLibraryImplCros::CallConfigureService(const std::string& identifier, | 228 void NetworkLibraryImplCros::CallConfigureService(const std::string& identifier, |
| 231 const DictionaryValue* info) { | 229 const DictionaryValue* info) { |
| 232 CrosConfigureService(identifier.c_str(), *info, | 230 CrosConfigureService(identifier, *info, ConfigureServiceCallback, this); |
| 233 ConfigureServiceCallback, this); | |
| 234 } | 231 } |
| 235 | 232 |
| 236 // static callback | 233 // static callback |
| 237 void NetworkLibraryImplCros::NetworkConnectCallback( | 234 void NetworkLibraryImplCros::NetworkConnectCallback( |
| 238 void* object, | 235 void* object, |
| 239 const char* service_path, | 236 const char* service_path, |
| 240 NetworkMethodErrorType error, | 237 NetworkMethodErrorType error, |
| 241 const char* error_message) { | 238 const char* error_message) { |
| 242 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 239 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
| 243 NetworkConnectStatus status; | 240 NetworkConnectStatus status; |
| 244 if (error == NETWORK_METHOD_ERROR_NONE) { | 241 if (error == NETWORK_METHOD_ERROR_NONE) { |
| 245 status = CONNECT_SUCCESS; | 242 status = CONNECT_SUCCESS; |
| 246 } else { | 243 } else { |
| 247 LOG(WARNING) << "Error from ServiceConnect callback for: " | 244 LOG(WARNING) << "Error from ServiceConnect callback for: " |
| 248 << service_path | 245 << service_path |
| 249 << " Error: " << error << " Message: " << error_message; | 246 << " Error: " << error << " Message: " << error_message; |
| 250 if (error_message && | 247 if (error_message && |
| 251 strcmp(error_message, flimflam::kErrorPassphraseRequiredMsg) == 0) { | 248 strcmp(error_message, flimflam::kErrorPassphraseRequiredMsg) == 0) { |
| 252 status = CONNECT_BAD_PASSPHRASE; | 249 status = CONNECT_BAD_PASSPHRASE; |
| 253 } else { | 250 } else { |
| 254 status = CONNECT_FAILED; | 251 status = CONNECT_FAILED; |
| 255 } | 252 } |
| 256 } | 253 } |
| 257 NetworkLibraryImplCros* networklib = | 254 NetworkLibraryImplCros* networklib = |
| 258 static_cast<NetworkLibraryImplCros*>(object); | 255 static_cast<NetworkLibraryImplCros*>(object); |
| 259 Network* network = networklib->FindNetworkByPath(std::string(service_path)); | 256 Network* network = networklib->FindNetworkByPath(service_path); |
| 260 if (!network) { | 257 if (!network) { |
| 261 LOG(ERROR) << "No network for path: " << service_path; | 258 LOG(ERROR) << "No network for path: " << service_path; |
| 262 return; | 259 return; |
| 263 } | 260 } |
| 264 networklib->NetworkConnectCompleted(network, status); | 261 networklib->NetworkConnectCompleted(network, status); |
| 265 } | 262 } |
| 266 | 263 |
| 267 void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) { | 264 void NetworkLibraryImplCros::CallConnectToNetwork(Network* network) { |
| 268 DCHECK(network); | 265 DCHECK(network); |
| 269 CrosRequestNetworkServiceConnect(network->service_path().c_str(), | 266 CrosRequestNetworkServiceConnect(network->service_path(), |
| 270 NetworkConnectCallback, this); | 267 NetworkConnectCallback, this); |
| 271 } | 268 } |
| 272 | 269 |
| 273 // static callback | 270 // static callback |
| 274 void NetworkLibraryImplCros::WifiServiceUpdateAndConnect( | 271 void NetworkLibraryImplCros::WifiServiceUpdateAndConnect( |
| 275 void* object, | 272 void* object, |
| 276 const char* service_path, | 273 const std::string& service_path, |
| 277 const base::DictionaryValue* properties) { | 274 const base::DictionaryValue* properties) { |
| 278 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 275 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
| 279 NetworkLibraryImplCros* networklib = | 276 NetworkLibraryImplCros* networklib = |
| 280 static_cast<NetworkLibraryImplCros*>(object); | 277 static_cast<NetworkLibraryImplCros*>(object); |
| 281 DCHECK(networklib); | 278 DCHECK(networklib); |
| 282 if (service_path && properties) { | 279 if (properties) { |
| 283 Network* network = | 280 Network* network = networklib->ParseNetwork(service_path, *properties); |
| 284 networklib->ParseNetwork(std::string(service_path), *properties); | |
| 285 DCHECK_EQ(network->type(), TYPE_WIFI); | 281 DCHECK_EQ(network->type(), TYPE_WIFI); |
| 286 networklib->ConnectToWifiNetworkUsingConnectData( | 282 networklib->ConnectToWifiNetworkUsingConnectData( |
| 287 static_cast<WifiNetwork*>(network)); | 283 static_cast<WifiNetwork*>(network)); |
| 288 } | 284 } |
| 289 } | 285 } |
| 290 | 286 |
| 291 void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect( | 287 void NetworkLibraryImplCros::CallRequestWifiNetworkAndConnect( |
| 292 const std::string& ssid, ConnectionSecurity security) { | 288 const std::string& ssid, ConnectionSecurity security) { |
| 293 // Asynchronously request service properties and call | 289 // Asynchronously request service properties and call |
| 294 // WifiServiceUpdateAndConnect. | 290 // WifiServiceUpdateAndConnect. |
| 295 CrosRequestHiddenWifiNetworkProperties( | 291 CrosRequestHiddenWifiNetworkProperties( |
| 296 ssid.c_str(), | 292 ssid, |
| 297 SecurityToString(security), | 293 SecurityToString(security), |
| 298 base::Bind(&WifiServiceUpdateAndConnect, this)); | 294 base::Bind(&WifiServiceUpdateAndConnect, this)); |
| 299 } | 295 } |
| 300 | 296 |
| 301 // static callback | 297 // static callback |
| 302 void NetworkLibraryImplCros::VPNServiceUpdateAndConnect( | 298 void NetworkLibraryImplCros::VPNServiceUpdateAndConnect( |
| 303 void* object, | 299 void* object, |
| 304 const char* service_path, | 300 const std::string& service_path, |
| 305 const base::DictionaryValue* properties) { | 301 const base::DictionaryValue* properties) { |
| 306 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 302 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
| 307 NetworkLibraryImplCros* networklib = | 303 NetworkLibraryImplCros* networklib = |
| 308 static_cast<NetworkLibraryImplCros*>(object); | 304 static_cast<NetworkLibraryImplCros*>(object); |
| 309 DCHECK(networklib); | 305 DCHECK(networklib); |
| 310 if (service_path && properties) { | 306 if (properties) { |
| 311 VLOG(1) << "Connecting to new VPN Service: " << service_path; | 307 VLOG(1) << "Connecting to new VPN Service: " << service_path; |
| 312 Network* network = | 308 Network* network = networklib->ParseNetwork(service_path, *properties); |
| 313 networklib->ParseNetwork(std::string(service_path), *properties); | |
| 314 DCHECK_EQ(network->type(), TYPE_VPN); | 309 DCHECK_EQ(network->type(), TYPE_VPN); |
| 315 networklib->ConnectToVirtualNetworkUsingConnectData( | 310 networklib->ConnectToVirtualNetworkUsingConnectData( |
| 316 static_cast<VirtualNetwork*>(network)); | 311 static_cast<VirtualNetwork*>(network)); |
| 317 } else { | 312 } else { |
| 318 LOG(WARNING) << "Unable to create VPN Service: " << service_path; | 313 LOG(WARNING) << "Unable to create VPN Service: " << service_path; |
| 319 } | 314 } |
| 320 } | 315 } |
| 321 | 316 |
| 322 void NetworkLibraryImplCros::CallRequestVirtualNetworkAndConnect( | 317 void NetworkLibraryImplCros::CallRequestVirtualNetworkAndConnect( |
| 323 const std::string& service_name, | 318 const std::string& service_name, |
| 324 const std::string& server_hostname, | 319 const std::string& server_hostname, |
| 325 ProviderType provider_type) { | 320 ProviderType provider_type) { |
| 326 CrosRequestVirtualNetworkProperties( | 321 CrosRequestVirtualNetworkProperties( |
| 327 service_name.c_str(), | 322 service_name, |
| 328 server_hostname.c_str(), | 323 server_hostname, |
| 329 ProviderTypeToString(provider_type), | 324 ProviderTypeToString(provider_type), |
| 330 base::Bind(&VPNServiceUpdateAndConnect, this)); | 325 base::Bind(&VPNServiceUpdateAndConnect, this)); |
| 331 } | 326 } |
| 332 | 327 |
| 333 void NetworkLibraryImplCros::CallDeleteRememberedNetwork( | 328 void NetworkLibraryImplCros::CallDeleteRememberedNetwork( |
| 334 const std::string& profile_path, | 329 const std::string& profile_path, |
| 335 const std::string& service_path) { | 330 const std::string& service_path) { |
| 336 CrosDeleteServiceFromProfile( | 331 CrosDeleteServiceFromProfile(profile_path, service_path); |
| 337 profile_path.c_str(), service_path.c_str()); | |
| 338 } | 332 } |
| 339 | 333 |
| 340 ////////////////////////////////////////////////////////////////////////////// | 334 ////////////////////////////////////////////////////////////////////////////// |
| 341 // NetworkLibrary implementation. | 335 // NetworkLibrary implementation. |
| 342 | 336 |
| 343 void NetworkLibraryImplCros::SetCheckPortalList( | 337 void NetworkLibraryImplCros::SetCheckPortalList( |
| 344 const std::string& check_portal_list) { | 338 const std::string& check_portal_list) { |
| 345 base::StringValue value(check_portal_list); | 339 base::StringValue value(check_portal_list); |
| 346 CrosSetNetworkManagerProperty(flimflam::kCheckPortalListProperty, value); | 340 CrosSetNetworkManagerProperty(flimflam::kCheckPortalListProperty, value); |
| 347 } | 341 } |
| 348 | 342 |
| 349 void NetworkLibraryImplCros::SetDefaultCheckPortalList() { | 343 void NetworkLibraryImplCros::SetDefaultCheckPortalList() { |
| 350 SetCheckPortalList(kDefaultCheckPortalList); | 344 SetCheckPortalList(kDefaultCheckPortalList); |
| 351 } | 345 } |
| 352 | 346 |
| 353 void NetworkLibraryImplCros::ChangePin(const std::string& old_pin, | 347 void NetworkLibraryImplCros::ChangePin(const std::string& old_pin, |
| 354 const std::string& new_pin) { | 348 const std::string& new_pin) { |
| 355 const NetworkDevice* cellular = FindCellularDevice(); | 349 const NetworkDevice* cellular = FindCellularDevice(); |
| 356 if (!cellular) { | 350 if (!cellular) { |
| 357 NOTREACHED() << "Calling ChangePin method w/o cellular device."; | 351 NOTREACHED() << "Calling ChangePin method w/o cellular device."; |
| 358 return; | 352 return; |
| 359 } | 353 } |
| 360 sim_operation_ = SIM_OPERATION_CHANGE_PIN; | 354 sim_operation_ = SIM_OPERATION_CHANGE_PIN; |
| 361 CrosRequestChangePin(cellular->device_path().c_str(), | 355 CrosRequestChangePin(cellular->device_path(), old_pin, new_pin, |
| 362 old_pin.c_str(), new_pin.c_str(), | |
| 363 PinOperationCallback, this); | 356 PinOperationCallback, this); |
| 364 } | 357 } |
| 365 | 358 |
| 366 void NetworkLibraryImplCros::ChangeRequirePin(bool require_pin, | 359 void NetworkLibraryImplCros::ChangeRequirePin(bool require_pin, |
| 367 const std::string& pin) { | 360 const std::string& pin) { |
| 368 VLOG(1) << "ChangeRequirePin require_pin: " << require_pin | 361 VLOG(1) << "ChangeRequirePin require_pin: " << require_pin |
| 369 << " pin: " << pin; | 362 << " pin: " << pin; |
| 370 const NetworkDevice* cellular = FindCellularDevice(); | 363 const NetworkDevice* cellular = FindCellularDevice(); |
| 371 if (!cellular) { | 364 if (!cellular) { |
| 372 NOTREACHED() << "Calling ChangeRequirePin method w/o cellular device."; | 365 NOTREACHED() << "Calling ChangeRequirePin method w/o cellular device."; |
| 373 return; | 366 return; |
| 374 } | 367 } |
| 375 sim_operation_ = SIM_OPERATION_CHANGE_REQUIRE_PIN; | 368 sim_operation_ = SIM_OPERATION_CHANGE_REQUIRE_PIN; |
| 376 CrosRequestRequirePin(cellular->device_path().c_str(), | 369 CrosRequestRequirePin(cellular->device_path(), pin, require_pin, |
| 377 pin.c_str(), require_pin, | |
| 378 PinOperationCallback, this); | 370 PinOperationCallback, this); |
| 379 } | 371 } |
| 380 | 372 |
| 381 void NetworkLibraryImplCros::EnterPin(const std::string& pin) { | 373 void NetworkLibraryImplCros::EnterPin(const std::string& pin) { |
| 382 const NetworkDevice* cellular = FindCellularDevice(); | 374 const NetworkDevice* cellular = FindCellularDevice(); |
| 383 if (!cellular) { | 375 if (!cellular) { |
| 384 NOTREACHED() << "Calling EnterPin method w/o cellular device."; | 376 NOTREACHED() << "Calling EnterPin method w/o cellular device."; |
| 385 return; | 377 return; |
| 386 } | 378 } |
| 387 sim_operation_ = SIM_OPERATION_ENTER_PIN; | 379 sim_operation_ = SIM_OPERATION_ENTER_PIN; |
| 388 CrosRequestEnterPin(cellular->device_path().c_str(), | 380 CrosRequestEnterPin(cellular->device_path(), pin, PinOperationCallback, this); |
| 389 pin.c_str(), | |
| 390 PinOperationCallback, this); | |
| 391 } | 381 } |
| 392 | 382 |
| 393 void NetworkLibraryImplCros::UnblockPin(const std::string& puk, | 383 void NetworkLibraryImplCros::UnblockPin(const std::string& puk, |
| 394 const std::string& new_pin) { | 384 const std::string& new_pin) { |
| 395 const NetworkDevice* cellular = FindCellularDevice(); | 385 const NetworkDevice* cellular = FindCellularDevice(); |
| 396 if (!cellular) { | 386 if (!cellular) { |
| 397 NOTREACHED() << "Calling UnblockPin method w/o cellular device."; | 387 NOTREACHED() << "Calling UnblockPin method w/o cellular device."; |
| 398 return; | 388 return; |
| 399 } | 389 } |
| 400 sim_operation_ = SIM_OPERATION_UNBLOCK_PIN; | 390 sim_operation_ = SIM_OPERATION_UNBLOCK_PIN; |
| 401 CrosRequestUnblockPin(cellular->device_path().c_str(), | 391 CrosRequestUnblockPin(cellular->device_path(), puk, new_pin, |
| 402 puk.c_str(), new_pin.c_str(), | |
| 403 PinOperationCallback, this); | 392 PinOperationCallback, this); |
| 404 } | 393 } |
| 405 | 394 |
| 406 // static callback | 395 // static callback |
| 407 void NetworkLibraryImplCros::PinOperationCallback( | 396 void NetworkLibraryImplCros::PinOperationCallback( |
| 408 void* object, | 397 void* object, |
| 409 const char* path, | 398 const char* path, |
| 410 NetworkMethodErrorType error, | 399 NetworkMethodErrorType error, |
| 411 const char* error_message) { | 400 const char* error_message) { |
| 412 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 401 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 434 } | 423 } |
| 435 networklib->NotifyPinOperationCompleted(pin_error); | 424 networklib->NotifyPinOperationCompleted(pin_error); |
| 436 } | 425 } |
| 437 | 426 |
| 438 void NetworkLibraryImplCros::RequestCellularScan() { | 427 void NetworkLibraryImplCros::RequestCellularScan() { |
| 439 const NetworkDevice* cellular = FindCellularDevice(); | 428 const NetworkDevice* cellular = FindCellularDevice(); |
| 440 if (!cellular) { | 429 if (!cellular) { |
| 441 NOTREACHED() << "Calling RequestCellularScan method w/o cellular device."; | 430 NOTREACHED() << "Calling RequestCellularScan method w/o cellular device."; |
| 442 return; | 431 return; |
| 443 } | 432 } |
| 444 CrosProposeScan(cellular->device_path().c_str()); | 433 CrosProposeScan(cellular->device_path()); |
| 445 } | 434 } |
| 446 | 435 |
| 447 void NetworkLibraryImplCros::RequestCellularRegister( | 436 void NetworkLibraryImplCros::RequestCellularRegister( |
| 448 const std::string& network_id) { | 437 const std::string& network_id) { |
| 449 const NetworkDevice* cellular = FindCellularDevice(); | 438 const NetworkDevice* cellular = FindCellularDevice(); |
| 450 if (!cellular) { | 439 if (!cellular) { |
| 451 NOTREACHED() << "Calling CellularRegister method w/o cellular device."; | 440 NOTREACHED() << "Calling CellularRegister method w/o cellular device."; |
| 452 return; | 441 return; |
| 453 } | 442 } |
| 454 CrosRequestCellularRegister(cellular->device_path().c_str(), | 443 CrosRequestCellularRegister( |
| 455 network_id.c_str(), | 444 cellular->device_path(), network_id, CellularRegisterCallback, this); |
| 456 CellularRegisterCallback, | |
| 457 this); | |
| 458 } | 445 } |
| 459 | 446 |
| 460 // static callback | 447 // static callback |
| 461 void NetworkLibraryImplCros::CellularRegisterCallback( | 448 void NetworkLibraryImplCros::CellularRegisterCallback( |
| 462 void* object, | 449 void* object, |
| 463 const char* path, | 450 const char* path, |
| 464 NetworkMethodErrorType error, | 451 NetworkMethodErrorType error, |
| 465 const char* error_message) { | 452 const char* error_message) { |
| 466 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 453 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
| 467 NetworkLibraryImplCros* networklib = | 454 NetworkLibraryImplCros* networklib = |
| 468 static_cast<NetworkLibraryImplCros*>(object); | 455 static_cast<NetworkLibraryImplCros*>(object); |
| 469 DCHECK(networklib); | 456 DCHECK(networklib); |
| 470 // TODO(dpolukhin): Notify observers about network registration status | 457 // TODO(dpolukhin): Notify observers about network registration status |
| 471 // but not UI doesn't assume such notification so just ignore result. | 458 // but not UI doesn't assume such notification so just ignore result. |
| 472 } | 459 } |
| 473 | 460 |
| 474 void NetworkLibraryImplCros::SetCellularDataRoamingAllowed(bool new_value) { | 461 void NetworkLibraryImplCros::SetCellularDataRoamingAllowed(bool new_value) { |
| 475 const NetworkDevice* cellular = FindCellularDevice(); | 462 const NetworkDevice* cellular = FindCellularDevice(); |
| 476 if (!cellular) { | 463 if (!cellular) { |
| 477 NOTREACHED() << "Calling SetCellularDataRoamingAllowed method " | 464 NOTREACHED() << "Calling SetCellularDataRoamingAllowed method " |
| 478 "w/o cellular device."; | 465 "w/o cellular device."; |
| 479 return; | 466 return; |
| 480 } | 467 } |
| 481 base::FundamentalValue value(new_value); | 468 base::FundamentalValue value(new_value); |
| 482 CrosSetNetworkDeviceProperty(cellular->device_path().c_str(), | 469 CrosSetNetworkDeviceProperty(cellular->device_path(), |
| 483 flimflam::kCellularAllowRoamingProperty, | 470 flimflam::kCellularAllowRoamingProperty, |
| 484 value); | 471 value); |
| 485 } | 472 } |
| 486 | 473 |
| 487 bool NetworkLibraryImplCros::IsCellularAlwaysInRoaming() { | 474 bool NetworkLibraryImplCros::IsCellularAlwaysInRoaming() { |
| 488 const NetworkDevice* cellular = FindCellularDevice(); | 475 const NetworkDevice* cellular = FindCellularDevice(); |
| 489 if (!cellular) { | 476 if (!cellular) { |
| 490 NOTREACHED() << "Calling IsCellularAlwaysInRoaming method " | 477 NOTREACHED() << "Calling IsCellularAlwaysInRoaming method " |
| 491 "w/o cellular device."; | 478 "w/o cellular device."; |
| 492 return false; | 479 return false; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 result->push_back(ap); | 520 result->push_back(ap); |
| 534 } | 521 } |
| 535 CrosFreeDeviceNetworkList(network_list); | 522 CrosFreeDeviceNetworkList(network_list); |
| 536 return true; | 523 return true; |
| 537 } | 524 } |
| 538 | 525 |
| 539 void NetworkLibraryImplCros::DisconnectFromNetwork(const Network* network) { | 526 void NetworkLibraryImplCros::DisconnectFromNetwork(const Network* network) { |
| 540 DCHECK(network); | 527 DCHECK(network); |
| 541 // Asynchronous disconnect request. Network state will be updated through | 528 // Asynchronous disconnect request. Network state will be updated through |
| 542 // the network manager once disconnect completes. | 529 // the network manager once disconnect completes. |
| 543 CrosRequestNetworkServiceDisconnect(network->service_path().c_str()); | 530 CrosRequestNetworkServiceDisconnect(network->service_path()); |
| 544 } | 531 } |
| 545 | 532 |
| 546 void NetworkLibraryImplCros::CallEnableNetworkDeviceType( | 533 void NetworkLibraryImplCros::CallEnableNetworkDeviceType( |
| 547 ConnectionType device, bool enable) { | 534 ConnectionType device, bool enable) { |
| 548 busy_devices_ |= 1 << device; | 535 busy_devices_ |= 1 << device; |
| 549 CrosRequestNetworkDeviceEnable( | 536 CrosRequestNetworkDeviceEnable(ConnectionTypeToString(device), enable); |
| 550 ConnectionTypeToString(device), enable); | |
| 551 } | 537 } |
| 552 | 538 |
| 553 void NetworkLibraryImplCros::CallRemoveNetwork(const Network* network) { | 539 void NetworkLibraryImplCros::CallRemoveNetwork(const Network* network) { |
| 554 const char* service_path = network->service_path().c_str(); | 540 const std::string& service_path = network->service_path(); |
| 555 if (network->connected()) | 541 if (network->connected()) |
| 556 CrosRequestNetworkServiceDisconnect(service_path); | 542 CrosRequestNetworkServiceDisconnect(service_path); |
| 557 CrosRequestRemoveNetworkService(service_path); | 543 CrosRequestRemoveNetworkService(service_path); |
| 558 } | 544 } |
| 559 | 545 |
| 560 void NetworkLibraryImplCros::EnableOfflineMode(bool enable) { | 546 void NetworkLibraryImplCros::EnableOfflineMode(bool enable) { |
| 561 // If network device is already enabled/disabled, then don't do anything. | 547 // If network device is already enabled/disabled, then don't do anything. |
| 562 if (CrosSetOfflineMode(enable)) | 548 if (CrosSetOfflineMode(enable)) |
| 563 offline_mode_ = enable; | 549 offline_mode_ = enable; |
| 564 } | 550 } |
| 565 | 551 |
| 566 NetworkIPConfigVector NetworkLibraryImplCros::GetIPConfigs( | 552 NetworkIPConfigVector NetworkLibraryImplCros::GetIPConfigs( |
| 567 const std::string& device_path, | 553 const std::string& device_path, |
| 568 std::string* hardware_address, | 554 std::string* hardware_address, |
| 569 HardwareAddressFormat format) { | 555 HardwareAddressFormat format) { |
| 570 DCHECK(hardware_address); | 556 DCHECK(hardware_address); |
| 571 hardware_address->clear(); | 557 hardware_address->clear(); |
| 572 NetworkIPConfigVector ipconfig_vector; | 558 NetworkIPConfigVector ipconfig_vector; |
| 573 if (!device_path.empty()) { | 559 if (!device_path.empty()) { |
| 574 IPConfigStatus* ipconfig_status = CrosListIPConfigs(device_path.c_str()); | 560 IPConfigStatus* ipconfig_status = CrosListIPConfigs(device_path); |
| 575 if (ipconfig_status) { | 561 if (ipconfig_status) { |
| 576 for (int i = 0; i < ipconfig_status->size; ++i) { | 562 for (int i = 0; i < ipconfig_status->size; ++i) { |
| 577 IPConfig ipconfig = ipconfig_status->ips[i]; | 563 IPConfig ipconfig = ipconfig_status->ips[i]; |
| 578 ipconfig_vector.push_back( | 564 ipconfig_vector.push_back( |
| 579 NetworkIPConfig(device_path, ipconfig.type, ipconfig.address, | 565 NetworkIPConfig(device_path, ipconfig.type, ipconfig.address, |
| 580 ipconfig.netmask, ipconfig.gateway, | 566 ipconfig.netmask, ipconfig.gateway, |
| 581 ipconfig.name_servers)); | 567 ipconfig.name_servers)); |
| 582 } | 568 } |
| 583 *hardware_address = ipconfig_status->hardware_address; | 569 *hardware_address = ipconfig_status->hardware_address; |
| 584 CrosFreeIPConfigStatus(ipconfig_status); | 570 CrosFreeIPConfigStatus(ipconfig_status); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 604 } | 590 } |
| 605 | 591 |
| 606 void NetworkLibraryImplCros::SetIPConfig(const NetworkIPConfig& ipconfig) { | 592 void NetworkLibraryImplCros::SetIPConfig(const NetworkIPConfig& ipconfig) { |
| 607 if (ipconfig.device_path.empty()) | 593 if (ipconfig.device_path.empty()) |
| 608 return; | 594 return; |
| 609 | 595 |
| 610 IPConfig* ipconfig_dhcp = NULL; | 596 IPConfig* ipconfig_dhcp = NULL; |
| 611 IPConfig* ipconfig_static = NULL; | 597 IPConfig* ipconfig_static = NULL; |
| 612 | 598 |
| 613 IPConfigStatus* ipconfig_status = | 599 IPConfigStatus* ipconfig_status = |
| 614 CrosListIPConfigs(ipconfig.device_path.c_str()); | 600 CrosListIPConfigs(ipconfig.device_path); |
| 615 if (ipconfig_status) { | 601 if (ipconfig_status) { |
| 616 for (int i = 0; i < ipconfig_status->size; ++i) { | 602 for (int i = 0; i < ipconfig_status->size; ++i) { |
| 617 if (ipconfig_status->ips[i].type == chromeos::IPCONFIG_TYPE_DHCP) | 603 if (ipconfig_status->ips[i].type == chromeos::IPCONFIG_TYPE_DHCP) |
| 618 ipconfig_dhcp = &ipconfig_status->ips[i]; | 604 ipconfig_dhcp = &ipconfig_status->ips[i]; |
| 619 else if (ipconfig_status->ips[i].type == chromeos::IPCONFIG_TYPE_IPV4) | 605 else if (ipconfig_status->ips[i].type == chromeos::IPCONFIG_TYPE_IPV4) |
| 620 ipconfig_static = &ipconfig_status->ips[i]; | 606 ipconfig_static = &ipconfig_status->ips[i]; |
| 621 } | 607 } |
| 622 } | 608 } |
| 623 | 609 |
| 624 IPConfigStatus* ipconfig_status2 = NULL; | 610 IPConfigStatus* ipconfig_status2 = NULL; |
| 625 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) { | 611 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) { |
| 626 // If switching from static to dhcp, create new dhcp ip config. | 612 // If switching from static to dhcp, create new dhcp ip config. |
| 627 if (!ipconfig_dhcp) | 613 if (!ipconfig_dhcp) |
| 628 CrosAddIPConfig(ipconfig.device_path.c_str(), | 614 CrosAddIPConfig(ipconfig.device_path, chromeos::IPCONFIG_TYPE_DHCP); |
| 629 chromeos::IPCONFIG_TYPE_DHCP); | |
| 630 // User wants DHCP now. So delete the static ip config. | 615 // User wants DHCP now. So delete the static ip config. |
| 631 if (ipconfig_static) | 616 if (ipconfig_static) |
| 632 CrosRemoveIPConfig(ipconfig_static); | 617 CrosRemoveIPConfig(ipconfig_static); |
| 633 } else if (ipconfig.type == chromeos::IPCONFIG_TYPE_IPV4) { | 618 } else if (ipconfig.type == chromeos::IPCONFIG_TYPE_IPV4) { |
| 634 // If switching from dhcp to static, create new static ip config. | 619 // If switching from dhcp to static, create new static ip config. |
| 635 if (!ipconfig_static) { | 620 if (!ipconfig_static) { |
| 636 CrosAddIPConfig(ipconfig.device_path.c_str(), | 621 CrosAddIPConfig(ipconfig.device_path, chromeos::IPCONFIG_TYPE_IPV4); |
| 637 chromeos::IPCONFIG_TYPE_IPV4); | |
| 638 // Now find the newly created IP config. | 622 // Now find the newly created IP config. |
| 639 ipconfig_status2 = | 623 ipconfig_status2 = |
| 640 CrosListIPConfigs(ipconfig.device_path.c_str()); | 624 CrosListIPConfigs(ipconfig.device_path); |
| 641 if (ipconfig_status2) { | 625 if (ipconfig_status2) { |
| 642 for (int i = 0; i < ipconfig_status2->size; ++i) { | 626 for (int i = 0; i < ipconfig_status2->size; ++i) { |
| 643 if (ipconfig_status2->ips[i].type == chromeos::IPCONFIG_TYPE_IPV4) | 627 if (ipconfig_status2->ips[i].type == chromeos::IPCONFIG_TYPE_IPV4) |
| 644 ipconfig_static = &ipconfig_status2->ips[i]; | 628 ipconfig_static = &ipconfig_status2->ips[i]; |
| 645 } | 629 } |
| 646 } | 630 } |
| 647 } | 631 } |
| 648 if (ipconfig_static) { | 632 if (ipconfig_static) { |
| 649 // Save any changed details. | 633 // Save any changed details. |
| 650 if (ipconfig.address != ipconfig_static->address) { | 634 if (ipconfig.address != ipconfig_static->address) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 } | 774 } |
| 791 base::TimeDelta delta = base::TimeTicks::Now() - start; | 775 base::TimeDelta delta = base::TimeTicks::Now() - start; |
| 792 VLOG(2) << "NetworkManagerStatusChanged: time: " | 776 VLOG(2) << "NetworkManagerStatusChanged: time: " |
| 793 << delta.InMilliseconds() << " ms."; | 777 << delta.InMilliseconds() << " ms."; |
| 794 HISTOGRAM_TIMES("CROS_NETWORK_UPDATE", delta); | 778 HISTOGRAM_TIMES("CROS_NETWORK_UPDATE", delta); |
| 795 } | 779 } |
| 796 | 780 |
| 797 // static | 781 // static |
| 798 void NetworkLibraryImplCros::NetworkManagerUpdate( | 782 void NetworkLibraryImplCros::NetworkManagerUpdate( |
| 799 void* object, | 783 void* object, |
| 800 const char* manager_path, | 784 const std::string& manager_path, |
| 801 const base::DictionaryValue* properties) { | 785 const base::DictionaryValue* properties) { |
| 802 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 786 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
| 803 NetworkLibraryImplCros* networklib = | 787 NetworkLibraryImplCros* networklib = |
| 804 static_cast<NetworkLibraryImplCros*>(object); | 788 static_cast<NetworkLibraryImplCros*>(object); |
| 805 DCHECK(networklib); | 789 DCHECK(networklib); |
| 806 if (!properties) { | 790 if (!properties) { |
| 807 LOG(ERROR) << "Error retrieving manager properties: " << manager_path; | 791 LOG(ERROR) << "Error retrieving manager properties: " << manager_path; |
| 808 return; | 792 return; |
| 809 } | 793 } |
| 810 VLOG(1) << "Received NetworkManagerUpdate."; | 794 VLOG(1) << "Received NetworkManagerUpdate."; |
| 811 networklib->ParseNetworkManager(*properties); | 795 networklib->ParseNetworkManager(*properties); |
| 812 } | 796 } |
| 813 | 797 |
| 814 void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue& dict) { | 798 void NetworkLibraryImplCros::ParseNetworkManager(const DictionaryValue& dict) { |
| 815 for (DictionaryValue::key_iterator iter = dict.begin_keys(); | 799 for (DictionaryValue::key_iterator iter = dict.begin_keys(); |
| 816 iter != dict.end_keys(); ++iter) { | 800 iter != dict.end_keys(); ++iter) { |
| 817 const std::string& key = *iter; | 801 const std::string& key = *iter; |
| 818 Value* value; | 802 Value* value; |
| 819 bool res = dict.GetWithoutPathExpansion(key, &value); | 803 bool res = dict.GetWithoutPathExpansion(key, &value); |
| 820 CHECK(res); | 804 CHECK(res); |
| 821 NetworkManagerStatusChanged(key.c_str(), value); | 805 NetworkManagerStatusChanged(key, value); |
| 822 } | 806 } |
| 823 // If there is no Profiles entry, request remembered networks here. | 807 // If there is no Profiles entry, request remembered networks here. |
| 824 if (!dict.HasKey(flimflam::kProfilesProperty)) | 808 if (!dict.HasKey(flimflam::kProfilesProperty)) |
| 825 RequestRememberedNetworksUpdate(); | 809 RequestRememberedNetworksUpdate(); |
| 826 } | 810 } |
| 827 | 811 |
| 828 // static | 812 // static |
| 829 void NetworkLibraryImplCros::DataPlanUpdateHandler( | 813 void NetworkLibraryImplCros::DataPlanUpdateHandler( |
| 830 void* object, | 814 void* object, |
| 831 const char* modem_service_path, | 815 const char* modem_service_path, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 AddNetwork(found->second); | 911 AddNetwork(found->second); |
| 928 old_network_map.erase(found); | 912 old_network_map.erase(found); |
| 929 } | 913 } |
| 930 // Always request network updates. | 914 // Always request network updates. |
| 931 // TODO(stevenjb): Investigate why we are missing updates then | 915 // TODO(stevenjb): Investigate why we are missing updates then |
| 932 // rely on watched network updates and only request updates here for | 916 // rely on watched network updates and only request updates here for |
| 933 // new networks. | 917 // new networks. |
| 934 // Use update_request map to store network priority. | 918 // Use update_request map to store network priority. |
| 935 network_update_requests_[service_path] = network_priority_order++; | 919 network_update_requests_[service_path] = network_priority_order++; |
| 936 wifi_scanning_ = true; | 920 wifi_scanning_ = true; |
| 937 CrosRequestNetworkServiceProperties(service_path.c_str(), | 921 CrosRequestNetworkServiceProperties(service_path, |
| 938 base::Bind(&NetworkServiceUpdate, | 922 base::Bind(&NetworkServiceUpdate, |
| 939 this)); | 923 this)); |
| 940 } | 924 } |
| 941 } | 925 } |
| 942 // Iterate through list of remaining networks that are no longer in the | 926 // Iterate through list of remaining networks that are no longer in the |
| 943 // list and delete them or update their status and re-add them to the list. | 927 // list and delete them or update their status and re-add them to the list. |
| 944 for (NetworkMap::iterator iter = old_network_map.begin(); | 928 for (NetworkMap::iterator iter = old_network_map.begin(); |
| 945 iter != old_network_map.end(); ++iter) { | 929 iter != old_network_map.end(); ++iter) { |
| 946 Network* network = iter->second; | 930 Network* network = iter->second; |
| 947 VLOG(2) << "Delete Network: " << network->name() | 931 VLOG(2) << "Delete Network: " << network->name() |
| (...skipping 25 matching lines...) Expand all Loading... |
| 973 // in this list, but if there are they will be added appropriately. | 957 // in this list, but if there are they will be added appropriately. |
| 974 void NetworkLibraryImplCros::UpdateWatchedNetworkServiceList( | 958 void NetworkLibraryImplCros::UpdateWatchedNetworkServiceList( |
| 975 const ListValue* services) { | 959 const ListValue* services) { |
| 976 for (ListValue::const_iterator iter = services->begin(); | 960 for (ListValue::const_iterator iter = services->begin(); |
| 977 iter != services->end(); ++iter) { | 961 iter != services->end(); ++iter) { |
| 978 std::string service_path; | 962 std::string service_path; |
| 979 (*iter)->GetAsString(&service_path); | 963 (*iter)->GetAsString(&service_path); |
| 980 if (!service_path.empty()) { | 964 if (!service_path.empty()) { |
| 981 VLOG(1) << "Watched Service: " << service_path; | 965 VLOG(1) << "Watched Service: " << service_path; |
| 982 CrosRequestNetworkServiceProperties( | 966 CrosRequestNetworkServiceProperties( |
| 983 service_path.c_str(), | 967 service_path, |
| 984 base::Bind(&NetworkServiceUpdate, this)); | 968 base::Bind(&NetworkServiceUpdate, this)); |
| 985 } | 969 } |
| 986 } | 970 } |
| 987 } | 971 } |
| 988 | 972 |
| 989 // static | 973 // static |
| 990 void NetworkLibraryImplCros::NetworkServiceUpdate( | 974 void NetworkLibraryImplCros::NetworkServiceUpdate( |
| 991 void* object, | 975 void* object, |
| 992 const char* service_path, | 976 const std::string& service_path, |
| 993 const base::DictionaryValue* properties) { | 977 const base::DictionaryValue* properties) { |
| 994 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 978 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
| 995 NetworkLibraryImplCros* networklib = | 979 NetworkLibraryImplCros* networklib = |
| 996 static_cast<NetworkLibraryImplCros*>(object); | 980 static_cast<NetworkLibraryImplCros*>(object); |
| 997 DCHECK(networklib); | 981 DCHECK(networklib); |
| 998 if (service_path) { | 982 if (!properties) |
| 999 if (!properties) | 983 return; // Network no longer in visible list, ignore. |
| 1000 return; // Network no longer in visible list, ignore. | 984 networklib->ParseNetwork(service_path, *properties); |
| 1001 networklib->ParseNetwork(std::string(service_path), *properties); | |
| 1002 } | |
| 1003 } | 985 } |
| 1004 | 986 |
| 1005 // Called from NetworkServiceUpdate and WifiServiceUpdateAndConnect. | 987 // Called from NetworkServiceUpdate and WifiServiceUpdateAndConnect. |
| 1006 Network* NetworkLibraryImplCros::ParseNetwork( | 988 Network* NetworkLibraryImplCros::ParseNetwork( |
| 1007 const std::string& service_path, const DictionaryValue& info) { | 989 const std::string& service_path, const DictionaryValue& info) { |
| 1008 Network* network = FindNetworkByPath(service_path); | 990 Network* network = FindNetworkByPath(service_path); |
| 1009 if (!network) { | 991 if (!network) { |
| 1010 NativeNetworkParser parser; | 992 NativeNetworkParser parser; |
| 1011 network = parser.CreateNetworkFromInfo(service_path, info); | 993 network = parser.CreateNetworkFromInfo(service_path, info); |
| 1012 AddNetwork(network); | 994 AddNetwork(network); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 // remembered networks. This list updates infrequently. | 1073 // remembered networks. This list updates infrequently. |
| 1092 DeleteRememberedNetworks(); | 1074 DeleteRememberedNetworks(); |
| 1093 // Request remembered networks from each profile. Later entries will | 1075 // Request remembered networks from each profile. Later entries will |
| 1094 // override earlier entries, so default/local entries will override | 1076 // override earlier entries, so default/local entries will override |
| 1095 // user entries (as desired). | 1077 // user entries (as desired). |
| 1096 for (NetworkProfileList::iterator iter = profile_list_.begin(); | 1078 for (NetworkProfileList::iterator iter = profile_list_.begin(); |
| 1097 iter != profile_list_.end(); ++iter) { | 1079 iter != profile_list_.end(); ++iter) { |
| 1098 NetworkProfile& profile = *iter; | 1080 NetworkProfile& profile = *iter; |
| 1099 VLOG(1) << " Requesting Profile: " << profile.path; | 1081 VLOG(1) << " Requesting Profile: " << profile.path; |
| 1100 CrosRequestNetworkProfileProperties( | 1082 CrosRequestNetworkProfileProperties( |
| 1101 profile.path.c_str(), base::Bind(&ProfileUpdate, this)); | 1083 profile.path, base::Bind(&ProfileUpdate, this)); |
| 1102 } | 1084 } |
| 1103 } | 1085 } |
| 1104 | 1086 |
| 1105 // static | 1087 // static |
| 1106 void NetworkLibraryImplCros::ProfileUpdate( | 1088 void NetworkLibraryImplCros::ProfileUpdate( |
| 1107 void* object, | 1089 void* object, |
| 1108 const char* profile_path, | 1090 const std::string& profile_path, |
| 1109 const base::DictionaryValue* properties) { | 1091 const base::DictionaryValue* properties) { |
| 1110 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 1092 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
| 1111 NetworkLibraryImplCros* networklib = | 1093 NetworkLibraryImplCros* networklib = |
| 1112 static_cast<NetworkLibraryImplCros*>(object); | 1094 static_cast<NetworkLibraryImplCros*>(object); |
| 1113 DCHECK(networklib); | 1095 DCHECK(networklib); |
| 1114 if (!properties) { | 1096 if (!properties) { |
| 1115 LOG(ERROR) << "Error retrieving profile: " << profile_path; | 1097 LOG(ERROR) << "Error retrieving profile: " << profile_path; |
| 1116 return; | 1098 return; |
| 1117 } | 1099 } |
| 1118 VLOG(1) << "Received ProfileUpdate for: " << profile_path; | 1100 VLOG(1) << "Received ProfileUpdate for: " << profile_path; |
| 1119 ListValue* entries(NULL); | 1101 ListValue* entries(NULL); |
| 1120 properties->GetList(flimflam::kEntriesProperty, &entries); | 1102 properties->GetList(flimflam::kEntriesProperty, &entries); |
| 1121 DCHECK(entries); | 1103 DCHECK(entries); |
| 1122 networklib->UpdateRememberedServiceList(profile_path, entries); | 1104 networklib->UpdateRememberedServiceList(profile_path, entries); |
| 1123 } | 1105 } |
| 1124 | 1106 |
| 1125 void NetworkLibraryImplCros::UpdateRememberedServiceList( | 1107 void NetworkLibraryImplCros::UpdateRememberedServiceList( |
| 1126 const char* profile_path, const ListValue* profile_entries) { | 1108 const std::string& profile_path, const ListValue* profile_entries) { |
| 1127 DCHECK(profile_path); | |
| 1128 VLOG(1) << "UpdateRememberedServiceList for path: " << profile_path; | 1109 VLOG(1) << "UpdateRememberedServiceList for path: " << profile_path; |
| 1129 NetworkProfileList::iterator iter1; | 1110 NetworkProfileList::iterator iter1; |
| 1130 for (iter1 = profile_list_.begin(); iter1 != profile_list_.end(); ++iter1) { | 1111 for (iter1 = profile_list_.begin(); iter1 != profile_list_.end(); ++iter1) { |
| 1131 if (iter1->path == profile_path) | 1112 if (iter1->path == profile_path) |
| 1132 break; | 1113 break; |
| 1133 } | 1114 } |
| 1134 if (iter1 == profile_list_.end()) { | 1115 if (iter1 == profile_list_.end()) { |
| 1135 // This can happen if flimflam gets restarted while Chrome is running. | 1116 // This can happen if flimflam gets restarted while Chrome is running. |
| 1136 LOG(WARNING) << "Profile not in list: " << profile_path; | 1117 LOG(WARNING) << "Profile not in list: " << profile_path; |
| 1137 return; | 1118 return; |
| 1138 } | 1119 } |
| 1139 NetworkProfile& profile = *iter1; | 1120 NetworkProfile& profile = *iter1; |
| 1140 // |profile_entries| is a list of remembered networks from |profile_path|. | 1121 // |profile_entries| is a list of remembered networks from |profile_path|. |
| 1141 profile.services.clear(); | 1122 profile.services.clear(); |
| 1142 for (ListValue::const_iterator iter2 = profile_entries->begin(); | 1123 for (ListValue::const_iterator iter2 = profile_entries->begin(); |
| 1143 iter2 != profile_entries->end(); ++iter2) { | 1124 iter2 != profile_entries->end(); ++iter2) { |
| 1144 std::string service_path; | 1125 std::string service_path; |
| 1145 (*iter2)->GetAsString(&service_path); | 1126 (*iter2)->GetAsString(&service_path); |
| 1146 if (service_path.empty()) { | 1127 if (service_path.empty()) { |
| 1147 LOG(WARNING) << "Empty service path in profile."; | 1128 LOG(WARNING) << "Empty service path in profile."; |
| 1148 continue; | 1129 continue; |
| 1149 } | 1130 } |
| 1150 VLOG(1) << " Remembered service: " << service_path; | 1131 VLOG(1) << " Remembered service: " << service_path; |
| 1151 // Add service to profile list. | 1132 // Add service to profile list. |
| 1152 profile.services.insert(service_path); | 1133 profile.services.insert(service_path); |
| 1153 // Request update for remembered network. | 1134 // Request update for remembered network. |
| 1154 CrosRequestNetworkProfileEntryProperties( | 1135 CrosRequestNetworkProfileEntryProperties( |
| 1155 profile_path, | 1136 profile_path, |
| 1156 service_path.c_str(), | 1137 service_path, |
| 1157 base::Bind(&RememberedNetworkServiceUpdate, this)); | 1138 base::Bind(&RememberedNetworkServiceUpdate, this)); |
| 1158 } | 1139 } |
| 1159 } | 1140 } |
| 1160 | 1141 |
| 1161 // static | 1142 // static |
| 1162 void NetworkLibraryImplCros::RememberedNetworkServiceUpdate( | 1143 void NetworkLibraryImplCros::RememberedNetworkServiceUpdate( |
| 1163 void* object, | 1144 void* object, |
| 1164 const char* service_path, | 1145 const std::string& service_path, |
| 1165 const base::DictionaryValue* properties) { | 1146 const base::DictionaryValue* properties) { |
| 1166 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 1147 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
| 1167 NetworkLibraryImplCros* networklib = | 1148 NetworkLibraryImplCros* networklib = |
| 1168 static_cast<NetworkLibraryImplCros*>(object); | 1149 static_cast<NetworkLibraryImplCros*>(object); |
| 1169 DCHECK(networklib); | 1150 DCHECK(networklib); |
| 1170 if (service_path) { | 1151 if (!properties) { |
| 1171 if (!properties) { | 1152 // Remembered network no longer exists. |
| 1172 // Remembered network no longer exists. | 1153 networklib->DeleteRememberedNetwork(service_path); |
| 1173 networklib->DeleteRememberedNetwork(std::string(service_path)); | 1154 } else { |
| 1174 } else { | 1155 networklib->ParseRememberedNetwork(service_path, *properties); |
| 1175 networklib->ParseRememberedNetwork( | |
| 1176 std::string(service_path), *properties); | |
| 1177 } | |
| 1178 } | 1156 } |
| 1179 } | 1157 } |
| 1180 | 1158 |
| 1181 // Returns NULL if |service_path| refers to a network that is not a | 1159 // Returns NULL if |service_path| refers to a network that is not a |
| 1182 // remembered type. Called from RememberedNetworkServiceUpdate. | 1160 // remembered type. Called from RememberedNetworkServiceUpdate. |
| 1183 Network* NetworkLibraryImplCros::ParseRememberedNetwork( | 1161 Network* NetworkLibraryImplCros::ParseRememberedNetwork( |
| 1184 const std::string& service_path, const DictionaryValue& info) { | 1162 const std::string& service_path, const DictionaryValue& info) { |
| 1185 Network* remembered; | 1163 Network* remembered; |
| 1186 NetworkMap::iterator found = remembered_network_map_.find(service_path); | 1164 NetworkMap::iterator found = remembered_network_map_.find(service_path); |
| 1187 if (found != remembered_network_map_.end()) { | 1165 if (found != remembered_network_map_.end()) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1218 if (remembered->type() == TYPE_VPN) { | 1196 if (remembered->type() == TYPE_VPN) { |
| 1219 // VPNs are only stored in profiles. If we don't have a network for it, | 1197 // VPNs are only stored in profiles. If we don't have a network for it, |
| 1220 // request one. | 1198 // request one. |
| 1221 if (!FindNetworkByUniqueId(remembered->unique_id())) { | 1199 if (!FindNetworkByUniqueId(remembered->unique_id())) { |
| 1222 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(remembered); | 1200 VirtualNetwork* vpn = static_cast<VirtualNetwork*>(remembered); |
| 1223 std::string provider_type = ProviderTypeToString(vpn->provider_type()); | 1201 std::string provider_type = ProviderTypeToString(vpn->provider_type()); |
| 1224 VLOG(1) << "Requesting VPN: " << vpn->name() | 1202 VLOG(1) << "Requesting VPN: " << vpn->name() |
| 1225 << " Server: " << vpn->server_hostname() | 1203 << " Server: " << vpn->server_hostname() |
| 1226 << " Type: " << provider_type; | 1204 << " Type: " << provider_type; |
| 1227 CrosRequestVirtualNetworkProperties( | 1205 CrosRequestVirtualNetworkProperties( |
| 1228 vpn->name().c_str(), | 1206 vpn->name(), |
| 1229 vpn->server_hostname().c_str(), | 1207 vpn->server_hostname(), |
| 1230 provider_type.c_str(), | 1208 provider_type, |
| 1231 base::Bind(&NetworkServiceUpdate, this)); | 1209 base::Bind(&NetworkServiceUpdate, this)); |
| 1232 } | 1210 } |
| 1233 } | 1211 } |
| 1234 | 1212 |
| 1235 return remembered; | 1213 return remembered; |
| 1236 } | 1214 } |
| 1237 | 1215 |
| 1238 //////////////////////////////////////////////////////////////////////////// | 1216 //////////////////////////////////////////////////////////////////////////// |
| 1239 // NetworkDevice list management functions. | 1217 // NetworkDevice list management functions. |
| 1240 | 1218 |
| 1241 // Update device list, and request associated device updates. | 1219 // Update device list, and request associated device updates. |
| 1242 // |devices| represents a complete list of devices. | 1220 // |devices| represents a complete list of devices. |
| 1243 void NetworkLibraryImplCros::UpdateNetworkDeviceList(const ListValue* devices) { | 1221 void NetworkLibraryImplCros::UpdateNetworkDeviceList(const ListValue* devices) { |
| 1244 NetworkDeviceMap old_device_map = device_map_; | 1222 NetworkDeviceMap old_device_map = device_map_; |
| 1245 device_map_.clear(); | 1223 device_map_.clear(); |
| 1246 VLOG(2) << "Updating Device List."; | 1224 VLOG(2) << "Updating Device List."; |
| 1247 for (ListValue::const_iterator iter = devices->begin(); | 1225 for (ListValue::const_iterator iter = devices->begin(); |
| 1248 iter != devices->end(); ++iter) { | 1226 iter != devices->end(); ++iter) { |
| 1249 std::string device_path; | 1227 std::string device_path; |
| 1250 (*iter)->GetAsString(&device_path); | 1228 (*iter)->GetAsString(&device_path); |
| 1251 if (!device_path.empty()) { | 1229 if (!device_path.empty()) { |
| 1252 NetworkDeviceMap::iterator found = old_device_map.find(device_path); | 1230 NetworkDeviceMap::iterator found = old_device_map.find(device_path); |
| 1253 if (found != old_device_map.end()) { | 1231 if (found != old_device_map.end()) { |
| 1254 VLOG(2) << " Adding existing device: " << device_path; | 1232 VLOG(2) << " Adding existing device: " << device_path; |
| 1255 CHECK(found->second) << "Attempted to add NULL device pointer"; | 1233 CHECK(found->second) << "Attempted to add NULL device pointer"; |
| 1256 device_map_[device_path] = found->second; | 1234 device_map_[device_path] = found->second; |
| 1257 old_device_map.erase(found); | 1235 old_device_map.erase(found); |
| 1258 } | 1236 } |
| 1259 CrosRequestNetworkDeviceProperties( | 1237 CrosRequestNetworkDeviceProperties( |
| 1260 device_path.c_str(), | 1238 device_path, |
| 1261 base::Bind(&NetworkDeviceUpdate, this)); | 1239 base::Bind(&NetworkDeviceUpdate, this)); |
| 1262 } | 1240 } |
| 1263 } | 1241 } |
| 1264 // Delete any old devices that no longer exist. | 1242 // Delete any old devices that no longer exist. |
| 1265 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); | 1243 for (NetworkDeviceMap::iterator iter = old_device_map.begin(); |
| 1266 iter != old_device_map.end(); ++iter) { | 1244 iter != old_device_map.end(); ++iter) { |
| 1267 DeleteDeviceFromDeviceObserversMap(iter->first); | 1245 DeleteDeviceFromDeviceObserversMap(iter->first); |
| 1268 // Delete device. | 1246 // Delete device. |
| 1269 delete iter->second; | 1247 delete iter->second; |
| 1270 } | 1248 } |
| 1271 } | 1249 } |
| 1272 | 1250 |
| 1273 // static | 1251 // static |
| 1274 void NetworkLibraryImplCros::NetworkDeviceUpdate( | 1252 void NetworkLibraryImplCros::NetworkDeviceUpdate( |
| 1275 void* object, | 1253 void* object, |
| 1276 const char* device_path, | 1254 const std::string& device_path, |
| 1277 const base::DictionaryValue* properties) { | 1255 const base::DictionaryValue* properties) { |
| 1278 DCHECK(CrosLibrary::Get()->libcros_loaded()); | 1256 DCHECK(CrosLibrary::Get()->libcros_loaded()); |
| 1279 NetworkLibraryImplCros* networklib = | 1257 NetworkLibraryImplCros* networklib = |
| 1280 static_cast<NetworkLibraryImplCros*>(object); | 1258 static_cast<NetworkLibraryImplCros*>(object); |
| 1281 DCHECK(networklib); | 1259 DCHECK(networklib); |
| 1282 if (device_path) { | 1260 if (!properties) { |
| 1283 if (!properties) { | 1261 // device no longer exists. |
| 1284 // device no longer exists. | 1262 networklib->DeleteDevice(device_path); |
| 1285 networklib->DeleteDevice(std::string(device_path)); | 1263 } else { |
| 1286 } else { | 1264 networklib->ParseNetworkDevice(device_path, *properties); |
| 1287 networklib->ParseNetworkDevice(std::string(device_path), *properties); | |
| 1288 } | |
| 1289 } | 1265 } |
| 1290 } | 1266 } |
| 1291 | 1267 |
| 1292 void NetworkLibraryImplCros::ParseNetworkDevice(const std::string& device_path, | 1268 void NetworkLibraryImplCros::ParseNetworkDevice(const std::string& device_path, |
| 1293 const DictionaryValue& info) { | 1269 const DictionaryValue& info) { |
| 1294 NetworkDeviceMap::iterator found = device_map_.find(device_path); | 1270 NetworkDeviceMap::iterator found = device_map_.find(device_path); |
| 1295 NetworkDevice* device; | 1271 NetworkDevice* device; |
| 1296 if (found != device_map_.end()) { | 1272 if (found != device_map_.end()) { |
| 1297 device = found->second; | 1273 device = found->second; |
| 1298 device->device_parser()->UpdateDeviceFromInfo(info, device); | 1274 device->device_parser()->UpdateDeviceFromInfo(info, device); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1317 // Switch back to signed settings value. | 1293 // Switch back to signed settings value. |
| 1318 SetCellularDataRoamingAllowed(settings_value); | 1294 SetCellularDataRoamingAllowed(settings_value); |
| 1319 } | 1295 } |
| 1320 } | 1296 } |
| 1321 } | 1297 } |
| 1322 NotifyNetworkManagerChanged(false); // Not forced. | 1298 NotifyNetworkManagerChanged(false); // Not forced. |
| 1323 AddNetworkDeviceObserver(device_path, network_device_observer_.get()); | 1299 AddNetworkDeviceObserver(device_path, network_device_observer_.get()); |
| 1324 } | 1300 } |
| 1325 | 1301 |
| 1326 } // namespace chromeos | 1302 } // namespace chromeos |
| OLD | NEW |