Commit ad7b1f1d authored by Tomasz Tylenda's avatar Tomasz Tylenda Committed by Commit Bot

Migrating base::Callback to base::OnceCallback.

This is a follow-up on a comment in crrev.com/c/2463051. In
nss_context.cc we make GetNSSCertDatabaseForProfile take OnceCallback
instead of RepeatingCallback. This is possible, because the callback
will be used only once in GetCertDBOnIOThread. We then make all
callers use base::BindOnce.

BUG=764795
TESTED=build

Change-Id: I9120f3c4d0ff70be2dc6c146295a40cc4db17bb5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2484069Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarMatt Mueller <mattm@chromium.org>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Reviewed-by: default avatarCarlos IL <carlosil@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Commit-Queue: Tomasz Tylenda <ttylenda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819690}
parent 502ec4ce
...@@ -189,8 +189,8 @@ void ArcCertStoreBridge::ListCertificates(ListCertificatesCallback callback) { ...@@ -189,8 +189,8 @@ void ArcCertStoreBridge::ListCertificates(ListCertificatesCallback callback) {
GetNSSCertDatabaseForProfile( GetNSSCertDatabaseForProfile(
Profile::FromBrowserContext(context_), Profile::FromBrowserContext(context_),
base::Bind(&ArcCertStoreBridge::OnGetNSSCertDatabaseForProfile, base::BindOnce(&ArcCertStoreBridge::OnGetNSSCertDatabaseForProfile,
weak_ptr_factory_.GetWeakPtr(), base::Passed(&callback))); weak_ptr_factory_.GetWeakPtr(), std::move(callback)));
} }
void ArcCertStoreBridge::GetKeyCharacteristics( void ArcCertStoreBridge::GetKeyCharacteristics(
......
...@@ -247,8 +247,8 @@ class ArcCertStoreBridgeTest : public MixinBasedInProcessBrowserTest { ...@@ -247,8 +247,8 @@ class ArcCertStoreBridgeTest : public MixinBasedInProcessBrowserTest {
base::RunLoop loop; base::RunLoop loop;
GetNSSCertDatabaseForProfile( GetNSSCertDatabaseForProfile(
browser()->profile(), browser()->profile(),
base::Bind(&ArcCertStoreBridgeTest::SetUpTestClientCerts, base::BindOnce(&ArcCertStoreBridgeTest::SetUpTestClientCerts,
base::Unretained(this), loop.QuitClosure())); base::Unretained(this), loop.QuitClosure()));
loop.Run(); loop.Run();
// Certificates must be imported. // Certificates must be imported.
ASSERT_NE(nullptr, client_cert1_); ASSERT_NE(nullptr, client_cert1_);
......
...@@ -148,7 +148,7 @@ void UserSessionInitializer::InitializeCerts(Profile* profile) { ...@@ -148,7 +148,7 @@ void UserSessionInitializer::InitializeCerts(Profile* profile) {
if (NetworkCertLoader::IsInitialized() && if (NetworkCertLoader::IsInitialized() &&
base::SysInfo::IsRunningOnChromeOS()) { base::SysInfo::IsRunningOnChromeOS()) {
GetNSSCertDatabaseForProfile(profile, GetNSSCertDatabaseForProfile(profile,
base::Bind(&OnGetNSSCertDatabaseForUser)); base::BindOnce(&OnGetNSSCertDatabaseForUser));
} }
} }
......
...@@ -135,8 +135,8 @@ class PlatformKeysServiceBrowserTestBase ...@@ -135,8 +135,8 @@ class PlatformKeysServiceBrowserTestBase
base::RunLoop loop; base::RunLoop loop;
GetNSSCertDatabaseForProfile( GetNSSCertDatabaseForProfile(
profile_, profile_,
base::BindRepeating(&PlatformKeysServiceBrowserTestBase::SetUserSlot, base::BindOnce(&PlatformKeysServiceBrowserTestBase::SetUserSlot,
base::Unretained(this), loop.QuitClosure())); base::Unretained(this), loop.QuitClosure()));
loop.Run(); loop.Run();
} }
ASSERT_TRUE(profile_); ASSERT_TRUE(profile_);
......
...@@ -130,10 +130,9 @@ void UserNetworkConfigurationUpdater::Observe( ...@@ -130,10 +130,9 @@ void UserNetworkConfigurationUpdater::Observe(
Profile* profile = content::Source<Profile>(source).ptr(); Profile* profile = content::Source<Profile>(source).ptr();
GetNSSCertDatabaseForProfile( GetNSSCertDatabaseForProfile(
profile, base::AdaptCallbackForRepeating( profile, base::BindOnce(&UserNetworkConfigurationUpdater::
base::BindOnce(&UserNetworkConfigurationUpdater:: CreateAndSetClientCertificateImporter,
CreateAndSetClientCertificateImporter, weak_factory_.GetWeakPtr()));
weak_factory_.GetWeakPtr())));
} }
void UserNetworkConfigurationUpdater::CreateAndSetClientCertificateImporter( void UserNetworkConfigurationUpdater::CreateAndSetClientCertificateImporter(
......
...@@ -255,9 +255,8 @@ IN_PROC_BROWSER_TEST_P(EnterprisePlatformKeysTest, Basic) { ...@@ -255,9 +255,8 @@ IN_PROC_BROWSER_TEST_P(EnterprisePlatformKeysTest, Basic) {
base::RunLoop loop; base::RunLoop loop;
GetNSSCertDatabaseForProfile( GetNSSCertDatabaseForProfile(
profile(), profile(),
base::Bind(&EnterprisePlatformKeysTest::DidGetCertDatabase, base::BindOnce(&EnterprisePlatformKeysTest::DidGetCertDatabase,
base::Unretained(this), base::Unretained(this), loop.QuitClosure()));
loop.QuitClosure()));
loop.Run(); loop.Run();
} }
policy_test_utils::SetExtensionInstallForcelistPolicy( policy_test_utils::SetExtensionInstallForcelistPolicy(
......
...@@ -76,8 +76,8 @@ class PlatformKeysTest : public PlatformKeysTestBase { ...@@ -76,8 +76,8 @@ class PlatformKeysTest : public PlatformKeysTestBase {
base::RunLoop loop; base::RunLoop loop;
GetNSSCertDatabaseForProfile( GetNSSCertDatabaseForProfile(
profile(), profile(),
base::BindRepeating(&PlatformKeysTest::SetupTestCerts, base::BindOnce(&PlatformKeysTest::SetupTestCerts,
base::Unretained(this), loop.QuitClosure())); base::Unretained(this), loop.QuitClosure()));
loop.Run(); loop.Run();
} }
......
...@@ -32,28 +32,29 @@ void DidGetCertDBOnIOThread( ...@@ -32,28 +32,29 @@ void DidGetCertDBOnIOThread(
void GetCertDBOnIOThread( void GetCertDBOnIOThread(
content::ResourceContext* context, content::ResourceContext* context,
scoped_refptr<base::SequencedTaskRunner> response_task_runner, scoped_refptr<base::SequencedTaskRunner> response_task_runner,
const base::RepeatingCallback<void(net::NSSCertDatabase*)>& callback) { base::OnceCallback<void(net::NSSCertDatabase*)> callback) {
DCHECK_CURRENTLY_ON(BrowserThread::IO); DCHECK_CURRENTLY_ON(BrowserThread::IO);
// Note that the callback will be used only if the cert database hasn't yet // Note that the callback will be used only if the cert database hasn't yet
// been initialized. // been initialized.
net::NSSCertDatabase* cert_db = GetNSSCertDatabaseForResourceContext( auto completion_callback = base::AdaptCallbackForRepeating(base::BindOnce(
context, &DidGetCertDBOnIOThread, response_task_runner, std::move(callback)));
base::BindOnce(&DidGetCertDBOnIOThread, response_task_runner, callback)); net::NSSCertDatabase* cert_db =
GetNSSCertDatabaseForResourceContext(context, completion_callback);
if (cert_db) if (cert_db)
DidGetCertDBOnIOThread(response_task_runner, callback, cert_db); completion_callback.Run(cert_db);
} }
} // namespace } // namespace
void GetNSSCertDatabaseForProfile( void GetNSSCertDatabaseForProfile(
Profile* profile, Profile* profile,
const base::RepeatingCallback<void(net::NSSCertDatabase*)>& callback) { base::OnceCallback<void(net::NSSCertDatabase*)> callback) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
content::GetIOThreadTaskRunner({})->PostTask( content::GetIOThreadTaskRunner({})->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(&GetCertDBOnIOThread, profile->GetResourceContext(), base::BindOnce(&GetCertDBOnIOThread, profile->GetResourceContext(),
base::ThreadTaskRunnerHandle::Get(), callback)); base::ThreadTaskRunnerHandle::Get(), std::move(callback)));
} }
...@@ -48,6 +48,6 @@ void EnableNSSSystemKeySlotForResourceContext( ...@@ -48,6 +48,6 @@ void EnableNSSSystemKeySlotForResourceContext(
// It's accessing profile, so it should be called on the UI thread. // It's accessing profile, so it should be called on the UI thread.
void GetNSSCertDatabaseForProfile( void GetNSSCertDatabaseForProfile(
Profile* profile, Profile* profile,
const base::RepeatingCallback<void(net::NSSCertDatabase*)>& callback); base::OnceCallback<void(net::NSSCertDatabase*)> callback);
#endif // CHROME_BROWSER_NET_NSS_CONTEXT_H_ #endif // CHROME_BROWSER_NET_NSS_CONTEXT_H_
...@@ -1998,8 +1998,8 @@ class SSLUITestWithClientCert : public SSLUITestBase { ...@@ -1998,8 +1998,8 @@ class SSLUITestWithClientCert : public SSLUITestBase {
base::RunLoop loop; base::RunLoop loop;
GetNSSCertDatabaseForProfile( GetNSSCertDatabaseForProfile(
browser()->profile(), browser()->profile(),
base::Bind(&SSLUITestWithClientCert::DidGetCertDatabase, base::BindOnce(&SSLUITestWithClientCert::DidGetCertDatabase,
base::Unretained(this), &loop)); base::Unretained(this), &loop));
loop.Run(); loop.Run();
} }
...@@ -5873,8 +5873,8 @@ class SSLUITestCustomCACerts : public SSLUITestNoCert { ...@@ -5873,8 +5873,8 @@ class SSLUITestCustomCACerts : public SSLUITestNoCert {
base::RunLoop loop; base::RunLoop loop;
GetNSSCertDatabaseForProfile( GetNSSCertDatabaseForProfile(
profile_1_, profile_1_,
base::Bind(&SSLUITestCustomCACerts::DidGetCertDatabase, base::BindOnce(&SSLUITestCustomCACerts::DidGetCertDatabase,
base::Unretained(this), &loop, &profile_1_cert_db_)); base::Unretained(this), &loop, &profile_1_cert_db_));
loop.Run(); loop.Run();
} }
...@@ -5882,8 +5882,8 @@ class SSLUITestCustomCACerts : public SSLUITestNoCert { ...@@ -5882,8 +5882,8 @@ class SSLUITestCustomCACerts : public SSLUITestNoCert {
base::RunLoop loop; base::RunLoop loop;
GetNSSCertDatabaseForProfile( GetNSSCertDatabaseForProfile(
profile_2_, profile_2_,
base::Bind(&SSLUITestCustomCACerts::DidGetCertDatabase, base::BindOnce(&SSLUITestCustomCACerts::DidGetCertDatabase,
base::Unretained(this), &loop, &profile_2_cert_db_)); base::Unretained(this), &loop, &profile_2_cert_db_));
loop.Run(); loop.Run();
} }
......
...@@ -48,8 +48,8 @@ void OncImportMessageHandler::OnImportONC(const base::ListValue* list) { ...@@ -48,8 +48,8 @@ void OncImportMessageHandler::OnImportONC(const base::ListValue* list) {
AllowJavascript(); AllowJavascript();
GetNSSCertDatabaseForProfile( GetNSSCertDatabaseForProfile(
Profile::FromWebUI(web_ui()), Profile::FromWebUI(web_ui()),
base::Bind(&OncImportMessageHandler::ImportONCToNSSDB, base::BindOnce(&OncImportMessageHandler::ImportONCToNSSDB,
weak_factory_.GetWeakPtr(), callback_id, onc_blob)); weak_factory_.GetWeakPtr(), callback_id, onc_blob));
} }
void OncImportMessageHandler::ImportONCToNSSDB(const std::string& callback_id, void OncImportMessageHandler::ImportONCToNSSDB(const std::string& callback_id,
......
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