From 960e7d6c067979e2a85d4a1dfd3d87c68a386a08 Mon Sep 17 00:00:00 2001 From: Mario Sanchez Prada Date: Thu, 14 Oct 2021 11:39:04 +0200 Subject: [PATCH] Adapt to using the new form of base::DoNothing() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No need to use the templated syntax anymore. Chromium change: https://source.chromium.org/chromium/chromium/src/+/e0fc463ca6d8dedd64bb520779aa367c0831581b commit e0fc463ca6d8dedd64bb520779aa367c0831581b Author: Daniel Cheng 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 --- .../brave_wallet_event_emitter_browsertest.cc | 2 +- .../brave_wallet_provider_impl_unittest.cc | 5 +-- .../keyring_controller_unittest.cc | 44 +++++++++---------- .../sync/brave_sync_service_impl_delegate.cc | 3 +- .../browser/eth_tx_controller_unittest.cc | 6 +-- components/tor/tor_control.cc | 18 +++----- components/tor/tor_launcher_factory.cc | 20 ++++----- 7 files changed, 44 insertions(+), 54 deletions(-) diff --git a/browser/brave_wallet/brave_wallet_event_emitter_browsertest.cc b/browser/brave_wallet/brave_wallet_event_emitter_browsertest.cc index 90016fa34e3..30c2bee23ef 100644 --- a/browser/brave_wallet/brave_wallet_event_emitter_browsertest.cc +++ b/browser/brave_wallet/brave_wallet_event_emitter_browsertest.cc @@ -136,7 +136,7 @@ IN_PROC_BROWSER_TEST_F(BraveWalletEventEmitterTest, WaitForLoadStop(contents); auto controller = GetEthJsonRpcController(); controller->SetNetwork(brave_wallet::mojom::kGoerliChainId, - base::DoNothing::Once()); + base::DoNothing()); auto result_first = EvalJs(contents, CheckForEventScript("received_chain_changed_event"), diff --git a/browser/brave_wallet/brave_wallet_provider_impl_unittest.cc b/browser/brave_wallet/brave_wallet_provider_impl_unittest.cc index c5d511adf40..56fbfbd06f8 100644 --- a/browser/brave_wallet/brave_wallet_provider_impl_unittest.cc +++ b/browser/brave_wallet/brave_wallet_provider_impl_unittest.cc @@ -9,6 +9,7 @@ #include #include +#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()); + provider()->SignMessage(address, message, base::DoNothing()); base::RunLoop().RunUntilIdle(); return provider()->sign_message_id_ - 1; } diff --git a/browser/brave_wallet/keyring_controller_unittest.cc b/browser/brave_wallet/keyring_controller_unittest.cc index 60964d81043..0f1d47e512b 100644 --- a/browser/brave_wallet/keyring_controller_unittest.cc +++ b/browser/brave_wallet/keyring_controller_unittest.cc @@ -8,6 +8,7 @@ #include #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()); + 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()); + 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()); + controller.CreateWallet("brave", base::DoNothing()); base::RunLoop().RunUntilIdle(); - controller.AddAccount("Account2", base::DoNothing::Once()); + 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()); + 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()); + 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()); + 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()); + 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()); + 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()); + 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()); + 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()); + 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()); + 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()); + controller.CreateWallet("brave", base::DoNothing()); base::RunLoop().RunUntilIdle(); std::vector new_accounts; @@ -1736,7 +1736,7 @@ TEST_F(KeyringControllerUnitTest, HardwareAccounts) { TEST_F(KeyringControllerUnitTest, AutoLock) { KeyringController controller(GetPrefs()); - controller.CreateWallet("brave", base::DoNothing::Once()); + 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()); + 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()); + controller.CreateWallet("brave", base::DoNothing()); base::RunLoop().RunUntilIdle(); ASSERT_FALSE(controller.IsLocked()); - controller.AddAccount("AccountAAAAH", base::DoNothing::Once()); + 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()); + 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()); + controller.CreateWallet("brave", base::DoNothing()); base::RunLoop().RunUntilIdle(); const struct { diff --git a/browser/sync/brave_sync_service_impl_delegate.cc b/browser/sync/brave_sync_service_impl_delegate.cc index 40ea204d301..8bba457da71 100644 --- a/browser/sync/brave_sync_service_impl_delegate.cc +++ b/browser/sync/brave_sync_service_impl_delegate.cc @@ -8,6 +8,7 @@ #include #include +#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() { diff --git a/components/brave_wallet/browser/eth_tx_controller_unittest.cc b/components/brave_wallet/browser/eth_tx_controller_unittest.cc index 1546fa8ccbf..f70cf7984c1 100644 --- a/components/brave_wallet/browser/eth_tx_controller_unittest.cc +++ b/components/brave_wallet/browser/eth_tx_controller_unittest.cc @@ -10,6 +10,7 @@ #include #include +#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()); + keyring_controller_->CreateWallet("testing123", base::DoNothing()); base::RunLoop().RunUntilIdle(); - keyring_controller_->AddAccount("Account 1", base::DoNothing::Once()); + keyring_controller_->AddAccount("Account 1", base::DoNothing()); base::RunLoop().RunUntilIdle(); ASSERT_TRUE(base::HexStringToBytes( diff --git a/components/tor/tor_control.cc b/components/tor/tor_control.cc index 69277e06e35..c2b2207172f 100644 --- a/components/tor/tor_control.cc +++ b/components/tor/tor_control.cc @@ -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 cookie, int rv) { } DoCmd("AUTHENTICATE " + base::HexEncode(cookie.data(), cookie.size()), - base::DoNothing::Repeatedly(), + 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(), - base::DoNothing::Once()); - DoCmd("RESETCONF __OwningControllerProcess", - base::DoNothing::Repeatedly(), - base::DoNothing::Once()); + 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(), + 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(), + SetEventsCmd(), base::DoNothing(), base::BindOnce(&TorControl::Unsubscribed, weak_ptr_factory_.GetWeakPtr(), event, std::move(callback))); } diff --git a/components/tor/tor_launcher_factory.cc b/components/tor/tor_launcher_factory.cc index 3ca4bf8ea56..61dcceed4c4 100644 --- a/components/tor/tor_launcher_factory.cc +++ b/components/tor/tor_launcher_factory.cc @@ -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()); - control_->Subscribe(tor::TorControlEvent::STATUS_CLIENT, - base::DoNothing::Once()); - control_->Subscribe(tor::TorControlEvent::STATUS_GENERAL, - base::DoNothing::Once()); - control_->Subscribe(tor::TorControlEvent::STREAM, - base::DoNothing::Once()); - control_->Subscribe(tor::TorControlEvent::NOTICE, - base::DoNothing::Once()); - control_->Subscribe(tor::TorControlEvent::WARN, - base::DoNothing::Once()); - control_->Subscribe(tor::TorControlEvent::ERR, base::DoNothing::Once()); + 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) {