Commit 03509fc0 authored by Reilly Grant's avatar Reilly Grant Committed by Chromium LUCI CQ

Convert callbacks in //chrome/browser/chromeos/login/easy_unlock

This change converts callbacks from base::Bind and base::Callback to
Once/Repeating in //chrome/browser/chromeos/login/easy_unlock.

This should unblock conversion of //chromeos/components/proximity_auth.

Bug: 1148570
Change-Id: I4da7c25ef8e20d3700bc49348d109424b64975af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2638359
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Ryan Hansberry <hansberry@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#844914}
parent 6b78ae9c
......@@ -33,8 +33,8 @@ EasyUnlockChallengeWrapper::EasyUnlockChallengeWrapper(
EasyUnlockChallengeWrapper::~EasyUnlockChallengeWrapper() {}
void EasyUnlockChallengeWrapper::WrapChallenge(
const WrappedChallengeCallback& callback) {
callback_ = callback;
WrappedChallengeCallback callback) {
callback_ = std::move(callback);
// Because the TPM is used to sign the channel binding data, we need to
// construct the SecureMessage by hand instead of using the
......@@ -54,14 +54,14 @@ void EasyUnlockChallengeWrapper::WrapChallenge(
SignUsingTpmKey(
data_to_sign,
base::Bind(&EasyUnlockChallengeWrapper::OnChannelBindingDataSigned,
base::BindOnce(&EasyUnlockChallengeWrapper::OnChannelBindingDataSigned,
weak_ptr_factory_.GetWeakPtr(), signature_metadata));
}
void EasyUnlockChallengeWrapper::SignUsingTpmKey(
const std::string& data_to_sign,
const base::Callback<void(const std::string&)>& callback) {
key_manager_->SignUsingTpmKey(account_id_, data_to_sign, callback);
base::OnceCallback<void(const std::string&)> callback) {
key_manager_->SignUsingTpmKey(account_id_, data_to_sign, std::move(callback));
}
void EasyUnlockChallengeWrapper::OnChannelBindingDataSigned(
......@@ -77,7 +77,7 @@ void EasyUnlockChallengeWrapper::OnChannelBindingDataSigned(
wrapped_challenge.set_signature(signature_container.SerializeAsString());
PA_LOG(VERBOSE) << "Finished wrapping challenge.";
callback_.Run(wrapped_challenge.SerializeAsString());
std::move(callback_).Run(wrapped_challenge.SerializeAsString());
}
} // namespace chromeos
......@@ -36,16 +36,16 @@ class EasyUnlockChallengeWrapper {
// Wraps the challenge and invokes `callback` with the `wrapped_challenge`
// that will be send directly to the remote device.
typedef base::Callback<void(const std::string& wrapped_challenge)>
WrappedChallengeCallback;
void WrapChallenge(const WrappedChallengeCallback& callback);
using WrappedChallengeCallback =
base::OnceCallback<void(const std::string& wrapped_challenge)>;
void WrapChallenge(WrappedChallengeCallback callback);
protected:
// Signs `data_to_sign` with the TPM. `callback` will be invoked upon
// completion. Exposed for testing.
virtual void SignUsingTpmKey(
const std::string& data_to_sign,
const base::Callback<void(const std::string&)>& callback);
base::OnceCallback<void(const std::string&)> callback);
private:
// Called when the channel binding data is signed by the TPM and completes the
......
......@@ -37,7 +37,7 @@ class TestableEasyUnlockChallengeWrapper : public EasyUnlockChallengeWrapper {
private:
void SignUsingTpmKey(
const std::string& data_to_sign,
const base::Callback<void(const std::string&)>& callback) override {
base::OnceCallback<void(const std::string&)> callback) override {
std::string expected_salt = std::string(kSalt);
std::string expected_channel_binding_data =
std::string(kChannelBindingData);
......@@ -54,7 +54,7 @@ class TestableEasyUnlockChallengeWrapper : public EasyUnlockChallengeWrapper {
securemessage::HeaderAndBody proto;
EXPECT_TRUE(proto.ParseFromString(header_and_body));
callback.Run(kSignature);
std::move(callback).Run(kSignature);
}
DISALLOW_COPY_AND_ASSIGN(TestableEasyUnlockChallengeWrapper);
......@@ -65,7 +65,7 @@ class TestableEasyUnlockChallengeWrapper : public EasyUnlockChallengeWrapper {
TEST(EasyUnlockChallengeWrapperTest, TestWrapChallenge) {
TestableEasyUnlockChallengeWrapper wrapper;
std::string wrapped_challenge;
wrapper.WrapChallenge(base::Bind(&SaveResult, &wrapped_challenge));
wrapper.WrapChallenge(base::BindOnce(&SaveResult, &wrapped_challenge));
securemessage::SecureMessage challenge_secure_message;
ASSERT_TRUE(challenge_secure_message.ParseFromString(wrapped_challenge));
......
......@@ -47,12 +47,12 @@ const int kEasyUnlockKeyPrivileges =
class EasyUnlockCreateKeysOperation::ChallengeCreator {
public:
typedef base::Callback<void(bool success)> ChallengeCreatedCallback;
using ChallengeCreatedCallback = base::OnceCallback<void(bool success)>;
ChallengeCreator(const std::string& user_key,
const std::string& session_key,
const std::string& tpm_pub_key,
EasyUnlockDeviceKeyData* device,
const ChallengeCreatedCallback& callback);
ChallengeCreatedCallback callback);
~ChallengeCreator();
void Start();
......@@ -95,12 +95,12 @@ EasyUnlockCreateKeysOperation::ChallengeCreator::ChallengeCreator(
const std::string& session_key,
const std::string& tpm_pub_key,
EasyUnlockDeviceKeyData* device,
const ChallengeCreatedCallback& callback)
ChallengeCreatedCallback callback)
: user_key_(user_key),
session_key_(session_key),
tpm_pub_key_(tpm_pub_key),
device_(device),
callback_(callback),
callback_(std::move(callback)),
easy_unlock_client_(DBusThreadManager::Get()->GetEasyUnlockClient()) {}
EasyUnlockCreateKeysOperation::ChallengeCreator::~ChallengeCreator() {}
......@@ -115,7 +115,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnEcKeyPairGenerated(
const std::string& ec_public_key) {
if (ec_private_key.empty() || ec_public_key.empty()) {
PA_LOG(ERROR) << "Easy unlock failed to generate ec key pair.";
callback_.Run(false);
std::move(callback_).Run(false);
return;
}
......@@ -124,7 +124,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnEcKeyPairGenerated(
base::Base64UrlDecodePolicy::REQUIRE_PADDING,
&device_pub_key)) {
PA_LOG(ERROR) << "Easy unlock failed to decode device public key.";
callback_.Run(false);
std::move(callback_).Run(false);
return;
}
......@@ -139,7 +139,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnEskGenerated(
const std::string& esk) {
if (esk.empty()) {
PA_LOG(ERROR) << "Easy unlock failed to generate challenge esk.";
callback_.Run(false);
std::move(callback_).Run(false);
return;
}
......@@ -158,7 +158,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnTPMPublicKeyWrapped(
const std::string& wrapped_key) {
if (wrapped_key.empty()) {
PA_LOG(ERROR) << "Unable to wrap RSA key";
callback_.Run(false);
std::move(callback_).Run(false);
return;
}
wrapped_tpm_pub_key_ = wrapped_key;
......@@ -196,7 +196,7 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnPayloadGenerated(
const std::string& payload) {
if (payload.empty()) {
PA_LOG(ERROR) << "Easy unlock failed to generate challenge payload.";
callback_.Run(false);
std::move(callback_).Run(false);
return;
}
......@@ -216,12 +216,12 @@ void EasyUnlockCreateKeysOperation::ChallengeCreator::OnChallengeGenerated(
const std::string& challenge) {
if (challenge.empty()) {
PA_LOG(ERROR) << "Easy unlock failed to generate challenge.";
callback_.Run(false);
std::move(callback_).Run(false);
return;
}
device_->challenge = challenge;
callback_.Run(true);
std::move(callback_).Run(true);
}
/////////////////////////////////////////////////////////////////////////////
......@@ -231,11 +231,11 @@ EasyUnlockCreateKeysOperation::EasyUnlockCreateKeysOperation(
const UserContext& user_context,
const std::string& tpm_public_key,
const EasyUnlockDeviceKeyDataList& devices,
const CreateKeysCallback& callback)
CreateKeysCallback callback)
: user_context_(user_context),
tpm_public_key_(tpm_public_key),
devices_(devices),
callback_(callback),
callback_(std::move(callback)),
key_creation_index_(0) {
// Must have the secret and callback.
DCHECK(!user_context_.GetKey()->GetSecret().empty());
......@@ -252,7 +252,7 @@ void EasyUnlockCreateKeysOperation::Start() {
void EasyUnlockCreateKeysOperation::CreateKeyForDeviceAtIndex(size_t index) {
DCHECK_GE(index, 0u);
if (index == devices_.size()) {
callback_.Run(true);
std::move(callback_).Run(true);
return;
}
......@@ -268,20 +268,20 @@ void EasyUnlockCreateKeysOperation::CreateKeyForDeviceAtIndex(size_t index) {
crypto::Encryptor encryptor;
if (!encryptor.Init(session_key.get(), crypto::Encryptor::CBC, iv)) {
PA_LOG(ERROR) << "Easy unlock failed to init encryptor for key creation.";
callback_.Run(false);
std::move(callback_).Run(false);
return;
}
EasyUnlockDeviceKeyData* device = &devices_[index];
if (!encryptor.Encrypt(user_key, &device->wrapped_secret)) {
PA_LOG(ERROR) << "Easy unlock failed to encrypt user key for key creation.";
callback_.Run(false);
std::move(callback_).Run(false);
return;
}
challenge_creator_.reset(new ChallengeCreator(
user_key, session_key->key(), tpm_public_key_, device,
base::Bind(&EasyUnlockCreateKeysOperation::OnChallengeCreated,
base::BindOnce(&EasyUnlockCreateKeysOperation::OnChallengeCreated,
weak_ptr_factory_.GetWeakPtr(), index)));
challenge_creator_->Start();
}
......@@ -292,7 +292,7 @@ void EasyUnlockCreateKeysOperation::OnChallengeCreated(size_t index,
if (!success) {
PA_LOG(ERROR) << "Easy unlock failed to create challenge for key creation.";
callback_.Run(false);
std::move(callback_).Run(false);
return;
}
......@@ -307,7 +307,7 @@ void EasyUnlockCreateKeysOperation::OnGetSystemSalt(
DCHECK_EQ(key_creation_index_, index);
if (system_salt.empty()) {
PA_LOG(ERROR) << "Easy unlock failed to get system salt for key creation.";
callback_.Run(false);
std::move(callback_).Run(false);
return;
}
......@@ -367,7 +367,7 @@ void EasyUnlockCreateKeysOperation::OnKeyCreated(
if (!success) {
PA_LOG(ERROR) << "Easy unlock failed to create key, code=" << return_code;
callback_.Run(false);
std::move(callback_).Run(false);
return;
}
......
......@@ -24,11 +24,11 @@ class UserContext;
// A class to create Easy unlock cryptohome keys for the given user and devices.
class EasyUnlockCreateKeysOperation {
public:
typedef base::Callback<void(bool success)> CreateKeysCallback;
using CreateKeysCallback = base::OnceCallback<void(bool success)>;
EasyUnlockCreateKeysOperation(const UserContext& user_context,
const std::string& tpm_public_key,
const EasyUnlockDeviceKeyDataList& devices,
const CreateKeysCallback& callback);
CreateKeysCallback callback);
~EasyUnlockCreateKeysOperation();
void Start();
......
......@@ -22,8 +22,10 @@ namespace chromeos {
EasyUnlockGetKeysOperation::EasyUnlockGetKeysOperation(
const UserContext& user_context,
const GetKeysCallback& callback)
: user_context_(user_context), callback_(callback), key_index_(0) {}
GetKeysCallback callback)
: user_context_(user_context),
callback_(std::move(callback)),
key_index_(0) {}
EasyUnlockGetKeysOperation::~EasyUnlockGetKeysOperation() {}
......@@ -37,7 +39,7 @@ void EasyUnlockGetKeysOperation::Start() {
void EasyUnlockGetKeysOperation::OnCryptohomeAvailable(bool available) {
if (!available) {
PA_LOG(ERROR) << "Failed to wait for cryptohome to become available";
callback_.Run(false, EasyUnlockDeviceKeyDataList());
std::move(callback_).Run(false, EasyUnlockDeviceKeyDataList());
return;
}
......@@ -81,12 +83,12 @@ void EasyUnlockGetKeysOperation::OnGetKeyData(
if (devices_.size() == 1)
devices_[0].unlock_key = true;
callback_.Run(true, devices_);
std::move(callback_).Run(true, devices_);
return;
}
PA_LOG(ERROR) << "Easy unlock failed to get key data, code=" << return_code;
callback_.Run(false, EasyUnlockDeviceKeyDataList());
std::move(callback_).Run(false, EasyUnlockDeviceKeyDataList());
return;
}
......
......@@ -21,11 +21,11 @@ namespace chromeos {
class EasyUnlockGetKeysOperation {
public:
typedef base::Callback<void(bool success,
const EasyUnlockDeviceKeyDataList& data_list)>
GetKeysCallback;
using GetKeysCallback =
base::OnceCallback<void(bool success,
const EasyUnlockDeviceKeyDataList& data_list)>;
EasyUnlockGetKeysOperation(const UserContext& user_context,
const GetKeysCallback& callback);
GetKeysCallback callback);
~EasyUnlockGetKeysOperation();
// Starts the operation. If the cryptohome service is not yet available, the
......
......@@ -25,24 +25,26 @@ EasyUnlockKeyManager::~EasyUnlockKeyManager() {}
void EasyUnlockKeyManager::RefreshKeys(const UserContext& user_context,
const base::ListValue& remote_devices,
const RefreshKeysCallback& callback) {
base::Closure do_refresh_keys =
base::Bind(&EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent,
weak_ptr_factory_.GetWeakPtr(), user_context,
base::Owned(remote_devices.DeepCopy()), callback);
RefreshKeysCallback callback) {
EasyUnlockTpmKeyManager* tpm_key_manager =
EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser(
user_context.GetAccountId().GetUserEmail());
if (!tpm_key_manager) {
PA_LOG(ERROR) << "No TPM key manager.";
callback.Run(false);
std::move(callback).Run(false);
return;
}
// This callback will only be executed once but must be marked repeating
// because it could be discarded by PrepareTpmKey() and invoked here instead.
auto do_refresh_keys = base::BindRepeating(
&EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent,
weak_ptr_factory_.GetWeakPtr(), user_context,
base::Owned(remote_devices.DeepCopy()), base::Passed(&callback));
// Private TPM key is needed only when adding new keys.
if (remote_devices.empty() ||
tpm_key_manager->PrepareTpmKey(false /* check_private_key */,
tpm_key_manager->PrepareTpmKey(/*check_private_key=*/false,
do_refresh_keys)) {
do_refresh_keys.Run();
} else {
......@@ -59,7 +61,7 @@ void EasyUnlockKeyManager::RefreshKeys(const UserContext& user_context,
void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent(
const UserContext& user_context,
base::ListValue* remote_devices,
const RefreshKeysCallback& callback) {
RefreshKeysCallback callback) {
EasyUnlockTpmKeyManager* tpm_key_manager =
EasyUnlockTpmKeyManagerFactory::GetInstance()->GetForUser(
user_context.GetAccountId().GetUserEmail());
......@@ -73,17 +75,18 @@ void EasyUnlockKeyManager::RefreshKeysWithTpmKeyPresent(
write_operation_queue_.push_back(
std::make_unique<EasyUnlockRefreshKeysOperation>(
user_context, tpm_public_key, devices,
base::Bind(&EasyUnlockKeyManager::OnKeysRefreshed,
weak_ptr_factory_.GetWeakPtr(), callback)));
base::BindOnce(&EasyUnlockKeyManager::OnKeysRefreshed,
weak_ptr_factory_.GetWeakPtr(), std::move(callback))));
RunNextOperation();
}
void EasyUnlockKeyManager::GetDeviceDataList(
const UserContext& user_context,
const GetDeviceDataListCallback& callback) {
GetDeviceDataListCallback callback) {
read_operation_queue_.push_back(std::make_unique<EasyUnlockGetKeysOperation>(
user_context, base::Bind(&EasyUnlockKeyManager::OnKeysFetched,
weak_ptr_factory_.GetWeakPtr(), callback)));
user_context,
base::BindOnce(&EasyUnlockKeyManager::OnKeysFetched,
weak_ptr_factory_.GetWeakPtr(), std::move(callback))));
RunNextOperation();
}
......@@ -205,10 +208,10 @@ void EasyUnlockKeyManager::RunNextOperation() {
}
}
void EasyUnlockKeyManager::OnKeysRefreshed(const RefreshKeysCallback& callback,
void EasyUnlockKeyManager::OnKeysRefreshed(RefreshKeysCallback callback,
bool refresh_success) {
if (!callback.is_null())
callback.Run(refresh_success);
std::move(callback).Run(refresh_success);
DCHECK(pending_write_operation_);
pending_write_operation_.reset();
......@@ -216,11 +219,11 @@ void EasyUnlockKeyManager::OnKeysRefreshed(const RefreshKeysCallback& callback,
}
void EasyUnlockKeyManager::OnKeysFetched(
const GetDeviceDataListCallback& callback,
GetDeviceDataListCallback callback,
bool fetch_success,
const EasyUnlockDeviceKeyDataList& fetched_data) {
if (!callback.is_null())
callback.Run(fetch_success, fetched_data);
std::move(callback).Run(fetch_success, fetched_data);
DCHECK(pending_read_operation_);
pending_read_operation_.reset();
......
......@@ -33,9 +33,9 @@ class UserContext;
// A class to manage Easy unlock cryptohome keys.
class EasyUnlockKeyManager {
public:
typedef EasyUnlockRefreshKeysOperation::RefreshKeysCallback
RefreshKeysCallback;
typedef EasyUnlockGetKeysOperation::GetKeysCallback GetDeviceDataListCallback;
using RefreshKeysCallback =
EasyUnlockRefreshKeysOperation::RefreshKeysCallback;
using GetDeviceDataListCallback = EasyUnlockGetKeysOperation::GetKeysCallback;
EasyUnlockKeyManager();
~EasyUnlockKeyManager();
......@@ -45,12 +45,12 @@ class EasyUnlockKeyManager {
// secret to allow keys to be created.
void RefreshKeys(const UserContext& user_context,
const base::ListValue& remote_devices,
const RefreshKeysCallback& callback);
RefreshKeysCallback callback);
// Retrieves the remote device data from cryptohome keys for the given
// `user_context`.
void GetDeviceDataList(const UserContext& user_context,
const GetDeviceDataListCallback& callback);
GetDeviceDataListCallback callback);
// Helpers to convert between DeviceData and remote device dictionary.
// DeviceDataToRemoteDeviceDictionary fills the remote device dictionary and
......@@ -88,14 +88,13 @@ class EasyUnlockKeyManager {
// challenges.
void RefreshKeysWithTpmKeyPresent(const UserContext& user_context,
base::ListValue* remote_devices,
const RefreshKeysCallback& callback);
RefreshKeysCallback callback);
// Callback invoked after refresh keys operation.
void OnKeysRefreshed(const RefreshKeysCallback& callback,
bool create_success);
void OnKeysRefreshed(RefreshKeysCallback callback, bool create_success);
// Callback invoked after get keys op.
void OnKeysFetched(const GetDeviceDataListCallback& callback,
void OnKeysFetched(GetDeviceDataListCallback callback,
bool fetch_success,
const EasyUnlockDeviceKeyDataList& fetched_data);
......
......@@ -13,11 +13,11 @@ EasyUnlockRefreshKeysOperation::EasyUnlockRefreshKeysOperation(
const UserContext& user_context,
const std::string& tpm_public_key,
const EasyUnlockDeviceKeyDataList& devices,
const RefreshKeysCallback& callback)
RefreshKeysCallback callback)
: user_context_(user_context),
tpm_public_key_(tpm_public_key),
devices_(devices),
callback_(callback) {}
callback_(std::move(callback)) {}
EasyUnlockRefreshKeysOperation::~EasyUnlockRefreshKeysOperation() {}
......@@ -30,14 +30,14 @@ void EasyUnlockRefreshKeysOperation::Start() {
create_keys_operation_.reset(new EasyUnlockCreateKeysOperation(
user_context_, tpm_public_key_, devices_,
base::Bind(&EasyUnlockRefreshKeysOperation::OnKeysCreated,
base::BindOnce(&EasyUnlockRefreshKeysOperation::OnKeysCreated,
weak_ptr_factory_.GetWeakPtr())));
create_keys_operation_->Start();
}
void EasyUnlockRefreshKeysOperation::OnKeysCreated(bool success) {
if (!success) {
callback_.Run(false);
std::move(callback_).Run(false);
return;
}
......@@ -56,13 +56,13 @@ void EasyUnlockRefreshKeysOperation::RemoveKeysStartingFromIndex(
size_t key_index) {
remove_keys_operation_.reset(new EasyUnlockRemoveKeysOperation(
user_context_, key_index,
base::Bind(&EasyUnlockRefreshKeysOperation::OnKeysRemoved,
base::BindOnce(&EasyUnlockRefreshKeysOperation::OnKeysRemoved,
weak_ptr_factory_.GetWeakPtr())));
remove_keys_operation_->Start();
}
void EasyUnlockRefreshKeysOperation::OnKeysRemoved(bool success) {
callback_.Run(success);
std::move(callback_).Run(success);
}
} // namespace chromeos
......@@ -24,11 +24,11 @@ class UserContext;
// remove keys operations.
class EasyUnlockRefreshKeysOperation {
public:
typedef base::Callback<void(bool success)> RefreshKeysCallback;
using RefreshKeysCallback = base::OnceCallback<void(bool success)>;
EasyUnlockRefreshKeysOperation(const UserContext& user_context,
const std::string& tpm_public_key,
const EasyUnlockDeviceKeyDataList& devices,
const RefreshKeysCallback& callback);
RefreshKeysCallback callback);
~EasyUnlockRefreshKeysOperation();
void Start();
......
......@@ -17,9 +17,9 @@ namespace chromeos {
EasyUnlockRemoveKeysOperation::EasyUnlockRemoveKeysOperation(
const UserContext& user_context,
size_t start_index,
const RemoveKeysCallback& callback)
RemoveKeysCallback callback)
: user_context_(user_context),
callback_(callback),
callback_(std::move(callback)),
key_index_(start_index) {
// Must have the secret and callback.
DCHECK(!user_context_.GetKey()->GetSecret().empty());
......@@ -74,11 +74,11 @@ void EasyUnlockRemoveKeysOperation::OnKeyRemoved(
// MOUNT_ERROR_KEY_FAILURE is considered as success. Other error codes are
// treated as failures.
if (return_code == cryptohome::MOUNT_ERROR_KEY_FAILURE) {
callback_.Run(true);
std::move(callback_).Run(true);
} else {
LOG(ERROR) << "Easy unlock remove keys operation failed, code="
<< return_code;
callback_.Run(false);
std::move(callback_).Run(false);
}
}
......
......@@ -21,10 +21,10 @@ class UserContext;
// index.
class EasyUnlockRemoveKeysOperation {
public:
typedef base::Callback<void(bool success)> RemoveKeysCallback;
using RemoveKeysCallback = base::OnceCallback<void(bool success)>;
EasyUnlockRemoveKeysOperation(const UserContext& user_context,
size_t start_index,
const RemoveKeysCallback& callback);
RemoveKeysCallback callback);
~EasyUnlockRemoveKeysOperation();
void Start();
......
......@@ -397,8 +397,9 @@ void EasyUnlockService::CheckCryptohomeKeysAndMaybeHardlock() {
DCHECK(user);
key_manager->GetDeviceDataList(
UserContext(*user),
base::Bind(&EasyUnlockService::OnCryptohomeKeysFetchedForChecking,
weak_ptr_factory_.GetWeakPtr(), account_id, paired_devices));
base::BindOnce(&EasyUnlockService::OnCryptohomeKeysFetchedForChecking,
weak_ptr_factory_.GetWeakPtr(), account_id,
paired_devices));
}
void EasyUnlockService::Shutdown() {
......@@ -685,7 +686,7 @@ void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() {
// TODO(tbarzic): Set check_private_key only if previous sign-in attempt
// failed.
EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_)->PrepareTpmKey(
true /* check_private_key */, base::Closure());
/*check_private_key=*/true, base::OnceClosure());
tpm_key_checked_ = true;
}
......
......@@ -326,7 +326,8 @@ void EasyUnlockServiceRegular::InitializeInternal() {
registrar_.Init(profile()->GetPrefs());
registrar_.Add(
proximity_auth::prefs::kProximityAuthIsChromeOSLoginEnabled,
base::Bind(&EasyUnlockServiceRegular::CheckCryptohomeKeysAndMaybeHardlock,
base::BindRepeating(
&EasyUnlockServiceRegular::CheckCryptohomeKeysAndMaybeHardlock,
weak_ptr_factory_.GetWeakPtr()));
// If `device_sync_client_` is not ready yet, wait for it to call back on
......
......@@ -56,10 +56,9 @@ uint32_t GetNextBackoffInterval(uint32_t backoff) {
return backoff * 2;
}
void LoadDataForUser(
const AccountId& account_id,
void LoadDataForUser(const AccountId& account_id,
uint32_t backoff_ms,
const EasyUnlockKeyManager::GetDeviceDataListCallback& callback);
EasyUnlockKeyManager::GetDeviceDataListCallback callback);
// Callback passed to `LoadDataForUser()`.
// If `LoadDataForUser` function succeeded, it invokes `callback` with the
......@@ -70,31 +69,31 @@ void LoadDataForUser(
void RetryDataLoadOnError(
const AccountId& account_id,
uint32_t backoff_ms,
const EasyUnlockKeyManager::GetDeviceDataListCallback& callback,
EasyUnlockKeyManager::GetDeviceDataListCallback callback,
bool success,
const EasyUnlockDeviceKeyDataList& data_list) {
if (success) {
callback.Run(success, data_list);
std::move(callback).Run(success, data_list);
return;
}
uint32_t next_backoff_ms = GetNextBackoffInterval(backoff_ms);
if (next_backoff_ms > kMaxCryptohomeBackoffIntervalMs) {
callback.Run(false, data_list);
std::move(callback).Run(false, data_list);
return;
}
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&LoadDataForUser, account_id, next_backoff_ms, callback),
base::BindOnce(&LoadDataForUser, account_id, next_backoff_ms,
std::move(callback)),
base::TimeDelta::FromMilliseconds(next_backoff_ms));
}
// Loads device data list associated with the user's Easy unlock keys.
void LoadDataForUser(
const AccountId& account_id,
void LoadDataForUser(const AccountId& account_id,
uint32_t backoff_ms,
const EasyUnlockKeyManager::GetDeviceDataListCallback& callback) {
EasyUnlockKeyManager::GetDeviceDataListCallback callback) {
EasyUnlockKeyManager* key_manager =
UserSessionManager::GetInstance()->GetEasyUnlockKeyManager();
DCHECK(key_manager);
......@@ -103,8 +102,8 @@ void LoadDataForUser(
user_manager::UserManager::Get()->FindUser(account_id);
DCHECK(user);
key_manager->GetDeviceDataList(
UserContext(*user),
base::Bind(&RetryDataLoadOnError, account_id, backoff_ms, callback));
UserContext(*user), base::BindOnce(&RetryDataLoadOnError, account_id,
backoff_ms, std::move(callback)));
}
// Deserializes a vector of BeaconSeeds. If an error occurs, an empty vector
......@@ -183,11 +182,11 @@ void EasyUnlockServiceSignin::WrapChallengeForUserAndDevice(
const AccountId& account_id,
const std::string& device_public_key,
const std::string& channel_binding_data,
base::Callback<void(const std::string& wraped_challenge)> callback) {
base::OnceCallback<void(const std::string& wraped_challenge)> callback) {
auto it = user_data_.find(account_id);
if (it == user_data_.end() || it->second->state != USER_DATA_STATE_LOADED) {
PA_LOG(ERROR) << "TPM data not loaded for " << account_id.Serialize();
callback.Run(std::string());
std::move(callback).Run(std::string());
return;
}
......@@ -202,14 +201,14 @@ void EasyUnlockServiceSignin::WrapChallengeForUserAndDevice(
challenge_wrapper_.reset(new EasyUnlockChallengeWrapper(
device_data.challenge, channel_binding_data, account_id,
EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile())));
challenge_wrapper_->WrapChallenge(callback);
challenge_wrapper_->WrapChallenge(std::move(callback));
return;
}
}
PA_LOG(ERROR) << "Unable to find device record for "
<< account_id.Serialize();
callback.Run(std::string());
std::move(callback).Run(std::string());
}
proximity_auth::ProximityAuthPrefManager*
......@@ -437,7 +436,7 @@ void EasyUnlockServiceSignin::LoadCurrentUserDataIfNeeded() {
LoadDataForUser(
account_id_,
allow_cryptohome_backoff_ ? 0u : kMaxCryptohomeBackoffIntervalMs,
base::Bind(&EasyUnlockServiceSignin::OnUserDataLoaded,
base::BindOnce(&EasyUnlockServiceSignin::OnUserDataLoaded,
weak_ptr_factory_.GetWeakPtr(), account_id_));
}
......
......@@ -53,7 +53,7 @@ class EasyUnlockServiceSignin
const AccountId& account_id,
const std::string& device_public_key,
const std::string& channel_binding_data,
base::Callback<void(const std::string& wraped_challenge)> callback);
base::OnceCallback<void(const std::string& wraped_challenge)> callback);
private:
// The load state of a user's cryptohome key data.
......
......@@ -58,7 +58,7 @@ class EasyUnlockTpmKeyManager : public KeyedService {
// signin does not remain permanently broken if something goes wrong.
// `callback`: If the method cannot return immediately, called when the key
// pair presence is confirmed (or a key pair for the user is created).
bool PrepareTpmKey(bool check_private_key, const base::Closure& callback);
bool PrepareTpmKey(bool check_private_key, base::OnceClosure callback);
// If called, posts a delayed task that cancels `PrepareTpmKey` and all other
// started timeouts in case getting system slot takes more than `timeout_ms`.
......@@ -75,7 +75,7 @@ class EasyUnlockTpmKeyManager : public KeyedService {
void SignUsingTpmKey(
const AccountId& account_id,
const std::string& data,
const base::Callback<void(const std::string& data)> callback);
base::OnceCallback<void(const std::string& data)> callback);
bool StartedCreatingTpmKeys() const;
......@@ -117,7 +117,7 @@ class EasyUnlockTpmKeyManager : public KeyedService {
void SignDataWithSystemSlot(
const std::string& public_key,
const std::string& data,
const base::Callback<void(const std::string& data)> callback,
base::OnceCallback<void(const std::string& data)> callback,
crypto::ScopedPK11Slot system_slot);
// Called when a RSA key pair is created for a user in TPM system slot.
......@@ -128,7 +128,7 @@ class EasyUnlockTpmKeyManager : public KeyedService {
// Called when data signing requested in `SignUsingTpmKey` is done.
// It runs `callback` with the created `signature`. On error the callback will
// be run with an empty string.
void OnDataSigned(const base::Callback<void(const std::string&)>& callback,
void OnDataSigned(base::OnceCallback<void(const std::string&)> callback,
const std::string& signature);
const AccountId account_id_;
......@@ -142,7 +142,7 @@ class EasyUnlockTpmKeyManager : public KeyedService {
CreateTpmKeyState create_tpm_key_state_;
// Queued up `PrepareTpmKey` callbacks.
std::vector<base::Closure> prepare_tpm_key_callbacks_;
std::vector<base::OnceClosure> prepare_tpm_key_callbacks_;
base::WeakPtrFactory<EasyUnlockTpmKeyManager> get_tpm_slot_weak_ptr_factory_{
this};
......
......@@ -188,10 +188,10 @@ void IncreaseCount(int* count) {
// Sets `*result` to `value` and runs `callback`.
// Used as a callback to EasyUnlockTpmKeyManager::SignUsingTpmKey in tests.
void RecordStringAndRunClosure(std::string* result,
const base::Closure& callback,
base::OnceClosure callback,
const std::string& value) {
*result = value;
callback.Run();
std::move(callback).Run();
}
class EasyUnlockTpmKeyManagerTest : public testing::Test {
......@@ -380,7 +380,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPair) {
signin_key_manager()->GetPublicTpmKey(test_account_id_));
EXPECT_TRUE(user_key_manager()->PrepareTpmKey(
false /* check_private_key */, base::Bind(&ExpectNotCalledCallback)));
/*check_private_key=*/false, base::BindOnce(&ExpectNotCalledCallback)));
}
TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPairMultipleCallbacks) {
......@@ -392,14 +392,14 @@ TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPairMultipleCallbacks) {
ASSERT_FALSE(user_key_manager()->PrepareTpmKey(false /* check_private_key */,
run_loop.QuitClosure()));
EXPECT_FALSE(user_key_manager()->PrepareTpmKey(
false /* check_private_key */,
base::Bind(&IncreaseCount, &callback_count)));
/*check_private_key=*/false,
base::BindOnce(&IncreaseCount, &callback_count)));
EXPECT_FALSE(user_key_manager()->PrepareTpmKey(
false /* check_private_key */,
base::Bind(&IncreaseCount, &callback_count)));
/*check_private_key=*/false,
base::BindOnce(&IncreaseCount, &callback_count)));
// Verify that the method works with empty callback.
EXPECT_FALSE(user_key_manager()->PrepareTpmKey(false /* check_private_key */,
base::Closure()));
EXPECT_FALSE(user_key_manager()->PrepareTpmKey(/*check_private_key=*/false,
base::OnceClosure()));
ASSERT_TRUE(SetUpTestSystemSlot());
VerifyKeyGenerationNotStartedAndFinalizeTestNssUser();
......@@ -413,7 +413,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, CreateKeyPairMultipleCallbacks) {
signin_key_manager()->GetPublicTpmKey(test_account_id_));
EXPECT_TRUE(user_key_manager()->PrepareTpmKey(
false /* check_private_key */, base::Bind(&ExpectNotCalledCallback)));
/*check_private_key=*/false, base::BindOnce(&ExpectNotCalledCallback)));
}
TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefs) {
......@@ -422,7 +422,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefs) {
std::string(kTestPublicKey, base::size(kTestPublicKey)));
EXPECT_TRUE(user_key_manager()->PrepareTpmKey(
false /* check_private_key */, base::Bind(&ExpectNotCalledCallback)));
/*check_private_key=*/false, base::BindOnce(&ExpectNotCalledCallback)));
EXPECT_FALSE(user_key_manager()->GetPublicTpmKey(test_account_id_).empty());
EXPECT_EQ(user_key_manager()->GetPublicTpmKey(test_account_id_),
......@@ -468,8 +468,8 @@ TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefsCheckPrivateKey_OK) {
run_loop.QuitClosure()));
EXPECT_FALSE(user_key_manager()->PrepareTpmKey(
false /* check_private_key */,
base::Bind(&IncreaseCount, &callback_count)));
/*check_private_key=*/false,
base::BindOnce(&IncreaseCount, &callback_count)));
run_loop.Run();
......@@ -481,7 +481,7 @@ TEST_F(EasyUnlockTpmKeyManagerTest, PublicKeySetInPrefsCheckPrivateKey_OK) {
signin_key_manager()->GetPublicTpmKey(test_account_id_));
EXPECT_TRUE(user_key_manager()->PrepareTpmKey(
true /* check_private_key */, base::Bind(&ExpectNotCalledCallback)));
/*check_private_key=*/true, base::BindOnce(&ExpectNotCalledCallback)));
}
TEST_F(EasyUnlockTpmKeyManagerTest, GetSystemSlotTimeoutTriggers) {
......@@ -559,7 +559,8 @@ TEST_F(EasyUnlockTpmKeyManagerTest, SignData) {
std::string signed_data;
signin_key_manager()->SignUsingTpmKey(
test_account_id_, "data",
base::Bind(&RecordStringAndRunClosure, &signed_data, loop.QuitClosure()));
base::BindOnce(&RecordStringAndRunClosure, &signed_data,
loop.QuitClosure()));
loop.Run();
EXPECT_FALSE(signed_data.empty());
......@@ -570,7 +571,8 @@ TEST_F(EasyUnlockTpmKeyManagerTest, SignNoPublicKeySet) {
std::string signed_data;
signin_key_manager()->SignUsingTpmKey(
test_account_id_, "data",
base::Bind(&RecordStringAndRunClosure, &signed_data, loop.QuitClosure()));
base::BindOnce(&RecordStringAndRunClosure, &signed_data,
loop.QuitClosure()));
loop.Run();
EXPECT_TRUE(signed_data.empty());
......@@ -585,7 +587,8 @@ TEST_F(EasyUnlockTpmKeyManagerTest, SignDataNoPrivateKeyPresent) {
std::string signed_data;
signin_key_manager()->SignUsingTpmKey(
test_account_id_, "data",
base::Bind(&RecordStringAndRunClosure, &signed_data, loop.QuitClosure()));
base::BindOnce(&RecordStringAndRunClosure, &signed_data,
loop.QuitClosure()));
ASSERT_TRUE(SetUpTestSystemSlot());
......
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