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/json/json_writer.h" | |
| 9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 11 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
| 14 #include "chromeos/dbus/shill_device_client.h" | 15 #include "chromeos/dbus/shill_device_client.h" |
| 15 #include "chromeos/dbus/shill_ipconfig_client.h" | 16 #include "chromeos/dbus/shill_ipconfig_client.h" |
| 16 #include "chromeos/dbus/shill_manager_client.h" | 17 #include "chromeos/dbus/shill_manager_client.h" |
| 17 #include "chromeos/dbus/shill_service_client.h" | 18 #include "chromeos/dbus/shill_service_client.h" |
| 18 #include "chromeos/network/network_event_log.h" | 19 #include "chromeos/network/network_event_log.h" |
| 19 #include "chromeos/network/network_state.h" | 20 #include "chromeos/network/network_state.h" |
| 20 #include "dbus/object_path.h" | 21 #include "dbus/object_path.h" |
| 21 #include "third_party/cros_system_api/dbus/service_constants.h" | 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 const char kLogModule[] = "ShillPropertyHandler"; | |
| 26 | |
| 27 // Limit the number of services or devices we observe. Since they are listed in | 26 // Limit the number of services or devices we observe. Since they are listed in |
| 28 // priority order, it should be reasonable to ignore services past this. | 27 // priority order, it should be reasonable to ignore services past this. |
| 29 const size_t kMaxObserved = 100; | 28 const size_t kMaxObserved = 100; |
| 30 | 29 |
| 31 const base::ListValue* GetListValue(const std::string& key, | 30 const base::ListValue* GetListValue(const std::string& key, |
| 32 const base::Value& value) { | 31 const base::Value& value) { |
| 33 const base::ListValue* vlist = NULL; | 32 const base::ListValue* vlist = NULL; |
| 34 if (!value.GetAsList(&vlist)) { | 33 if (!value.GetAsList(&vlist)) { |
| 35 LOG(ERROR) << "Error parsing key as list: " << key; | 34 LOG(ERROR) << "Error parsing key as list: " << key; |
| 36 return NULL; | 35 return NULL; |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 base::Bind(&ShillPropertyHandler::EnableTechnologyFailed, | 152 base::Bind(&ShillPropertyHandler::EnableTechnologyFailed, |
| 154 AsWeakPtr(), technology, error_callback)); | 153 AsWeakPtr(), technology, error_callback)); |
| 155 } else { | 154 } else { |
| 156 // Imediately clear locally from enabled and enabling lists. | 155 // Imediately clear locally from enabled and enabling lists. |
| 157 enabled_technologies_.erase(technology); | 156 enabled_technologies_.erase(technology); |
| 158 enabling_technologies_.erase(technology); | 157 enabling_technologies_.erase(technology); |
| 159 shill_manager_->DisableTechnology( | 158 shill_manager_->DisableTechnology( |
| 160 technology, | 159 technology, |
| 161 base::Bind(&base::DoNothing), | 160 base::Bind(&base::DoNothing), |
| 162 base::Bind(&network_handler::ShillErrorCallbackFunction, | 161 base::Bind(&network_handler::ShillErrorCallbackFunction, |
| 163 kLogModule, technology, error_callback)); | 162 technology, error_callback)); |
| 164 } | 163 } |
| 165 } | 164 } |
| 166 | 165 |
| 167 void ShillPropertyHandler::RequestScan() const { | 166 void ShillPropertyHandler::RequestScan() const { |
| 168 shill_manager_->RequestScan( | 167 shill_manager_->RequestScan( |
| 169 "", | 168 "", |
| 170 base::Bind(&base::DoNothing), | 169 base::Bind(&base::DoNothing), |
| 171 base::Bind(&network_handler::ShillErrorCallbackFunction, | 170 base::Bind(&network_handler::ShillErrorCallbackFunction, |
| 172 kLogModule, "", network_handler::ErrorCallback())); | 171 "", network_handler::ErrorCallback())); |
| 173 } | 172 } |
| 174 | 173 |
| 175 void ShillPropertyHandler::ConnectToBestServices() const { | 174 void ShillPropertyHandler::ConnectToBestServices() const { |
| 176 network_event_log::AddEntry(kLogModule, "ConnectToBestServices", ""); | 175 NET_LOG_EVENT("ConnectToBestServices", ""); |
| 177 shill_manager_->ConnectToBestServices( | 176 shill_manager_->ConnectToBestServices( |
| 178 base::Bind(&base::DoNothing), | 177 base::Bind(&base::DoNothing), |
| 179 base::Bind(&network_handler::ShillErrorCallbackFunction, | 178 base::Bind(&network_handler::ShillErrorCallbackFunction, |
| 180 kLogModule, "", network_handler::ErrorCallback())); | 179 "", network_handler::ErrorCallback())); |
| 181 } | 180 } |
| 182 | 181 |
| 183 void ShillPropertyHandler::RequestProperties(ManagedState::ManagedType type, | 182 void ShillPropertyHandler::RequestProperties(ManagedState::ManagedType type, |
| 184 const std::string& path) { | 183 const std::string& path) { |
| 185 if (pending_updates_[type].find(path) != pending_updates_[type].end()) | 184 if (pending_updates_[type].find(path) != pending_updates_[type].end()) |
| 186 return; // Update already requested. | 185 return; // Update already requested. |
| 187 | 186 |
| 188 pending_updates_[type].insert(path); | 187 pending_updates_[type].insert(path); |
| 189 if (type == ManagedState::MANAGED_TYPE_NETWORK) { | 188 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
| 190 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( | 189 DBusThreadManager::Get()->GetShillServiceClient()->GetProperties( |
| 191 dbus::ObjectPath(path), | 190 dbus::ObjectPath(path), |
| 192 base::Bind(&ShillPropertyHandler::GetPropertiesCallback, | 191 base::Bind(&ShillPropertyHandler::GetPropertiesCallback, |
| 193 AsWeakPtr(), type, path)); | 192 AsWeakPtr(), type, path)); |
| 194 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { | 193 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
| 195 DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties( | 194 DBusThreadManager::Get()->GetShillDeviceClient()->GetProperties( |
| 196 dbus::ObjectPath(path), | 195 dbus::ObjectPath(path), |
| 197 base::Bind(&ShillPropertyHandler::GetPropertiesCallback, | 196 base::Bind(&ShillPropertyHandler::GetPropertiesCallback, |
| 198 AsWeakPtr(), type, path)); | 197 AsWeakPtr(), type, path)); |
| 199 } else { | 198 } else { |
| 200 NOTREACHED(); | 199 NOTREACHED(); |
| 201 } | 200 } |
| 202 } | 201 } |
| 203 | 202 |
| 204 void ShillPropertyHandler::OnPropertyChanged(const std::string& key, | 203 void ShillPropertyHandler::OnPropertyChanged(const std::string& key, |
| 205 const base::Value& value) { | 204 const base::Value& value) { |
| 206 if (ManagerPropertyChanged(key, value)) | 205 if (ManagerPropertyChanged(key, value)) { |
| 207 listener_->ManagerPropertyChanged(); | 206 std::string detail = key; |
| 207 std::string vstr; | |
| 208 base::JSONWriter::Write(&value, &vstr); | |
| 209 if (!vstr.empty()) | |
|
pneubeck (no reviews)
2013/05/16 08:21:07
same here.
stevenjb
2013/05/16 17:09:53
ditto
| |
| 210 detail += " = " + vstr; | |
| 211 NET_LOG_DEBUG("ManagerPropertyChanged", detail); | |
| 212 listener_->NotifyManagerPropertyChanged(); | |
| 213 } | |
| 208 // If the service or device list changed and there are no pending | 214 // If the service or device list changed and there are no pending |
| 209 // updates, signal the state list changed callback. | 215 // updates, signal the state list changed callback. |
| 210 if ((key == flimflam::kServicesProperty) && | 216 if ((key == flimflam::kServicesProperty) && |
| 211 pending_updates_[ManagedState::MANAGED_TYPE_NETWORK].size() == 0) { | 217 pending_updates_[ManagedState::MANAGED_TYPE_NETWORK].size() == 0) { |
| 212 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_NETWORK); | 218 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_NETWORK); |
| 213 } | 219 } |
| 214 if (key == flimflam::kDevicesProperty && | 220 if (key == flimflam::kDevicesProperty && |
| 215 pending_updates_[ManagedState::MANAGED_TYPE_DEVICE].size() == 0) { | 221 pending_updates_[ManagedState::MANAGED_TYPE_DEVICE].size() == 0) { |
| 216 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_DEVICE); | 222 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_DEVICE); |
| 217 } | 223 } |
| 218 } | 224 } |
| 219 | 225 |
| 220 //------------------------------------------------------------------------------ | 226 //------------------------------------------------------------------------------ |
| 221 // Private methods | 227 // Private methods |
| 222 | 228 |
| 223 void ShillPropertyHandler::ManagerPropertiesCallback( | 229 void ShillPropertyHandler::ManagerPropertiesCallback( |
| 224 DBusMethodCallStatus call_status, | 230 DBusMethodCallStatus call_status, |
| 225 const base::DictionaryValue& properties) { | 231 const base::DictionaryValue& properties) { |
| 226 if (call_status != DBUS_METHOD_CALL_SUCCESS) { | 232 if (call_status != DBUS_METHOD_CALL_SUCCESS) { |
| 227 LOG(ERROR) << "Failed to get Manager properties:" << call_status; | 233 NET_LOG_ERROR("ManagerPropertiesCallback", |
| 234 base::StringPrintf("Failed: %d", call_status)); | |
| 228 return; | 235 return; |
| 229 } | 236 } |
| 237 NET_LOG_EVENT("ManagerPropertiesCallback", "Success"); | |
| 230 bool notify = false; | 238 bool notify = false; |
| 231 bool update_service_list = false; | 239 bool update_service_list = false; |
| 232 for (base::DictionaryValue::Iterator iter(properties); | 240 for (base::DictionaryValue::Iterator iter(properties); |
| 233 !iter.IsAtEnd(); iter.Advance()) { | 241 !iter.IsAtEnd(); iter.Advance()) { |
| 234 // Defer updating Services until all other properties have been updated. | 242 // Defer updating Services until all other properties have been updated. |
| 235 if (iter.key() == flimflam::kServicesProperty) | 243 if (iter.key() == flimflam::kServicesProperty) |
| 236 update_service_list = true; | 244 update_service_list = true; |
| 237 else | 245 else |
| 238 notify |= ManagerPropertyChanged(iter.key(), iter.value()); | 246 notify |= ManagerPropertyChanged(iter.key(), iter.value()); |
| 239 } | 247 } |
| 240 // Now update the service list which can safely assume other properties have | 248 // Now update the service list which can safely assume other properties have |
| 241 // been initially set. | 249 // been initially set. |
| 242 if (update_service_list) { | 250 if (update_service_list) { |
| 243 const base::Value* value = NULL; | 251 const base::Value* value = NULL; |
| 244 if (properties.GetWithoutPathExpansion(flimflam::kServicesProperty, &value)) | 252 if (properties.GetWithoutPathExpansion(flimflam::kServicesProperty, &value)) |
| 245 notify |= ManagerPropertyChanged(flimflam::kServicesProperty, *value); | 253 notify |= ManagerPropertyChanged(flimflam::kServicesProperty, *value); |
| 246 } | 254 } |
| 247 if (notify) | 255 if (notify) |
| 248 listener_->ManagerPropertyChanged(); | 256 listener_->NotifyManagerPropertyChanged(); |
| 249 // If there are no pending updates, signal the state list changed callbacks. | 257 // If there are no pending updates, signal the state list changed callbacks. |
| 250 if (pending_updates_[ManagedState::MANAGED_TYPE_NETWORK].size() == 0) | 258 if (pending_updates_[ManagedState::MANAGED_TYPE_NETWORK].size() == 0) |
| 251 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_NETWORK); | 259 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_NETWORK); |
| 252 if (pending_updates_[ManagedState::MANAGED_TYPE_DEVICE].size() == 0) | 260 if (pending_updates_[ManagedState::MANAGED_TYPE_DEVICE].size() == 0) |
| 253 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_DEVICE); | 261 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_DEVICE); |
| 254 } | 262 } |
| 255 | 263 |
| 256 bool ShillPropertyHandler::ManagerPropertyChanged(const std::string& key, | 264 bool ShillPropertyHandler::ManagerPropertyChanged(const std::string& key, |
| 257 const base::Value& value) { | 265 const base::Value& value) { |
| 258 bool notify_manager_changed = false; | 266 bool notify_manager_changed = false; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 ShillPropertyObserverMap::iterator iter2 = observer_map.find(path); | 319 ShillPropertyObserverMap::iterator iter2 = observer_map.find(path); |
| 312 if (iter2 != observer_map.end()) { | 320 if (iter2 != observer_map.end()) { |
| 313 new_observed[path] = iter2->second; | 321 new_observed[path] = iter2->second; |
| 314 } else { | 322 } else { |
| 315 // Request an update. | 323 // Request an update. |
| 316 RequestProperties(type, path); | 324 RequestProperties(type, path); |
| 317 // Create an observer for future updates. | 325 // Create an observer for future updates. |
| 318 new_observed[path] = new ShillPropertyObserver( | 326 new_observed[path] = new ShillPropertyObserver( |
| 319 type, path, base::Bind( | 327 type, path, base::Bind( |
| 320 &ShillPropertyHandler::PropertyChangedCallback, AsWeakPtr())); | 328 &ShillPropertyHandler::PropertyChangedCallback, AsWeakPtr())); |
| 321 network_event_log::AddEntry(kLogModule, "StartObserving", path); | 329 NET_LOG_DEBUG("StartObserving", path); |
| 322 } | 330 } |
| 323 observer_map.erase(path); | 331 observer_map.erase(path); |
| 324 // Limit the number of observed services. | 332 // Limit the number of observed services. |
| 325 if (new_observed.size() >= kMaxObserved) | 333 if (new_observed.size() >= kMaxObserved) |
| 326 break; | 334 break; |
| 327 } | 335 } |
| 328 // Delete network service observers still in observer_map. | 336 // Delete network service observers still in observer_map. |
| 329 for (ShillPropertyObserverMap::iterator iter = observer_map.begin(); | 337 for (ShillPropertyObserverMap::iterator iter = observer_map.begin(); |
| 330 iter != observer_map.end(); ++iter) { | 338 iter != observer_map.end(); ++iter) { |
| 331 network_event_log::AddEntry(kLogModule, "StopObserving", iter->first); | 339 NET_LOG_DEBUG("StopObserving", iter->first); |
| 332 delete iter->second; | 340 delete iter->second; |
| 333 } | 341 } |
| 334 observer_map.swap(new_observed); | 342 observer_map.swap(new_observed); |
| 335 } | 343 } |
| 336 | 344 |
| 337 void ShillPropertyHandler::UpdateAvailableTechnologies( | 345 void ShillPropertyHandler::UpdateAvailableTechnologies( |
| 338 const base::ListValue& technologies) { | 346 const base::ListValue& technologies) { |
| 339 available_technologies_.clear(); | 347 available_technologies_.clear(); |
| 340 network_event_log::AddEntry( | 348 NET_LOG_EVENT("AvailableTechnologiesChanged", |
| 341 kLogModule, "AvailableTechnologiesChanged", | 349 base::StringPrintf("Size: %"PRIuS, technologies.GetSize())); |
| 342 base::StringPrintf("Size: %"PRIuS, technologies.GetSize())); | |
| 343 for (base::ListValue::const_iterator iter = technologies.begin(); | 350 for (base::ListValue::const_iterator iter = technologies.begin(); |
| 344 iter != technologies.end(); ++iter) { | 351 iter != technologies.end(); ++iter) { |
| 345 std::string technology; | 352 std::string technology; |
| 346 (*iter)->GetAsString(&technology); | 353 (*iter)->GetAsString(&technology); |
| 347 DCHECK(!technology.empty()); | 354 DCHECK(!technology.empty()); |
| 348 available_technologies_.insert(technology); | 355 available_technologies_.insert(technology); |
| 349 } | 356 } |
| 350 } | 357 } |
| 351 | 358 |
| 352 void ShillPropertyHandler::UpdateEnabledTechnologies( | 359 void ShillPropertyHandler::UpdateEnabledTechnologies( |
| 353 const base::ListValue& technologies) { | 360 const base::ListValue& technologies) { |
| 354 enabled_technologies_.clear(); | 361 enabled_technologies_.clear(); |
| 355 network_event_log::AddEntry( | 362 NET_LOG_EVENT("EnabledTechnologiesChanged", |
| 356 kLogModule, "EnabledTechnologiesChanged", | 363 base::StringPrintf("Size: %"PRIuS, technologies.GetSize())); |
| 357 base::StringPrintf("Size: %"PRIuS, technologies.GetSize())); | |
| 358 for (base::ListValue::const_iterator iter = technologies.begin(); | 364 for (base::ListValue::const_iterator iter = technologies.begin(); |
| 359 iter != technologies.end(); ++iter) { | 365 iter != technologies.end(); ++iter) { |
| 360 std::string technology; | 366 std::string technology; |
| 361 (*iter)->GetAsString(&technology); | 367 (*iter)->GetAsString(&technology); |
| 362 DCHECK(!technology.empty()); | 368 DCHECK(!technology.empty()); |
| 363 enabled_technologies_.insert(technology); | 369 enabled_technologies_.insert(technology); |
| 364 enabling_technologies_.erase(technology); | 370 enabling_technologies_.erase(technology); |
| 365 } | 371 } |
| 366 } | 372 } |
| 367 | 373 |
| 368 void ShillPropertyHandler::UpdateUninitializedTechnologies( | 374 void ShillPropertyHandler::UpdateUninitializedTechnologies( |
| 369 const base::ListValue& technologies) { | 375 const base::ListValue& technologies) { |
| 370 uninitialized_technologies_.clear(); | 376 uninitialized_technologies_.clear(); |
| 371 network_event_log::AddEntry( | 377 NET_LOG_EVENT("UninitializedTechnologiesChanged", |
| 372 kLogModule, "UninitializedTechnologiesChanged", | 378 base::StringPrintf("Size: %"PRIuS, technologies.GetSize())); |
| 373 base::StringPrintf("Size: %"PRIuS, technologies.GetSize())); | |
| 374 for (base::ListValue::const_iterator iter = technologies.begin(); | 379 for (base::ListValue::const_iterator iter = technologies.begin(); |
| 375 iter != technologies.end(); ++iter) { | 380 iter != technologies.end(); ++iter) { |
| 376 std::string technology; | 381 std::string technology; |
| 377 (*iter)->GetAsString(&technology); | 382 (*iter)->GetAsString(&technology); |
| 378 DCHECK(!technology.empty()); | 383 DCHECK(!technology.empty()); |
| 379 uninitialized_technologies_.insert(technology); | 384 uninitialized_technologies_.insert(technology); |
| 380 } | 385 } |
| 381 } | 386 } |
| 382 | 387 |
| 383 void ShillPropertyHandler::EnableTechnologyFailed( | 388 void ShillPropertyHandler::EnableTechnologyFailed( |
| 384 const std::string& technology, | 389 const std::string& technology, |
| 385 const network_handler::ErrorCallback& error_callback, | 390 const network_handler::ErrorCallback& error_callback, |
| 386 const std::string& error_name, | 391 const std::string& error_name, |
| 387 const std::string& error_message) { | 392 const std::string& error_message) { |
| 388 enabling_technologies_.erase(technology); | 393 enabling_technologies_.erase(technology); |
| 389 network_handler::ShillErrorCallbackFunction( | 394 network_handler::ShillErrorCallbackFunction( |
| 390 kLogModule, technology, error_callback, error_name, error_message); | 395 technology, error_callback, error_name, error_message); |
| 391 } | 396 } |
| 392 | 397 |
| 393 void ShillPropertyHandler::GetPropertiesCallback( | 398 void ShillPropertyHandler::GetPropertiesCallback( |
| 394 ManagedState::ManagedType type, | 399 ManagedState::ManagedType type, |
| 395 const std::string& path, | 400 const std::string& path, |
| 396 DBusMethodCallStatus call_status, | 401 DBusMethodCallStatus call_status, |
| 397 const base::DictionaryValue& properties) { | 402 const base::DictionaryValue& properties) { |
| 398 VLOG(2) << "GetPropertiesCallback: " << type << " : " << path; | 403 VLOG(2) << "GetPropertiesCallback: " << type << " : " << path; |
| 399 pending_updates_[type].erase(path); | 404 pending_updates_[type].erase(path); |
| 400 if (call_status != DBUS_METHOD_CALL_SUCCESS) { | 405 if (call_status != DBUS_METHOD_CALL_SUCCESS) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 486 | 491 |
| 487 void ShillPropertyHandler::NetworkDevicePropertyChangedCallback( | 492 void ShillPropertyHandler::NetworkDevicePropertyChangedCallback( |
| 488 const std::string& path, | 493 const std::string& path, |
| 489 const std::string& key, | 494 const std::string& key, |
| 490 const base::Value& value) { | 495 const base::Value& value) { |
| 491 listener_->UpdateDeviceProperty(path, key, value); | 496 listener_->UpdateDeviceProperty(path, key, value); |
| 492 } | 497 } |
| 493 | 498 |
| 494 } // namespace internal | 499 } // namespace internal |
| 495 } // namespace chromeos | 500 } // namespace chromeos |
| OLD | NEW |