Skip to content

Commit

Permalink
Apply base_bind_rewriters to //chromeos
Browse files Browse the repository at this point in the history
This CL applies //tools/clang/base_bind_rewriters to //chromeos.
It rewrites base::Bind to base::BindOnce where the resulting base::Callback
is immediately converted to base::OnceCallback, which is considered safe
to use base::BindOnce.

E.g.:
  base::PostTask(FROM_HERE, base::Bind([]{}));
  base::OnceClosure cb = base::Bind([]{});
are converted to:
  base::PostTask(FROM_HERE, base::BindOnce([]{}));
  base::OnceClosure cb = base::BindOnce([]{});

This reduces the number of 'base::Bind' in //chromeos from from 791 to 569
as tracked at http://goo.gl/LUVhDj


Change-Id: I5e641cb305638cae71bcb3570da76da54c8f28a4
Reviewed-on: https://chromium-review.googlesource.com/1004494
Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Taiju Tsuiki <tzik@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549751}
  • Loading branch information
tzik authored and Commit Bot committed Apr 11, 2018
1 parent 0746643 commit c8fdd6c
Show file tree
Hide file tree
Showing 90 changed files with 477 additions and 481 deletions.
8 changes: 4 additions & 4 deletions chromeos/accelerometer/accelerometer_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void AccelerometerFileReader::Read() {
DCHECK(base::SequencedTaskRunnerHandle::IsSet());
ReadFileAndNotify();
task_runner_->PostNonNestableDelayedTask(
FROM_HERE, base::Bind(&AccelerometerFileReader::Read, this),
FROM_HERE, base::BindOnce(&AccelerometerFileReader::Read, this),
base::TimeDelta::FromMilliseconds(
AccelerometerReader::kDelayBetweenReadsMs));
}
Expand All @@ -349,7 +349,7 @@ void AccelerometerFileReader::AddObserver(
if (initialization_successful_) {
task_runner_->PostNonNestableTask(
FROM_HERE,
base::Bind(&AccelerometerFileReader::ReadFileAndNotify, this));
base::BindOnce(&AccelerometerFileReader::ReadFileAndNotify, this));
}
}

Expand Down Expand Up @@ -522,8 +522,8 @@ void AccelerometerReader::Initialize(
// startup.
sequenced_task_runner->PostNonNestableTask(
FROM_HERE,
base::Bind(&AccelerometerFileReader::Initialize,
accelerometer_file_reader_.get(), sequenced_task_runner));
base::BindOnce(&AccelerometerFileReader::Initialize,
accelerometer_file_reader_.get(), sequenced_task_runner));
}

void AccelerometerReader::AddObserver(Observer* observer) {
Expand Down
9 changes: 5 additions & 4 deletions chromeos/attestation/attestation_flow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void AttestationFlow::StartCertificateRequest(
certificate_profile, account_id, request_origin, true, callback);
cryptohome_client_->TpmAttestationDoesKeyExist(
key_type, cryptohome::Identification(account_id), key_name,
base::BindRepeating(
base::BindOnce(
&DBusBoolRedirectCallback, on_key_exists, on_key_not_exists,
base::BindRepeating(callback, ATTESTATION_UNSPECIFIED_FAILURE, ""),
"check for existence of attestation key"));
Expand Down Expand Up @@ -317,7 +317,7 @@ void AttestationFlow::GetExistingCertificate(
const CertificateCallback& callback) {
cryptohome_client_->TpmAttestationGetCertificate(
key_type, cryptohome::Identification(account_id), key_name,
base::BindRepeating(&DBusCertificateMethodCallback, callback));
base::BindOnce(&DBusCertificateMethodCallback, callback));
}

void AttestationFlow::CheckAttestationReadyAndReschedule(
Expand All @@ -329,8 +329,9 @@ void AttestationFlow::CheckAttestationReadyAndReschedule(
<< " Retrying in " << retry_delay_ << ".";
base::MessageLoop::current()->task_runner()->PostDelayedTask(
FROM_HERE,
base::Bind(&AttestationFlow::WaitForAttestationReadyAndStartEnroll,
weak_factory_.GetWeakPtr(), end_time, on_failure, next_task),
base::BindOnce(&AttestationFlow::WaitForAttestationReadyAndStartEnroll,
weak_factory_.GetWeakPtr(), end_time, on_failure,
next_task),
retry_delay_);
} else {
LOG(ERROR) << "Attestation: Not prepared. Giving up on retrying.";
Expand Down
10 changes: 5 additions & 5 deletions chromeos/audio/cras_audio_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -895,9 +895,9 @@ void CrasAudioHandler::InitializeAudioState() {

// Defer querying cras for GetNodes until cras service becomes available.
cras_service_available_ = false;
GetCrasAudioClient()->WaitForServiceToBeAvailable(
base::Bind(&CrasAudioHandler::InitializeAudioAfterCrasServiceAvailable,
weak_ptr_factory_.GetWeakPtr()));
GetCrasAudioClient()->WaitForServiceToBeAvailable(base::BindOnce(
&CrasAudioHandler::InitializeAudioAfterCrasServiceAvailable,
weak_ptr_factory_.GetWeakPtr()));
}

void CrasAudioHandler::InitializeAudioAfterCrasServiceAvailable(
Expand Down Expand Up @@ -1661,8 +1661,8 @@ bool CrasAudioHandler::HasExternalDevice(bool is_input) const {

void CrasAudioHandler::GetDefaultOutputBufferSizeInternal() {
GetCrasAudioClient()->GetDefaultOutputBufferSize(
base::Bind(&CrasAudioHandler::HandleGetDefaultOutputBufferSize,
weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(&CrasAudioHandler::HandleGetDefaultOutputBufferSize,
weak_ptr_factory_.GetWeakPtr()));
}

void CrasAudioHandler::HandleGetDefaultOutputBufferSize(
Expand Down
4 changes: 2 additions & 2 deletions chromeos/audio/cras_audio_handler_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ class HDMIRediscoverWaiter {
}
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::Bind(&HDMIRediscoverWaiter::CheckHDMIRediscoverGracePeriodEnd,
base::Unretained(this), quit_loop_func),
base::BindOnce(&HDMIRediscoverWaiter::CheckHDMIRediscoverGracePeriodEnd,
base::Unretained(this), quit_loop_func),
base::TimeDelta::FromMilliseconds(grace_period_duration_in_ms_ / 4));
}

Expand Down
2 changes: 1 addition & 1 deletion chromeos/binder/transaction_data_from_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ TransactionDataFromDriver::~TransactionDataFromDriver() {
buffer_deleter_.Run(GetData());
} else {
delete_task_runner_->PostTask(FROM_HERE,
base::Bind(buffer_deleter_, GetData()));
base::BindOnce(buffer_deleter_, GetData()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ void BluetoothLowEnergyConnectionFinder::OnStartDiscoverySessionError() {
<< kRestartDiscoveryOnErrorDelaySeconds << " seconds.";
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::Bind(
base::BindOnce(
&BluetoothLowEnergyConnectionFinder::RestartDiscoverySessionAsync,
weak_ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(kRestartDiscoveryOnErrorDelaySeconds));
Expand Down Expand Up @@ -250,15 +250,15 @@ void BluetoothLowEnergyConnectionFinder::OnConnectionStatusChanged(
// asynchronously.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(&BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync,
weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(&BluetoothLowEnergyConnectionFinder::InvokeCallbackAsync,
weak_ptr_factory_.GetWeakPtr()));
} else if (old_status == cryptauth::Connection::IN_PROGRESS) {
PA_LOG(WARNING) << "Connection failed. Retrying.";
connection_->RemoveObserver(this);
connection_.reset();
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(
base::BindOnce(
&BluetoothLowEnergyConnectionFinder::RestartDiscoverySessionAsync,
weak_ptr_factory_.GetWeakPtr()));
}
Expand Down
2 changes: 1 addition & 1 deletion chromeos/components/proximity_auth/bluetooth_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ SeekDeviceResult SeekDeviceByAddressImpl(
if (result == 0) {
seek_result.success = true;
task_runner->PostDelayedTask(
FROM_HERE, base::Bind(&CloseSocket, socket_descriptor),
FROM_HERE, base::BindOnce(&CloseSocket, socket_descriptor),
base::TimeDelta::FromSeconds(kCloseSDPConnectionDelaySec));
} else {
// TODO(isherman): Pass a better message based on the errno?
Expand Down
4 changes: 2 additions & 2 deletions chromeos/components/proximity_auth/promotion_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ void PromotionManager::OnFindEligibleForPromotionSuccess(
}
task_runner_->PostDelayedTask(
FROM_HERE,
base::Bind(&PromotionManager::FindEligibleUnlockDevices,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&PromotionManager::FindEligibleUnlockDevices,
weak_ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromSeconds(kWaitForPhoneOnlineDelaySec));
}

Expand Down
5 changes: 3 additions & 2 deletions chromeos/components/proximity_auth/proximity_monitor_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,9 @@ void ProximityMonitorImpl::UpdatePollingState() {
// schedule the next polling iteration prior to executing the current one.
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::Bind(&ProximityMonitorImpl::PerformScheduledUpdatePollingState,
polling_weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(
&ProximityMonitorImpl::PerformScheduledUpdatePollingState,
polling_weak_ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kPollingTimeoutMs));
Poll();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ void RemoteDeviceLifeCycleImpl::OnAuthenticationResult(
// |OnSendCompleted()| as an observer call for |messenger_|.
secure_context_ = std::move(secure_context);
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&RemoteDeviceLifeCycleImpl::CreateMessenger,
weak_ptr_factory_.GetWeakPtr()));
FROM_HERE, base::BindOnce(&RemoteDeviceLifeCycleImpl::CreateMessenger,
weak_ptr_factory_.GetWeakPtr()));
}

void RemoteDeviceLifeCycleImpl::CreateMessenger() {
Expand Down
2 changes: 1 addition & 1 deletion chromeos/components/proximity_auth/run_all_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ int main(int argc, char** argv) {
base::TestSuite test_suite(argc, argv);
return base::LaunchUnitTests(
argc, argv,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
9 changes: 5 additions & 4 deletions chromeos/components/proximity_auth/unlock_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,8 @@ void UnlockManagerImpl::OnAuthAttempted(mojom::AuthType auth_type) {

base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::Bind(&UnlockManagerImpl::AcceptAuthAttempt,
reject_auth_attempt_weak_ptr_factory_.GetWeakPtr(), false),
base::BindOnce(&UnlockManagerImpl::AcceptAuthAttempt,
reject_auth_attempt_weak_ptr_factory_.GetWeakPtr(), false),
base::TimeDelta::FromSeconds(kAuthAttemptTimeoutSecs));

if (screenlock_type_ == ProximityAuthSystem::SIGN_IN) {
Expand Down Expand Up @@ -448,8 +448,9 @@ void UnlockManagerImpl::SetWakingUpState(bool is_waking_up) {
if (is_waking_up_) {
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::Bind(&UnlockManagerImpl::SetWakingUpState,
clear_waking_up_state_weak_ptr_factory_.GetWeakPtr(), false),
base::BindOnce(&UnlockManagerImpl::SetWakingUpState,
clear_waking_up_state_weak_ptr_factory_.GetWeakPtr(),
false),
base::TimeDelta::FromSeconds(kWakingUpDurationSecs));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ void ProximityAuthWebUIHandler::OnLifeCycleStateChanged(
// call stack of |life_cycle_|.
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE,
base::Bind(&ProximityAuthWebUIHandler::CleanUpRemoteDeviceLifeCycle,
weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(&ProximityAuthWebUIHandler::CleanUpRemoteDeviceLifeCycle,
weak_ptr_factory_.GetWeakPtr()));
} else if (new_state ==
RemoteDeviceLifeCycle::State::SECURE_CHANNEL_ESTABLISHED) {
life_cycle_->GetMessenger()->AddObserver(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ void ReachablePhoneFlow::OnSyncTickleSuccess(
<< "ms for phones to callback to CryptAuth...";
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
FROM_HERE,
base::Bind(&ReachablePhoneFlow::QueryReachablePhones,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&ReachablePhoneFlow::QueryReachablePhones,
weak_ptr_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kWaitTimeMillis));
}

Expand Down
2 changes: 1 addition & 1 deletion chromeos/components/run_all_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ int main(int argc, char** argv) {
base::TestSuite test_suite(argc, argv);
return base::LaunchUnitTests(
argc, argv,
base::Bind(&base::TestSuite::Run, base::Unretained(&test_suite)));
base::BindOnce(&base::TestSuite::Run, base::Unretained(&test_suite)));
}
6 changes: 3 additions & 3 deletions chromeos/components/tether/ble_advertiser_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,9 @@ void BleAdvertiserImpl::OnAdvertisementStopped(size_t index) {

// Update advertisements, but do so as part of a new task in the run loop to
// prevent the possibility of a crash. See crbug.com/776241.
task_runner_->PostTask(FROM_HERE,
base::Bind(&BleAdvertiserImpl::UpdateAdvertisements,
weak_ptr_factory_.GetWeakPtr()));
task_runner_->PostTask(
FROM_HERE, base::BindOnce(&BleAdvertiserImpl::UpdateAdvertisements,
weak_ptr_factory_.GetWeakPtr()));

if (!AreAdvertisementsRegistered())
NotifyAllAdvertisementsUnregistered();
Expand Down
4 changes: 2 additions & 2 deletions chromeos/components/tether/ble_scanner_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ void BleScannerImpl::ScheduleStatusChangeNotification(
// cannot occur. See crbug.com/776241.
task_runner_->PostTask(
FROM_HERE,
base::Bind(&BleScannerImpl::NotifyDiscoverySessionStateChanged,
weak_ptr_factory_.GetWeakPtr(), discovery_session_active));
base::BindOnce(&BleScannerImpl::NotifyDiscoverySessionStateChanged,
weak_ptr_factory_.GetWeakPtr(), discovery_session_active));
}

} // namespace tether
Expand Down
6 changes: 3 additions & 3 deletions chromeos/components/tether/ble_synchronizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ void BleSynchronizer::ScheduleCommandCompletion() {
// instance variables in this class after the object has been deleted.
// Completing the current command as part of the next task ensures that this
// cannot occur. See crbug.com/770863.
task_runner_->PostTask(FROM_HERE,
base::Bind(&BleSynchronizer::CompleteCurrentCommand,
weak_ptr_factory_.GetWeakPtr()));
task_runner_->PostTask(
FROM_HERE, base::BindOnce(&BleSynchronizer::CompleteCurrentCommand,
weak_ptr_factory_.GetWeakPtr()));
}

void BleSynchronizer::CompleteCurrentCommand() {
Expand Down
4 changes: 2 additions & 2 deletions chromeos/components/tether/host_scan_scheduler_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ void HostScanSchedulerImpl::DefaultNetworkChanged(const NetworkState* network) {
// NetworkStateHandlerObservers are finished running. Processing the
// network change immediately can cause crashes; see https://crbug.com/800370.
task_runner_->PostTask(FROM_HERE,
base::Bind(&HostScanSchedulerImpl::EnsureScan,
weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(&HostScanSchedulerImpl::EnsureScan,
weak_ptr_factory_.GetWeakPtr()));
}

void HostScanSchedulerImpl::ScanRequested() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ void TetherNetworkDisconnectionHandler::NetworkConnectionStateChanged(
// NetworkStateHandlerObservers are finished running. Processing the
// disconnection immediately can cause crashes; see https://crbug.com/800370.
task_runner_->PostTask(
FROM_HERE, base::Bind(&TetherNetworkDisconnectionHandler::
HandleActiveWifiNetworkDisconnection,
weak_ptr_factory_.GetWeakPtr(), network->guid(),
network->path()));
FROM_HERE, base::BindOnce(&TetherNetworkDisconnectionHandler::
HandleActiveWifiNetworkDisconnection,
weak_ptr_factory_.GetWeakPtr(), network->guid(),
network->path()));
}

void TetherNetworkDisconnectionHandler::HandleActiveWifiNetworkDisconnection(
Expand Down
13 changes: 7 additions & 6 deletions chromeos/components/tether/wifi_hotspot_connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ void WifiHotspotConnector::NetworkPropertiesUpdated(
// notifying observers. See https://crbug.com/800370.
task_runner_->PostTask(
FROM_HERE,
base::Bind(&WifiHotspotConnector::CompleteActiveConnectionAttempt,
weak_ptr_factory_.GetWeakPtr(), true /* success */));
base::BindOnce(&WifiHotspotConnector::CompleteActiveConnectionAttempt,
weak_ptr_factory_.GetWeakPtr(), true /* success */));
return;
}

Expand All @@ -146,8 +146,9 @@ void WifiHotspotConnector::NetworkPropertiesUpdated(
// notifying observers. See https://crbug.com/800370.
task_runner_->PostTask(
FROM_HERE,
base::Bind(&WifiHotspotConnector::InitiateConnectionToCurrentNetwork,
weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(
&WifiHotspotConnector::InitiateConnectionToCurrentNetwork,
weak_ptr_factory_.GetWeakPtr()));
}
}

Expand All @@ -169,8 +170,8 @@ void WifiHotspotConnector::UpdateWaitingForWifi() {
return;

task_runner_->PostTask(
FROM_HERE, base::Bind(&WifiHotspotConnector::CreateWifiConfiguration,
weak_ptr_factory_.GetWeakPtr()));
FROM_HERE, base::BindOnce(&WifiHotspotConnector::CreateWifiConfiguration,
weak_ptr_factory_.GetWeakPtr()));
}

void WifiHotspotConnector::InitiateConnectionToCurrentNetwork() {
Expand Down
Loading

0 comments on commit c8fdd6c

Please sign in to comment.