Index: chromeos/network/managed_network_configuration_handler_impl.cc |
diff --git a/chromeos/network/managed_network_configuration_handler_impl.cc b/chromeos/network/managed_network_configuration_handler_impl.cc |
index f233147e2d720d7143361437edeee75c4465354b..5415a7608b1104083231745fc4fe0201f31fa9eb 100644 |
--- a/chromeos/network/managed_network_configuration_handler_impl.cc |
+++ b/chromeos/network/managed_network_configuration_handler_impl.cc |
@@ -18,6 +18,7 @@ |
#include "chromeos/dbus/shill_manager_client.h" |
#include "chromeos/dbus/shill_profile_client.h" |
#include "chromeos/dbus/shill_service_client.h" |
+#include "chromeos/network/device_state.h" |
#include "chromeos/network/network_configuration_handler.h" |
#include "chromeos/network/network_event_log.h" |
#include "chromeos/network/network_policy_observer.h" |
@@ -83,17 +84,6 @@ const base::DictionaryValue* GetByGUID(const GuidToPolicyMap& policies, |
return it->second; |
} |
-void TranslatePropertiesToOncAndRunCallback( |
- const network_handler::DictionaryResultCallback& callback, |
- const std::string& service_path, |
- const base::DictionaryValue& shill_properties) { |
- scoped_ptr<base::DictionaryValue> onc_network( |
- onc::TranslateShillServiceToONCPart( |
- shill_properties, |
- &onc::kNetworkWithStateSignature)); |
- callback.Run(service_path, *onc_network); |
-} |
- |
} // namespace |
struct ManagedNetworkConfigurationHandlerImpl::Policies { |
@@ -169,9 +159,14 @@ void ManagedNetworkConfigurationHandlerImpl::GetManagedPropertiesCallback( |
// properties _might_ be user configured. |
} |
+ scoped_ptr<base::DictionaryValue> properties_copy( |
+ shill_properties.DeepCopy()); |
+ // Add the IPConfigs to the dictionary before the ONC translation. |
+ GetIPConfigs(service_path, properties_copy.get()); |
+ |
scoped_ptr<base::DictionaryValue> active_settings( |
onc::TranslateShillServiceToONCPart( |
- shill_properties, |
+ *properties_copy, |
&onc::kNetworkWithStateSignature)); |
std::string guid; |
@@ -212,13 +207,31 @@ void ManagedNetworkConfigurationHandlerImpl::GetManagedPropertiesCallback( |
void ManagedNetworkConfigurationHandlerImpl::GetProperties( |
const std::string& service_path, |
const network_handler::DictionaryResultCallback& callback, |
- const network_handler::ErrorCallback& error_callback) const { |
+ const network_handler::ErrorCallback& error_callback) { |
network_configuration_handler_->GetProperties( |
service_path, |
- base::Bind(&TranslatePropertiesToOncAndRunCallback, callback), |
+ base::Bind(&ManagedNetworkConfigurationHandlerImpl::GetPropertiesCallback, |
+ weak_ptr_factory_.GetWeakPtr(), |
+ callback), |
error_callback); |
} |
+void ManagedNetworkConfigurationHandlerImpl::GetPropertiesCallback( |
+ const network_handler::DictionaryResultCallback& callback, |
+ const std::string& service_path, |
+ const base::DictionaryValue& shill_properties) { |
+ scoped_ptr<base::DictionaryValue> properties_copy( |
+ shill_properties.DeepCopy()); |
+ // Add the IPConfigs to the dictionary before the ONC translation. |
+ GetIPConfigs(service_path, properties_copy.get()); |
+ |
+ scoped_ptr<base::DictionaryValue> onc_network( |
+ onc::TranslateShillServiceToONCPart( |
+ *properties_copy, |
+ &onc::kNetworkWithStateSignature)); |
+ callback.Run(service_path, *onc_network); |
+} |
+ |
void ManagedNetworkConfigurationHandlerImpl::SetProperties( |
const std::string& service_path, |
const base::DictionaryValue& user_settings, |
@@ -596,4 +609,34 @@ void ManagedNetworkConfigurationHandlerImpl::OnPolicyAppliedToNetwork( |
NetworkPolicyObserver, observers_, PolicyApplied(service_path)); |
} |
+void ManagedNetworkConfigurationHandlerImpl::GetIPConfigs( |
+ const std::string& service_path, |
+ base::DictionaryValue* properties) { |
+ std::string connection_state; |
+ properties->GetStringWithoutPathExpansion( |
+ shill::kStateProperty, &connection_state); |
+ if (!NetworkState::StateIsConnected(connection_state)) |
+ return; |
+ |
+ // Get the IPConfig properties from the device and store them in "IPConfigs" |
+ // (plural) in the properties dictionary. (Note: Shill only provides a single |
+ // "IPConfig" property for a network service, but a consumer of this API may |
+ // want information about all ipv4 and ipv6 IPConfig properties. |
+ std::string device; |
+ properties->GetStringWithoutPathExpansion(shill::kDeviceProperty, &device); |
+ const DeviceState* device_state = |
+ network_state_handler_->GetDeviceState(device); |
+ if (!device_state) { |
+ NET_LOG_ERROR("GetIPConfigs: no device: " + device, service_path); |
+ return; |
+ } |
+ // Convert IPConfig dictionary to a ListValue. |
+ base::ListValue* ip_configs = new base::ListValue; |
+ for (base::DictionaryValue::Iterator iter(device_state->ip_configs()); |
+ !iter.IsAtEnd(); iter.Advance()) { |
+ ip_configs->Append(iter.value().DeepCopy()); |
+ } |
+ properties->SetWithoutPathExpansion(shill::kIPConfigsProperty, ip_configs); |
+} |
+ |
} // namespace chromeos |