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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
482 // Only networks with a ProfilePath set are Favorites. | 482 // Only networks with a ProfilePath set are Favorites. |
483 std::string profile_path; | 483 std::string profile_path; |
484 properties.GetStringWithoutPathExpansion( | 484 properties.GetStringWithoutPathExpansion( |
485 shill::kProfileProperty, &profile_path); | 485 shill::kProfileProperty, &profile_path); |
486 if (!profile_path.empty()) { | 486 if (!profile_path.empty()) { |
487 listener_->UpdateManagedStateProperties( | 487 listener_->UpdateManagedStateProperties( |
488 ManagedState::MANAGED_TYPE_FAVORITE, path, properties); | 488 ManagedState::MANAGED_TYPE_FAVORITE, path, properties); |
489 } | 489 } |
490 } | 490 } |
491 listener_->UpdateManagedStateProperties(type, path, properties); | 491 listener_->UpdateManagedStateProperties(type, path, properties); |
492 // Request IPConfig parameters for networks. | 492 |
493 if (type == ManagedState::MANAGED_TYPE_NETWORK && | 493 if (type == ManagedState::MANAGED_TYPE_NETWORK) { |
pneubeck (no reviews)
2014/05/05 21:09:28
you could drop the type conditions (type == Manage
stevenjb
2014/05/06 01:15:11
I would rather have the explicit logic.
| |
494 properties.HasKey(shill::kIPConfigProperty)) { | 494 // Request IPConfig properties. |
495 std::string ip_config_path; | 495 const base::Value* value; |
pneubeck (no reviews)
2014/05/05 21:09:28
initialize with NULL
stevenjb
2014/05/06 01:15:11
Not necessary.
| |
496 if (properties.GetString(shill::kIPConfigProperty, &ip_config_path)) { | 496 if (properties.Get(shill::kIPConfigProperty, &value)) |
pneubeck (no reviews)
2014/05/05 21:09:28
here and below, Get -> GetWithoutPathExpansion
stevenjb
2014/05/06 01:15:11
Done.
| |
497 DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties( | 497 RequestIPConfig(type, path, *value); |
498 dbus::ObjectPath(ip_config_path), | 498 } else if (type == ManagedState::MANAGED_TYPE_DEVICE) { |
499 base::Bind(&ShillPropertyHandler::GetIPConfigCallback, | 499 // Clear and request IPConfig properties for each entry in IPConfigs. |
500 AsWeakPtr(), path)); | 500 const base::Value* value; |
pneubeck (no reviews)
2014/05/05 21:09:28
initialize with NULL
stevenjb
2014/05/06 01:15:11
Not necessary.
| |
501 } | 501 if (properties.Get(shill::kIPConfigsProperty, &value)) |
502 RequestIPConfigsList(type, path, *value); | |
502 } | 503 } |
503 | 504 |
504 // Notify the listener only when all updates for that type have completed. | 505 // Notify the listener only when all updates for that type have completed. |
505 if (pending_updates_[type].size() == 0) { | 506 if (pending_updates_[type].size() == 0) { |
506 listener_->ManagedStateListChanged(type); | 507 listener_->ManagedStateListChanged(type); |
507 // Notify that Favorites have changed when notifying for Networks if there | 508 // Notify that Favorites have changed when notifying for Networks if there |
508 // are no additional Favorite updates pending. | 509 // are no additional Favorite updates pending. |
509 if (type == ManagedState::MANAGED_TYPE_NETWORK && | 510 if (type == ManagedState::MANAGED_TYPE_NETWORK && |
510 pending_updates_[ManagedState::MANAGED_TYPE_FAVORITE].size() == 0) { | 511 pending_updates_[ManagedState::MANAGED_TYPE_FAVORITE].size() == 0) { |
511 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_FAVORITE); | 512 listener_->ManagedStateListChanged(ManagedState::MANAGED_TYPE_FAVORITE); |
512 } | 513 } |
513 } | 514 } |
514 } | 515 } |
515 | 516 |
516 void ShillPropertyHandler::PropertyChangedCallback( | 517 void ShillPropertyHandler::PropertyChangedCallback( |
517 ManagedState::ManagedType type, | 518 ManagedState::ManagedType type, |
518 const std::string& path, | 519 const std::string& path, |
519 const std::string& key, | 520 const std::string& key, |
520 const base::Value& value) { | 521 const base::Value& value) { |
522 if (type == ManagedState::MANAGED_TYPE_NETWORK && | |
pneubeck (no reviews)
2014/05/05 21:09:28
again, checking for |type| not really necessary
stevenjb
2014/05/06 01:15:11
I'd rather be explicit.
| |
523 key == shill::kIPConfigProperty) { | |
524 RequestIPConfig(type, path, value); | |
525 } else if (type == ManagedState::MANAGED_TYPE_DEVICE && | |
526 key == shill::kIPConfigsProperty) { | |
527 RequestIPConfigsList(type, path, value); | |
528 } | |
529 | |
521 if (type == ManagedState::MANAGED_TYPE_NETWORK) | 530 if (type == ManagedState::MANAGED_TYPE_NETWORK) |
522 NetworkServicePropertyChangedCallback(path, key, value); | 531 listener_->UpdateNetworkServiceProperty(path, key, value); |
523 else if (type == ManagedState::MANAGED_TYPE_DEVICE) | 532 else if (type == ManagedState::MANAGED_TYPE_DEVICE) |
524 NetworkDevicePropertyChangedCallback(path, key, value); | 533 listener_->UpdateDeviceProperty(path, key, value); |
525 else | 534 else |
526 NOTREACHED(); | 535 NOTREACHED(); |
527 } | 536 } |
528 | 537 |
529 void ShillPropertyHandler::NetworkServicePropertyChangedCallback( | 538 void ShillPropertyHandler::RequestIPConfig( |
539 ManagedState::ManagedType type, | |
530 const std::string& path, | 540 const std::string& path, |
531 const std::string& key, | |
532 const base::Value& value) { | 541 const base::Value& value) { |
533 if (key == shill::kIPConfigProperty) { | 542 std::string ip_config_path; |
534 // Request the IPConfig for the network and update network properties | 543 value.GetAsString(&ip_config_path); |
535 // when the request completes. | 544 if (ip_config_path.empty()) |
545 return; | |
546 DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties( | |
547 dbus::ObjectPath(ip_config_path), | |
548 base::Bind(&ShillPropertyHandler::GetIPConfigCallback, | |
549 AsWeakPtr(), type, path, ip_config_path)); | |
550 } | |
551 | |
552 void ShillPropertyHandler::RequestIPConfigsList( | |
553 ManagedState::ManagedType type, | |
554 const std::string& path, | |
555 const base::Value& value) { | |
556 const base::ListValue* ip_configs; | |
pneubeck (no reviews)
2014/05/05 21:09:28
initialize with NULL
stevenjb
2014/05/06 01:15:11
Unneeded
| |
557 if (!value.GetAsList(&ip_configs)) | |
558 return; | |
559 for (size_t i = 0; i < ip_configs->GetSize(); i++) { | |
pneubeck (no reviews)
2014/05/05 21:09:28
better use base::ListValue::const_iterator
stevenjb
2014/05/06 01:15:11
Done.
| |
536 std::string ip_config_path; | 560 std::string ip_config_path; |
537 value.GetAsString(&ip_config_path); | 561 if (!ip_configs->GetString(i, &ip_config_path) || ip_config_path.empty()) { |
pneubeck (no reviews)
2014/05/05 21:09:28
should call RequestIPConfig
stevenjb
2014/05/06 01:15:11
I don't follow.
pneubeck (no reviews)
2014/05/06 07:31:17
for (base::ListValue::const_iterator iter...)
Re
stevenjb
2014/05/06 16:56:19
Oh, I see. I guess that's a little more clear. Don
| |
538 DCHECK(!ip_config_path.empty()); | 562 NET_LOG_ERROR("Missing or empty IPConfig in list", path); |
563 continue; | |
564 } | |
539 DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties( | 565 DBusThreadManager::Get()->GetShillIPConfigClient()->GetProperties( |
540 dbus::ObjectPath(ip_config_path), | 566 dbus::ObjectPath(ip_config_path), |
541 base::Bind(&ShillPropertyHandler::GetIPConfigCallback, | 567 base::Bind(&ShillPropertyHandler::GetIPConfigCallback, |
542 AsWeakPtr(), path)); | 568 AsWeakPtr(), type, path, ip_config_path)); |
543 } else { | |
544 listener_->UpdateNetworkServiceProperty(path, key, value); | |
545 } | 569 } |
546 } | 570 } |
547 | 571 |
548 void ShillPropertyHandler::GetIPConfigCallback( | 572 void ShillPropertyHandler::GetIPConfigCallback( |
549 const std::string& service_path, | 573 ManagedState::ManagedType type, |
574 const std::string& path, | |
575 const std::string& ip_config_path, | |
550 DBusMethodCallStatus call_status, | 576 DBusMethodCallStatus call_status, |
551 const base::DictionaryValue& properties) { | 577 const base::DictionaryValue& properties) { |
552 if (call_status != DBUS_METHOD_CALL_SUCCESS) { | 578 if (call_status != DBUS_METHOD_CALL_SUCCESS) { |
553 NET_LOG_ERROR("Failed to get IP Config properties", | 579 NET_LOG_ERROR("Failed to get IP Config properties", |
554 base::StringPrintf("%s: %d", | 580 base::StringPrintf("%s: %d", path.c_str(), call_status)); |
555 service_path.c_str(), call_status)); | |
556 return; | 581 return; |
557 } | 582 } |
558 UpdateIPConfigProperty(service_path, properties, shill::kAddressProperty); | 583 NET_LOG_EVENT("IP Config properties received", path); |
559 UpdateIPConfigProperty(service_path, properties, shill::kNameServersProperty); | 584 listener_->UpdateIPConfigProperites(type, path, ip_config_path, properties); |
560 UpdateIPConfigProperty(service_path, properties, shill::kPrefixlenProperty); | |
561 UpdateIPConfigProperty(service_path, properties, shill::kGatewayProperty); | |
562 UpdateIPConfigProperty(service_path, properties, | |
563 shill::kWebProxyAutoDiscoveryUrlProperty); | |
564 } | |
565 | |
566 void ShillPropertyHandler::UpdateIPConfigProperty( | |
567 const std::string& service_path, | |
568 const base::DictionaryValue& properties, | |
569 const char* property) { | |
570 const base::Value* value; | |
571 if (!properties.GetWithoutPathExpansion(property, &value)) { | |
572 LOG(ERROR) << "Failed to get IPConfig property: " << property | |
573 << ", for: " << service_path; | |
574 return; | |
575 } | |
576 listener_->UpdateNetworkServiceProperty( | |
577 service_path, NetworkState::IPConfigProperty(property), *value); | |
578 } | |
579 | |
580 void ShillPropertyHandler::NetworkDevicePropertyChangedCallback( | |
581 const std::string& path, | |
582 const std::string& key, | |
583 const base::Value& value) { | |
584 listener_->UpdateDeviceProperty(path, key, value); | |
585 } | 585 } |
586 | 586 |
587 } // namespace internal | 587 } // namespace internal |
588 } // namespace chromeos | 588 } // namespace chromeos |
OLD | NEW |