Commit 16f7b1ef authored by jdoerrie's avatar jdoerrie Committed by Commit Bot

Remove SetDictionaryWithoutPathExpansion in //chromeos

This change removes the deprecated SetDictionaryWithoutPathExpansion in
the //chromeos directory and replaces it with the new base::Value API.

Bug: 646113
Change-Id: Ia3be13e49959224db93a1dd67408590af780a98e
Reviewed-on: https://chromium-review.googlesource.com/776656
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517792}
parent 9626a0a7
...@@ -389,7 +389,7 @@ void FakeShillDeviceClient::AddDevice(const std::string& device_path, ...@@ -389,7 +389,7 @@ void FakeShillDeviceClient::AddDevice(const std::string& device_path,
DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()-> DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()->
AddDevice(device_path); AddDevice(device_path);
base::DictionaryValue* properties = GetDeviceProperties(device_path); base::Value* properties = GetDeviceProperties(device_path);
properties->SetKey(shill::kTypeProperty, base::Value(type)); properties->SetKey(shill::kTypeProperty, base::Value(type));
properties->SetKey(shill::kNameProperty, base::Value(name)); properties->SetKey(shill::kNameProperty, base::Value(name));
properties->SetKey(shill::kDBusObjectProperty, base::Value(device_path)); properties->SetKey(shill::kDBusObjectProperty, base::Value(device_path));
...@@ -521,21 +521,18 @@ FakeShillDeviceClient::SimLockStatus FakeShillDeviceClient::GetSimLockStatus( ...@@ -521,21 +521,18 @@ FakeShillDeviceClient::SimLockStatus FakeShillDeviceClient::GetSimLockStatus(
void FakeShillDeviceClient::SetSimLockStatus(const std::string& device_path, void FakeShillDeviceClient::SetSimLockStatus(const std::string& device_path,
const SimLockStatus& status) { const SimLockStatus& status) {
base::DictionaryValue* device_properties = NULL; base::Value* device_properties =
if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path, stub_devices_.FindKeyOfType(device_path, base::Value::Type::DICTIONARY);
&device_properties)) {
if (!device_properties) {
NOTREACHED() << "Device not found: " << device_path; NOTREACHED() << "Device not found: " << device_path;
return; return;
} }
base::DictionaryValue* simlock_dict = nullptr; base::Value* simlock_dict =
if (!device_properties->GetDictionaryWithoutPathExpansion( device_properties->SetKey(shill::kSIMLockStatusProperty,
shill::kSIMLockStatusProperty, &simlock_dict)) { base::Value(base::Value::Type::DICTIONARY));
simlock_dict = device_properties->SetDictionaryWithoutPathExpansion(
shill::kSIMLockStatusProperty,
std::make_unique<base::DictionaryValue>());
}
simlock_dict->Clear();
simlock_dict->SetKey(shill::kSIMLockTypeProperty, base::Value(status.type)); simlock_dict->SetKey(shill::kSIMLockTypeProperty, base::Value(status.type));
simlock_dict->SetKey(shill::kSIMLockRetriesLeftProperty, simlock_dict->SetKey(shill::kSIMLockRetriesLeftProperty,
base::Value(status.retries_left)); base::Value(status.retries_left));
...@@ -642,15 +639,14 @@ void FakeShillDeviceClient::NotifyObserversPropertyChanged( ...@@ -642,15 +639,14 @@ void FakeShillDeviceClient::NotifyObserversPropertyChanged(
observer.OnPropertyChanged(property, *value); observer.OnPropertyChanged(property, *value);
} }
base::DictionaryValue* FakeShillDeviceClient::GetDeviceProperties( base::Value* FakeShillDeviceClient::GetDeviceProperties(
const std::string& device_path) { const std::string& device_path) {
base::DictionaryValue* properties = NULL; base::Value* properties =
if (!stub_devices_.GetDictionaryWithoutPathExpansion( stub_devices_.FindKeyOfType(device_path, base::Value::Type::DICTIONARY);
device_path, &properties)) { if (properties)
properties = stub_devices_.SetDictionaryWithoutPathExpansion(
device_path, std::make_unique<base::DictionaryValue>());
}
return properties; return properties;
return stub_devices_.SetKey(device_path,
base::Value(base::Value::Type::DICTIONARY));
} }
FakeShillDeviceClient::PropertyObserverList& FakeShillDeviceClient::PropertyObserverList&
......
...@@ -140,7 +140,7 @@ class CHROMEOS_EXPORT FakeShillDeviceClient ...@@ -140,7 +140,7 @@ class CHROMEOS_EXPORT FakeShillDeviceClient
void NotifyObserversPropertyChanged(const dbus::ObjectPath& device_path, void NotifyObserversPropertyChanged(const dbus::ObjectPath& device_path,
const std::string& property); const std::string& property);
base::DictionaryValue* GetDeviceProperties(const std::string& device_path); base::Value* GetDeviceProperties(const std::string& device_path);
PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path); PropertyObserverList& GetObserverList(const dbus::ObjectPath& device_path);
// Dictionary of <device_name, Dictionary>. // Dictionary of <device_name, Dictionary>.
......
...@@ -61,12 +61,13 @@ void FakeShillIPConfigClient::SetProperty(const dbus::ObjectPath& ipconfig_path, ...@@ -61,12 +61,13 @@ void FakeShillIPConfigClient::SetProperty(const dbus::ObjectPath& ipconfig_path,
const std::string& name, const std::string& name,
const base::Value& value, const base::Value& value,
VoidDBusMethodCallback callback) { VoidDBusMethodCallback callback) {
base::DictionaryValue* dict = NULL; base::Value* dict = ipconfigs_.FindKeyOfType(ipconfig_path.value(),
if (!ipconfigs_.GetDictionaryWithoutPathExpansion(ipconfig_path.value(), base::Value::Type::DICTIONARY);
&dict)) { if (!dict) {
dict = ipconfigs_.SetDictionaryWithoutPathExpansion( dict = ipconfigs_.SetKey(ipconfig_path.value(),
ipconfig_path.value(), std::make_unique<base::DictionaryValue>()); base::Value(base::Value::Type::DICTIONARY));
} }
// Update existing ip config stub object's properties. // Update existing ip config stub object's properties.
dict->SetKey(name, value.Clone()); dict->SetKey(name, value.Clone());
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
......
...@@ -402,10 +402,8 @@ bool FakeShillServiceClient::SetServiceProperty(const std::string& service_path, ...@@ -402,10 +402,8 @@ bool FakeShillServiceClient::SetServiceProperty(const std::string& service_path,
std::string key = property; std::string key = property;
if (base::StartsWith(property, "Provider.", case_sensitive)) if (base::StartsWith(property, "Provider.", case_sensitive))
key = property.substr(strlen("Provider.")); key = property.substr(strlen("Provider."));
base::DictionaryValue* provider = base::Value* provider = new_properties.SetKey(
new_properties.SetDictionaryWithoutPathExpansion( shill::kProviderProperty, base::Value(base::Value::Type::DICTIONARY));
shill::kProviderProperty,
std::make_unique<base::DictionaryValue>());
provider->SetKey(key, value.Clone()); provider->SetKey(key, value.Clone());
changed_property = shill::kProviderProperty; changed_property = shill::kProviderProperty;
} else if (value.GetType() == base::Value::Type::DICTIONARY) { } else if (value.GetType() == base::Value::Type::DICTIONARY) {
......
...@@ -186,7 +186,7 @@ void GetClientCertFromShillProperties( ...@@ -186,7 +186,7 @@ void GetClientCertFromShillProperties(
void SetShillProperties(const ConfigType cert_config_type, void SetShillProperties(const ConfigType cert_config_type,
const int tpm_slot, const int tpm_slot,
const std::string& pkcs11_id, const std::string& pkcs11_id,
base::DictionaryValue* properties) { base::Value* properties) {
switch (cert_config_type) { switch (cert_config_type) {
case CONFIG_TYPE_NONE: { case CONFIG_TYPE_NONE: {
return; return;
...@@ -224,7 +224,7 @@ void SetShillProperties(const ConfigType cert_config_type, ...@@ -224,7 +224,7 @@ void SetShillProperties(const ConfigType cert_config_type,
} }
void SetEmptyShillProperties(const ConfigType cert_config_type, void SetEmptyShillProperties(const ConfigType cert_config_type,
base::DictionaryValue* properties) { base::Value* properties) {
switch (cert_config_type) { switch (cert_config_type) {
case CONFIG_TYPE_NONE: { case CONFIG_TYPE_NONE: {
return; return;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/onc/onc_constants.h" #include "components/onc/onc_constants.h"
namespace base { namespace base {
class Value;
class DictionaryValue; class DictionaryValue;
} }
...@@ -91,12 +92,12 @@ CHROMEOS_EXPORT void GetClientCertFromShillProperties( ...@@ -91,12 +92,12 @@ CHROMEOS_EXPORT void GetClientCertFromShillProperties(
CHROMEOS_EXPORT void SetShillProperties(const ConfigType cert_config_type, CHROMEOS_EXPORT void SetShillProperties(const ConfigType cert_config_type,
const int tpm_slot, const int tpm_slot,
const std::string& pkcs11_id, const std::string& pkcs11_id,
base::DictionaryValue* properties); base::Value* properties);
// Like SetShillProperties but instead sets the properties to empty strings. // Like SetShillProperties but instead sets the properties to empty strings.
// This should be used to clear previously set client certificate properties. // This should be used to clear previously set client certificate properties.
CHROMEOS_EXPORT void SetEmptyShillProperties(const ConfigType cert_config_type, CHROMEOS_EXPORT void SetEmptyShillProperties(const ConfigType cert_config_type,
base::DictionaryValue* properties); base::Value* properties);
// Returns true if all required configuration properties are set and not empty. // Returns true if all required configuration properties are set and not empty.
bool IsCertificateConfigured(const client_cert::ConfigType cert_config_type, bool IsCertificateConfigured(const client_cert::ConfigType cert_config_type,
......
...@@ -123,20 +123,11 @@ bool DeviceState::PropertyChanged(const std::string& key, ...@@ -123,20 +123,11 @@ bool DeviceState::PropertyChanged(const std::string& key,
return false; return false;
} }
void DeviceState::IPConfigPropertiesChanged( void DeviceState::IPConfigPropertiesChanged(const std::string& ip_config_path,
const std::string& ip_config_path, const base::Value& properties) {
const base::DictionaryValue& properties) { NET_LOG(EVENT) << "IPConfig for: " << path()
base::DictionaryValue* ip_config = nullptr; << " Changed: " << ip_config_path;
if (ip_configs_.GetDictionaryWithoutPathExpansion( ip_configs_.SetKey(ip_config_path, properties.Clone());
ip_config_path, &ip_config)) {
NET_LOG_EVENT("IPConfig Updated: " + ip_config_path, path());
ip_config->Clear();
} else {
NET_LOG_EVENT("IPConfig Added: " + ip_config_path, path());
ip_config = ip_configs_.SetDictionaryWithoutPathExpansion(
ip_config_path, std::make_unique<base::DictionaryValue>());
}
ip_config->MergeDictionary(&properties);
} }
std::string DeviceState::GetName() const { std::string DeviceState::GetName() const {
......
...@@ -28,7 +28,7 @@ class CHROMEOS_EXPORT DeviceState : public ManagedState { ...@@ -28,7 +28,7 @@ class CHROMEOS_EXPORT DeviceState : public ManagedState {
const base::Value& value) override; const base::Value& value) override;
void IPConfigPropertiesChanged(const std::string& ip_config_path, void IPConfigPropertiesChanged(const std::string& ip_config_path,
const base::DictionaryValue& properties); const base::Value& properties);
// Accessors // Accessors
const std::string& mac_address() const { return mac_address_; } const std::string& mac_address() const { return mac_address_; }
......
...@@ -433,25 +433,22 @@ void LocalTranslator::TranslateWithTableAndSet( ...@@ -433,25 +433,22 @@ void LocalTranslator::TranslateWithTableAndSet(
// results are written to |shill_dictionary|. // results are written to |shill_dictionary|.
void TranslateONCHierarchy(const OncValueSignature& signature, void TranslateONCHierarchy(const OncValueSignature& signature,
const base::DictionaryValue& onc_object, const base::DictionaryValue& onc_object,
base::DictionaryValue* shill_dictionary) { base::Value* shill_dictionary) {
base::DictionaryValue* target_shill_dictionary = shill_dictionary; const std::vector<std::string> path =
std::vector<std::string> path_to_shill_dictionary =
GetPathToNestedShillDictionary(signature); GetPathToNestedShillDictionary(signature);
for (std::vector<std::string>::const_iterator it = const std::vector<base::StringPiece> path_pieces(path.begin(), path.end());
path_to_shill_dictionary.begin(); base::Value* target_shill_dictionary = shill_dictionary->FindPathOfType(
it != path_to_shill_dictionary.end(); ++it) { path_pieces, base::Value::Type::DICTIONARY);
base::DictionaryValue* nested_shill_dict = NULL; if (!target_shill_dictionary) {
if (!target_shill_dictionary->GetDictionaryWithoutPathExpansion( target_shill_dictionary = shill_dictionary->SetPath(
*it, &nested_shill_dict)) { path_pieces, base::Value(base::Value::Type::DICTIONARY));
nested_shill_dict =
target_shill_dictionary->SetDictionaryWithoutPathExpansion(
*it, std::make_unique<base::DictionaryValue>());
}
target_shill_dictionary = nested_shill_dict;
} }
// Translates fields of |onc_object| and writes them to // Translates fields of |onc_object| and writes them to
// |target_shill_dictionary_| nested in |shill_dictionary|. // |target_shill_dictionary_| nested in |shill_dictionary|.
LocalTranslator translator(signature, onc_object, target_shill_dictionary); LocalTranslator translator(
signature, onc_object,
static_cast<base::DictionaryValue*>(target_shill_dictionary));
translator.TranslateFields(); translator.TranslateFields();
// Recurse into nested objects. // Recurse into nested objects.
......
...@@ -731,13 +731,7 @@ void ShillToONCTranslator::SetNestedOncValue( ...@@ -731,13 +731,7 @@ void ShillToONCTranslator::SetNestedOncValue(
const std::string& onc_dictionary_name, const std::string& onc_dictionary_name,
const std::string& onc_field_name, const std::string& onc_field_name,
const base::Value& value) { const base::Value& value) {
base::DictionaryValue* nested = nullptr; onc_object_->SetPath({onc_dictionary_name, onc_field_name}, value.Clone());
if (!onc_object_->GetDictionaryWithoutPathExpansion(onc_dictionary_name,
&nested)) {
nested = onc_object_->SetDictionaryWithoutPathExpansion(
onc_dictionary_name, std::make_unique<base::DictionaryValue>());
}
nested->SetKey(onc_field_name, value.Clone());
} }
void ShillToONCTranslator::TranslateAndAddListOfObjects( void ShillToONCTranslator::TranslateAndAddListOfObjects(
......
...@@ -161,22 +161,15 @@ bool IsAutoConnectEnabledInPolicy(const base::DictionaryValue& policy) { ...@@ -161,22 +161,15 @@ bool IsAutoConnectEnabledInPolicy(const base::DictionaryValue& policy) {
return autoconnect; return autoconnect;
} }
base::DictionaryValue* GetOrCreateDictionary(const std::string& key, base::Value* GetOrCreateNestedDictionary(const std::string& key1,
base::DictionaryValue* dict) {
base::DictionaryValue* inner_dict = NULL;
if (!dict->GetDictionaryWithoutPathExpansion(key, &inner_dict)) {
inner_dict = dict->SetDictionaryWithoutPathExpansion(
key, std::make_unique<base::DictionaryValue>());
}
return inner_dict;
}
base::DictionaryValue* GetOrCreateNestedDictionary(
const std::string& key1,
const std::string& key2, const std::string& key2,
base::DictionaryValue* dict) { base::Value* dict) {
base::DictionaryValue* inner_dict = GetOrCreateDictionary(key1, dict); base::Value* inner_dict =
return GetOrCreateDictionary(key2, inner_dict); dict->FindPathOfType({key1, key2}, base::Value::Type::DICTIONARY);
if (inner_dict)
return inner_dict;
return dict->SetPath({key1, key2},
base::Value(base::Value::Type::DICTIONARY));
} }
void ApplyGlobalAutoconnectPolicy( void ApplyGlobalAutoconnectPolicy(
...@@ -192,7 +185,7 @@ void ApplyGlobalAutoconnectPolicy( ...@@ -192,7 +185,7 @@ void ApplyGlobalAutoconnectPolicy(
// Managed dictionaries don't contain empty dictionaries (see onc_merger.cc), // Managed dictionaries don't contain empty dictionaries (see onc_merger.cc),
// so add the Autoconnect dictionary in case Shill didn't report a value. // so add the Autoconnect dictionary in case Shill didn't report a value.
base::DictionaryValue* auto_connect_dictionary = NULL; base::Value* auto_connect_dictionary = nullptr;
if (type == ::onc::network_type::kWiFi) { if (type == ::onc::network_type::kWiFi) {
auto_connect_dictionary = auto_connect_dictionary =
GetOrCreateNestedDictionary(::onc::network_config::kWiFi, GetOrCreateNestedDictionary(::onc::network_config::kWiFi,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment