Skip to content

Commit

Permalink
Update chromeos/ash/components/network/onc to new Value API
Browse files Browse the repository at this point in the history
Bug: 1412465
Change-Id: Iaea7638ace5ebed0c7405d772254176981981c48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4229511
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1104147}
  • Loading branch information
Avi Drissman authored and Chromium LUCI CQ committed Feb 11, 2023
1 parent a5159e4 commit 2fbe9cc
Show file tree
Hide file tree
Showing 38 changed files with 789 additions and 744 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ void UserNetworkConfigurationUpdaterAsh::ApplyNetworkPolicy(
// Call on UserSessionManager to send the user's password to session manager
// if the password substitution variable exists in the ONC.
bool save_password =
ash::onc::HasUserPasswordSubsitutionVariable(network_configs_onc);
ash::onc::HasUserPasswordSubstitutionVariable(network_configs_onc);
ash::UserSessionManager::GetInstance()->VoteForSavingLoginPassword(
ash::UserSessionManager::PasswordConsumingService::kNetwork,
save_password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class COMPONENT_EXPORT(SHILL_CLIENT) ModemMessagingClient {
virtual void CompletePendingDeleteRequest(bool success) = 0;

protected:
virtual ~TestInterface() {}
virtual ~TestInterface() = default;
};

// Creates and initializes the global instance. |bus| must not be null.
Expand Down
13 changes: 6 additions & 7 deletions chromeos/ash/components/network/cellular_policy_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,10 @@ base::Value::Dict CellularPolicyHandler::GetNewShillProperties() {
::onc::network_config::kGUID);
DCHECK(guid);

return std::move(policy_util::CreateShillConfiguration(
*profile, *guid, /*global_policy=*/nullptr,
&(remaining_install_requests_.front()->onc_config),
/*user_settings=*/nullptr)
.GetDict());
return policy_util::CreateShillConfiguration(
*profile, *guid, /*global_policy=*/nullptr,
&(remaining_install_requests_.front()->onc_config.GetDict()),
/*user_settings=*/nullptr);
}

const std::string& CellularPolicyHandler::GetCurrentSmdpAddress() const {
Expand All @@ -271,7 +270,7 @@ void CellularPolicyHandler::OnConfigureESimService(
NET_LOG(EVENT) << "Successfully configured service for existing eSIM profile";
current_request->retry_backoff.InformOfRequest(/*succeeded=*/true);
const std::string* iccid =
policy_util::GetIccidFromONC(current_request->onc_config);
policy_util::GetIccidFromONC(current_request->onc_config.GetDict());
managed_cellular_pref_handler_->AddIccidSmdpPair(
*iccid, current_request->smdp_address);
ProcessRequests();
Expand Down Expand Up @@ -349,7 +348,7 @@ void CellularPolicyHandler::PopRequest() {
absl::optional<dbus::ObjectPath>
CellularPolicyHandler::FindExistingMatchingESimProfile() {
const std::string* iccid = policy_util::GetIccidFromONC(
remaining_install_requests_.front()->onc_config);
remaining_install_requests_.front()->onc_config.GetDict());
if (!iccid) {
return absl::nullopt;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ManagedNetworkConfigurationHandler::InitializeForTesting(
/*managed_cellular_pref_handler=*/nullptr,
network_state_handler, network_profile_handler,
network_configuration_handler, network_device_handler,
/*prohibitied_technologies_handler=*/nullptr);
/*prohibited_technologies_handler=*/nullptr);
handler->set_ui_proxy_config_service(ui_proxy_config_service);
return base::WrapUnique(handler);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) ManagedNetworkConfigurationHandler {
// before calling this method. |callback| will be called after the
// configuration update has been reflected in NetworkStateHandler, or on
// error. This fires OnPolicyApplied notification on success.
virtual void ConfigurePolicyNetwork(const base::Value& shill_properties,
virtual void ConfigurePolicyNetwork(const base::Value::Dict& shill_properties,
base::OnceClosure callback) const = 0;

// Removes the user's configuration from the network with |service_path|. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,9 @@ void ManagedNetworkConfigurationHandlerImpl::SetProperties(
if (network_policy)
NET_LOG(DEBUG) << "Configuration is managed: " << NetworkId(state);

base::Value shill_dictionary = policy_util::CreateShillConfiguration(
*profile, guid, policies->GetGlobalNetworkConfig(), network_policy,
base::Value::Dict shill_dictionary = policy_util::CreateShillConfiguration(
*profile, guid, policies->GetGlobalNetworkConfig(),
network_policy ? &network_policy->GetDict() : nullptr,
&validated_user_settings);

SetShillProperties(service_path, std::move(shill_dictionary),
Expand All @@ -332,30 +333,26 @@ void ManagedNetworkConfigurationHandlerImpl::SetProperties(

void ManagedNetworkConfigurationHandlerImpl::SetManagedActiveProxyValues(
const std::string& guid,
base::Value* dictionary) {
base::Value::Dict* dictionary) {
DCHECK(ui_proxy_config_service_);
const std::string proxy_settings_key = ::onc::network_config::kProxySettings;
base::Value::Dict* proxy_settings =
dictionary->GetDict().FindDict(proxy_settings_key);

if (!proxy_settings) {
proxy_settings = dictionary->GetDict()
.Set(proxy_settings_key, base::Value::Dict())
->GetIfDict();
}
base::Value::Dict* proxy_settings =
dictionary->EnsureDict(proxy_settings_key);
ui_proxy_config_service_->MergeEnforcedProxyConfig(guid, proxy_settings);

if (proxy_settings->empty())
dictionary->GetDict().Remove(proxy_settings_key);
if (proxy_settings->empty()) {
dictionary->Remove(proxy_settings_key);
}
}

void ManagedNetworkConfigurationHandlerImpl::SetShillProperties(
const std::string& service_path,
base::Value shill_dictionary,
base::Value::Dict shill_dictionary,
base::OnceClosure callback,
network_handler::ErrorCallback error_callback) {
network_configuration_handler_->SetShillProperties(
service_path, shill_dictionary.GetDict(), std::move(callback),
service_path, shill_dictionary, std::move(callback),
std::move(error_callback));
}

Expand Down Expand Up @@ -465,23 +462,22 @@ void ManagedNetworkConfigurationHandlerImpl::CreateConfiguration(
guid = base::GenerateGUID();
}

base::Value shill_dictionary =
base::Value::Dict shill_dictionary =
policy_util::CreateShillConfiguration(*profile, guid,
nullptr, // no global policy
nullptr, // no network policy
&validated_properties);

network_configuration_handler_->CreateShillConfiguration(
shill_dictionary.GetDict(), std::move(callback),
std::move(error_callback));
shill_dictionary, std::move(callback), std::move(error_callback));
}

void ManagedNetworkConfigurationHandlerImpl::ConfigurePolicyNetwork(
const base::Value& shill_properties,
const base::Value::Dict& shill_properties,
base::OnceClosure callback) const {
auto split_callback = base::SplitOnceCallback(std::move(callback));
network_configuration_handler_->CreateShillConfiguration(
shill_properties.GetDict(),
shill_properties,
base::BindOnce(
&ManagedNetworkConfigurationHandlerImpl::OnPolicyAppliedToNetwork,
weak_ptr_factory_.GetWeakPtr(), std::move(split_callback.first)),
Expand Down Expand Up @@ -682,7 +678,7 @@ void ManagedNetworkConfigurationHandlerImpl::OnProfileAdded(

// The profile's network policy may have a GlobalNetworkConfiguration which
// can affect unmanaged networks (see ApplyGlobalPolicyOnUnmanagedEntry in
// PolicyAppliactor), so set can_affect_other_networks to true.
// PolicyApplicator), so set can_affect_other_networks to true.
ApplyOrQueuePolicies(profile.userhash, policies->GetAllPolicyGuids(),
/*can_affect_other_networks=*/true);
}
Expand All @@ -693,17 +689,17 @@ void ManagedNetworkConfigurationHandlerImpl::OnProfileRemoved(
}

void ManagedNetworkConfigurationHandlerImpl::CreateConfigurationFromPolicy(
const base::Value& shill_properties,
const base::Value::Dict& shill_properties,
base::OnceClosure callback) {
ConfigurePolicyNetwork(shill_properties, std::move(callback));
}

void ManagedNetworkConfigurationHandlerImpl::
UpdateExistingConfigurationWithPropertiesFromPolicy(
const base::Value& existing_properties,
const base::Value& new_properties,
const base::Value::Dict& new_properties,
base::OnceClosure callback) {
base::Value shill_properties(base::Value::Type::DICT);
base::Value::Dict shill_properties;

const std::string* profile =
existing_properties.FindStringKey(shill::kProfileProperty);
Expand All @@ -716,21 +712,21 @@ void ManagedNetworkConfigurationHandlerImpl::
std::move(callback).Run();
return;
}
shill_properties.SetKey(shill::kProfileProperty, base::Value(*profile));
shill_properties.Set(shill::kProfileProperty, *profile);

if (!shill_property_util::CopyIdentifyingProperties(
existing_properties, true /* properties were read from Shill */,
&shill_properties)) {
existing_properties.GetDict(),
/*properties_read_from_shill=*/true, &shill_properties)) {
NET_LOG(ERROR) << "Missing identifying properties",
shill_property_util::GetNetworkIdFromProperties(
existing_properties.GetDict());
}

shill_properties.MergeDictionary(&new_properties);
shill_properties.Merge(new_properties.Clone());

auto split_callback = base::SplitOnceCallback(std::move(callback));
network_configuration_handler_->CreateShillConfiguration(
shill_properties.GetDict(),
shill_properties,
base::BindOnce(
&ManagedNetworkConfigurationHandlerImpl::OnPolicyAppliedToNetwork,
weak_ptr_factory_.GetWeakPtr(), std::move(split_callback.first)),
Expand All @@ -749,7 +745,7 @@ void ManagedNetworkConfigurationHandlerImpl::TriggerCellularPolicyApplication(
DCHECK(network_policy);

const std::string* smdp_address =
policy_util::GetSMDPAddressFromONC(*network_policy);
policy_util::GetSMDPAddressFromONC(network_policy->GetDict());
if (smdp_address) {
NET_LOG(EVENT)
<< "Found ONC configuration with SMDP: " << *smdp_address
Expand Down Expand Up @@ -1086,7 +1082,7 @@ void ManagedNetworkConfigurationHandlerImpl::OnPolicyAppliedToNetwork(
const std::string& service_path,
const std::string& guid) const {
// When this is called, the policy has been fully applied and is reflected in
// NetworkStateHandler, so it is safe to notify obserers.
// NetworkStateHandler, so it is safe to notify observers.
// Notifying observers is the last step of policy application to
// |service_path|.
NotifyPolicyAppliedToNetwork(service_path);
Expand Down Expand Up @@ -1259,14 +1255,14 @@ void ManagedNetworkConfigurationHandlerImpl::SendProperties(
network_state_handler_->GetNetworkState(service_path);
::onc::ONCSource onc_source;
FindPolicyByGUID(userhash, *guid, &onc_source);
base::Value onc_network = onc::TranslateShillServiceToONCPart(
*shill_properties, onc_source, &chromeos::onc::kNetworkWithStateSignature,
network_state);
base::Value::Dict onc_network = onc::TranslateShillServiceToONCPart(
shill_properties->GetDict(), onc_source,
&chromeos::onc::kNetworkWithStateSignature, network_state);

if (properties_type == PropertiesType::kUnmanaged) {
std::move(callback).Run(service_path,
absl::make_optional(std::move(onc_network)),
absl::nullopt);
std::move(callback).Run(
service_path, absl::make_optional(base::Value(std::move(onc_network))),
absl::nullopt);
return;
}

Expand Down Expand Up @@ -1313,12 +1309,13 @@ void ManagedNetworkConfigurationHandlerImpl::SendProperties(
global_policy = policies->GetGlobalNetworkConfig();
}

base::Value augmented_properties = policy_util::CreateManagedONC(
base::Value::Dict augmented_properties = policy_util::CreateManagedONC(
global_policy, network_policy, user_settings, &onc_network, profile);
SetManagedActiveProxyValues(*guid, &augmented_properties);
std::move(callback).Run(service_path,
absl::make_optional(std::move(augmented_properties)),
absl::nullopt);
std::move(callback).Run(
service_path,
absl::make_optional(base::Value(std::move(augmented_properties))),
absl::nullopt);
}

void ManagedNetworkConfigurationHandlerImpl::NotifyPolicyAppliedToNetwork(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) ManagedNetworkConfigurationHandlerImpl
network_handler::ServiceResultCallback callback,
network_handler::ErrorCallback error_callback) const override;

void ConfigurePolicyNetwork(const base::Value& shill_properties,
void ConfigurePolicyNetwork(const base::Value::Dict& shill_properties,
base::OnceClosure callback) const override;

void RemoveConfiguration(
Expand Down Expand Up @@ -148,12 +148,12 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) ManagedNetworkConfigurationHandlerImpl
void OnProfileRemoved(const NetworkProfile& profile) override;

// PolicyApplicator::ConfigurationHandler overrides
void CreateConfigurationFromPolicy(const base::Value& shill_properties,
void CreateConfigurationFromPolicy(const base::Value::Dict& shill_properties,
base::OnceClosure callback) override;

void UpdateExistingConfigurationWithPropertiesFromPolicy(
const base::Value& existing_properties,
const base::Value& new_properties,
const base::Value::Dict& new_properties,
base::OnceClosure callback) override;

void OnPoliciesApplied(
Expand Down Expand Up @@ -232,7 +232,7 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) ManagedNetworkConfigurationHandlerImpl
NetworkProfileHandler* network_profile_handler,
NetworkConfigurationHandler* network_configuration_handler,
NetworkDeviceHandler* network_device_handler,
ProhibitedTechnologiesHandler* prohibitied_technologies_handler);
ProhibitedTechnologiesHandler* prohibited_technologies_handler);

// Returns the ProfilePolicies for the given |userhash|, or the device
// policies if |userhash| is empty. Creates the ProfilePolicies entry if it
Expand Down Expand Up @@ -284,16 +284,16 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) ManagedNetworkConfigurationHandlerImpl

// Called from SetProperties, calls NCH::SetShillProperties.
void SetShillProperties(const std::string& service_path,
base::Value shill_dictionary,
base::Value::Dict shill_dictionary,
base::OnceClosure callback,
network_handler::ErrorCallback error_callback);

// Sets the active proxy values in managed network configurations depending on
// the source of the configuration. Proxy enforced by user policy
// (provided by kProxy prefence) should have precedence over configurations
// (provided by kProxy preference) should have precedence over configurations
// set by ONC policy.
void SetManagedActiveProxyValues(const std::string& guid,
base::Value* dictionary);
base::Value::Dict* dictionary);

// Applies policies for |userhash|.
// |modified_policies| contains the GUIDs of the network configurations that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) MockManagedNetworkConfigurationHandler
network_handler::ServiceResultCallback callback,
network_handler::ErrorCallback error_callback));
MOCK_CONST_METHOD2(ConfigurePolicyNetwork,
void(const base::Value& shill_properties,
void(const base::Value::Dict& shill_properties,
base::OnceClosure callback));
MOCK_CONST_METHOD3(RemoveConfiguration,
void(const std::string& service_path,
Expand Down

0 comments on commit 2fbe9cc

Please sign in to comment.