Skip to content

Commit

Permalink
Update chromeos/ash/components/dbus/shill/shill_[device|service]_clie…
Browse files Browse the repository at this point in the history
…nt.h to new Value API

Bug: 1412465
Change-Id: Ia8714e45f0946d9ec858be6126f653ab0238f468
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4221520
Reviewed-by: Yuichiro Hanada <yhanada@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Commit-Queue: Yuichiro Hanada <yhanada@chromium.org>
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1106548}
  • Loading branch information
Avi Drissman authored and Chromium LUCI CQ committed Feb 17, 2023
1 parent 9ed3e99 commit af33e6b
Show file tree
Hide file tree
Showing 75 changed files with 719 additions and 700 deletions.
5 changes: 3 additions & 2 deletions ash/components/arc/net/arc_net_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ void ArcNetHostImpl::NetworkPropertiesUpdated(

void ArcNetHostImpl::ReceiveShillProperties(
const std::string& service_path,
absl::optional<base::Value> shill_properties) {
absl::optional<base::Value::Dict> shill_properties) {
if (!shill_properties) {
NET_LOG(ERROR) << "Failed to get shill Service properties for "
<< service_path;
Expand All @@ -1081,7 +1081,8 @@ void ArcNetHostImpl::ReceiveShillProperties(
return;
}

shill_network_properties_[service_path] = std::move(*shill_properties);
shill_network_properties_[service_path] =
base::Value(std::move(*shill_properties));

// Get patchpanel devices and update active networks.
ash::PatchPanelClient::Get()->GetDevices(base::BindOnce(
Expand Down
5 changes: 3 additions & 2 deletions ash/components/arc/net/arc_net_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ class ArcNetHostImpl : public KeyedService,
const std::string& error_name);

// Callback for ash::NetworkHandler::GetShillProperties
void ReceiveShillProperties(const std::string& service_path,
absl::optional<base::Value> shill_properties);
void ReceiveShillProperties(
const std::string& service_path,
absl::optional<base::Value::Dict> shill_properties);

// PatchPanelClient::Observer implementation:
void NetworkConfigurationChanged() override;
Expand Down
12 changes: 7 additions & 5 deletions chrome/browser/ash/crosapi/vpn_service_ash.cc
Original file line number Diff line number Diff line change
Expand Up @@ -612,18 +612,20 @@ void VpnServiceAsh::OnVpnExtensionsChanged(

void VpnServiceAsh::OnGetShillProperties(
const std::string& service_path,
absl::optional<base::Value> configuration_properties) {
absl::optional<base::Value::Dict> configuration_properties) {
if (!configuration_properties) {
return;
}
const std::string* vpn_type =
configuration_properties->FindStringPath(shill::kProviderTypeProperty);
configuration_properties->FindStringByDottedPath(
shill::kProviderTypeProperty);
const std::string* extension_id =
configuration_properties->FindStringPath(shill::kProviderHostProperty);
configuration_properties->FindStringByDottedPath(
shill::kProviderHostProperty);
const std::string* type =
configuration_properties->FindStringPath(shill::kTypeProperty);
configuration_properties->FindStringByDottedPath(shill::kTypeProperty);
const std::string* configuration_name =
configuration_properties->FindStringPath(shill::kNameProperty);
configuration_properties->FindStringByDottedPath(shill::kNameProperty);
if (!vpn_type || !extension_id || !type || !configuration_name ||
*vpn_type != shill::kProviderThirdPartyVpn || *type != shill::kTypeVPN) {
return;
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ash/crosapi/vpn_service_ash.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class VpnServiceAsh : public crosapi::mojom::VpnService,
// configuration provided that it belongs to some enabled extension.
void OnGetShillProperties(
const std::string& service_path,
absl::optional<base::Value> configuration_properties);
absl::optional<base::Value::Dict> configuration_properties);

// Always returns a valid pointer.
VpnServiceForExtensionAsh* GetVpnServiceForExtension(
Expand Down
11 changes: 6 additions & 5 deletions chrome/browser/ash/net/apn_migrator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,13 @@ void ApnMigrator::MigrateNetwork(const NetworkState& network) {
weak_factory_.GetWeakPtr(), network.iccid()));
}

void ApnMigrator::OnGetManagedProperties(std::string iccid,
const std::string& service_path,
absl::optional<base::Value> properties,
absl::optional<std::string> error) {
void ApnMigrator::OnGetManagedProperties(
std::string iccid,
const std::string& service_path,
absl::optional<base::Value::Dict> properties,
absl::optional<std::string> error) {
// TODO(b/162365553): Implement this case: Network with custom APNs needs to
// be migrated
// be migrated.
managed_cellular_pref_handler_->AddApnMigratedIccid(iccid);
iccids_in_migration_.erase(iccid);
}
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/ash/net/apn_migrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) ApnMigrator
// fields.
void OnGetManagedProperties(std::string iccid,
const std::string& service_path,
absl::optional<base::Value> properties,
absl::optional<base::Value::Dict> properties,
absl::optional<std::string> error);

base::flat_set<std::string> iccids_in_migration_;
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/ash/net/apn_migrator_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,8 @@ TEST_F(ApnMigratorTest, ApnRevampFlagEnabled_MigrateNetwork) {
// Execute the GetManagedProperties callback, expect that the migration
// service marks the network as migrated.
std::move(get_managed_properties_callback)
.Run(cellular_service_path_1, base::Value(), /*error=*/absl::nullopt);
.Run(cellular_service_path_1, base::Value::Dict(),
/*error=*/absl::nullopt);
}

} // namespace ash
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ bool IsDeviceEnterpriseEnrolled() {
return InstallAttributes::Get()->IsEnterpriseManaged();
}

bool OncIsPskWiFi(const base::Value& network) {
bool OncIsPskWiFi(const base::Value::Dict& network) {
return rollback_network_config::OncIsWiFi(network) &&
rollback_network_config::OncWiFiIsPsk(network);
}

bool ShouldSaveNetwork(const base::Value& network) {
bool ShouldSaveNetwork(const base::Value::Dict& network) {
return (rollback_network_config::OncIsSourceDevicePolicy(network) ||
rollback_network_config::OncIsSourceDevice(network)) &&
(rollback_network_config::OncHasNoSecurity(network) ||
Expand Down Expand Up @@ -78,7 +78,7 @@ void ManagedOncConfigureActivePartAsDeviceWide(
rollback_network_config::ManagedOncCollapseToActive(&network);

const std::string& guid = rollback_network_config::GetStringValue(
network, onc::network_config::kGUID);
network.GetDict(), onc::network_config::kGUID);
const NetworkState* network_state =
network_state_handler()->GetNetworkStateFromGuid(guid);

Expand Down Expand Up @@ -182,7 +182,7 @@ class RollbackNetworkConfig::Exporter {
private:
void OnGetManagedNetworkConfig(base::OnceClosure network_finished,
const std::string& service_path,
absl::optional<base::Value> properties,
absl::optional<base::Value::Dict> properties,
absl::optional<std::string> error);

void AddPskPassword(base::ScopedClosureRunner exit_call,
Expand All @@ -199,7 +199,7 @@ class RollbackNetworkConfig::Exporter {
void SendNetworkConfigs(ExportCallback callback);
std::string SerializeNetworkConfigs() const;

std::vector<base::Value> network_configs_;
std::vector<base::Value::Dict> network_configs_;
ExportCallback callback_;

base::WeakPtrFactory<Exporter> weak_factory_{this};
Expand Down Expand Up @@ -228,7 +228,7 @@ void RollbackNetworkConfig::Exporter::Export(ExportCallback callback) {
void RollbackNetworkConfig::Exporter::OnGetManagedNetworkConfig(
base::OnceClosure network_finished,
const std::string& service_path,
absl::optional<base::Value> managed_network,
absl::optional<base::Value::Dict> managed_network,
absl::optional<std::string> error) {
base::ScopedClosureRunner exit_call(std::move(network_finished));

Expand All @@ -238,24 +238,24 @@ void RollbackNetworkConfig::Exporter::OnGetManagedNetworkConfig(
return;
}

base::Value active_network = managed_network->Clone();
base::Value active_network = base::Value(managed_network->Clone());
rollback_network_config::ManagedOncCollapseToActive(&active_network);

if (!ShouldSaveNetwork(active_network)) {
if (!ShouldSaveNetwork(active_network.GetDict())) {
return;
}

network_configs_.push_back(std::move(*managed_network));
int network_idx = network_configs_.size() - 1;

if (OncIsPskWiFi(active_network)) {
if (OncIsPskWiFi(active_network.GetDict())) {
GetPskPassword(
base::BindOnce(&RollbackNetworkConfig::Exporter::AddPskPassword,
weak_factory_.GetWeakPtr(), std::move(exit_call),
network_idx),
service_path);
} else if (rollback_network_config::OncIsEapWithoutClientCertificate(
active_network)) {
active_network.GetDict())) {
GetEapPassword(
base::BindOnce(&RollbackNetworkConfig::Exporter::AddEapPassword,
weak_factory_.GetWeakPtr(), std::move(exit_call),
Expand All @@ -274,7 +274,7 @@ void RollbackNetworkConfig::Exporter::AddPskPassword(
LOG(ERROR) << error_name << " " << error_message;
return;
}
base::Value* network = &network_configs_[network_idx];
base::Value::Dict* network = &network_configs_[network_idx];
rollback_network_config::ManagedOncWiFiSetPskPassword(network, *password);
}

Expand All @@ -288,7 +288,7 @@ void RollbackNetworkConfig::Exporter::AddEapPassword(
LOG(ERROR) << error_name << " " << error_message;
return;
}
base::Value* network = &network_configs_[network_idx];
base::Value::Dict* network = &network_configs_[network_idx];
rollback_network_config::ManagedOncSetEapPassword(network, *password);
}

Expand Down Expand Up @@ -417,12 +417,12 @@ void RollbackNetworkConfig::Importer::PoliciesApplied(
const std::string& userhash) {
for (const base::Value& network_config : imported_networks_) {
const std::string& guid = rollback_network_config::GetStringValue(
network_config, onc::network_config::kGUID);
network_config.GetDict(), onc::network_config::kGUID);
const NetworkState* network_state =
network_state_handler()->GetNetworkStateFromGuid(guid);

if (network_state &&
rollback_network_config::OncIsSourceDevicePolicy(network_config)) {
if (network_state && rollback_network_config::OncIsSourceDevicePolicy(
network_config.GetDict())) {
if (network_state->IsManagedByPolicy()) {
ReconfigureUiData(network_config, guid);
} else { // Policy did not reconfigure the network, delete it.
Expand All @@ -437,9 +437,10 @@ void RollbackNetworkConfig::Importer::PoliciesApplied(
void RollbackNetworkConfig::Importer::DeleteImportedPolicyNetworks() {
for (const base::Value& network_config : imported_networks_) {
const std::string& guid = rollback_network_config::GetStringValue(
network_config, onc::network_config::kGUID);
network_config.GetDict(), onc::network_config::kGUID);

if (rollback_network_config::OncIsSourceDevicePolicy(network_config)) {
if (rollback_network_config::OncIsSourceDevicePolicy(
network_config.GetDict())) {
const NetworkState* network_state =
network_state_handler()->GetNetworkStateFromGuid(guid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace ash {
// the device settings that were imported remain, the rest is deleted.
// Note: Import expects ONC dictionaries to be valid, do not use with
// non validated input.
// If implot or export are called multiple times, all but the latest request
// If import or export are called multiple times, all but the latest request
// will be cancelled.
class RollbackNetworkConfig
: public rollback_network_config::mojom::RollbackNetworkConfig {
Expand Down

0 comments on commit af33e6b

Please sign in to comment.