Commit face6a9b authored by Reilly Grant's avatar Reilly Grant Committed by Chromium LUCI CQ

Convert callbacks in //chrome/browser/chromeos/lock_screen_apps

This change converts callbacks from base::Bind and base::Callback to
Once/Repeating in //chrome/browser/chromeos/lock_screen_apps.

Bug: 1148570
Change-Id: I85b8e4e83d9f61d3cdc0da02f6650418c1ccccff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2644110
Auto-Submit: Reilly Grant <reillyg@chromium.org>
Reviewed-by: default avatarToni Baržić <tbarzic@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#846204}
parent d2adbc52
...@@ -43,7 +43,8 @@ class AppManager { ...@@ -43,7 +43,8 @@ class AppManager {
// taking app availability changes. It's cleared when the AppManager is // taking app availability changes. It's cleared when the AppManager is
// stopped. It is not expected to be run after the app manager instance // stopped. It is not expected to be run after the app manager instance
// is destroyed. // is destroyed.
virtual void Start(const base::Closure& note_taking_changed_callback) = 0; virtual void Start(
const base::RepeatingClosure& note_taking_changed_callback) = 0;
// Stops the manager. After this is called, the app can be unloaded from the // Stops the manager. After this is called, the app can be unloaded from the
// lock screen enabled profile. Subsequent launch requests should not be // lock screen enabled profile. Subsequent launch requests should not be
......
...@@ -41,7 +41,7 @@ namespace lock_screen_apps { ...@@ -41,7 +41,7 @@ namespace lock_screen_apps {
namespace { namespace {
using ExtensionCallback = base::Callback<void( using ExtensionCallback = base::OnceCallback<void(
const scoped_refptr<const extensions::Extension>& extension)>; const scoped_refptr<const extensions::Extension>& extension)>;
// The max number of times the lock screen app can be relaoded if it gets // The max number of times the lock screen app can be relaoded if it gets
...@@ -94,10 +94,11 @@ ActionAvailability GetLockScreenNoteTakingAvailability( ...@@ -94,10 +94,11 @@ ActionAvailability GetLockScreenNoteTakingAvailability(
} }
void InvokeCallbackOnTaskRunner( void InvokeCallbackOnTaskRunner(
const ExtensionCallback& callback, ExtensionCallback callback,
const scoped_refptr<base::SequencedTaskRunner>& task_runner, const scoped_refptr<base::SequencedTaskRunner>& task_runner,
const scoped_refptr<const extensions::Extension>& extension) { const scoped_refptr<const extensions::Extension>& extension) {
task_runner->PostTask(FROM_HERE, base::BindOnce(callback, extension)); task_runner->PostTask(FROM_HERE,
base::BindOnce(std::move(callback), extension));
} }
// Loads extension with the provided |extension_id|, |location|, and // Loads extension with the provided |extension_id|, |location|, and
...@@ -111,10 +112,10 @@ void LoadInstalledExtension(const std::string& extension_id, ...@@ -111,10 +112,10 @@ void LoadInstalledExtension(const std::string& extension_id,
extensions::Manifest::Location install_source, extensions::Manifest::Location install_source,
int creation_flags, int creation_flags,
std::unique_ptr<base::ScopedTempDir> temp_copy, std::unique_ptr<base::ScopedTempDir> temp_copy,
const ExtensionCallback& callback, ExtensionCallback callback,
const base::FilePath& version_dir) { const base::FilePath& version_dir) {
if (version_dir.empty()) { if (version_dir.empty()) {
callback.Run(nullptr); std::move(callback).Run(nullptr);
return; return;
} }
...@@ -122,7 +123,7 @@ void LoadInstalledExtension(const std::string& extension_id, ...@@ -122,7 +123,7 @@ void LoadInstalledExtension(const std::string& extension_id,
scoped_refptr<const extensions::Extension> extension = scoped_refptr<const extensions::Extension> extension =
extensions::file_util::LoadExtension( extensions::file_util::LoadExtension(
version_dir, extension_id, install_source, creation_flags, &error); version_dir, extension_id, install_source, creation_flags, &error);
callback.Run(extension); std::move(callback).Run(extension);
} }
// Installs |extension| as a copy of an extension unpacked at |original_path| // Installs |extension| as a copy of an extension unpacked at |original_path|
...@@ -135,14 +136,14 @@ void InstallExtensionCopy( ...@@ -135,14 +136,14 @@ void InstallExtensionCopy(
const base::FilePath& target_install_dir, const base::FilePath& target_install_dir,
Profile* profile, Profile* profile,
bool updates_from_webstore_or_empty_update_url, bool updates_from_webstore_or_empty_update_url,
const ExtensionCallback& callback) { ExtensionCallback callback) {
base::FilePath target_dir = target_install_dir.Append(extension->id()); base::FilePath target_dir = target_install_dir.Append(extension->id());
base::FilePath install_temp_dir = base::FilePath install_temp_dir =
extensions::file_util::GetInstallTempDir(target_dir); extensions::file_util::GetInstallTempDir(target_dir);
auto extension_temp_dir = std::make_unique<base::ScopedTempDir>(); auto extension_temp_dir = std::make_unique<base::ScopedTempDir>();
if (install_temp_dir.empty() || if (install_temp_dir.empty() ||
!extension_temp_dir->CreateUniqueTempDirUnderPath(install_temp_dir)) { !extension_temp_dir->CreateUniqueTempDirUnderPath(install_temp_dir)) {
callback.Run(nullptr); std::move(callback).Run(nullptr);
return; return;
} }
...@@ -152,7 +153,7 @@ void InstallExtensionCopy( ...@@ -152,7 +153,7 @@ void InstallExtensionCopy(
base::FilePath temp_copy = base::FilePath temp_copy =
extension_temp_dir->GetPath().Append(original_path.BaseName()); extension_temp_dir->GetPath().Append(original_path.BaseName());
if (!base::CopyDirectory(original_path, temp_copy, true /* recursive */)) { if (!base::CopyDirectory(original_path, temp_copy, true /* recursive */)) {
callback.Run(nullptr); std::move(callback).Run(nullptr);
return; return;
} }
...@@ -160,9 +161,9 @@ void InstallExtensionCopy( ...@@ -160,9 +161,9 @@ void InstallExtensionCopy(
// until the app installation is done. // until the app installation is done.
extensions::ExtensionAssetsManager::GetInstance()->InstallExtension( extensions::ExtensionAssetsManager::GetInstance()->InstallExtension(
extension.get(), temp_copy, target_install_dir, profile, extension.get(), temp_copy, target_install_dir, profile,
base::Bind(&LoadInstalledExtension, extension->id(), base::BindOnce(&LoadInstalledExtension, extension->id(),
extension->location(), extension->creation_flags(), extension->location(), extension->creation_flags(),
base::Passed(std::move(extension_temp_dir)), callback), std::move(extension_temp_dir), std::move(callback)),
updates_from_webstore_or_empty_update_url); updates_from_webstore_or_empty_update_url);
} }
...@@ -216,7 +217,8 @@ void AppManagerImpl::OnLockScreenProfileLoaded() { ...@@ -216,7 +217,8 @@ void AppManagerImpl::OnLockScreenProfileLoaded() {
OnNoteTakingExtensionChanged(); OnNoteTakingExtensionChanged();
} }
void AppManagerImpl::Start(const base::Closure& note_taking_changed_callback) { void AppManagerImpl::Start(
const base::RepeatingClosure& note_taking_changed_callback) {
DCHECK_NE(State::kNotInitialized, state_); DCHECK_NE(State::kNotInitialized, state_);
note_taking_changed_callback_ = note_taking_changed_callback; note_taking_changed_callback_ = note_taking_changed_callback;
...@@ -440,11 +442,12 @@ AppManagerImpl::State AppManagerImpl::AddAppToLockScreenProfile( ...@@ -440,11 +442,12 @@ AppManagerImpl::State AppManagerImpl::AddAppToLockScreenProfile(
&InstallExtensionCopy, lock_profile_app, app->path(), &InstallExtensionCopy, lock_profile_app, app->path(),
lock_screen_service->install_directory(), lock_screen_profile_, lock_screen_service->install_directory(), lock_screen_profile_,
updates_from_webstore_or_empty_update_url, updates_from_webstore_or_empty_update_url,
base::Bind(&InvokeCallbackOnTaskRunner, base::BindOnce(
base::Bind(&AppManagerImpl::CompleteLockScreenAppInstall, &InvokeCallbackOnTaskRunner,
weak_ptr_factory_.GetWeakPtr(), install_count_, base::BindOnce(&AppManagerImpl::CompleteLockScreenAppInstall,
tick_clock_->NowTicks()), weak_ptr_factory_.GetWeakPtr(), install_count_,
base::ThreadTaskRunnerHandle::Get()))); tick_clock_->NowTicks()),
base::ThreadTaskRunnerHandle::Get())));
return State::kActivating; return State::kActivating;
} }
......
...@@ -42,7 +42,8 @@ class AppManagerImpl : public AppManager, ...@@ -42,7 +42,8 @@ class AppManagerImpl : public AppManager,
// AppManager implementation: // AppManager implementation:
void Initialize(Profile* primary_profile, void Initialize(Profile* primary_profile,
LockScreenProfileCreator* profile_creator) override; LockScreenProfileCreator* profile_creator) override;
void Start(const base::Closure& note_taking_changed_callback) override; void Start(
const base::RepeatingClosure& note_taking_changed_callback) override;
void Stop() override; void Stop() override;
bool LaunchNoteTaking() override; bool LaunchNoteTaking() override;
bool IsNoteTakingAppAvailable() const override; bool IsNoteTakingAppAvailable() const override;
...@@ -168,7 +169,7 @@ class AppManagerImpl : public AppManager, ...@@ -168,7 +169,7 @@ class AppManagerImpl : public AppManager,
chromeos::NoteTakingHelper::Observer> chromeos::NoteTakingHelper::Observer>
note_taking_helper_observer_; note_taking_helper_observer_;
base::Closure note_taking_changed_callback_; base::RepeatingClosure note_taking_changed_callback_;
// Counts app installs. Passed to app install callback as install request // Counts app installs. Passed to app install callback as install request
// identifier to determine whether the completed install is stale. // identifier to determine whether the completed install is stale.
......
...@@ -382,15 +382,15 @@ class LockScreenAppManagerImplTest ...@@ -382,15 +382,15 @@ class LockScreenAppManagerImplTest
if (create_lock_screen_profile) if (create_lock_screen_profile)
CreateLockScreenProfile(); CreateLockScreenProfile();
app_manager()->Start( app_manager()->Start(
base::Bind(&LockScreenAppManagerImplTest::OnNoteTakingChanged, base::BindRepeating(&LockScreenAppManagerImplTest::OnNoteTakingChanged,
base::Unretained(this))); base::Unretained(this)));
} }
void RestartLockScreenAppManager() { void RestartLockScreenAppManager() {
app_manager()->Stop(); app_manager()->Stop();
app_manager()->Start( app_manager()->Start(
base::Bind(&LockScreenAppManagerImplTest::OnNoteTakingChanged, base::BindRepeating(&LockScreenAppManagerImplTest::OnNoteTakingChanged,
base::Unretained(this))); base::Unretained(this)));
} }
void CreateLockScreenProfile() { void CreateLockScreenProfile() {
......
...@@ -19,7 +19,8 @@ class FocusCyclerDelegate { ...@@ -19,7 +19,8 @@ class FocusCyclerDelegate {
// Registers a callback that should be called when the focus should be moved // Registers a callback that should be called when the focus should be moved
// to the app window. // to the app window.
using LockScreenAppFocusCallback = base::Callback<void(bool reverse)>; using LockScreenAppFocusCallback =
base::RepeatingCallback<void(bool reverse)>;
virtual void RegisterLockScreenAppFocusHandler( virtual void RegisterLockScreenAppFocusHandler(
const LockScreenAppFocusCallback& focus_handler) = 0; const LockScreenAppFocusCallback& focus_handler) = 0;
......
...@@ -158,7 +158,7 @@ class PendingProfileCreation : public Profile::Delegate { ...@@ -158,7 +158,7 @@ class PendingProfileCreation : public Profile::Delegate {
base::FilePath path_; base::FilePath path_;
Profile::Delegate* delegate_ = nullptr; Profile::Delegate* delegate_ = nullptr;
base::Closure wait_quit_closure_; base::OnceClosure wait_quit_closure_;
Profile* profile_ = nullptr; Profile* profile_ = nullptr;
bool success_ = false; bool success_ = false;
......
...@@ -68,7 +68,7 @@ class LockScreenAppsEnabledWaiter : public lock_screen_apps::StateObserver { ...@@ -68,7 +68,7 @@ class LockScreenAppsEnabledWaiter : public lock_screen_apps::StateObserver {
lock_screen_apps::StateObserver> lock_screen_apps::StateObserver>
lock_screen_apps_state_observer_; lock_screen_apps_state_observer_;
base::Closure state_change_callback_; base::OnceClosure state_change_callback_;
DISALLOW_COPY_AND_ASSIGN(LockScreenAppsEnabledWaiter); DISALLOW_COPY_AND_ASSIGN(LockScreenAppsEnabledWaiter);
}; };
......
...@@ -97,10 +97,10 @@ void StateController::FlushTrayActionForTesting() { ...@@ -97,10 +97,10 @@ void StateController::FlushTrayActionForTesting() {
} }
void StateController::SetReadyCallbackForTesting( void StateController::SetReadyCallbackForTesting(
const base::Closure& ready_callback) { base::OnceClosure ready_callback) {
DCHECK(ready_callback_.is_null()); DCHECK(ready_callback_.is_null());
ready_callback_ = ready_callback; ready_callback_ = std::move(ready_callback);
} }
void StateController::SetTickClockForTesting(const base::TickClock* clock) { void StateController::SetTickClockForTesting(const base::TickClock* clock) {
...@@ -265,8 +265,9 @@ void StateController::SetFocusCyclerDelegate(FocusCyclerDelegate* delegate) { ...@@ -265,8 +265,9 @@ void StateController::SetFocusCyclerDelegate(FocusCyclerDelegate* delegate) {
focus_cycler_delegate_ = delegate; focus_cycler_delegate_ = delegate;
if (focus_cycler_delegate_ && note_app_window_) { if (focus_cycler_delegate_ && note_app_window_) {
focus_cycler_delegate_->RegisterLockScreenAppFocusHandler(base::Bind( focus_cycler_delegate_->RegisterLockScreenAppFocusHandler(
&StateController::FocusAppWindow, weak_ptr_factory_.GetWeakPtr())); base::BindRepeating(&StateController::FocusAppWindow,
weak_ptr_factory_.GetWeakPtr()));
} }
} }
...@@ -313,8 +314,8 @@ void StateController::OnSessionStateChanged() { ...@@ -313,8 +314,8 @@ void StateController::OnSessionStateChanged() {
// and the callback will not be invoked after |app_manager_| goes out of // and the callback will not be invoked after |app_manager_| goes out of
// scope. // scope.
app_manager_->Start( app_manager_->Start(
base::Bind(&StateController::OnNoteTakingAvailabilityChanged, base::BindRepeating(&StateController::OnNoteTakingAvailabilityChanged,
base::Unretained(this))); base::Unretained(this)));
note_app_window_metrics_ = note_app_window_metrics_ =
std::make_unique<AppWindowMetricsTracker>(tick_clock_); std::make_unique<AppWindowMetricsTracker>(tick_clock_);
lock_screen_data_->SetSessionLocked(true); lock_screen_data_->SetSessionLocked(true);
...@@ -333,8 +334,9 @@ void StateController::OnWindowVisibilityChanged(aura::Window* window, ...@@ -333,8 +334,9 @@ void StateController::OnWindowVisibilityChanged(aura::Window* window,
UpdateLockScreenNoteState(TrayActionState::kActive); UpdateLockScreenNoteState(TrayActionState::kActive);
if (focus_cycler_delegate_) { if (focus_cycler_delegate_) {
focus_cycler_delegate_->RegisterLockScreenAppFocusHandler(base::Bind( focus_cycler_delegate_->RegisterLockScreenAppFocusHandler(
&StateController::FocusAppWindow, weak_ptr_factory_.GetWeakPtr())); base::BindRepeating(&StateController::FocusAppWindow,
weak_ptr_factory_.GetWeakPtr()));
} }
} }
......
...@@ -85,7 +85,7 @@ class StateController : public ash::mojom::TrayActionClient, ...@@ -85,7 +85,7 @@ class StateController : public ash::mojom::TrayActionClient,
void FlushTrayActionForTesting(); void FlushTrayActionForTesting();
// Sets the callback that will be run when the state controller is fully // Sets the callback that will be run when the state controller is fully
// initialized and ready for action. // initialized and ready for action.
void SetReadyCallbackForTesting(const base::Closure& ready_callback); void SetReadyCallbackForTesting(base::OnceClosure ready_callback);
// Sets the tick clock to be used in tests. // Sets the tick clock to be used in tests.
void SetTickClockForTesting(const base::TickClock* clock); void SetTickClockForTesting(const base::TickClock* clock);
// Sets test AppManager implementation. Should be called before // Sets test AppManager implementation. Should be called before
...@@ -262,7 +262,7 @@ class StateController : public ash::mojom::TrayActionClient, ...@@ -262,7 +262,7 @@ class StateController : public ash::mojom::TrayActionClient,
// initialized. It can be used to throttle tests until state controller // initialized. It can be used to throttle tests until state controller
// is ready for action - i.e. until the state controller starts reacting // is ready for action - i.e. until the state controller starts reacting
// to session / app manager changes. // to session / app manager changes.
base::Closure ready_callback_; base::OnceClosure ready_callback_;
// The clock used to keep track of time, for example to report app window // The clock used to keep track of time, for example to report app window
// lifetime metrics. // lifetime metrics.
......
...@@ -177,7 +177,7 @@ class TestAppManager : public lock_screen_apps::AppManager { ...@@ -177,7 +177,7 @@ class TestAppManager : public lock_screen_apps::AppManager {
state_ = State::kStopped; state_ = State::kStopped;
} }
void Start(const base::Closure& change_callback) override { void Start(const base::RepeatingClosure& change_callback) override {
ASSERT_TRUE(change_callback_.is_null()); ASSERT_TRUE(change_callback_.is_null());
ASSERT_FALSE(change_callback.is_null()); ASSERT_FALSE(change_callback.is_null());
change_callback_ = change_callback; change_callback_ = change_callback;
...@@ -232,7 +232,7 @@ class TestAppManager : public lock_screen_apps::AppManager { ...@@ -232,7 +232,7 @@ class TestAppManager : public lock_screen_apps::AppManager {
const Profile* const expected_primary_profile_; const Profile* const expected_primary_profile_;
lock_screen_apps::LockScreenProfileCreator* lock_screen_profile_creator_; lock_screen_apps::LockScreenProfileCreator* lock_screen_profile_creator_;
base::Closure change_callback_; base::RepeatingClosure change_callback_;
State state_ = State::kNotInitialized; State state_ = State::kNotInitialized;
......
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