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