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,
DBusThreadManager::Get()->GetShillManagerClient()->GetTestInterface()->
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::kNameProperty, base::Value(name));
properties->SetKey(shill::kDBusObjectProperty, base::Value(device_path));
......@@ -521,21 +521,18 @@ FakeShillDeviceClient::SimLockStatus FakeShillDeviceClient::GetSimLockStatus(
void FakeShillDeviceClient::SetSimLockStatus(const std::string& device_path,
const SimLockStatus& status) {
base::DictionaryValue* device_properties = NULL;
if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path,
&device_properties)) {
base::Value* device_properties =
stub_devices_.FindKeyOfType(device_path, base::Value::Type::DICTIONARY);
if (!device_properties) {
NOTREACHED() << "Device not found: " << device_path;
return;
}
base::DictionaryValue* simlock_dict = nullptr;
if (!device_properties->GetDictionaryWithoutPathExpansion(
shill::kSIMLockStatusProperty, &simlock_dict)) {
simlock_dict = device_properties->SetDictionaryWithoutPathExpansion(
shill::kSIMLockStatusProperty,
std::make_unique<base::DictionaryValue>());
}
simlock_dict->Clear();
base::Value* simlock_dict =
device_properties->SetKey(shill::kSIMLockStatusProperty,
base::Value(base::Value::Type::DICTIONARY));
simlock_dict->SetKey(shill::kSIMLockTypeProperty, base::Value(status.type));
simlock_dict->SetKey(shill::kSIMLockRetriesLeftProperty,
base::Value(status.retries_left));
......@@ -642,15 +639,14 @@ void FakeShillDeviceClient::NotifyObserversPropertyChanged(
observer.OnPropertyChanged(property, *value);
}
base::DictionaryValue* FakeShillDeviceClient::GetDeviceProperties(
base::Value* FakeShillDeviceClient::GetDeviceProperties(
const std::string& device_path) {
base::DictionaryValue* properties = NULL;
if (!stub_devices_.GetDictionaryWithoutPathExpansion(
device_path, &properties)) {
properties = stub_devices_.SetDictionaryWithoutPathExpansion(
device_path, std::make_unique<base::DictionaryValue>());
}
return properties;
base::Value* properties =
stub_devices_.FindKeyOfType(device_path, base::Value::Type::DICTIONARY);
if (properties)
return properties;
return stub_devices_.SetKey(device_path,
base::Value(base::Value::Type::DICTIONARY));
}
FakeShillDeviceClient::PropertyObserverList&
......
......@@ -140,7 +140,7 @@ class CHROMEOS_EXPORT FakeShillDeviceClient
void NotifyObserversPropertyChanged(const dbus::ObjectPath& device_path,
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);
// Dictionary of <device_name, Dictionary>.
......
......@@ -61,12 +61,13 @@ void FakeShillIPConfigClient::SetProperty(const dbus::ObjectPath& ipconfig_path,
const std::string& name,
const base::Value& value,
VoidDBusMethodCallback callback) {
base::DictionaryValue* dict = NULL;
if (!ipconfigs_.GetDictionaryWithoutPathExpansion(ipconfig_path.value(),
&dict)) {
dict = ipconfigs_.SetDictionaryWithoutPathExpansion(
ipconfig_path.value(), std::make_unique<base::DictionaryValue>());
base::Value* dict = ipconfigs_.FindKeyOfType(ipconfig_path.value(),
base::Value::Type::DICTIONARY);
if (!dict) {
dict = ipconfigs_.SetKey(ipconfig_path.value(),
base::Value(base::Value::Type::DICTIONARY));
}
// Update existing ip config stub object's properties.
dict->SetKey(name, value.Clone());
base::ThreadTaskRunnerHandle::Get()->PostTask(
......
......@@ -402,10 +402,8 @@ bool FakeShillServiceClient::SetServiceProperty(const std::string& service_path,
std::string key = property;
if (base::StartsWith(property, "Provider.", case_sensitive))
key = property.substr(strlen("Provider."));
base::DictionaryValue* provider =
new_properties.SetDictionaryWithoutPathExpansion(
shill::kProviderProperty,
std::make_unique<base::DictionaryValue>());
base::Value* provider = new_properties.SetKey(
shill::kProviderProperty, base::Value(base::Value::Type::DICTIONARY));
provider->SetKey(key, value.Clone());
changed_property = shill::kProviderProperty;
} else if (value.GetType() == base::Value::Type::DICTIONARY) {
......
......@@ -186,7 +186,7 @@ void GetClientCertFromShillProperties(
void SetShillProperties(const ConfigType cert_config_type,
const int tpm_slot,
const std::string& pkcs11_id,
base::DictionaryValue* properties) {
base::Value* properties) {
switch (cert_config_type) {
case CONFIG_TYPE_NONE: {
return;
......@@ -224,7 +224,7 @@ void SetShillProperties(const ConfigType cert_config_type,
}
void SetEmptyShillProperties(const ConfigType cert_config_type,
base::DictionaryValue* properties) {
base::Value* properties) {
switch (cert_config_type) {
case CONFIG_TYPE_NONE: {
return;
......
......@@ -14,6 +14,7 @@
#include "components/onc/onc_constants.h"
namespace base {
class Value;
class DictionaryValue;
}
......@@ -91,12 +92,12 @@ CHROMEOS_EXPORT void GetClientCertFromShillProperties(
CHROMEOS_EXPORT void SetShillProperties(const ConfigType cert_config_type,
const int tpm_slot,
const std::string& pkcs11_id,
base::DictionaryValue* properties);
base::Value* properties);
// Like SetShillProperties but instead sets the properties to empty strings.
// This should be used to clear previously set client certificate properties.
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.
bool IsCertificateConfigured(const client_cert::ConfigType cert_config_type,
......
......@@ -123,20 +123,11 @@ bool DeviceState::PropertyChanged(const std::string& key,
return false;
}
void DeviceState::IPConfigPropertiesChanged(
const std::string& ip_config_path,
const base::DictionaryValue& properties) {
base::DictionaryValue* ip_config = nullptr;
if (ip_configs_.GetDictionaryWithoutPathExpansion(
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);
void DeviceState::IPConfigPropertiesChanged(const std::string& ip_config_path,
const base::Value& properties) {
NET_LOG(EVENT) << "IPConfig for: " << path()
<< " Changed: " << ip_config_path;
ip_configs_.SetKey(ip_config_path, properties.Clone());
}
std::string DeviceState::GetName() const {
......
......@@ -28,7 +28,7 @@ class CHROMEOS_EXPORT DeviceState : public ManagedState {
const base::Value& value) override;
void IPConfigPropertiesChanged(const std::string& ip_config_path,
const base::DictionaryValue& properties);
const base::Value& properties);
// Accessors
const std::string& mac_address() const { return mac_address_; }
......
......@@ -433,25 +433,22 @@ void LocalTranslator::TranslateWithTableAndSet(
// results are written to |shill_dictionary|.
void TranslateONCHierarchy(const OncValueSignature& signature,
const base::DictionaryValue& onc_object,
base::DictionaryValue* shill_dictionary) {
base::DictionaryValue* target_shill_dictionary = shill_dictionary;
std::vector<std::string> path_to_shill_dictionary =
base::Value* shill_dictionary) {
const std::vector<std::string> path =
GetPathToNestedShillDictionary(signature);
for (std::vector<std::string>::const_iterator it =
path_to_shill_dictionary.begin();
it != path_to_shill_dictionary.end(); ++it) {
base::DictionaryValue* nested_shill_dict = NULL;
if (!target_shill_dictionary->GetDictionaryWithoutPathExpansion(
*it, &nested_shill_dict)) {
nested_shill_dict =
target_shill_dictionary->SetDictionaryWithoutPathExpansion(
*it, std::make_unique<base::DictionaryValue>());
}
target_shill_dictionary = nested_shill_dict;
const std::vector<base::StringPiece> path_pieces(path.begin(), path.end());
base::Value* target_shill_dictionary = shill_dictionary->FindPathOfType(
path_pieces, base::Value::Type::DICTIONARY);
if (!target_shill_dictionary) {
target_shill_dictionary = shill_dictionary->SetPath(
path_pieces, base::Value(base::Value::Type::DICTIONARY));
}
// Translates fields of |onc_object| and writes them to
// |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();
// Recurse into nested objects.
......
......@@ -731,13 +731,7 @@ void ShillToONCTranslator::SetNestedOncValue(
const std::string& onc_dictionary_name,
const std::string& onc_field_name,
const base::Value& value) {
base::DictionaryValue* nested = nullptr;
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());
onc_object_->SetPath({onc_dictionary_name, onc_field_name}, value.Clone());
}
void ShillToONCTranslator::TranslateAndAddListOfObjects(
......
......@@ -161,22 +161,15 @@ bool IsAutoConnectEnabledInPolicy(const base::DictionaryValue& policy) {
return autoconnect;
}
base::DictionaryValue* GetOrCreateDictionary(const std::string& key,
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,
base::DictionaryValue* dict) {
base::DictionaryValue* inner_dict = GetOrCreateDictionary(key1, dict);
return GetOrCreateDictionary(key2, inner_dict);
base::Value* GetOrCreateNestedDictionary(const std::string& key1,
const std::string& key2,
base::Value* dict) {
base::Value* 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(
......@@ -192,7 +185,7 @@ void ApplyGlobalAutoconnectPolicy(
// Managed dictionaries don't contain empty dictionaries (see onc_merger.cc),
// 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) {
auto_connect_dictionary =
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