Commit 74b483f3 authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Convert base::Bind and base::Callback in ash/system to Once/Repeating

Bug: 1007633
Change-Id: I225b0ac97a202041fbe6cd92fa78ae5a1f4d79b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1931621
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718802}
parent fc8b656f
...@@ -93,7 +93,7 @@ void BluetoothPowerController::StartWatchingLocalStatePrefsChanges() { ...@@ -93,7 +93,7 @@ void BluetoothPowerController::StartWatchingLocalStatePrefsChanges() {
local_state_pref_change_registrar_->Init(local_state_); local_state_pref_change_registrar_->Init(local_state_);
local_state_pref_change_registrar_->Add( local_state_pref_change_registrar_->Add(
prefs::kSystemBluetoothAdapterEnabled, prefs::kSystemBluetoothAdapterEnabled,
base::Bind( base::BindRepeating(
&BluetoothPowerController::OnBluetoothPowerLocalStatePrefChanged, &BluetoothPowerController::OnBluetoothPowerLocalStatePrefChanged,
base::Unretained(this))); base::Unretained(this)));
} }
...@@ -245,12 +245,10 @@ void BluetoothPowerController::SetBluetoothPowerOnAdapterReady() { ...@@ -245,12 +245,10 @@ void BluetoothPowerController::SetBluetoothPowerOnAdapterReady() {
pending_bluetooth_power_target_.reset(); pending_bluetooth_power_target_.reset();
// Always run the next pending task after SetPowered completes regardless // Always run the next pending task after SetPowered completes regardless
// the error. // the error.
bluetooth_adapter_->SetPowered( auto run_next_task = base::BindRepeating(
enabled, &BluetoothPowerController::RunNextPendingBluetoothTask,
base::Bind(&BluetoothPowerController::RunNextPendingBluetoothTask, weak_ptr_factory_.GetWeakPtr());
weak_ptr_factory_.GetWeakPtr()), bluetooth_adapter_->SetPowered(enabled, run_next_task, run_next_task);
base::Bind(&BluetoothPowerController::RunNextPendingBluetoothTask,
weak_ptr_factory_.GetWeakPtr()));
} }
void BluetoothPowerController::RunBluetoothTaskWhenAdapterReady( void BluetoothPowerController::RunBluetoothTaskWhenAdapterReady(
......
...@@ -187,10 +187,11 @@ void TrayBluetoothHelperLegacy::StartBluetoothDiscovering() { ...@@ -187,10 +187,11 @@ void TrayBluetoothHelperLegacy::StartBluetoothDiscovering() {
} }
VLOG(1) << "Requesting new Bluetooth device discovery session."; VLOG(1) << "Requesting new Bluetooth device discovery session.";
should_run_discovery_ = true; should_run_discovery_ = true;
// TODO(crbug/1007780): This function should take OnceCallbacks.
adapter_->StartDiscoverySession( adapter_->StartDiscoverySession(
base::Bind(&TrayBluetoothHelperLegacy::OnStartDiscoverySession, base::BindRepeating(&TrayBluetoothHelperLegacy::OnStartDiscoverySession,
weak_ptr_factory_.GetWeakPtr()), weak_ptr_factory_.GetWeakPtr()),
base::Bind(&BluetoothSetDiscoveringError)); base::BindRepeating(&BluetoothSetDiscoveringError));
} }
void TrayBluetoothHelperLegacy::StopBluetoothDiscovering() { void TrayBluetoothHelperLegacy::StopBluetoothDiscovering() {
...@@ -202,8 +203,7 @@ void TrayBluetoothHelperLegacy::StopBluetoothDiscovering() { ...@@ -202,8 +203,7 @@ void TrayBluetoothHelperLegacy::StopBluetoothDiscovering() {
return; return;
} }
VLOG(1) << "Stopping Bluetooth device discovery session."; VLOG(1) << "Stopping Bluetooth device discovery session.";
discovery_session_->Stop(base::DoNothing(), discovery_session_.reset();
base::Bind(&BluetoothSetDiscoveringError));
} }
void TrayBluetoothHelperLegacy::ConnectToBluetoothDevice( void TrayBluetoothHelperLegacy::ConnectToBluetoothDevice(
...@@ -234,19 +234,21 @@ void TrayBluetoothHelperLegacy::ConnectToBluetoothDevice( ...@@ -234,19 +234,21 @@ void TrayBluetoothHelperLegacy::ConnectToBluetoothDevice(
return; return;
} }
// TODO(crbug/1007780): This function should take OnceCallbacks.
device->Connect(nullptr /* pairing_delegate */, device->Connect(nullptr /* pairing_delegate */,
base::Bind(&OnBluetoothDeviceConnect, base::BindRepeating(&OnBluetoothDeviceConnect,
true /* was_device_already_paired */), true /* was_device_already_paired */),
base::Bind(&OnBluetoothDeviceConnectError, base::BindRepeating(&OnBluetoothDeviceConnectError,
true /* was_device_already_paired */)); true /* was_device_already_paired */));
return; return;
} }
// Simply connect without pairing for devices which do not support pairing. // Simply connect without pairing for devices which do not support pairing.
if (!device->IsPairable()) { if (!device->IsPairable()) {
// TODO(crbug/1007780): This function should take OnceCallbacks.
device->Connect(nullptr /* pairing_delegate */, base::DoNothing(), device->Connect(nullptr /* pairing_delegate */, base::DoNothing(),
base::Bind(&OnBluetoothDeviceConnectError, base::BindRepeating(&OnBluetoothDeviceConnectError,
false /* was_device_already_paired */)); false /* was_device_already_paired */));
return; return;
} }
......
...@@ -890,10 +890,10 @@ void NightLightControllerImpl::ScheduleNextToggle(base::TimeDelta delay) { ...@@ -890,10 +890,10 @@ void NightLightControllerImpl::ScheduleNextToggle(base::TimeDelta delay) {
VLOG(1) << "Setting Night Light to toggle to " VLOG(1) << "Setting Night Light to toggle to "
<< (new_status ? "enabled" : "disabled") << " at " << (new_status ? "enabled" : "disabled") << " at "
<< base::TimeFormatTimeOfDay(delegate_->GetNow() + delay); << base::TimeFormatTimeOfDay(delegate_->GetNow() + delay);
timer_.Start( timer_.Start(FROM_HERE, delay,
FROM_HERE, delay, base::BindOnce(&NightLightControllerImpl::SetEnabled,
base::Bind(&NightLightControllerImpl::SetEnabled, base::Unretained(this), base::Unretained(this), new_status,
new_status, AnimationDuration::kLong)); AnimationDuration::kLong));
} }
} // namespace ash } // namespace ash
...@@ -336,7 +336,7 @@ void PowerEventObserver::StopCompositingAndSuspendDisplays() { ...@@ -336,7 +336,7 @@ void PowerEventObserver::StopCompositingAndSuspendDisplays() {
ui::UserActivityDetector::Get()->OnDisplayPowerChanging(); ui::UserActivityDetector::Get()->OnDisplayPowerChanging();
Shell::Get()->display_configurator()->SuspendDisplays( Shell::Get()->display_configurator()->SuspendDisplays(
base::Bind(&OnSuspendDisplaysCompleted, block_suspend_token_)); base::BindOnce(&OnSuspendDisplaysCompleted, block_suspend_token_));
block_suspend_token_ = {}; block_suspend_token_ = {};
} }
......
...@@ -15,9 +15,11 @@ class ScreenCaptureObserver { ...@@ -15,9 +15,11 @@ class ScreenCaptureObserver {
// Called when screen capture is started. // Called when screen capture is started.
// |stop_callback| is a callback to stop the stream. // |stop_callback| is a callback to stop the stream.
// |source_callback| is a callback to change the desktop capture source. // |source_callback| is a callback to change the desktop capture source.
// These must be base::RepeatingCallbacks so that they can be passed to all
// observers.
virtual void OnScreenCaptureStart( virtual void OnScreenCaptureStart(
base::RepeatingClosure stop_callback, const base::RepeatingClosure& stop_callback,
base::RepeatingClosure source_callback, const base::RepeatingClosure& source_callback,
const base::string16& screen_capture_status) = 0; const base::string16& screen_capture_status) = 0;
// Called when screen capture is stopped. // Called when screen capture is stopped.
......
...@@ -118,11 +118,11 @@ void ScreenSecurityNotificationController::ChangeSource() { ...@@ -118,11 +118,11 @@ void ScreenSecurityNotificationController::ChangeSource() {
} }
void ScreenSecurityNotificationController::OnScreenCaptureStart( void ScreenSecurityNotificationController::OnScreenCaptureStart(
base::RepeatingClosure stop_callback, const base::RepeatingClosure& stop_callback,
base::RepeatingClosure source_callback, const base::RepeatingClosure& source_callback,
const base::string16& screen_capture_status) { const base::string16& screen_capture_status) {
capture_stop_callbacks_.emplace_back(std::move(stop_callback)); capture_stop_callbacks_.push_back(stop_callback);
change_source_callback_ = std::move(source_callback); change_source_callback_ = source_callback;
// We do not want to show the screen capture notification and the chromecast // We do not want to show the screen capture notification and the chromecast
// casting tray notification at the same time. // casting tray notification at the same time.
...@@ -142,7 +142,7 @@ void ScreenSecurityNotificationController::OnScreenCaptureStop() { ...@@ -142,7 +142,7 @@ void ScreenSecurityNotificationController::OnScreenCaptureStop() {
} }
void ScreenSecurityNotificationController::OnScreenShareStart( void ScreenSecurityNotificationController::OnScreenShareStart(
const base::Closure& stop_callback, const base::RepeatingClosure& stop_callback,
const base::string16& helper_name) { const base::string16& helper_name) {
share_stop_callbacks_.emplace_back(std::move(stop_callback)); share_stop_callbacks_.emplace_back(std::move(stop_callback));
......
...@@ -39,13 +39,13 @@ class ASH_EXPORT ScreenSecurityNotificationController ...@@ -39,13 +39,13 @@ class ASH_EXPORT ScreenSecurityNotificationController
// ScreenCaptureObserver: // ScreenCaptureObserver:
void OnScreenCaptureStart( void OnScreenCaptureStart(
base::RepeatingClosure stop_callback, const base::RepeatingClosure& stop_callback,
base::RepeatingClosure source_callback, const base::RepeatingClosure& source_callback,
const base::string16& screen_capture_status) override; const base::string16& screen_capture_status) override;
void OnScreenCaptureStop() override; void OnScreenCaptureStop() override;
// ScreenShareObserver: // ScreenShareObserver:
void OnScreenShareStart(const base::Closure& stop_callback, void OnScreenShareStart(const base::RepeatingClosure& stop_callback,
const base::string16& helper_name) override; const base::string16& helper_name) override;
void OnScreenShareStop() override; void OnScreenShareStop() override;
......
...@@ -13,7 +13,9 @@ namespace ash { ...@@ -13,7 +13,9 @@ namespace ash {
class ScreenShareObserver { class ScreenShareObserver {
public: public:
// Called when screen share is started. // Called when screen share is started.
virtual void OnScreenShareStart(const base::Closure& stop_callback, // |stop_callback| must be a base::RepeatingCallback so that it can be passed
// to all observers.
virtual void OnScreenShareStart(const base::RepeatingClosure& stop_callback,
const base::string16& helper_name) = 0; const base::string16& helper_name) = 0;
// Called when screen share is stopped. // Called when screen share is stopped.
......
...@@ -97,8 +97,8 @@ void ScreenSwitchCheckController::CanSwitchAwayFromActiveUser( ...@@ -97,8 +97,8 @@ void ScreenSwitchCheckController::CanSwitchAwayFromActiveUser(
} }
void ScreenSwitchCheckController::OnScreenCaptureStart( void ScreenSwitchCheckController::OnScreenCaptureStart(
base::RepeatingClosure stop_callback, const base::RepeatingClosure& stop_callback,
base::RepeatingClosure source_callback, const base::RepeatingClosure& source_callback,
const base::string16& screen_capture_status) { const base::string16& screen_capture_status) {
has_capture_ = true; has_capture_ = true;
} }
...@@ -110,7 +110,7 @@ void ScreenSwitchCheckController::OnScreenCaptureStop() { ...@@ -110,7 +110,7 @@ void ScreenSwitchCheckController::OnScreenCaptureStop() {
} }
void ScreenSwitchCheckController::OnScreenShareStart( void ScreenSwitchCheckController::OnScreenShareStart(
const base::Closure& stop_callback, const base::RepeatingClosure& stop_callback,
const base::string16& helper_name) { const base::string16& helper_name) {
has_share_ = true; has_share_ = true;
} }
......
...@@ -26,13 +26,13 @@ class ScreenSwitchCheckController : public ScreenCaptureObserver, ...@@ -26,13 +26,13 @@ class ScreenSwitchCheckController : public ScreenCaptureObserver,
private: private:
// ScreenCaptureObserver: // ScreenCaptureObserver:
void OnScreenCaptureStart( void OnScreenCaptureStart(
base::RepeatingClosure stop_callback, const base::RepeatingClosure& stop_callback,
base::RepeatingClosure source_callback, const base::RepeatingClosure& source_callback,
const base::string16& screen_capture_status) override; const base::string16& screen_capture_status) override;
void OnScreenCaptureStop() override; void OnScreenCaptureStop() override;
// ScreenShareObserver: // ScreenShareObserver:
void OnScreenShareStart(const base::Closure& stop_callback, void OnScreenShareStart(const base::RepeatingClosure& stop_callback,
const base::string16& helper_name) override; const base::string16& helper_name) override;
void OnScreenShareStop() override; void OnScreenShareStop() override;
......
...@@ -82,7 +82,7 @@ void SystemTrayNotifier::RemoveScreenShareObserver( ...@@ -82,7 +82,7 @@ void SystemTrayNotifier::RemoveScreenShareObserver(
} }
void SystemTrayNotifier::NotifyScreenShareStart( void SystemTrayNotifier::NotifyScreenShareStart(
const base::Closure& stop_callback, base::RepeatingClosure stop_callback,
const base::string16& helper_name) { const base::string16& helper_name) {
for (auto& observer : screen_share_observers_) for (auto& observer : screen_share_observers_)
observer.OnScreenShareStart(stop_callback, helper_name); observer.OnScreenShareStart(stop_callback, helper_name);
......
...@@ -55,7 +55,7 @@ class ASH_EXPORT SystemTrayNotifier { ...@@ -55,7 +55,7 @@ class ASH_EXPORT SystemTrayNotifier {
// Screen share. // Screen share.
void AddScreenShareObserver(ScreenShareObserver* observer); void AddScreenShareObserver(ScreenShareObserver* observer);
void RemoveScreenShareObserver(ScreenShareObserver* observer); void RemoveScreenShareObserver(ScreenShareObserver* observer);
void NotifyScreenShareStart(const base::Closure& stop_callback, void NotifyScreenShareStart(base::RepeatingClosure stop_callback,
const base::string16& helper_name); const base::string16& helper_name);
void NotifyScreenShareStop(); void NotifyScreenShareStop();
......
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