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( ...@@ -53,18 +53,18 @@ void ChromeProximityAuthClient::GetChallengeForUserAndDevice(
const std::string& user_email, const std::string& user_email,
const std::string& remote_public_key, const std::string& remote_public_key,
const std::string& channel_binding_data, 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_); EasyUnlockService* easy_unlock_service = EasyUnlockService::Get(profile_);
if (easy_unlock_service->GetType() == EasyUnlockService::TYPE_REGULAR) { if (easy_unlock_service->GetType() == EasyUnlockService::TYPE_REGULAR) {
PA_LOG(ERROR) << "Unable to get challenge when user is logged in."; 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; return;
} }
static_cast<EasyUnlockServiceSignin*>(easy_unlock_service) static_cast<EasyUnlockServiceSignin*>(easy_unlock_service)
->WrapChallengeForUserAndDevice(AccountId::FromUserEmail(user_email), ->WrapChallengeForUserAndDevice(AccountId::FromUserEmail(user_email),
remote_public_key, channel_binding_data, remote_public_key, channel_binding_data,
callback); std::move(callback));
} }
proximity_auth::ProximityAuthPrefManager* proximity_auth::ProximityAuthPrefManager*
......
...@@ -27,7 +27,7 @@ class ChromeProximityAuthClient : public proximity_auth::ProximityAuthClient { ...@@ -27,7 +27,7 @@ class ChromeProximityAuthClient : public proximity_auth::ProximityAuthClient {
const std::string& user_email, const std::string& user_email,
const std::string& remote_public_key, const std::string& remote_public_key,
const std::string& nonce, 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; proximity_auth::ProximityAuthPrefManager* GetPrefManager() override;
private: private:
......
...@@ -30,7 +30,7 @@ class MockProximityAuthClient : public ProximityAuthClient { ...@@ -30,7 +30,7 @@ class MockProximityAuthClient : public ProximityAuthClient {
void(const std::string& user_id, void(const std::string& user_id,
const std::string& remote_public_key, const std::string& remote_public_key,
const std::string& channel_binding_data, 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_CONST_METHOD0(GetAuthenticatedUsername, std::string(void));
MOCK_METHOD0(GetPrefManager, ProximityAuthPrefManager*(void)); MOCK_METHOD0(GetPrefManager, ProximityAuthPrefManager*(void));
......
...@@ -44,7 +44,7 @@ class ProximityAuthClient { ...@@ -44,7 +44,7 @@ class ProximityAuthClient {
const std::string& user_email, const std::string& user_email,
const std::string& remote_public_key, const std::string& remote_public_key,
const std::string& channel_binding_data, 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. // Returns the manager responsible for EasyUnlock preferences.
virtual ProximityAuthPrefManager* GetPrefManager() = 0; virtual ProximityAuthPrefManager* GetPrefManager() = 0;
......
...@@ -61,8 +61,8 @@ void ProximityAuthProfilePrefManager::StartSyncingToLocalState( ...@@ -61,8 +61,8 @@ void ProximityAuthProfilePrefManager::StartSyncingToLocalState(
return; return;
} }
base::Closure on_pref_changed_callback = auto on_pref_changed_callback = base::BindRepeating(
base::Bind(&ProximityAuthProfilePrefManager::SyncPrefsToLocalState, &ProximityAuthProfilePrefManager::SyncPrefsToLocalState,
weak_ptr_factory_.GetWeakPtr()); weak_ptr_factory_.GetWeakPtr());
registrar_.Init(pref_service_); registrar_.Init(pref_service_);
......
...@@ -612,7 +612,7 @@ void UnlockManagerImpl::OnGetConnectionMetadata( ...@@ -612,7 +612,7 @@ void UnlockManagerImpl::OnGetConnectionMetadata(
proximity_auth_client_->GetChallengeForUserAndDevice( proximity_auth_client_->GetChallengeForUserAndDevice(
remote_device.user_email(), remote_device.public_key(), remote_device.user_email(), remote_device.public_key(),
connection_metadata_ptr->channel_binding_data, connection_metadata_ptr->channel_binding_data,
base::Bind(&UnlockManagerImpl::OnGotSignInChallenge, base::BindOnce(&UnlockManagerImpl::OnGotSignInChallenge,
weak_ptr_factory_.GetWeakPtr())); weak_ptr_factory_.GetWeakPtr()));
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/test/gmock_callback_support.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/test_simple_task_runner.h" #include "base/test/test_simple_task_runner.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
...@@ -828,12 +829,7 @@ TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_SignIn_Success) { ...@@ -828,12 +829,7 @@ TEST_F(ProximityAuthUnlockManagerImplTest, OnAuthAttempted_SignIn_Success) {
GetChallengeForUserAndDevice(remote_device_.user_email(), GetChallengeForUserAndDevice(remote_device_.user_email(),
remote_device_.public_key(), remote_device_.public_key(),
channel_binding_data, _)) channel_binding_data, _))
.WillOnce(Invoke( .WillOnce(base::test::RunOnceCallback<3>(kChallenge));
[](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);
}));
EXPECT_CALL(messenger_, RequestDecryption(kChallenge)); EXPECT_CALL(messenger_, RequestDecryption(kChallenge));
unlock_manager_->OnAuthAttempted(mojom::AuthType::USER_CLICK); 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