Commit 4fb93a25 authored by Reilly Grant's avatar Reilly Grant Committed by Chromium LUCI CQ

Convert callbacks in //chromeos/components/proximity_auth

This change converts callbacks from base::Bind and base::Callback to
Once/Repeating in //chromeos/components/proximity_auth.

Bug: 1007654
Change-Id: I55f3a3a1a4b30a628f106886ffa9937c01849fc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2637412
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845365}
parent d300702e
......@@ -53,18 +53,18 @@ void ChromeProximityAuthClient::GetChallengeForUserAndDevice(
const std::string& user_email,
const std::string& remote_public_key,
const std::string& channel_binding_data,
base::Callback<void(const std::string& challenge)> callback) {
base::OnceCallback<void(const std::string& challenge)> callback) {
EasyUnlockService* easy_unlock_service = EasyUnlockService::Get(profile_);
if (easy_unlock_service->GetType() == EasyUnlockService::TYPE_REGULAR) {
PA_LOG(ERROR) << "Unable to get challenge when user is logged in.";
callback.Run(std::string() /* challenge */);
std::move(callback).Run(/*challenge=*/std::string());
return;
}
static_cast<EasyUnlockServiceSignin*>(easy_unlock_service)
->WrapChallengeForUserAndDevice(AccountId::FromUserEmail(user_email),
remote_public_key, channel_binding_data,
callback);
std::move(callback));
}
proximity_auth::ProximityAuthPrefManager*
......
......@@ -27,7 +27,7 @@ class ChromeProximityAuthClient : public proximity_auth::ProximityAuthClient {
const std::string& user_email,
const std::string& remote_public_key,
const std::string& nonce,
base::Callback<void(const std::string& challenge)> callback) override;
base::OnceCallback<void(const std::string& challenge)> callback) override;
proximity_auth::ProximityAuthPrefManager* GetPrefManager() override;
private:
......
......@@ -30,7 +30,7 @@ class MockProximityAuthClient : public ProximityAuthClient {
void(const std::string& user_id,
const std::string& remote_public_key,
const std::string& channel_binding_data,
base::Callback<void(const std::string& challenge)> callback));
base::OnceCallback<void(const std::string& challenge)> callback));
MOCK_CONST_METHOD0(GetAuthenticatedUsername, std::string(void));
MOCK_METHOD0(GetPrefManager, ProximityAuthPrefManager*(void));
......
......@@ -44,7 +44,7 @@ class ProximityAuthClient {
const std::string& user_email,
const std::string& remote_public_key,
const std::string& channel_binding_data,
base::Callback<void(const std::string& challenge)> callback) = 0;
base::OnceCallback<void(const std::string& challenge)> callback) = 0;
// Returns the manager responsible for EasyUnlock preferences.
virtual ProximityAuthPrefManager* GetPrefManager() = 0;
......
......@@ -61,9 +61,9 @@ void ProximityAuthProfilePrefManager::StartSyncingToLocalState(
return;
}
base::Closure on_pref_changed_callback =
base::Bind(&ProximityAuthProfilePrefManager::SyncPrefsToLocalState,
weak_ptr_factory_.GetWeakPtr());
auto on_pref_changed_callback = base::BindRepeating(
&ProximityAuthProfilePrefManager::SyncPrefsToLocalState,
weak_ptr_factory_.GetWeakPtr());
registrar_.Init(pref_service_);
registrar_.Add(chromeos::multidevice_setup::kSmartLockAllowedPrefName,
......@@ -175,7 +175,7 @@ void ProximityAuthProfilePrefManager::SetHasShownLoginDisabledMessage(
bool has_shown) {
// This is persisted within SyncPrefsToLocalState() instead, since the local
// state must act as the source of truth for this pref.
// TODO(crbug.com/1152491): Add a NOTREACHED() to ensure this method is not
// called. It is currently incorrectly, though harmlessly, called by virtual
// Chrome OS on Linux.
......
......@@ -612,8 +612,8 @@ void UnlockManagerImpl::OnGetConnectionMetadata(
proximity_auth_client_->GetChallengeForUserAndDevice(
remote_device.user_email(), remote_device.public_key(),
connection_metadata_ptr->channel_binding_data,
base::Bind(&UnlockManagerImpl::OnGotSignInChallenge,
weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(&UnlockManagerImpl::OnGotSignInChallenge,
weak_ptr_factory_.GetWeakPtr()));
}
void UnlockManagerImpl::OnGotSignInChallenge(const std::string& challenge) {
......
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_simple_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
......@@ -828,12 +829,7 @@ TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_SignIn_Success) {
GetChallengeForUserAndDevice(remote_device_.user_email(),
remote_device_.public_key(),
channel_binding_data, _))
.WillOnce(Invoke(
[](const std::string& user_id, const std::string& public_key,
const std::string& channel_binding_data,
base::Callback<void(const std::string& challenge)> callback) {
callback.Run(kChallenge);
}));
.WillOnce(base::test::RunOnceCallback<3>(kChallenge));
EXPECT_CALL(messenger_, RequestDecryption(kChallenge));
unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK);
......
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