Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chromeos/network/shill_property_handler.h" | 5 #include "chromeos/network/shill_property_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/format_macros.h" | 8 #include "base/format_macros.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 dbus::ObjectPath(path), | 217 dbus::ObjectPath(path), |
| 218 base::Bind(&ShillPropertyHandler::GetPropertiesCallback, | 218 base::Bind(&ShillPropertyHandler::GetPropertiesCallback, |
| 219 AsWeakPtr(), type, path)); | 219 AsWeakPtr(), type, path)); |
| 220 } else { | 220 } else { |
| 221 NOTREACHED(); | 221 NOTREACHED(); |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 | 224 |
| 225 void ShillPropertyHandler::OnPropertyChanged(const std::string& key, | 225 void ShillPropertyHandler::OnPropertyChanged(const std::string& key, |
| 226 const base::Value& value) { | 226 const base::Value& value) { |
| 227 if (ManagerPropertyChanged(key, value)) { | 227 ManagerPropertyChanged(key, value); |
| 228 std::string detail = key; | |
| 229 detail += " = " + network_event_log::ValueAsString(value); | |
| 230 NET_LOG_DEBUG("ManagerPropertyChanged", detail); | |
| 231 listener_->NotifyManagerPropertyChanged(); | |
| 232 } | |
| 233 CheckPendingStateListUpdates(key); | 228 CheckPendingStateListUpdates(key); |
| 234 } | 229 } |
| 235 | 230 |
| 236 //------------------------------------------------------------------------------ | 231 //------------------------------------------------------------------------------ |
| 237 // Private methods | 232 // Private methods |
| 238 | 233 |
| 239 void ShillPropertyHandler::ManagerPropertiesCallback( | 234 void ShillPropertyHandler::ManagerPropertiesCallback( |
| 240 DBusMethodCallStatus call_status, | 235 DBusMethodCallStatus call_status, |
| 241 const base::DictionaryValue& properties) { | 236 const base::DictionaryValue& properties) { |
| 242 if (call_status != DBUS_METHOD_CALL_SUCCESS) { | 237 if (call_status != DBUS_METHOD_CALL_SUCCESS) { |
| 243 NET_LOG_ERROR("ManagerPropertiesCallback", | 238 NET_LOG_ERROR("ManagerPropertiesCallback", |
| 244 base::StringPrintf("Failed: %d", call_status)); | 239 base::StringPrintf("Failed: %d", call_status)); |
| 245 return; | 240 return; |
| 246 } | 241 } |
| 247 NET_LOG_EVENT("ManagerPropertiesCallback", "Success"); | 242 NET_LOG_EVENT("ManagerPropertiesCallback", "Success"); |
| 248 bool notify = false; | |
| 249 const base::Value* update_service_value = NULL; | 243 const base::Value* update_service_value = NULL; |
| 250 const base::Value* update_service_complete_value = NULL; | 244 const base::Value* update_service_complete_value = NULL; |
| 251 for (base::DictionaryValue::Iterator iter(properties); | 245 for (base::DictionaryValue::Iterator iter(properties); |
| 252 !iter.IsAtEnd(); iter.Advance()) { | 246 !iter.IsAtEnd(); iter.Advance()) { |
| 253 // Defer updating Services until all other properties have been updated. | 247 // Defer updating Services until all other properties have been updated. |
| 254 if (iter.key() == flimflam::kServicesProperty) | 248 if (iter.key() == flimflam::kServicesProperty) |
| 255 update_service_value = &iter.value(); | 249 update_service_value = &iter.value(); |
| 256 else if (iter.key() == shill::kServiceCompleteListProperty) | 250 else if (iter.key() == shill::kServiceCompleteListProperty) |
| 257 update_service_complete_value = &iter.value(); | 251 update_service_complete_value = &iter.value(); |
| 258 else | 252 else |
| 259 notify |= ManagerPropertyChanged(iter.key(), iter.value()); | 253 ManagerPropertyChanged(iter.key(), iter.value()); |
| 260 } | 254 } |
| 261 // Update Services which can safely assume other properties have been set. | 255 // Update Services which can safely assume other properties have been set. |
| 262 if (update_service_value) { | 256 if (update_service_value) |
| 263 notify |= ManagerPropertyChanged(flimflam::kServicesProperty, | 257 ManagerPropertyChanged(flimflam::kServicesProperty, *update_service_value); |
| 264 *update_service_value); | |
| 265 } | |
| 266 // Update ServiceCompleteList which skips entries that have already been | 258 // Update ServiceCompleteList which skips entries that have already been |
| 267 // requested for Services. | 259 // requested for Services. |
| 268 if (update_service_complete_value) { | 260 if (update_service_complete_value) { |
| 269 notify |= ManagerPropertyChanged(shill::kServiceCompleteListProperty, | 261 ManagerPropertyChanged(shill::kServiceCompleteListProperty, |
| 270 *update_service_complete_value); | 262 *update_service_complete_value); |
| 271 } | 263 } |
| 272 | 264 |
| 273 if (notify) | |
| 274 listener_->NotifyManagerPropertyChanged(); | |
| 275 CheckPendingStateListUpdates(""); | 265 CheckPendingStateListUpdates(""); |
| 276 } | 266 } |
| 277 | 267 |
| 278 void ShillPropertyHandler::CheckPendingStateListUpdates( | 268 void ShillPropertyHandler::CheckPendingStateListUpdates( |
| 279 const std::string& key) { | 269 const std::string& key) { |
| 280 // Once there are no pending updates, signal the state list changed callbacks. | 270 // Once there are no pending updates, signal the state list changed callbacks. |
| 281 if ((key.empty() || key == flimflam::kServicesProperty) && | 271 if ((key.empty() || key == flimflam::kServicesProperty) && |
| 282 pending_updates_[ManagedState::MANAGED_TYPE_NETWORK].size() == 0) { | 272 pending_updates_[ManagedState::MANAGED_TYPE_NETWORK].size() == 0) { |
| 283 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_NETWORK); | 273 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_NETWORK); |
| 284 } | 274 } |
| 285 // Both Network update requests and Favorite update requests will affect | 275 // Both Network update requests and Favorite update requests will affect |
| 286 // the list of favorites, so wait for both to complete. | 276 // the list of favorites, so wait for both to complete. |
| 287 if ((key.empty() || key == shill::kServiceCompleteListProperty) && | 277 if ((key.empty() || key == shill::kServiceCompleteListProperty) && |
| 288 pending_updates_[ManagedState::MANAGED_TYPE_NETWORK].size() == 0 && | 278 pending_updates_[ManagedState::MANAGED_TYPE_NETWORK].size() == 0 && |
| 289 pending_updates_[ManagedState::MANAGED_TYPE_FAVORITE].size() == 0) { | 279 pending_updates_[ManagedState::MANAGED_TYPE_FAVORITE].size() == 0) { |
| 290 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_FAVORITE); | 280 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_FAVORITE); |
| 291 } | 281 } |
| 292 if ((key.empty() || key == flimflam::kDevicesProperty) && | 282 if ((key.empty() || key == flimflam::kDevicesProperty) && |
| 293 pending_updates_[ManagedState::MANAGED_TYPE_DEVICE].size() == 0) { | 283 pending_updates_[ManagedState::MANAGED_TYPE_DEVICE].size() == 0) { |
| 294 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_DEVICE); | 284 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_DEVICE); |
| 295 } | 285 } |
| 296 } | 286 } |
| 297 | 287 |
| 298 bool ShillPropertyHandler::ManagerPropertyChanged(const std::string& key, | 288 void ShillPropertyHandler::ManagerPropertyChanged(const std::string& key, |
| 299 const base::Value& value) { | 289 const base::Value& value) { |
| 300 bool notify_manager_changed = false; | |
| 301 if (key == flimflam::kServicesProperty) { | 290 if (key == flimflam::kServicesProperty) { |
| 302 const base::ListValue* vlist = GetListValue(key, value); | 291 const base::ListValue* vlist = GetListValue(key, value); |
| 303 if (vlist) { | 292 if (vlist) { |
| 304 listener_->UpdateManagedList(ManagedState::MANAGED_TYPE_NETWORK, *vlist); | 293 listener_->UpdateManagedList(ManagedState::MANAGED_TYPE_NETWORK, *vlist); |
| 305 UpdateProperties(ManagedState::MANAGED_TYPE_NETWORK, *vlist); | 294 UpdateProperties(ManagedState::MANAGED_TYPE_NETWORK, *vlist); |
| 306 // UpdateObserved used to use kServiceWatchListProperty for TYPE_NETWORK, | 295 // UpdateObserved used to use kServiceWatchListProperty for TYPE_NETWORK, |
| 307 // however that prevents us from receiving Strength updates from inactive | 296 // however that prevents us from receiving Strength updates from inactive |
| 308 // networks. The overhead for observing all services is not unreasonable | 297 // networks. The overhead for observing all services is not unreasonable |
| 309 // (and we limit the max number of observed services to kMaxObserved). | 298 // (and we limit the max number of observed services to kMaxObserved). |
| 310 UpdateObserved(ManagedState::MANAGED_TYPE_NETWORK, *vlist); | 299 UpdateObserved(ManagedState::MANAGED_TYPE_NETWORK, *vlist); |
| 311 } | 300 } |
| 312 } else if (key == shill::kServiceCompleteListProperty) { | 301 } else if (key == shill::kServiceCompleteListProperty) { |
| 313 const ListValue* vlist = GetListValue(key, value); | 302 const ListValue* vlist = GetListValue(key, value); |
| 314 if (vlist) { | 303 if (vlist) { |
| 315 listener_->UpdateManagedList(ManagedState::MANAGED_TYPE_FAVORITE, *vlist); | 304 listener_->UpdateManagedList(ManagedState::MANAGED_TYPE_FAVORITE, *vlist); |
| 316 UpdateProperties(ManagedState::MANAGED_TYPE_FAVORITE, *vlist); | 305 UpdateProperties(ManagedState::MANAGED_TYPE_FAVORITE, *vlist); |
| 317 } | 306 } |
| 318 } else if (key == flimflam::kDevicesProperty) { | 307 } else if (key == flimflam::kDevicesProperty) { |
| 319 const base::ListValue* vlist = GetListValue(key, value); | 308 const base::ListValue* vlist = GetListValue(key, value); |
| 320 if (vlist) { | 309 if (vlist) { |
| 321 listener_->UpdateManagedList(ManagedState::MANAGED_TYPE_DEVICE, *vlist); | 310 listener_->UpdateManagedList(ManagedState::MANAGED_TYPE_DEVICE, *vlist); |
| 322 UpdateProperties(ManagedState::MANAGED_TYPE_DEVICE, *vlist); | 311 UpdateProperties(ManagedState::MANAGED_TYPE_DEVICE, *vlist); |
| 323 UpdateObserved(ManagedState::MANAGED_TYPE_DEVICE, *vlist); | 312 UpdateObserved(ManagedState::MANAGED_TYPE_DEVICE, *vlist); |
| 324 } | 313 } |
| 325 } else if (key == flimflam::kAvailableTechnologiesProperty) { | 314 } else if (key == flimflam::kAvailableTechnologiesProperty) { |
| 326 const base::ListValue* vlist = GetListValue(key, value); | 315 const base::ListValue* vlist = GetListValue(key, value); |
| 327 if (vlist) { | 316 if (vlist) |
| 328 UpdateAvailableTechnologies(*vlist); | 317 UpdateAvailableTechnologies(*vlist); |
| 329 notify_manager_changed = true; | |
| 330 } | |
| 331 } else if (key == flimflam::kEnabledTechnologiesProperty) { | 318 } else if (key == flimflam::kEnabledTechnologiesProperty) { |
| 332 const base::ListValue* vlist = GetListValue(key, value); | 319 const base::ListValue* vlist = GetListValue(key, value); |
| 333 if (vlist) { | 320 if (vlist) |
| 334 UpdateEnabledTechnologies(*vlist); | 321 UpdateEnabledTechnologies(*vlist); |
| 335 notify_manager_changed = true; | |
| 336 } | |
| 337 } else if (key == shill::kUninitializedTechnologiesProperty) { | 322 } else if (key == shill::kUninitializedTechnologiesProperty) { |
| 338 const base::ListValue* vlist = GetListValue(key, value); | 323 const base::ListValue* vlist = GetListValue(key, value); |
| 339 if (vlist) { | 324 if (vlist) |
| 340 UpdateUninitializedTechnologies(*vlist); | 325 UpdateUninitializedTechnologies(*vlist); |
| 341 notify_manager_changed = true; | |
| 342 } | |
| 343 } else if (key == flimflam::kProfilesProperty) { | 326 } else if (key == flimflam::kProfilesProperty) { |
| 344 listener_->ProfileListChanged(); | 327 listener_->ProfileListChanged(); |
| 345 } else if (key == flimflam::kCheckPortalListProperty) { | 328 } else if (key == flimflam::kCheckPortalListProperty) { |
| 346 std::string check_portal_list; | 329 std::string check_portal_list; |
| 347 if (value.GetAsString(&check_portal_list)) { | 330 if (value.GetAsString(&check_portal_list)) |
| 348 listener_->CheckPortalListChanged(check_portal_list); | 331 listener_->CheckPortalListChanged(check_portal_list); |
| 349 notify_manager_changed = true; | |
| 350 } | |
| 351 } else { | 332 } else { |
| 352 VLOG(2) << "Ignored Manager Property: " << key; | 333 VLOG(2) << "Ignored Manager Property: " << key; |
| 353 } | 334 } |
| 354 return notify_manager_changed; | |
| 355 } | 335 } |
| 356 | 336 |
| 357 void ShillPropertyHandler::UpdateProperties(ManagedState::ManagedType type, | 337 void ShillPropertyHandler::UpdateProperties(ManagedState::ManagedType type, |
| 358 const base::ListValue& entries) { | 338 const base::ListValue& entries) { |
| 359 std::set<std::string>& requested_updates = requested_updates_[type]; | 339 std::set<std::string>& requested_updates = requested_updates_[type]; |
| 360 std::set<std::string>& requested_service_updates = | 340 std::set<std::string>& requested_service_updates = |
| 361 requested_updates_[ManagedState::MANAGED_TYPE_NETWORK]; // For favorites | 341 requested_updates_[ManagedState::MANAGED_TYPE_NETWORK]; // For favorites |
| 362 std::set<std::string> new_requested_updates; | 342 std::set<std::string> new_requested_updates; |
| 363 VLOG(2) << "Update Properties: " << type << " Entries: " << entries.GetSize(); | 343 VLOG(2) << "Update Properties: " << type << " Entries: " << entries.GetSize(); |
| 364 for (base::ListValue::const_iterator iter = entries.begin(); | 344 for (base::ListValue::const_iterator iter = entries.begin(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 void ShillPropertyHandler::UpdateAvailableTechnologies( | 396 void ShillPropertyHandler::UpdateAvailableTechnologies( |
| 417 const base::ListValue& technologies) { | 397 const base::ListValue& technologies) { |
| 418 available_technologies_.clear(); | 398 available_technologies_.clear(); |
| 419 NET_LOG_EVENT("AvailableTechnologiesChanged", | 399 NET_LOG_EVENT("AvailableTechnologiesChanged", |
| 420 base::StringPrintf("Size: %" PRIuS, technologies.GetSize())); | 400 base::StringPrintf("Size: %" PRIuS, technologies.GetSize())); |
| 421 for (base::ListValue::const_iterator iter = technologies.begin(); | 401 for (base::ListValue::const_iterator iter = technologies.begin(); |
| 422 iter != technologies.end(); ++iter) { | 402 iter != technologies.end(); ++iter) { |
| 423 std::string technology; | 403 std::string technology; |
| 424 (*iter)->GetAsString(&technology); | 404 (*iter)->GetAsString(&technology); |
| 425 DCHECK(!technology.empty()); | 405 DCHECK(!technology.empty()); |
| 426 available_technologies_.insert(technology); | 406 available_technologies_.insert(technology); |
|
pneubeck (no reviews)
2013/09/11 20:13:35
how about checking the result value of each insert
stevenjb
2013/09/11 21:23:46
We clear the lists then insert the technologies. W
| |
| 427 } | 407 } |
| 408 listener_->TechnologyListChanged(); | |
| 428 } | 409 } |
| 429 | 410 |
| 430 void ShillPropertyHandler::UpdateEnabledTechnologies( | 411 void ShillPropertyHandler::UpdateEnabledTechnologies( |
| 431 const base::ListValue& technologies) { | 412 const base::ListValue& technologies) { |
| 432 enabled_technologies_.clear(); | 413 enabled_technologies_.clear(); |
| 433 NET_LOG_EVENT("EnabledTechnologiesChanged", | 414 NET_LOG_EVENT("EnabledTechnologiesChanged", |
| 434 base::StringPrintf("Size: %" PRIuS, technologies.GetSize())); | 415 base::StringPrintf("Size: %" PRIuS, technologies.GetSize())); |
| 435 for (base::ListValue::const_iterator iter = technologies.begin(); | 416 for (base::ListValue::const_iterator iter = technologies.begin(); |
| 436 iter != technologies.end(); ++iter) { | 417 iter != technologies.end(); ++iter) { |
| 437 std::string technology; | 418 std::string technology; |
| 438 (*iter)->GetAsString(&technology); | 419 (*iter)->GetAsString(&technology); |
| 439 DCHECK(!technology.empty()); | 420 DCHECK(!technology.empty()); |
| 440 enabled_technologies_.insert(technology); | 421 enabled_technologies_.insert(technology); |
| 441 enabling_technologies_.erase(technology); | 422 enabling_technologies_.erase(technology); |
| 442 } | 423 } |
| 424 listener_->TechnologyListChanged(); | |
| 443 } | 425 } |
| 444 | 426 |
| 445 void ShillPropertyHandler::UpdateUninitializedTechnologies( | 427 void ShillPropertyHandler::UpdateUninitializedTechnologies( |
| 446 const base::ListValue& technologies) { | 428 const base::ListValue& technologies) { |
| 447 uninitialized_technologies_.clear(); | 429 uninitialized_technologies_.clear(); |
| 448 NET_LOG_EVENT("UninitializedTechnologiesChanged", | 430 NET_LOG_EVENT("UninitializedTechnologiesChanged", |
| 449 base::StringPrintf("Size: %" PRIuS, technologies.GetSize())); | 431 base::StringPrintf("Size: %" PRIuS, technologies.GetSize())); |
| 450 for (base::ListValue::const_iterator iter = technologies.begin(); | 432 for (base::ListValue::const_iterator iter = technologies.begin(); |
| 451 iter != technologies.end(); ++iter) { | 433 iter != technologies.end(); ++iter) { |
| 452 std::string technology; | 434 std::string technology; |
| 453 (*iter)->GetAsString(&technology); | 435 (*iter)->GetAsString(&technology); |
| 454 DCHECK(!technology.empty()); | 436 DCHECK(!technology.empty()); |
| 455 uninitialized_technologies_.insert(technology); | 437 uninitialized_technologies_.insert(technology); |
| 456 } | 438 } |
| 439 listener_->TechnologyListChanged(); | |
| 457 } | 440 } |
| 458 | 441 |
| 459 void ShillPropertyHandler::EnableTechnologyFailed( | 442 void ShillPropertyHandler::EnableTechnologyFailed( |
| 460 const std::string& technology, | 443 const std::string& technology, |
| 461 const network_handler::ErrorCallback& error_callback, | 444 const network_handler::ErrorCallback& error_callback, |
| 462 const std::string& dbus_error_name, | 445 const std::string& dbus_error_name, |
| 463 const std::string& dbus_error_message) { | 446 const std::string& dbus_error_message) { |
| 464 enabling_technologies_.erase(technology); | 447 enabling_technologies_.erase(technology); |
| 465 network_handler::ShillErrorCallbackFunction( | 448 network_handler::ShillErrorCallbackFunction( |
| 466 "EnableTechnology Failed", | 449 "EnableTechnology Failed", |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 | 569 |
| 587 void ShillPropertyHandler::NetworkDevicePropertyChangedCallback( | 570 void ShillPropertyHandler::NetworkDevicePropertyChangedCallback( |
| 588 const std::string& path, | 571 const std::string& path, |
| 589 const std::string& key, | 572 const std::string& key, |
| 590 const base::Value& value) { | 573 const base::Value& value) { |
| 591 listener_->UpdateDeviceProperty(path, key, value); | 574 listener_->UpdateDeviceProperty(path, key, value); |
| 592 } | 575 } |
| 593 | 576 |
| 594 } // namespace internal | 577 } // namespace internal |
| 595 } // namespace chromeos | 578 } // namespace chromeos |
| OLD | NEW |