Commit 27477af7 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[base] Apply BindOnceRewriter in //chrome/browser/chromeos/attestation

This change applies the BindOnceRewriter in //chrome/browser/chromeos/attestation.
This rewriter replaces calls to base::Bind and base::BindRepeating with
calls to base::BindOnce, in case the result is immediately assigned to a
base::OnceCallback. Given that base::RepeatingCallback is implicitly
convertible to base::OnceCallback, there is no change in functionality.

Steps:
  1. run_tool.py --tool base_bind_rewriters \
                 --tool-arg='--rewriter=bind_to_bind_once'
  2. git cl format

This CL was uploaded by git cl split.

R=emaxx@chromium.org

Bug: 714018
Change-Id: Iebee9bd19db9cd252dffa538ea34ebb1d169df62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2132253
Auto-Submit: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Commit-Queue: Maksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755394}
parent 97aeb037
...@@ -98,8 +98,7 @@ class AttestationCAClientTest : public ::testing::Test { ...@@ -98,8 +98,7 @@ class AttestationCAClientTest : public ::testing::Test {
TEST_F(AttestationCAClientTest, EnrollRequest) { TEST_F(AttestationCAClientTest, EnrollRequest) {
AttestationCAClient client; AttestationCAClient client;
client.SendEnrollRequest( client.SendEnrollRequest(
"enroll", "enroll", base::BindOnce(&AttestationCAClientTest::DataCallback,
base::Bind(&AttestationCAClientTest::DataCallback,
base::Unretained(this))); base::Unretained(this)));
CheckURLAndSendResponse(GURL("https://chromeos-ca.gstatic.com/enroll"), CheckURLAndSendResponse(GURL("https://chromeos-ca.gstatic.com/enroll"),
net::OK, net::HTTP_OK); net::OK, net::HTTP_OK);
...@@ -112,8 +111,7 @@ TEST_F(AttestationCAClientTest, EnrollRequest) { ...@@ -112,8 +111,7 @@ TEST_F(AttestationCAClientTest, EnrollRequest) {
TEST_F(AttestationCAClientTest, CertificateRequest) { TEST_F(AttestationCAClientTest, CertificateRequest) {
AttestationCAClient client; AttestationCAClient client;
client.SendCertificateRequest( client.SendCertificateRequest(
"certificate", "certificate", base::BindOnce(&AttestationCAClientTest::DataCallback,
base::Bind(&AttestationCAClientTest::DataCallback,
base::Unretained(this))); base::Unretained(this)));
CheckURLAndSendResponse(GURL("https://chromeos-ca.gstatic.com/sign"), net::OK, CheckURLAndSendResponse(GURL("https://chromeos-ca.gstatic.com/sign"), net::OK,
net::HTTP_OK); net::HTTP_OK);
...@@ -126,8 +124,7 @@ TEST_F(AttestationCAClientTest, CertificateRequest) { ...@@ -126,8 +124,7 @@ TEST_F(AttestationCAClientTest, CertificateRequest) {
TEST_F(AttestationCAClientTest, CertificateRequestNetworkFailure) { TEST_F(AttestationCAClientTest, CertificateRequestNetworkFailure) {
AttestationCAClient client; AttestationCAClient client;
client.SendCertificateRequest( client.SendCertificateRequest(
"certificate", "certificate", base::BindOnce(&AttestationCAClientTest::DataCallback,
base::Bind(&AttestationCAClientTest::DataCallback,
base::Unretained(this))); base::Unretained(this)));
SendResponse(net::ERR_FAILED, net::HTTP_OK); SendResponse(net::ERR_FAILED, net::HTTP_OK);
...@@ -139,8 +136,7 @@ TEST_F(AttestationCAClientTest, CertificateRequestNetworkFailure) { ...@@ -139,8 +136,7 @@ TEST_F(AttestationCAClientTest, CertificateRequestNetworkFailure) {
TEST_F(AttestationCAClientTest, CertificateRequestHttpError) { TEST_F(AttestationCAClientTest, CertificateRequestHttpError) {
AttestationCAClient client; AttestationCAClient client;
client.SendCertificateRequest( client.SendCertificateRequest(
"certificate", "certificate", base::BindOnce(&AttestationCAClientTest::DataCallback,
base::Bind(&AttestationCAClientTest::DataCallback,
base::Unretained(this))); base::Unretained(this)));
SendResponse(net::OK, net::HTTP_NOT_FOUND); SendResponse(net::OK, net::HTTP_NOT_FOUND);
...@@ -153,9 +149,8 @@ TEST_F(AttestationCAClientTest, DeleteOnCallback) { ...@@ -153,9 +149,8 @@ TEST_F(AttestationCAClientTest, DeleteOnCallback) {
AttestationCAClient* client = new AttestationCAClient(); AttestationCAClient* client = new AttestationCAClient();
client->SendCertificateRequest( client->SendCertificateRequest(
"certificate", "certificate",
base::Bind(&AttestationCAClientTest::DeleteClientDataCallback, base::BindOnce(&AttestationCAClientTest::DeleteClientDataCallback,
base::Unretained(this), base::Unretained(this), client));
client));
SendResponse(net::OK, net::HTTP_OK); SendResponse(net::OK, net::HTTP_OK);
EXPECT_EQ(1, num_invocations_); EXPECT_EQ(1, num_invocations_);
...@@ -170,8 +165,8 @@ TEST_F(AttestationCAClientAttestationServerTest, DefaultEnrollRequest) { ...@@ -170,8 +165,8 @@ TEST_F(AttestationCAClientAttestationServerTest, DefaultEnrollRequest) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
chromeos::switches::kAttestationServer, "default"); chromeos::switches::kAttestationServer, "default");
AttestationCAClient client; AttestationCAClient client;
client.SendEnrollRequest("enroll", client.SendEnrollRequest(
base::Bind(&AttestationCAClientTest::DataCallback, "enroll", base::BindOnce(&AttestationCAClientTest::DataCallback,
base::Unretained(this))); base::Unretained(this)));
CheckURLAndSendResponse(GURL("https://chromeos-ca.gstatic.com/enroll"), CheckURLAndSendResponse(GURL("https://chromeos-ca.gstatic.com/enroll"),
net::OK, net::HTTP_OK); net::OK, net::HTTP_OK);
...@@ -186,7 +181,7 @@ TEST_F(AttestationCAClientAttestationServerTest, DefaultCertificateRequest) { ...@@ -186,7 +181,7 @@ TEST_F(AttestationCAClientAttestationServerTest, DefaultCertificateRequest) {
chromeos::switches::kAttestationServer, "default"); chromeos::switches::kAttestationServer, "default");
AttestationCAClient client; AttestationCAClient client;
client.SendCertificateRequest( client.SendCertificateRequest(
"certificate", base::Bind(&AttestationCAClientTest::DataCallback, "certificate", base::BindOnce(&AttestationCAClientTest::DataCallback,
base::Unretained(this))); base::Unretained(this)));
CheckURLAndSendResponse(GURL("https://chromeos-ca.gstatic.com/sign"), net::OK, CheckURLAndSendResponse(GURL("https://chromeos-ca.gstatic.com/sign"), net::OK,
net::HTTP_OK); net::HTTP_OK);
...@@ -200,8 +195,8 @@ TEST_F(AttestationCAClientAttestationServerTest, TestEnrollRequest) { ...@@ -200,8 +195,8 @@ TEST_F(AttestationCAClientAttestationServerTest, TestEnrollRequest) {
base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
chromeos::switches::kAttestationServer, "test"); chromeos::switches::kAttestationServer, "test");
AttestationCAClient client; AttestationCAClient client;
client.SendEnrollRequest("enroll", client.SendEnrollRequest(
base::Bind(&AttestationCAClientTest::DataCallback, "enroll", base::BindOnce(&AttestationCAClientTest::DataCallback,
base::Unretained(this))); base::Unretained(this)));
CheckURLAndSendResponse(GURL("https://asbestos-qa.corp.google.com/enroll"), CheckURLAndSendResponse(GURL("https://asbestos-qa.corp.google.com/enroll"),
net::OK, net::HTTP_OK); net::OK, net::HTTP_OK);
...@@ -216,7 +211,7 @@ TEST_F(AttestationCAClientAttestationServerTest, TestCertificateRequest) { ...@@ -216,7 +211,7 @@ TEST_F(AttestationCAClientAttestationServerTest, TestCertificateRequest) {
chromeos::switches::kAttestationServer, "test"); chromeos::switches::kAttestationServer, "test");
AttestationCAClient client; AttestationCAClient client;
client.SendCertificateRequest( client.SendCertificateRequest(
"certificate", base::Bind(&AttestationCAClientTest::DataCallback, "certificate", base::BindOnce(&AttestationCAClientTest::DataCallback,
base::Unretained(this))); base::Unretained(this)));
CheckURLAndSendResponse(GURL("https://asbestos-qa.corp.google.com/sign"), CheckURLAndSendResponse(GURL("https://asbestos-qa.corp.google.com/sign"),
net::OK, net::HTTP_OK); net::OK, net::HTTP_OK);
......
...@@ -119,7 +119,7 @@ void EnrollmentCertificateUploaderImpl::GetCertificate() { ...@@ -119,7 +119,7 @@ void EnrollmentCertificateUploaderImpl::GetCertificate() {
std::string(), // Not used. std::string(), // Not used.
false, // Do not force a new key to be generated. false, // Do not force a new key to be generated.
std::string(), // Leave key name empty to generate a default name. std::string(), // Leave key name empty to generate a default name.
base::BindRepeating( base::BindOnce(
[](const base::RepeatingCallback<void(const std::string&)> on_success, [](const base::RepeatingCallback<void(const std::string&)> on_success,
const base::RepeatingCallback<void(AttestationStatus)> on_failure, const base::RepeatingCallback<void(AttestationStatus)> on_failure,
const base::Location& from_here, AttestationStatus status, const base::Location& from_here, AttestationStatus status,
...@@ -140,7 +140,7 @@ void EnrollmentCertificateUploaderImpl::UploadCertificate( ...@@ -140,7 +140,7 @@ void EnrollmentCertificateUploaderImpl::UploadCertificate(
const std::string& pem_certificate_chain) { const std::string& pem_certificate_chain) {
policy_client_->UploadEnterpriseEnrollmentCertificate( policy_client_->UploadEnterpriseEnrollmentCertificate(
pem_certificate_chain, pem_certificate_chain,
base::BindRepeating(&EnrollmentCertificateUploaderImpl::OnUploadComplete, base::BindOnce(&EnrollmentCertificateUploaderImpl::OnUploadComplete,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
......
...@@ -152,8 +152,7 @@ void EnrollmentPolicyObserver::HandleEnrollmentId( ...@@ -152,8 +152,7 @@ void EnrollmentPolicyObserver::HandleEnrollmentId(
" obtained is empty."; " obtained is empty.";
} }
policy_client_->UploadEnterpriseEnrollmentId( policy_client_->UploadEnterpriseEnrollmentId(
enrollment_id, enrollment_id, base::BindOnce(&EnrollmentPolicyObserver::OnUploadComplete,
base::BindRepeating(&EnrollmentPolicyObserver::OnUploadComplete,
weak_factory_.GetWeakPtr(), enrollment_id)); weak_factory_.GetWeakPtr(), enrollment_id));
} }
......
...@@ -204,7 +204,7 @@ void MachineCertificateUploaderImpl::GetNewCertificate() { ...@@ -204,7 +204,7 @@ void MachineCertificateUploaderImpl::GetNewCertificate() {
std::string(), // Not used. std::string(), // Not used.
true, // Force a new key to be generated. true, // Force a new key to be generated.
std::string(), // Leave key name empty to generate a default name. std::string(), // Leave key name empty to generate a default name.
base::BindRepeating( base::BindOnce(
[](const base::RepeatingCallback<void(const std::string&)> on_success, [](const base::RepeatingCallback<void(const std::string&)> on_success,
const base::RepeatingCallback<void(AttestationStatus)> on_failure, const base::RepeatingCallback<void(AttestationStatus)> on_failure,
const base::Location& from_here, AttestationStatus status, const base::Location& from_here, AttestationStatus status,
...@@ -226,7 +226,7 @@ void MachineCertificateUploaderImpl::GetExistingCertificate() { ...@@ -226,7 +226,7 @@ void MachineCertificateUploaderImpl::GetExistingCertificate() {
KEY_DEVICE, KEY_DEVICE,
cryptohome::AccountIdentifier(), // Not used. cryptohome::AccountIdentifier(), // Not used.
kEnterpriseMachineKey, kEnterpriseMachineKey,
base::BindRepeating( base::BindOnce(
DBusStringCallback, DBusStringCallback,
base::BindRepeating( base::BindRepeating(
&MachineCertificateUploaderImpl::CheckCertificateExpiry, &MachineCertificateUploaderImpl::CheckCertificateExpiry,
...@@ -279,7 +279,7 @@ void MachineCertificateUploaderImpl::UploadCertificate( ...@@ -279,7 +279,7 @@ void MachineCertificateUploaderImpl::UploadCertificate(
const std::string& pem_certificate_chain) { const std::string& pem_certificate_chain) {
policy_client_->UploadEnterpriseMachineCertificate( policy_client_->UploadEnterpriseMachineCertificate(
pem_certificate_chain, pem_certificate_chain,
base::BindRepeating(&MachineCertificateUploaderImpl::OnUploadComplete, base::BindOnce(&MachineCertificateUploaderImpl::OnUploadComplete,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
...@@ -302,7 +302,7 @@ void MachineCertificateUploaderImpl::GetKeyPayload( ...@@ -302,7 +302,7 @@ void MachineCertificateUploaderImpl::GetKeyPayload(
KEY_DEVICE, KEY_DEVICE,
cryptohome::AccountIdentifier(), // Not used. cryptohome::AccountIdentifier(), // Not used.
kEnterpriseMachineKey, kEnterpriseMachineKey,
base::BindRepeating(DBusStringCallback, callback, on_failure, FROM_HERE)); base::BindOnce(DBusStringCallback, callback, on_failure, FROM_HERE));
} }
void MachineCertificateUploaderImpl::OnUploadComplete(bool status) { void MachineCertificateUploaderImpl::OnUploadComplete(bool status) {
...@@ -331,7 +331,7 @@ void MachineCertificateUploaderImpl::MarkAsUploaded( ...@@ -331,7 +331,7 @@ void MachineCertificateUploaderImpl::MarkAsUploaded(
KEY_DEVICE, KEY_DEVICE,
cryptohome::AccountIdentifier(), // Not used. cryptohome::AccountIdentifier(), // Not used.
kEnterpriseMachineKey, new_payload, kEnterpriseMachineKey, new_payload,
base::BindRepeating(DBusBoolRedirectCallback, base::RepeatingClosure(), base::BindOnce(DBusBoolRedirectCallback, base::RepeatingClosure(),
base::RepeatingClosure(), base::RepeatingClosure(), base::RepeatingClosure(), base::RepeatingClosure(),
FROM_HERE)); FROM_HERE));
} }
...@@ -346,9 +346,8 @@ void MachineCertificateUploaderImpl::HandleGetCertificateFailure( ...@@ -346,9 +346,8 @@ void MachineCertificateUploaderImpl::HandleGetCertificateFailure(
void MachineCertificateUploaderImpl::Reschedule() { void MachineCertificateUploaderImpl::Reschedule() {
if (++num_retries_ < retry_limit_) { if (++num_retries_ < retry_limit_) {
base::PostDelayedTask( base::PostDelayedTask(FROM_HERE, {content::BrowserThread::UI},
FROM_HERE, {content::BrowserThread::UI}, base::BindOnce(&MachineCertificateUploaderImpl::Start,
base::BindRepeating(&MachineCertificateUploaderImpl::Start,
weak_factory_.GetWeakPtr()), weak_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(retry_delay_)); base::TimeDelta::FromSeconds(retry_delay_));
} else { } else {
......
...@@ -300,9 +300,8 @@ void TpmChallengeKeySubtleImpl::GetDeviceAttestationEnabled( ...@@ -300,9 +300,8 @@ void TpmChallengeKeySubtleImpl::GetDeviceAttestationEnabled(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
CrosSettings* settings = CrosSettings::Get(); CrosSettings* settings = CrosSettings::Get();
CrosSettingsProvider::TrustedStatus status = CrosSettingsProvider::TrustedStatus status = settings->PrepareTrustedValues(
settings->PrepareTrustedValues(base::BindRepeating( base::BindOnce(&TpmChallengeKeySubtleImpl::GetDeviceAttestationEnabled,
&TpmChallengeKeySubtleImpl::GetDeviceAttestationEnabled,
weak_factory_.GetWeakPtr(), callback)); weak_factory_.GetWeakPtr(), callback));
bool value = false; bool value = false;
...@@ -369,7 +368,7 @@ void TpmChallengeKeySubtleImpl::IsAttestationPreparedCallback( ...@@ -369,7 +368,7 @@ void TpmChallengeKeySubtleImpl::IsAttestationPreparedCallback(
std::string(), // Not used. std::string(), // Not used.
true, // Force a new key to be generated. true, // Force a new key to be generated.
key_name_for_spkac_, key_name_for_spkac_,
base::BindRepeating(&TpmChallengeKeySubtleImpl::GetCertificateCallback, base::BindOnce(&TpmChallengeKeySubtleImpl::GetCertificateCallback,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
return; return;
} }
...@@ -379,7 +378,7 @@ void TpmChallengeKeySubtleImpl::IsAttestationPreparedCallback( ...@@ -379,7 +378,7 @@ void TpmChallengeKeySubtleImpl::IsAttestationPreparedCallback(
key_type_, key_type_,
cryptohome::CreateAccountIdentifierFromAccountId(GetAccountId()), cryptohome::CreateAccountIdentifierFromAccountId(GetAccountId()),
key_name_, key_name_,
base::BindRepeating(&TpmChallengeKeySubtleImpl::DoesKeyExistCallback, base::BindOnce(&TpmChallengeKeySubtleImpl::DoesKeyExistCallback,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
...@@ -453,7 +452,7 @@ void TpmChallengeKeySubtleImpl::AskForUserConsentCallback(bool result) { ...@@ -453,7 +452,7 @@ void TpmChallengeKeySubtleImpl::AskForUserConsentCallback(bool result) {
std::string(), // Not used. std::string(), // Not used.
true, // Force a new key to be generated. true, // Force a new key to be generated.
key_name_, key_name_,
base::BindRepeating(&TpmChallengeKeySubtleImpl::GetCertificateCallback, base::BindOnce(&TpmChallengeKeySubtleImpl::GetCertificateCallback,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
...@@ -513,7 +512,7 @@ void TpmChallengeKeySubtleImpl::StartSignChallengeStep( ...@@ -513,7 +512,7 @@ void TpmChallengeKeySubtleImpl::StartSignChallengeStep(
include_signed_public_key ? CHALLENGE_INCLUDE_SIGNED_PUBLIC_KEY include_signed_public_key ? CHALLENGE_INCLUDE_SIGNED_PUBLIC_KEY
: CHALLENGE_OPTION_NONE, : CHALLENGE_OPTION_NONE,
challenge, key_name_for_spkac_, challenge, key_name_for_spkac_,
base::BindRepeating(&TpmChallengeKeySubtleImpl::SignChallengeCallback, base::BindOnce(&TpmChallengeKeySubtleImpl::SignChallengeCallback,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
...@@ -541,7 +540,7 @@ void TpmChallengeKeySubtleImpl::StartRegisterKeyStep( ...@@ -541,7 +540,7 @@ void TpmChallengeKeySubtleImpl::StartRegisterKeyStep(
cryptohome::AsyncMethodCaller::GetInstance()->TpmAttestationRegisterKey( cryptohome::AsyncMethodCaller::GetInstance()->TpmAttestationRegisterKey(
key_type_, cryptohome::Identification(GetAccountId()), key_type_, cryptohome::Identification(GetAccountId()),
GetKeyNameForRegister(), GetKeyNameForRegister(),
base::BindRepeating(&TpmChallengeKeySubtleImpl::RegisterKeyCallback, base::BindOnce(&TpmChallengeKeySubtleImpl::RegisterKeyCallback,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
......
...@@ -243,8 +243,9 @@ class TpmChallengeKeyTestBase : public BrowserWithTestWindowTest { ...@@ -243,8 +243,9 @@ class TpmChallengeKeyTestBase : public BrowserWithTestWindowTest {
base::RunLoop loop; base::RunLoop loop;
challenge_key_impl_->BuildResponse( challenge_key_impl_->BuildResponse(
key_type_, GetProfile(), base::Bind(callback, loop.QuitClosure(), res), key_type_, GetProfile(),
challenge, register_key, key_name_for_spkac); base::BindOnce(callback, loop.QuitClosure(), res), challenge,
register_key, key_name_for_spkac);
loop.Run(); loop.Run();
} }
......
...@@ -28,7 +28,7 @@ void TpmChallengeKeyWithTimeout::BuildResponse( ...@@ -28,7 +28,7 @@ void TpmChallengeKeyWithTimeout::BuildResponse(
base::SequencedTaskRunnerHandle::Get()->PostDelayedTask( base::SequencedTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE, FROM_HERE,
base::Bind(&TpmChallengeKeyWithTimeout::ResolveCallback, base::BindOnce(&TpmChallengeKeyWithTimeout::ResolveCallback,
weak_factory_.GetWeakPtr(), weak_factory_.GetWeakPtr(),
TpmChallengeKeyResult::MakeError( TpmChallengeKeyResult::MakeError(
TpmChallengeKeyResultCode::kTimeoutError)), TpmChallengeKeyResultCode::kTimeoutError)),
......
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