Commit 850eab05 authored by Anand K. Mistry's avatar Anand K. Mistry Committed by Commit Bot

Convert base::Value usage in ShillClientHelper::DictionaryValueCallback functions to new style

This only changes the base::Value API usage to the new style, and avoids
changing functions signatures, except for private helper functions.

Bug: 646113
Change-Id: I5dcd6d5c7df7dd185f7fc84d4563da82394fca9f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2089438
Commit-Queue: Anand Mistry <amistry@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#749038}
parent 15b31343
......@@ -658,14 +658,15 @@ bool FakeShillDeviceClient::SimTryPuk(const std::string& device_path,
void FakeShillDeviceClient::PassStubDeviceProperties(
const dbus::ObjectPath& device_path,
DictionaryValueCallback callback) const {
const base::DictionaryValue* device_properties = nullptr;
if (!stub_devices_.GetDictionaryWithoutPathExpansion(device_path.value(),
&device_properties)) {
const base::Value* device_properties =
stub_devices_.FindDictKey(device_path.value());
if (!device_properties) {
base::DictionaryValue empty_dictionary;
std::move(callback).Run(DBUS_METHOD_CALL_FAILURE, empty_dictionary);
return;
}
std::move(callback).Run(DBUS_METHOD_CALL_SUCCESS, *device_properties);
std::move(callback).Run(DBUS_METHOD_CALL_SUCCESS,
base::Value::AsDictionaryValue(*device_properties));
}
// Posts a task to run a void callback with status code |status|.
......
......@@ -38,14 +38,14 @@ void FakeShillIPConfigClient::RemovePropertyChangedObserver(
void FakeShillIPConfigClient::GetProperties(
const dbus::ObjectPath& ipconfig_path,
DictionaryValueCallback callback) {
const base::DictionaryValue* dict = nullptr;
if (!ipconfigs_.GetDictionaryWithoutPathExpansion(ipconfig_path.value(),
&dict))
const base::Value* dict = ipconfigs_.FindDictKey(ipconfig_path.value());
if (!dict)
return;
std::unique_ptr<base::DictionaryValue> dict_copy =
base::DictionaryValue::From(dict->CreateDeepCopy());
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&FakeShillIPConfigClient::PassProperties,
weak_ptr_factory_.GetWeakPtr(), dict,
std::move(callback)));
FROM_HERE, base::BindOnce(std::move(callback), DBUS_METHOD_CALL_SUCCESS,
std::move(*dict_copy)));
}
void FakeShillIPConfigClient::SetProperty(const dbus::ObjectPath& ipconfig_path,
......@@ -92,12 +92,4 @@ void FakeShillIPConfigClient::AddIPConfig(
ipconfigs_.SetKey(ip_config_path, properties.Clone());
}
// Private methods
void FakeShillIPConfigClient::PassProperties(
const base::DictionaryValue* values,
DictionaryValueCallback callback) const {
std::move(callback).Run(DBUS_METHOD_CALL_SUCCESS, *values);
}
} // namespace chromeos
......@@ -46,10 +46,6 @@ class COMPONENT_EXPORT(SHILL_CLIENT) FakeShillIPConfigClient
const base::DictionaryValue& properties) override;
private:
// Runs callback with |values|.
void PassProperties(const base::DictionaryValue* values,
DictionaryValueCallback callback) const;
// Dictionary of <ipconfig_path, property dictionaries>
base::DictionaryValue ipconfigs_;
......
......@@ -1015,12 +1015,12 @@ void FakeShillManagerClient::SetupDefaultEnvironment() {
void FakeShillManagerClient::PassStubProperties(
DictionaryValueCallback callback) const {
std::unique_ptr<base::DictionaryValue> stub_properties(
stub_properties_.DeepCopy());
stub_properties->SetWithoutPathExpansion(
base::Value stub_properties = stub_properties_.Clone();
stub_properties.SetKey(
shill::kServiceCompleteListProperty,
GetEnabledServiceList(shill::kServiceCompleteListProperty));
std::move(callback).Run(DBUS_METHOD_CALL_SUCCESS, *stub_properties);
std::move(callback).Run(DBUS_METHOD_CALL_SUCCESS,
base::Value::AsDictionaryValue(stub_properties));
}
void FakeShillManagerClient::PassStubGeoNetworks(
......@@ -1049,9 +1049,9 @@ void FakeShillManagerClient::NotifyObserversPropertyChanged(
return;
}
if (property == shill::kServiceCompleteListProperty) {
std::unique_ptr<base::ListValue> services(GetEnabledServiceList(property));
base::Value services = GetEnabledServiceList(property);
for (auto& observer : observer_list_)
observer.OnPropertyChanged(property, *(services.get()));
observer.OnPropertyChanged(property, services);
return;
}
for (auto& observer : observer_list_)
......@@ -1100,9 +1100,9 @@ void FakeShillManagerClient::SetTechnologyEnabled(const std::string& type,
SortManagerServices(true);
}
std::unique_ptr<base::ListValue> FakeShillManagerClient::GetEnabledServiceList(
base::Value FakeShillManagerClient::GetEnabledServiceList(
const std::string& property) const {
auto new_service_list = std::make_unique<base::ListValue>();
base::Value new_service_list(base::Value::Type::LIST);
const base::ListValue* service_list;
if (stub_properties_.GetListWithoutPathExpansion(property, &service_list)) {
ShillServiceClient::TestInterface* service_client =
......@@ -1121,7 +1121,7 @@ std::unique_ptr<base::ListValue> FakeShillManagerClient::GetEnabledServiceList(
std::string type;
properties->GetString(shill::kTypeProperty, &type);
if (TechnologyEnabled(type))
new_service_list->Append(iter->CreateDeepCopy());
new_service_list.Append(iter->Clone());
}
}
return new_service_list;
......
......@@ -109,8 +109,7 @@ class COMPONENT_EXPORT(SHILL_CLIENT) FakeShillManagerClient
void SetTechnologyEnabled(const std::string& type,
base::OnceClosure callback,
bool enabled);
std::unique_ptr<base::ListValue> GetEnabledServiceList(
const std::string& property) const;
base::Value GetEnabledServiceList(const std::string& property) const;
void ScanCompleted(const std::string& device_path);
// Parses the command line for Shill stub switches and sets initial states.
......
......@@ -30,16 +30,6 @@ struct FakeShillProfileClient::ProfileProperties {
base::DictionaryValue properties; // Dictionary of Profile properties
};
namespace {
void PassDictionary(
ShillProfileClient::DictionaryValueCallbackWithoutStatus callback,
const base::DictionaryValue* dictionary) {
std::move(callback).Run(*dictionary);
}
} // namespace
FakeShillProfileClient::FakeShillProfileClient() = default;
FakeShillProfileClient::~FakeShillProfileClient() = default;
......@@ -62,20 +52,17 @@ void FakeShillProfileClient::GetProperties(
return;
}
auto entry_paths = std::make_unique<base::ListValue>();
for (base::DictionaryValue::Iterator it(profile->entries); !it.IsAtEnd();
it.Advance()) {
entry_paths->AppendString(it.key());
base::Value entry_paths(base::Value::Type::LIST);
for (const auto& it : profile->entries.DictItems()) {
entry_paths.Append(it.first);
}
std::unique_ptr<base::DictionaryValue> properties =
profile->properties.CreateDeepCopy();
properties->SetWithoutPathExpansion(shill::kEntriesProperty,
std::move(entry_paths));
properties->SetKey(shill::kEntriesProperty, std::move(entry_paths));
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&PassDictionary, std::move(callback),
base::Owned(properties.release())));
FROM_HERE, base::BindOnce(std::move(callback), std::move(*properties)));
}
void FakeShillProfileClient::GetEntry(
......@@ -89,17 +76,17 @@ void FakeShillProfileClient::GetEntry(
return;
}
base::DictionaryValue* entry = nullptr;
profile->entries.GetDictionaryWithoutPathExpansion(entry_path, &entry);
const base::Value* entry = profile->entries.FindDictKey(entry_path);
if (!entry) {
std::move(error_callback)
.Run("Error.InvalidProfileEntry", "Invalid profile entry");
return;
}
std::unique_ptr<base::DictionaryValue> entry_copy =
base::DictionaryValue::From(entry->CreateDeepCopy());
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&PassDictionary, std::move(callback),
base::Owned(entry->DeepCopy())));
FROM_HERE, base::BindOnce(std::move(callback), std::move(*entry_copy)));
}
void FakeShillProfileClient::DeleteEntry(const dbus::ObjectPath& profile_path,
......
......@@ -30,13 +30,6 @@ namespace chromeos {
namespace {
void PassStubServiceProperties(
ShillServiceClient::DictionaryValueCallback callback,
DBusMethodCallStatus call_status,
const base::DictionaryValue* properties) {
std::move(callback).Run(call_status, *properties);
}
void CallSortManagerServices() {
ShillManagerClient::Get()->GetTestInterface()->SortManagerServices(true);
}
......@@ -166,26 +159,23 @@ void FakeShillServiceClient::RemovePropertyChangedObserver(
void FakeShillServiceClient::GetProperties(const dbus::ObjectPath& service_path,
DictionaryValueCallback callback) {
base::DictionaryValue* nested_dict = nullptr;
std::unique_ptr<base::DictionaryValue> result_properties;
base::DictionaryValue result_properties;
DBusMethodCallStatus call_status;
stub_services_.GetDictionaryWithoutPathExpansion(service_path.value(),
&nested_dict);
if (nested_dict) {
result_properties.reset(nested_dict->DeepCopy());
result_properties = std::move(*nested_dict->CreateDeepCopy());
// Remove credentials that Shill wouldn't send.
result_properties->RemoveWithoutPathExpansion(shill::kPassphraseProperty,
nullptr);
result_properties.RemoveKey(shill::kPassphraseProperty);
call_status = DBUS_METHOD_CALL_SUCCESS;
} else {
// This may happen if we remove services from the list.
VLOG(2) << "Properties not found for: " << service_path.value();
result_properties.reset(new base::DictionaryValue);
call_status = DBUS_METHOD_CALL_FAILURE;
}
base::OnceClosure property_update =
base::BindOnce(&PassStubServiceProperties, std::move(callback),
call_status, base::Owned(result_properties.release()));
base::OnceClosure property_update = base::BindOnce(
std::move(callback), call_status, std::move(result_properties));
if (hold_back_service_property_updates_)
recorded_property_updates_.push_back(std::move(property_update));
else
......@@ -360,17 +350,14 @@ void FakeShillServiceClient::GetLoadableProfileEntries(
// Provide a dictionary with {profile_path: service_path} entries for
// profile_paths that contain the service.
std::unique_ptr<base::DictionaryValue> result_properties(
new base::DictionaryValue);
base::DictionaryValue result_properties;
for (const auto& profile : profiles) {
result_properties->SetKey(profile, base::Value(service_path.value()));
result_properties.SetKey(profile, base::Value(service_path.value()));
}
DBusMethodCallStatus call_status = DBUS_METHOD_CALL_SUCCESS;
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::BindOnce(&PassStubServiceProperties, std::move(callback),
call_status, base::Owned(result_properties.release())));
FROM_HERE, base::BindOnce(std::move(callback), DBUS_METHOD_CALL_SUCCESS,
std::move(result_properties)));
}
void FakeShillServiceClient::GetWiFiPassphrase(
......
......@@ -137,13 +137,13 @@ void OnDictionaryValueMethod(
}
dbus::MessageReader reader(response);
std::unique_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
base::DictionaryValue* result = NULL;
if (!value.get() || !value->GetAsDictionary(&result)) {
if (!value.get() || !value->is_dict()) {
base::DictionaryValue result;
std::move(callback).Run(DBUS_METHOD_CALL_FAILURE, result);
return;
}
std::move(callback).Run(DBUS_METHOD_CALL_SUCCESS, *result);
std::move(callback).Run(DBUS_METHOD_CALL_SUCCESS,
base::Value::AsDictionaryValue(*value));
}
// Handles responses for methods without results.
......@@ -162,13 +162,12 @@ void OnDictionaryValueMethodWithErrorCallback(
dbus::Response* response) {
dbus::MessageReader reader(response);
std::unique_ptr<base::Value> value(dbus::PopDataAsValue(&reader));
base::DictionaryValue* result = NULL;
if (!value.get() || !value->GetAsDictionary(&result)) {
if (!value.get() || !value->is_dict()) {
std::move(error_callback)
.Run(kInvalidResponseErrorName, kInvalidResponseErrorMessage);
return;
}
std::move(callback).Run(*result);
std::move(callback).Run(base::Value::AsDictionaryValue(*value));
}
// Handles responses for methods with ListValue results.
......
......@@ -24,6 +24,12 @@ std::string HexToDecimal(std::string hex_str) {
return std::to_string(std::stoi(hex_str, nullptr, 16));
}
std::string FindStringOrEmpty(const base::Value& dict,
const base::StringPiece key) {
const std::string* val = dict.FindStringKey(key);
return val ? *val : std::string();
}
} // namespace
GeolocationHandler::GeolocationHandler()
......@@ -92,8 +98,9 @@ void GeolocationHandler::OnPropertyChanged(const std::string& key,
void GeolocationHandler::ManagerPropertiesCallback(
DBusMethodCallStatus call_status,
const base::DictionaryValue& properties) {
const base::Value* value = nullptr;
if (properties.Get(shill::kEnabledTechnologiesProperty, &value) && value)
const base::Value* value =
properties.FindKey(shill::kEnabledTechnologiesProperty);
if (value)
HandlePropertyChanged(shill::kEnabledTechnologiesProperty, *value);
}
......@@ -143,7 +150,7 @@ void GeolocationHandler::GeolocationCallback(
}
wifi_access_points_.clear();
cell_towers_.clear();
if (properties.empty())
if (properties.DictEmpty())
return; // No enabled devices, don't update received time.
// Dictionary<device_type, entry_list>
......@@ -155,22 +162,21 @@ void GeolocationHandler::GeolocationCallback(
// kGeoCellTowersProperty: [ {kGeoCellIdProperty: cell_id_value, ...}, ... ]
// }
for (auto* device_type : kDevicePropertyNames) {
if (!properties.HasKey(device_type)) {
const base::Value* entry_list = properties.FindKey(device_type);
if (!entry_list) {
continue;
}
const base::ListValue* entry_list = nullptr;
if (!properties.GetList(device_type, &entry_list)) {
if (!entry_list->is_list()) {
LOG(WARNING) << "Geolocation dictionary value not a List: "
<< device_type;
continue;
}
// List[Dictionary<key, value_str>]
for (size_t i = 0; i < entry_list->GetSize(); ++i) {
const base::DictionaryValue* entry = nullptr;
if (!entry_list->GetDictionary(i, &entry) || !entry) {
LOG(WARNING) << "Geolocation list value not a Dictionary: " << i;
for (const auto& entry : entry_list->GetList()) {
if (!entry.is_dict()) {
LOG(WARNING) << "Geolocation list value not a Dictionary";
continue;
}
if (device_type == shill::kGeoWifiAccessPointsProperty) {
......@@ -183,68 +189,74 @@ void GeolocationHandler::GeolocationCallback(
geolocation_received_time_ = base::Time::Now();
}
void GeolocationHandler::AddAccessPointFromDict(
const base::DictionaryValue* entry) {
void GeolocationHandler::AddAccessPointFromDict(const base::Value& entry) {
// Docs: developers.google.com/maps/documentation/business/geolocation
WifiAccessPoint wap;
std::string age_str;
if (entry->GetString(shill::kGeoAgeProperty, &age_str)) {
const std::string* age_str = entry.FindStringKey(shill::kGeoAgeProperty);
if (age_str) {
int64_t age_ms;
if (base::StringToInt64(age_str, &age_ms)) {
if (base::StringToInt64(*age_str, &age_ms)) {
wap.timestamp =
base::Time::Now() - base::TimeDelta::FromMilliseconds(age_ms);
}
}
entry->GetString(shill::kGeoMacAddressProperty, &wap.mac_address);
std::string strength_str;
if (entry->GetString(shill::kGeoSignalStrengthProperty, &strength_str))
base::StringToInt(strength_str, &wap.signal_strength);
wap.mac_address = FindStringOrEmpty(entry, shill::kGeoMacAddressProperty);
std::string signal_str;
if (entry->GetString(shill::kGeoSignalToNoiseRatioProperty, &signal_str)) {
base::StringToInt(signal_str, &wap.signal_to_noise);
const std::string* strength_str =
entry.FindStringKey(shill::kGeoSignalStrengthProperty);
if (strength_str) {
base::StringToInt(*strength_str, &wap.signal_strength);
}
std::string channel_str;
if (entry->GetString(shill::kGeoChannelProperty, &channel_str))
base::StringToInt(channel_str, &wap.channel);
const std::string* signal_str =
entry.FindStringKey(shill::kGeoSignalToNoiseRatioProperty);
if (signal_str) {
base::StringToInt(*signal_str, &wap.signal_to_noise);
}
const std::string* channel_str =
entry.FindStringKey(shill::kGeoChannelProperty);
if (channel_str) {
base::StringToInt(*channel_str, &wap.channel);
}
wifi_access_points_.push_back(wap);
}
void GeolocationHandler::AddCellTowerFromDict(
const base::DictionaryValue* entry) {
void GeolocationHandler::AddCellTowerFromDict(const base::Value& entry) {
// Docs: developers.google.com/maps/documentation/business/geolocation
// Create object.
CellTower ct;
// Read time fields into object.
std::string age_str;
if (entry->GetString(shill::kGeoAgeProperty, &age_str)) {
const std::string* age_str = entry.FindStringKey(shill::kGeoAgeProperty);
if (age_str) {
int64_t age_ms;
if (base::StringToInt64(age_str, &age_ms)) {
if (base::StringToInt64(*age_str, &age_ms)) {
ct.timestamp =
base::Time::Now() - base::TimeDelta::FromMilliseconds(age_ms);
}
}
// Read hex fields into object.
std::string hex_cell_id;
if (entry->GetString(shill::kGeoCellIdProperty, &hex_cell_id)) {
ct.ci = HexToDecimal(hex_cell_id);
const std::string* hex_cell_id =
entry.FindStringKey(shill::kGeoCellIdProperty);
if (hex_cell_id) {
ct.ci = HexToDecimal(*hex_cell_id);
}
std::string hex_lac;
if (entry->GetString(shill::kGeoLocationAreaCodeProperty, &hex_lac)) {
ct.lac = HexToDecimal(hex_lac);
const std::string* hex_lac =
entry.FindStringKey(shill::kGeoLocationAreaCodeProperty);
if (hex_lac) {
ct.lac = HexToDecimal(*hex_lac);
}
// Read decimal fields into object.
entry->GetString(shill::kGeoMobileCountryCodeProperty, &ct.mcc);
entry->GetString(shill::kGeoMobileNetworkCodeProperty, &ct.mnc);
ct.mcc = FindStringOrEmpty(entry, shill::kGeoMobileCountryCodeProperty);
ct.mnc = FindStringOrEmpty(entry, shill::kGeoMobileNetworkCodeProperty);
// Add new object to vector.
cell_towers_.push_back(ct);
......
......@@ -17,6 +17,7 @@
namespace base {
class DictionaryValue;
class Value;
}
namespace chromeos {
......@@ -86,8 +87,8 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) GeolocationHandler
bool cellular_enabled_;
bool wifi_enabled_;
void AddCellTowerFromDict(const base::DictionaryValue* entry);
void AddAccessPointFromDict(const base::DictionaryValue* entry);
void AddCellTowerFromDict(const base::Value& entry);
void AddAccessPointFromDict(const base::Value& entry);
// Cached netork information and update time
WifiAccessPointVector wifi_access_points_;
......
......@@ -135,11 +135,12 @@ class NetworkConfigurationHandler::ProfileEntryDeleter {
return;
}
for (base::DictionaryValue::Iterator iter(profile_entries); !iter.IsAtEnd();
iter.Advance()) {
std::string profile_path = StripQuotations(iter.key());
for (const auto& iter : profile_entries.DictItems()) {
std::string profile_path = StripQuotations(iter.first);
std::string entry_path;
iter.value().GetAsString(&entry_path);
if (iter.second.is_string()) {
entry_path = iter.second.GetString();
}
if (profile_path.empty() || entry_path.empty()) {
NET_LOG(ERROR) << "Failed to parse Profile Entry: " << profile_path
<< ": " << entry_path;
......@@ -579,25 +580,25 @@ void NetworkConfigurationHandler::GetPropertiesCallback(
return;
// Get the correct name from WifiHex if necessary.
std::unique_ptr<base::DictionaryValue> properties_copy(properties.DeepCopy());
base::Value properties_copy = properties.Clone();
std::string name =
shill_property_util::GetNameFromProperties(service_path, properties);
if (!name.empty())
properties_copy->SetKey(shill::kNameProperty, base::Value(name));
properties_copy.SetKey(shill::kNameProperty, base::Value(name));
// Get the GUID property from NetworkState if it is not set in Shill.
std::string guid;
properties.GetStringWithoutPathExpansion(::onc::network_config::kGUID, &guid);
if (guid.empty()) {
const std::string* guid =
properties.FindStringKey(::onc::network_config::kGUID);
if (!guid) {
const NetworkState* network_state =
network_state_handler_->GetNetworkState(service_path);
if (network_state) {
properties_copy->SetKey(::onc::network_config::kGUID,
base::Value(network_state->guid()));
properties_copy.SetKey(::onc::network_config::kGUID,
base::Value(network_state->guid()));
}
}
callback.Run(service_path, *properties_copy.get());
callback.Run(service_path, base::Value::AsDictionaryValue(properties_copy));
}
void NetworkConfigurationHandler::SetPropertiesSuccessCallback(
......
......@@ -193,7 +193,7 @@ class NetworkConfigurationHandlerTest : public testing::Test {
void GetPropertiesCallback(const std::string& service_path,
const base::DictionaryValue& dictionary) {
get_properties_path_ = service_path;
get_properties_ = dictionary.CreateDeepCopy();
get_properties_ = dictionary.Clone();
}
void ManagerGetPropertiesCallback(const std::string& success_callback_name,
......@@ -201,7 +201,7 @@ class NetworkConfigurationHandlerTest : public testing::Test {
const base::DictionaryValue& result) {
if (call_status == chromeos::DBUS_METHOD_CALL_SUCCESS)
success_callback_name_ = success_callback_name;
manager_get_properties_ = result.CreateDeepCopy();
manager_get_properties_ = result.Clone();
}
void CreateConfigurationCallback(const std::string& service_path,
......@@ -288,10 +288,10 @@ class NetworkConfigurationHandlerTest : public testing::Test {
bool GetReceivedStringProperty(const std::string& service_path,
const std::string& key,
std::string* result) {
if (get_properties_path_ != service_path || !get_properties_)
if (get_properties_path_ != service_path || get_properties_.is_none())
return false;
const base::Value* value =
get_properties_->FindKeyOfType(key, base::Value::Type::STRING);
get_properties_.FindKeyOfType(key, base::Value::Type::STRING);
if (!value)
return false;
*result = value->GetString();
......@@ -300,10 +300,10 @@ class NetworkConfigurationHandlerTest : public testing::Test {
bool GetReceivedStringManagerProperty(const std::string& key,
std::string* result) {
if (!manager_get_properties_)
if (manager_get_properties_.is_none())
return false;
const base::Value* value =
manager_get_properties_->FindKeyOfType(key, base::Value::Type::STRING);
manager_get_properties_.FindKeyOfType(key, base::Value::Type::STRING);
if (!value)
return false;
*result = value->GetString();
......@@ -326,8 +326,8 @@ class NetworkConfigurationHandlerTest : public testing::Test {
base::test::SingleThreadTaskEnvironment::MainThreadType::UI};
std::string success_callback_name_;
std::string get_properties_path_;
std::unique_ptr<base::DictionaryValue> get_properties_;
std::unique_ptr<base::DictionaryValue> manager_get_properties_;
base::Value get_properties_;
base::Value manager_get_properties_;
std::string create_service_path_;
};
......
......@@ -77,8 +77,7 @@ void NetworkProfileHandler::GetManagerPropertiesCallback(
return;
}
const base::Value* profiles = NULL;
properties.GetWithoutPathExpansion(shill::kProfilesProperty, &profiles);
const base::Value* profiles = properties.FindKey(shill::kProfilesProperty);
if (!profiles) {
LOG(ERROR) << "Manager properties returned from Shill don't contain "
<< "the field " << shill::kProfilesProperty;
......@@ -146,10 +145,10 @@ void NetworkProfileHandler::GetProfilePropertiesCallback(
VLOG(1) << "Ignore received properties, profile is already created.";
return;
}
std::string userhash;
properties.GetStringWithoutPathExpansion(shill::kUserHashProperty, &userhash);
const std::string* userhash =
properties.FindStringKey(shill::kUserHashProperty);
AddProfile(NetworkProfile(profile_path, userhash));
AddProfile(NetworkProfile(profile_path, userhash ? *userhash : ""));
}
void NetworkProfileHandler::AddProfile(const NetworkProfile& profile) {
......
......@@ -250,12 +250,9 @@ void NetworkSmsHandler::RemoveObserver(Observer* observer) {
void NetworkSmsHandler::OnPropertyChanged(const std::string& name,
const base::Value& value) {
if (name != shill::kDevicesProperty)
if (name != shill::kDevicesProperty || !value.is_list())
return;
const base::ListValue* devices = NULL;
if (!value.GetAsList(&devices) || !devices)
return;
UpdateDevices(devices);
UpdateDevices(value);
}
// Private methods
......@@ -285,22 +282,21 @@ void NetworkSmsHandler::ManagerPropertiesCallback(
LOG(ERROR) << "NetworkSmsHandler: Failed to get manager properties.";
return;
}
const base::Value* value;
if (!properties.GetWithoutPathExpansion(shill::kDevicesProperty, &value) ||
!value->is_list()) {
const base::Value* value = properties.FindListKey(shill::kDevicesProperty);
if (!value) {
LOG(ERROR) << "NetworkSmsHandler: No list value for: "
<< shill::kDevicesProperty;
return;
}
const base::ListValue* devices = static_cast<const base::ListValue*>(value);
UpdateDevices(devices);
UpdateDevices(*value);
}
void NetworkSmsHandler::UpdateDevices(const base::ListValue* devices) {
for (base::ListValue::const_iterator iter = devices->begin();
iter != devices->end(); ++iter) {
std::string device_path;
iter->GetAsString(&device_path);
void NetworkSmsHandler::UpdateDevices(const base::Value& devices) {
for (const auto& item : devices.GetList()) {
if (!item.is_string())
continue;
std::string device_path = item.GetString();
if (!device_path.empty()) {
// Request device properties.
VLOG(1) << "GetDeviceProperties: " << device_path;
......@@ -322,33 +318,33 @@ void NetworkSmsHandler::DevicePropertiesCallback(
return;
}
std::string device_type;
if (!properties.GetStringWithoutPathExpansion(
shill::kTypeProperty, &device_type)) {
const std::string* device_type =
properties.FindStringKey(shill::kTypeProperty);
if (!device_type) {
LOG(ERROR) << "NetworkSmsHandler: No type for: " << device_path;
return;
}
if (device_type != shill::kTypeCellular)
if (*device_type != shill::kTypeCellular)
return;
std::string service_name;
if (!properties.GetStringWithoutPathExpansion(
shill::kDBusServiceProperty, &service_name)) {
const std::string* service_name =
properties.FindStringKey(shill::kDBusServiceProperty);
if (!service_name) {
LOG(ERROR) << "Device has no DBusService Property: " << device_path;
return;
}
std::string object_path_string;
if (!properties.GetStringWithoutPathExpansion(
shill::kDBusObjectProperty, &object_path_string)) {
const std::string* object_path_string =
properties.FindStringKey(shill::kDBusObjectProperty);
if (!object_path_string) {
LOG(ERROR) << "Device has no DBusObject Property: " << device_path;
return;
}
dbus::ObjectPath object_path(object_path_string);
if (service_name == modemmanager::kModemManager1ServiceName) {
dbus::ObjectPath object_path(*object_path_string);
if (*service_name == modemmanager::kModemManager1ServiceName) {
device_handlers_.push_back(
std::make_unique<ModemManager1NetworkSmsDeviceHandler>(
this, service_name, object_path));
this, *service_name, object_path));
}
}
......
......@@ -18,7 +18,6 @@
namespace base {
class DictionaryValue;
class ListValue;
class Value;
}
......@@ -84,7 +83,7 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkSmsHandler
const base::DictionaryValue& properties);
// Requests properties for each entry in |devices|.
void UpdateDevices(const base::ListValue* devices);
void UpdateDevices(const base::Value& devices);
// Callback to handle the device properties for |device_path|.
// A NetworkSmsDeviceHandler will be instantiated for each cellular device.
......
......@@ -94,9 +94,9 @@ void PolicyApplicator::GetProfilePropertiesCallback(
const base::DictionaryValue& profile_properties) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
VLOG(2) << "Received properties for profile " << profile_.ToDebugString();
const base::ListValue* entries = nullptr;
if (!profile_properties.GetListWithoutPathExpansion(
shill::kEntriesProperty, &entries)) {
const base::Value* entries =
profile_properties.FindListKey(shill::kEntriesProperty);
if (!entries) {
LOG(ERROR) << "Profile " << profile_.ToDebugString()
<< " doesn't contain the property "
<< shill::kEntriesProperty;
......@@ -104,10 +104,11 @@ void PolicyApplicator::GetProfilePropertiesCallback(
return;
}
for (base::ListValue::const_iterator it = entries->begin();
it != entries->end(); ++it) {
std::string entry;
it->GetAsString(&entry);
for (const auto& it : entries->GetList()) {
if (!it.is_string())
continue;
std::string entry = it.GetString();
// Skip "ethernet_any", as this is used by shill internally to persist
// ethernet settings and the policy application logic should not mess with
......
......@@ -309,9 +309,8 @@ void ShillPropertyHandler::ManagerPropertiesCallback(
return;
}
NET_LOG(EVENT) << "ManagerPropertiesCallback: Success";
for (base::DictionaryValue::Iterator iter(properties); !iter.IsAtEnd();
iter.Advance()) {
ManagerPropertyChanged(iter.key(), iter.value());
for (const auto& item : properties.DictItems()) {
ManagerPropertyChanged(item.first, item.second);
}
CheckPendingStateListUpdates("");
......@@ -543,13 +542,13 @@ void ShillPropertyHandler::GetPropertiesCallback(
if (type == ManagedState::MANAGED_TYPE_NETWORK) {
// Request IPConfig properties.
const base::Value* value;
if (properties.GetWithoutPathExpansion(shill::kIPConfigProperty, &value))
const base::Value* value = properties.FindKey(shill::kIPConfigProperty);
if (value)
RequestIPConfig(type, path, *value);
} else if (type == ManagedState::MANAGED_TYPE_DEVICE) {
// Clear and request IPConfig properties for each entry in IPConfigs.
const base::Value* value;
if (properties.GetWithoutPathExpansion(shill::kIPConfigsProperty, &value))
const base::Value* value = properties.FindKey(shill::kIPConfigsProperty);
if (value)
RequestIPConfigsList(type, path, *value);
}
......
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