Adapt to using the new form of base::DoNothing()

No need to use the templated syntax anymore.

Chromium change:

https://source.chromium.org/chromium/chromium/src/+/e0fc463ca6d8dedd64bb520779aa367c0831581b

commit e0fc463ca6d8dedd64bb520779aa367c0831581b
Author: Daniel Cheng <dcheng@chromium.org>
Date:   Fri Oct 1 00:37:41 2021 +0000

    Update base::DoNothing() / base::NullCallback() to use a type tag.

    This allows both helpers to be used in contexts where the original
    helper required templated arguments to be explicitly specified,
    generally leading to more concise code.

    However, since base::DoNothing() only returns a type tag now, it can no
    longer be used as a functor with base::BindOnce/base::BindRepeating.
    In general, this seems to be a net neutral to slight positive change:
    the lambda version is actually shorter—though some might argue less
    readable—and it generates more efficient code since running the callback
    now jumps through one less thunk.

    Bug: 1252980
This commit is contained in:
Mario Sanchez Prada
2021-11-02 12:38:04 -04:00
committed by Max Karolinskiy
parent 81f0971788
commit 960e7d6c06
7 changed files with 44 additions and 54 deletions
@@ -136,7 +136,7 @@ IN_PROC_BROWSER_TEST_F(BraveWalletEventEmitterTest,
WaitForLoadStop(contents);
auto controller = GetEthJsonRpcController();
controller->SetNetwork(brave_wallet::mojom::kGoerliChainId,
base::DoNothing::Once<bool>());
base::DoNothing());
auto result_first =
EvalJs(contents, CheckForEventScript("received_chain_changed_event"),
@@ -9,6 +9,7 @@
#include <utility>
#include <vector>
#include "base/callback_helpers.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
@@ -348,9 +349,7 @@ class BraveWalletProviderImplUnitTest : public testing::Test {
// current request id will be returned
int SignMessageRequest(const std::string& address,
const std::string& message) {
provider()->SignMessage(
address, message,
base::DoNothing::Once<const std::string&, int, const std::string&>());
provider()->SignMessage(address, message, base::DoNothing());
base::RunLoop().RunUntilIdle();
return provider()->sign_message_id_ - 1;
}
@@ -8,6 +8,7 @@
#include <utility>
#include "base/base64.h"
#include "base/callback_helpers.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "brave/components/brave_wallet/browser/brave_wallet_constants.h"
@@ -515,7 +516,7 @@ TEST_F(KeyringControllerUnitTest, CreateDefaultKeyring) {
TEST_F(KeyringControllerUnitTest, RestoreDefaultKeyring) {
KeyringController controller(GetPrefs());
controller.CreateWallet("brave", base::DoNothing::Once<const std::string&>());
controller.CreateWallet("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
std::string salt = GetStringPrefForKeyring(kPasswordEncryptorSalt, "default");
std::string encrypted_mnemonic =
@@ -575,7 +576,7 @@ TEST_F(KeyringControllerUnitTest, RestoreDefaultKeyring) {
// salt is regenerated and account num is cleared
EXPECT_NE(GetStringPrefForKeyring(kPasswordEncryptorSalt, "default"), salt);
EXPECT_NE(GetStringPrefForKeyring(kPasswordEncryptorNonce, "default"), nonce);
controller.AddAccount("Account 1", base::DoNothing::Once<bool>());
controller.AddAccount("Account 1", base::DoNothing());
base::RunLoop().RunUntilIdle();
EXPECT_EQ(controller.default_keyring_->GetAccountsNumber(), 1u);
EXPECT_EQ(controller.default_keyring_->GetAddress(0),
@@ -588,10 +589,9 @@ TEST_F(KeyringControllerUnitTest, UnlockResumesDefaultKeyring) {
std::string nonce;
{
KeyringController controller(GetPrefs());
controller.CreateWallet("brave",
base::DoNothing::Once<const std::string&>());
controller.CreateWallet("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
controller.AddAccount("Account2", base::DoNothing::Once<bool>());
controller.AddAccount("Account2", base::DoNothing());
base::RunLoop().RunUntilIdle();
salt = GetStringPrefForKeyring(kPasswordEncryptorSalt, "default");
@@ -688,7 +688,7 @@ TEST_F(KeyringControllerUnitTest, GetDefaultKeyringInfo) {
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(callback_called);
controller.CreateWallet("brave", base::DoNothing::Once<const std::string&>());
controller.CreateWallet("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
callback_called = false;
@@ -707,7 +707,7 @@ TEST_F(KeyringControllerUnitTest, GetDefaultKeyringInfo) {
EXPECT_TRUE(callback_called);
controller.NotifyWalletBackupComplete();
controller.AddAccount("Account5566", base::DoNothing::Once<bool>());
controller.AddAccount("Account5566", base::DoNothing());
base::RunLoop().RunUntilIdle();
callback_called = false;
@@ -930,7 +930,7 @@ TEST_F(KeyringControllerUnitTest, CreateAndRestoreWallet) {
TEST_F(KeyringControllerUnitTest, AddAccount) {
KeyringController controller(GetPrefs());
controller.CreateWallet("brave", base::DoNothing::Once<const std::string&>());
controller.CreateWallet("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
bool callback_called = false;
controller.AddAccount("Account5566",
@@ -1025,7 +1025,7 @@ TEST_F(KeyringControllerUnitTest, ImportedAccounts) {
TestKeyringControllerObserver observer;
controller.AddObserver(observer.GetReceiver());
controller.CreateWallet("brave", base::DoNothing::Once<const std::string&>());
controller.CreateWallet("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
const struct {
const char* name;
@@ -1133,7 +1133,7 @@ TEST_F(KeyringControllerUnitTest, ImportedAccounts) {
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(callback_called);
controller.Unlock("brave", base::DoNothing::Once<bool>());
controller.Unlock("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
callback_called = false;
@@ -1222,7 +1222,7 @@ TEST_F(KeyringControllerUnitTest, ImportedAccountFromJson) {
"0xB14Ab53E38DA1C172f877DBC6d65e4a1B0474C3c";
KeyringController controller(GetPrefs());
controller.CreateWallet("brave", base::DoNothing::Once<const std::string&>());
controller.CreateWallet("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
bool callback_called = false;
@@ -1259,7 +1259,7 @@ TEST_F(KeyringControllerUnitTest, ImportedAccountFromJson) {
EXPECT_TRUE(callback_called);
controller.Lock();
controller.Unlock("brave", base::DoNothing::Once<bool>());
controller.Unlock("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
// check restore by getting private key
@@ -1447,7 +1447,7 @@ TEST_F(KeyringControllerUnitTest, SetDefaultKeyringImportedAccountName) {
TestKeyringControllerObserver observer;
controller.AddObserver(observer.GetReceiver());
controller.CreateWallet("brave", base::DoNothing::Once<const std::string&>());
controller.CreateWallet("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
const struct {
@@ -1606,7 +1606,7 @@ TEST_F(KeyringControllerUnitTest, RestoreLegacyBraveWallet) {
// Test lock & unlock to check if it read the right
// legacy_brave_wallet pref so it will use the right seed
controller.Lock();
controller.Unlock("brave1", base::DoNothing::Once<bool>());
controller.Unlock("brave1", base::DoNothing());
base::RunLoop().RunUntilIdle();
account_infos.clear();
account_infos = controller.GetAccountInfosForKeyring("default");
@@ -1630,7 +1630,7 @@ TEST_F(KeyringControllerUnitTest, HardwareAccounts) {
TestKeyringControllerObserver observer;
controller.AddObserver(observer.GetReceiver());
controller.CreateWallet("brave", base::DoNothing::Once<const std::string&>());
controller.CreateWallet("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
std::vector<mojom::HardwareWalletAccountPtr> new_accounts;
@@ -1736,7 +1736,7 @@ TEST_F(KeyringControllerUnitTest, HardwareAccounts) {
TEST_F(KeyringControllerUnitTest, AutoLock) {
KeyringController controller(GetPrefs());
controller.CreateWallet("brave", base::DoNothing::Once<const std::string&>());
controller.CreateWallet("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
const std::string mnemonic = controller.GetMnemonicForDefaultKeyringImpl();
ASSERT_FALSE(controller.IsLocked());
@@ -1776,8 +1776,7 @@ TEST_F(KeyringControllerUnitTest, AutoLock) {
// Restoring keyring will auto lock too
controller.Reset();
controller.RestoreWallet(mnemonic, "brave", false,
base::DoNothing::Once<bool>());
controller.RestoreWallet(mnemonic, "brave", false, base::DoNothing());
ASSERT_FALSE(controller.IsLocked());
task_environment_.FastForwardBy(base::TimeDelta::FromMinutes(6));
ASSERT_TRUE(controller.IsLocked());
@@ -1877,11 +1876,11 @@ TEST_F(KeyringControllerUnitTest, SetSelectedAccount) {
TEST_F(KeyringControllerUnitTest, AddAccountsWithDefaultName) {
KeyringController controller(GetPrefs());
controller.CreateWallet("brave", base::DoNothing::Once<const std::string&>());
controller.CreateWallet("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
ASSERT_FALSE(controller.IsLocked());
controller.AddAccount("AccountAAAAH", base::DoNothing::Once<bool>());
controller.AddAccount("AccountAAAAH", base::DoNothing());
controller.AddAccountsWithDefaultName(3);
@@ -1904,8 +1903,7 @@ TEST_F(KeyringControllerUnitTest, AddAccountsWithDefaultName) {
TEST_F(KeyringControllerUnitTest, SignMessageByDefaultKeyring) {
// HDKeyringUnitTest.SignMessage already tests the correctness of signature
KeyringController controller(GetPrefs());
controller.RestoreWallet(kMnemonic1, "brave", false,
base::DoNothing::Once<bool>());
controller.RestoreWallet(kMnemonic1, "brave", false, base::DoNothing());
base::RunLoop().RunUntilIdle();
ASSERT_FALSE(controller.IsLocked());
@@ -1988,7 +1986,7 @@ TEST_F(KeyringControllerUnitTest, SetDefaultKeyringHardwareAccountName) {
TestKeyringControllerObserver observer;
controller.AddObserver(observer.GetReceiver());
controller.CreateWallet("brave", base::DoNothing::Once<const std::string&>());
controller.CreateWallet("brave", base::DoNothing());
base::RunLoop().RunUntilIdle();
const struct {
@@ -8,6 +8,7 @@
#include <algorithm>
#include <utility>
#include "base/callback_helpers.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/post_task.h"
#include "base/threading/thread_task_runner_handle.h"
@@ -65,7 +66,7 @@ void BraveSyncServiceImplDelegate::OnDeviceInfoChange() {
}
void BraveSyncServiceImplDelegate::OnSelfDeviceInfoDeleted() {
sync_service_impl_->OnSelfDeviceInfoDeleted(base::DoNothing::Once());
sync_service_impl_->OnSelfDeviceInfoDeleted(base::DoNothing());
}
void BraveSyncServiceImplDelegate::SuspendDeviceObserverForOwnReset() {
@@ -10,6 +10,7 @@
#include <utility>
#include <vector>
#include "base/callback_helpers.h"
#include "base/json/json_reader.h"
#include "base/test/bind.h"
#include "brave/components/brave_wallet/browser/asset_ratio_controller.h"
@@ -217,10 +218,9 @@ class EthTxControllerUnitTest : public testing::Test {
run_loop.Quit();
}));
run_loop.Run();
keyring_controller_->CreateWallet(
"testing123", base::DoNothing::Once<const std::string&>());
keyring_controller_->CreateWallet("testing123", base::DoNothing());
base::RunLoop().RunUntilIdle();
keyring_controller_->AddAccount("Account 1", base::DoNothing::Once<bool>());
keyring_controller_->AddAccount("Account 1", base::DoNothing());
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(base::HexStringToBytes(
+7 -11
View File
@@ -5,6 +5,7 @@
#include "brave/components/tor/tor_control.h"
#include "base/callback_helpers.h"
#include "base/sequenced_task_runner.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
@@ -177,7 +178,7 @@ void TorControl::Connected(std::vector<uint8_t> cookie, int rv) {
}
DoCmd("AUTHENTICATE " + base::HexEncode(cookie.data(), cookie.size()),
base::DoNothing::Repeatedly<const std::string&, const std::string&>(),
base::DoNothing(),
base::BindOnce(&TorControl::Authenticated,
weak_ptr_factory_.GetWeakPtr()));
}
@@ -202,12 +203,9 @@ void TorControl::Authenticated(bool error,
}
VLOG(2) << "tor: control connection ready";
DoCmd("TAKEOWNERSHIP",
base::DoNothing::Repeatedly<const std::string&, const std::string&>(),
base::DoNothing::Once<bool, const std::string&, const std::string&>());
DoCmd("RESETCONF __OwningControllerProcess",
base::DoNothing::Repeatedly<const std::string&, const std::string&>(),
base::DoNothing::Once<bool, const std::string&, const std::string&>());
DoCmd("TAKEOWNERSHIP", base::DoNothing(), base::DoNothing());
DoCmd("RESETCONF __OwningControllerProcess", base::DoNothing(),
base::DoNothing());
NotifyTorControlReady();
}
@@ -242,8 +240,7 @@ void TorControl::DoSubscribe(TorControlEvent event,
}
async_events_[event] = 1;
DoCmd(SetEventsCmd(),
base::DoNothing::Repeatedly<const std::string&, const std::string&>(),
DoCmd(SetEventsCmd(), base::DoNothing(),
base::BindOnce(&TorControl::Subscribed, weak_ptr_factory_.GetWeakPtr(),
event, std::move(callback)));
}
@@ -298,8 +295,7 @@ void TorControl::DoUnsubscribe(TorControlEvent event,
DCHECK_EQ(async_events_[event], 0u);
async_events_.erase(event);
DoCmd(
SetEventsCmd(),
base::DoNothing::Repeatedly<const std::string&, const std::string&>(),
SetEventsCmd(), base::DoNothing(),
base::BindOnce(&TorControl::Unsubscribed, weak_ptr_factory_.GetWeakPtr(),
event, std::move(callback)));
}
+8 -12
View File
@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/bind_post_task.h"
#include "base/callback_helpers.h"
#include "base/threading/sequenced_task_runner_handle.h"
#include "brave/components/tor/service_sandbox_type.h"
#include "brave/components/tor/tor_file_watcher.h"
@@ -211,18 +212,13 @@ void TorLauncherFactory::OnTorControlReady() {
base::BindOnce(&TorLauncherFactory::GotCircuitEstablished,
weak_ptr_factory_.GetWeakPtr())));
control_->Subscribe(tor::TorControlEvent::NETWORK_LIVENESS,
base::DoNothing::Once<bool>());
control_->Subscribe(tor::TorControlEvent::STATUS_CLIENT,
base::DoNothing::Once<bool>());
control_->Subscribe(tor::TorControlEvent::STATUS_GENERAL,
base::DoNothing::Once<bool>());
control_->Subscribe(tor::TorControlEvent::STREAM,
base::DoNothing::Once<bool>());
control_->Subscribe(tor::TorControlEvent::NOTICE,
base::DoNothing::Once<bool>());
control_->Subscribe(tor::TorControlEvent::WARN,
base::DoNothing::Once<bool>());
control_->Subscribe(tor::TorControlEvent::ERR, base::DoNothing::Once<bool>());
base::DoNothing());
control_->Subscribe(tor::TorControlEvent::STATUS_CLIENT, base::DoNothing());
control_->Subscribe(tor::TorControlEvent::STATUS_GENERAL, base::DoNothing());
control_->Subscribe(tor::TorControlEvent::STREAM, base::DoNothing());
control_->Subscribe(tor::TorControlEvent::NOTICE, base::DoNothing());
control_->Subscribe(tor::TorControlEvent::WARN, base::DoNothing());
control_->Subscribe(tor::TorControlEvent::ERR, base::DoNothing());
}
void TorLauncherFactory::GotVersion(bool error, const std::string& version) {