Commit 28db6c71 authored by Aya ElAttar's avatar Aya ElAttar Committed by Chromium LUCI CQ

Migrate to OnceCallback in DeviceLocalAccountPolicyStore

- Migrated ValidateCompletionCallback &
OwnershipStatusCallback from base::Callback
to base::OnceCallback as they are only run once.
- Moved the callbacks instead of const passing
them using constant references.

Bug: 714018
Change-Id: I1a92f95c8bd7cf373bd8cdc4d1fc79dd118855af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2627156Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Commit-Queue: Aya Elsayed <ayaelattar@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843426}
parent 122a3aa7
......@@ -96,7 +96,7 @@ void DeviceLocalAccountPolicyStore::Store(
CheckKeyAndValidate(
true, std::make_unique<em::PolicyFetchResponse>(policy),
true /*validate_in_background*/,
base::Bind(&DeviceLocalAccountPolicyStore::OnPolicyToStoreValidated,
base::BindOnce(&DeviceLocalAccountPolicyStore::OnPolicyToStoreValidated,
weak_factory_.GetWeakPtr()));
}
......@@ -114,7 +114,7 @@ void DeviceLocalAccountPolicyStore::ValidateLoadedPolicyBlob(
if (policy->ParseFromString(policy_blob)) {
CheckKeyAndValidate(
false, std::move(policy), validate_in_background,
base::Bind(&DeviceLocalAccountPolicyStore::UpdatePolicy,
base::BindOnce(&DeviceLocalAccountPolicyStore::UpdatePolicy,
weak_factory_.GetWeakPtr()));
} else {
status_ = CloudPolicyStore::STATUS_PARSE_ERROR;
......@@ -178,16 +178,16 @@ void DeviceLocalAccountPolicyStore::CheckKeyAndValidate(
bool valid_timestamp_required,
std::unique_ptr<em::PolicyFetchResponse> policy,
bool validate_in_background,
const ValidateCompletionCallback& callback) {
ValidateCompletionCallback callback) {
if (validate_in_background) {
device_settings_service_->GetOwnershipStatusAsync(
base::Bind(&DeviceLocalAccountPolicyStore::Validate,
weak_factory_.GetWeakPtr(), valid_timestamp_required,
base::Passed(&policy), callback, validate_in_background));
device_settings_service_->GetOwnershipStatusAsync(base::BindOnce(
&DeviceLocalAccountPolicyStore::Validate, weak_factory_.GetWeakPtr(),
valid_timestamp_required, base::Passed(&policy), std::move(callback),
validate_in_background));
} else {
chromeos::DeviceSettingsService::OwnershipStatus ownership_status =
device_settings_service_->GetOwnershipStatus();
Validate(valid_timestamp_required, std::move(policy), callback,
Validate(valid_timestamp_required, std::move(policy), std::move(callback),
validate_in_background, ownership_status);
}
}
......@@ -195,7 +195,7 @@ void DeviceLocalAccountPolicyStore::CheckKeyAndValidate(
void DeviceLocalAccountPolicyStore::Validate(
bool valid_timestamp_required,
std::unique_ptr<em::PolicyFetchResponse> policy_response,
const ValidateCompletionCallback& callback,
ValidateCompletionCallback callback,
bool validate_in_background,
chromeos::DeviceSettingsService::OwnershipStatus ownership_status) {
DCHECK_NE(chromeos::DeviceSettingsService::OWNERSHIP_UNKNOWN,
......@@ -244,7 +244,8 @@ void DeviceLocalAccountPolicyStore::Validate(
if (validate_in_background) {
UserCloudPolicyValidator::StartValidation(
std::move(validator), base::BindOnce(callback, key->as_string()));
std::move(validator),
base::BindOnce(std::move(callback), key->as_string()));
} else {
validator->RunValidation();
......
......@@ -61,7 +61,7 @@ class DeviceLocalAccountPolicyStore : public UserCloudPolicyStoreBase {
// The callback invoked once policy validation is complete. Passed are the
// used public key and the validator.
using ValidateCompletionCallback =
base::Callback<void(const std::string&, UserCloudPolicyValidator*)>;
base::OnceCallback<void(const std::string&, UserCloudPolicyValidator*)>;
// Called back by |session_manager_client_| after policy retrieval. Checks for
// success and triggers policy validation.
......@@ -88,13 +88,13 @@ class DeviceLocalAccountPolicyStore : public UserCloudPolicyStoreBase {
bool valid_timestamp_required,
std::unique_ptr<enterprise_management::PolicyFetchResponse> policy,
bool validate_in_background,
const ValidateCompletionCallback& callback);
ValidateCompletionCallback callback);
// Triggers policy validation.
void Validate(
bool valid_timestamp_required,
std::unique_ptr<enterprise_management::PolicyFetchResponse> policy,
const ValidateCompletionCallback& callback,
ValidateCompletionCallback callback,
bool validate_in_background,
chromeos::DeviceSettingsService::OwnershipStatus ownership_status);
......
......@@ -182,16 +182,16 @@ DeviceSettingsService::OwnershipStatus
}
void DeviceSettingsService::GetOwnershipStatusAsync(
const OwnershipStatusCallback& callback) {
OwnershipStatusCallback callback) {
if (GetOwnershipStatus() != OWNERSHIP_UNKNOWN) {
// Report status immediately.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback, GetOwnershipStatus()));
FROM_HERE, base::BindOnce(std::move(callback), GetOwnershipStatus()));
} else {
// If the key hasn't been loaded yet, enqueue the callback to be fired when
// the next SessionManagerOperation completes. If no operation is pending,
// start a load operation to fetch the key and report the result.
pending_ownership_status_callbacks_.push_back(callback);
pending_ownership_status_callbacks_.push_back(std::move(callback));
if (pending_operations_.empty())
EnqueueLoad(false);
}
......@@ -365,8 +365,8 @@ void DeviceSettingsService::NotifyDeviceSettingsUpdated() const {
void DeviceSettingsService::RunPendingOwnershipStatusCallbacks() {
std::vector<OwnershipStatusCallback> callbacks;
callbacks.swap(pending_ownership_status_callbacks_);
for (const auto& callback : callbacks) {
callback.Run(GetOwnershipStatus());
for (auto& callback : callbacks) {
std::move(callback).Run(GetOwnershipStatus());
}
}
......
......@@ -62,7 +62,7 @@ class DeviceSettingsService : public SessionManagerClient::Observer {
OWNERSHIP_TAKEN
};
typedef base::Callback<void(OwnershipStatus)> OwnershipStatusCallback;
typedef base::OnceCallback<void(OwnershipStatus)> OwnershipStatusCallback;
// Status codes for Load() and Store().
// These values are logged to UMA. Entries should not be renumbered and
......@@ -171,7 +171,7 @@ class DeviceSettingsService : public SessionManagerClient::Observer {
// Determines the ownership status and reports the result to |callback|. This
// is guaranteed to never return OWNERSHIP_UNKNOWN.
void GetOwnershipStatusAsync(const OwnershipStatusCallback& callback);
void GetOwnershipStatusAsync(OwnershipStatusCallback callback);
// Checks whether we have the private owner key.
//
......
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