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 {
// taking app availability changes. It's cleared when the AppManager is
// stopped. It is not expected to be run after the app manager instance
// 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
// lock screen enabled profile. Subsequent launch requests should not be
......
......@@ -41,7 +41,7 @@ namespace lock_screen_apps {
namespace {
using ExtensionCallback = base::Callback<void(
using ExtensionCallback = base::OnceCallback<void(
const scoped_refptr<const extensions::Extension>& extension)>;
// The max number of times the lock screen app can be relaoded if it gets
......@@ -94,10 +94,11 @@ ActionAvailability GetLockScreenNoteTakingAvailability(
}
void InvokeCallbackOnTaskRunner(
const ExtensionCallback& callback,
ExtensionCallback callback,
const scoped_refptr<base::SequencedTaskRunner>& task_runner,
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
......@@ -111,10 +112,10 @@ void LoadInstalledExtension(const std::string& extension_id,
extensions::Manifest::Location install_source,
int creation_flags,
std::unique_ptr<base::ScopedTempDir> temp_copy,
const ExtensionCallback& callback,
ExtensionCallback callback,
const base::FilePath& version_dir) {
if (version_dir.empty()) {
callback.Run(nullptr);
std::move(callback).Run(nullptr);
return;
}
......@@ -122,7 +123,7 @@ void LoadInstalledExtension(const std::string& extension_id,
scoped_refptr<const extensions::Extension> extension =
extensions::file_util::LoadExtension(
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|
......@@ -135,14 +136,14 @@ void InstallExtensionCopy(
const base::FilePath& target_install_dir,
Profile* profile,
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 install_temp_dir =
extensions::file_util::GetInstallTempDir(target_dir);
auto extension_temp_dir = std::make_unique<base::ScopedTempDir>();
if (install_temp_dir.empty() ||
!extension_temp_dir->CreateUniqueTempDirUnderPath(install_temp_dir)) {
callback.Run(nullptr);
std::move(callback).Run(nullptr);
return;
}
......@@ -152,7 +153,7 @@ void InstallExtensionCopy(
base::FilePath temp_copy =
extension_temp_dir->GetPath().Append(original_path.BaseName());
if (!base::CopyDirectory(original_path, temp_copy, true /* recursive */)) {
callback.Run(nullptr);
std::move(callback).Run(nullptr);
return;
}
......@@ -160,9 +161,9 @@ void InstallExtensionCopy(
// until the app installation is done.
extensions::ExtensionAssetsManager::GetInstance()->InstallExtension(
extension.get(), temp_copy, target_install_dir, profile,
base::Bind(&LoadInstalledExtension, extension->id(),
base::BindOnce(&LoadInstalledExtension, extension->id(),
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);
}
......@@ -216,7 +217,8 @@ void AppManagerImpl::OnLockScreenProfileLoaded() {
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_);
note_taking_changed_callback_ = note_taking_changed_callback;
......@@ -440,8 +442,9 @@ AppManagerImpl::State AppManagerImpl::AddAppToLockScreenProfile(
&InstallExtensionCopy, lock_profile_app, app->path(),
lock_screen_service->install_directory(), lock_screen_profile_,
updates_from_webstore_or_empty_update_url,
base::Bind(&InvokeCallbackOnTaskRunner,
base::Bind(&AppManagerImpl::CompleteLockScreenAppInstall,
base::BindOnce(
&InvokeCallbackOnTaskRunner,
base::BindOnce(&AppManagerImpl::CompleteLockScreenAppInstall,
weak_ptr_factory_.GetWeakPtr(), install_count_,
tick_clock_->NowTicks()),
base::ThreadTaskRunnerHandle::Get())));
......
......@@ -42,7 +42,8 @@ class AppManagerImpl : public AppManager,
// AppManager implementation:
void Initialize(Profile* primary_profile,
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;
bool LaunchNoteTaking() override;
bool IsNoteTakingAppAvailable() const override;
......@@ -168,7 +169,7 @@ class AppManagerImpl : public AppManager,
chromeos::NoteTakingHelper::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
// identifier to determine whether the completed install is stale.
......
......@@ -382,14 +382,14 @@ class LockScreenAppManagerImplTest
if (create_lock_screen_profile)
CreateLockScreenProfile();
app_manager()->Start(
base::Bind(&LockScreenAppManagerImplTest::OnNoteTakingChanged,
base::BindRepeating(&LockScreenAppManagerImplTest::OnNoteTakingChanged,
base::Unretained(this)));
}
void RestartLockScreenAppManager() {
app_manager()->Stop();
app_manager()->Start(
base::Bind(&LockScreenAppManagerImplTest::OnNoteTakingChanged,
base::BindRepeating(&LockScreenAppManagerImplTest::OnNoteTakingChanged,
base::Unretained(this)));
}
......
......@@ -19,7 +19,8 @@ class FocusCyclerDelegate {
// Registers a callback that should be called when the focus should be moved
// to the app window.
using LockScreenAppFocusCallback = base::Callback<void(bool reverse)>;
using LockScreenAppFocusCallback =
base::RepeatingCallback<void(bool reverse)>;
virtual void RegisterLockScreenAppFocusHandler(
const LockScreenAppFocusCallback& focus_handler) = 0;
......
......@@ -158,7 +158,7 @@ class PendingProfileCreation : public Profile::Delegate {
base::FilePath path_;
Profile::Delegate* delegate_ = nullptr;
base::Closure wait_quit_closure_;
base::OnceClosure wait_quit_closure_;
Profile* profile_ = nullptr;
bool success_ = false;
......
......@@ -68,7 +68,7 @@ class LockScreenAppsEnabledWaiter : public lock_screen_apps::StateObserver {
lock_screen_apps::StateObserver>
lock_screen_apps_state_observer_;
base::Closure state_change_callback_;
base::OnceClosure state_change_callback_;
DISALLOW_COPY_AND_ASSIGN(LockScreenAppsEnabledWaiter);
};
......
......@@ -97,10 +97,10 @@ void StateController::FlushTrayActionForTesting() {
}
void StateController::SetReadyCallbackForTesting(
const base::Closure& ready_callback) {
base::OnceClosure ready_callback) {
DCHECK(ready_callback_.is_null());
ready_callback_ = ready_callback;
ready_callback_ = std::move(ready_callback);
}
void StateController::SetTickClockForTesting(const base::TickClock* clock) {
......@@ -265,8 +265,9 @@ void StateController::SetFocusCyclerDelegate(FocusCyclerDelegate* delegate) {
focus_cycler_delegate_ = delegate;
if (focus_cycler_delegate_ && note_app_window_) {
focus_cycler_delegate_->RegisterLockScreenAppFocusHandler(base::Bind(
&StateController::FocusAppWindow, weak_ptr_factory_.GetWeakPtr()));
focus_cycler_delegate_->RegisterLockScreenAppFocusHandler(
base::BindRepeating(&StateController::FocusAppWindow,
weak_ptr_factory_.GetWeakPtr()));
}
}
......@@ -313,7 +314,7 @@ void StateController::OnSessionStateChanged() {
// and the callback will not be invoked after |app_manager_| goes out of
// scope.
app_manager_->Start(
base::Bind(&StateController::OnNoteTakingAvailabilityChanged,
base::BindRepeating(&StateController::OnNoteTakingAvailabilityChanged,
base::Unretained(this)));
note_app_window_metrics_ =
std::make_unique<AppWindowMetricsTracker>(tick_clock_);
......@@ -333,8 +334,9 @@ void StateController::OnWindowVisibilityChanged(aura::Window* window,
UpdateLockScreenNoteState(TrayActionState::kActive);
if (focus_cycler_delegate_) {
focus_cycler_delegate_->RegisterLockScreenAppFocusHandler(base::Bind(
&StateController::FocusAppWindow, weak_ptr_factory_.GetWeakPtr()));
focus_cycler_delegate_->RegisterLockScreenAppFocusHandler(
base::BindRepeating(&StateController::FocusAppWindow,
weak_ptr_factory_.GetWeakPtr()));
}
}
......
......@@ -85,7 +85,7 @@ class StateController : public ash::mojom::TrayActionClient,
void FlushTrayActionForTesting();
// Sets the callback that will be run when the state controller is fully
// 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.
void SetTickClockForTesting(const base::TickClock* clock);
// Sets test AppManager implementation. Should be called before
......@@ -262,7 +262,7 @@ class StateController : public ash::mojom::TrayActionClient,
// initialized. It can be used to throttle tests until state controller
// is ready for action - i.e. until the state controller starts reacting
// 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
// lifetime metrics.
......
......@@ -177,7 +177,7 @@ class TestAppManager : public lock_screen_apps::AppManager {
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_FALSE(change_callback.is_null());
change_callback_ = change_callback;
......@@ -232,7 +232,7 @@ class TestAppManager : public lock_screen_apps::AppManager {
const Profile* const expected_primary_profile_;
lock_screen_apps::LockScreenProfileCreator* lock_screen_profile_creator_;
base::Closure change_callback_;
base::RepeatingClosure change_callback_;
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