Commit 37bf62c8 authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

dekstop-pwas: Remove unnecessary use of BindOnce now that we support lambda capture expressions

Previously we couldn't capture OnceCallback because they are non-copyable.
Now that we allow capture expressions we can capture it by moving it
into the lambda.

Change-Id: I436d3d572cb7609b739acc518c7beb8fc5c73364
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1626054
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Auto-Submit: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#662480}
parent c0525e1e
...@@ -38,9 +38,11 @@ void TestPendingAppManager::Install(InstallOptions install_options, ...@@ -38,9 +38,11 @@ void TestPendingAppManager::Install(InstallOptions install_options,
// TODO(nigeltao): Add error simulation when error codes are added to the API. // TODO(nigeltao): Add error simulation when error codes are added to the API.
auto weak_ptr = weak_ptr_factory_.GetWeakPtr(); auto weak_ptr = weak_ptr_factory_.GetWeakPtr();
auto result_code = install_result_code_; auto result_code = install_result_code_;
auto do_install =
base::BindLambdaForTesting([this, weak_ptr, install_options, base::SequencedTaskRunnerHandle::Get()->PostTask(
result_code](OnceInstallCallback callback) { FROM_HERE,
base::BindLambdaForTesting([this, weak_ptr, install_options, result_code,
callback = std::move(callback)]() mutable {
// Use a WeakPtr to be able to simulate the Install callback running // Use a WeakPtr to be able to simulate the Install callback running
// after PendingAppManager gets deleted. // after PendingAppManager gets deleted.
if (weak_ptr) { if (weak_ptr) {
...@@ -52,10 +54,8 @@ void TestPendingAppManager::Install(InstallOptions install_options, ...@@ -52,10 +54,8 @@ void TestPendingAppManager::Install(InstallOptions install_options,
} }
install_requests_.push_back(install_options); install_requests_.push_back(install_options);
} }
std::move(callback).Run(install_options.url, result_code); std::move(std::move(callback)).Run(install_options.url, result_code);
}); }));
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(do_install, std::move(callback)));
} }
void TestPendingAppManager::InstallApps( void TestPendingAppManager::InstallApps(
...@@ -68,21 +68,20 @@ void TestPendingAppManager::InstallApps( ...@@ -68,21 +68,20 @@ void TestPendingAppManager::InstallApps(
void TestPendingAppManager::UninstallApps(std::vector<GURL> uninstall_urls, void TestPendingAppManager::UninstallApps(std::vector<GURL> uninstall_urls,
const UninstallCallback& callback) { const UninstallCallback& callback) {
auto weak_ptr = weak_ptr_factory_.GetWeakPtr(); auto weak_ptr = weak_ptr_factory_.GetWeakPtr();
auto do_uninstall = base::BindLambdaForTesting(
[this, weak_ptr](UninstallCallback callback, GURL url) {
if (weak_ptr) {
auto i = installed_apps_.find(url);
if (i != installed_apps_.end()) {
installed_apps_.erase(i);
deduped_uninstall_count_++;
}
uninstall_requests_.push_back(url);
}
callback.Run(url, true /* succeeded */);
});
for (const auto& url : uninstall_urls) { for (const auto& url : uninstall_urls) {
base::SequencedTaskRunnerHandle::Get()->PostTask( base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(do_uninstall, callback, url)); FROM_HERE,
base::BindLambdaForTesting([this, weak_ptr, url, callback]() {
if (weak_ptr) {
auto i = installed_apps_.find(url);
if (i != installed_apps_.end()) {
installed_apps_.erase(i);
deduped_uninstall_count_++;
}
uninstall_requests_.push_back(url);
}
callback.Run(url, true /* succeeded */);
}));
} }
} }
......
...@@ -182,13 +182,11 @@ class TestBookmarkAppInstallFinalizer : public web_app::InstallFinalizer { ...@@ -182,13 +182,11 @@ class TestBookmarkAppInstallFinalizer : public web_app::InstallFinalizer {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce( base::BindLambdaForTesting(
base::BindLambdaForTesting( [&, app_id, code, callback = std::move(callback)]() mutable {
[&, app_id, code](InstallFinalizedCallback callback) { registrar_->AddAsInstalled(app_id);
registrar_->AddAsInstalled(app_id); std::move(callback).Run(app_id, code);
std::move(callback).Run(app_id, code); }));
}),
std::move(callback)));
} }
void UninstallExternalWebApp( void UninstallExternalWebApp(
...@@ -206,14 +204,12 @@ class TestBookmarkAppInstallFinalizer : public web_app::InstallFinalizer { ...@@ -206,14 +204,12 @@ class TestBookmarkAppInstallFinalizer : public web_app::InstallFinalizer {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE,
base::BindOnce(base::BindLambdaForTesting( base::BindLambdaForTesting(
[&, app_id, uninstalled]( [&, app_id, uninstalled, callback = std::move(callback)]() mutable {
UninstallExternalWebAppCallback callback) { if (uninstalled)
if (uninstalled) registrar_->RemoveAsInstalled(app_id);
registrar_->RemoveAsInstalled(app_id); std::move(callback).Run(uninstalled);
std::move(callback).Run(uninstalled); }));
}),
std::move(callback)));
} }
bool CanCreateOsShortcuts() const override { return true; } bool CanCreateOsShortcuts() const override { return true; }
......
...@@ -50,15 +50,13 @@ void TestInstallFinalizer::UninstallExternalWebApp( ...@@ -50,15 +50,13 @@ void TestInstallFinalizer::UninstallExternalWebApp(
uninstall_external_web_app_urls_.push_back(app_url); uninstall_external_web_app_urls_.push_back(app_url);
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, FROM_HERE, base::BindLambdaForTesting(
base::BindOnce( [this, app_url, callback = std::move(callback)]() mutable {
base::BindLambdaForTesting( bool result =
[this, app_url](UninstallExternalWebAppCallback callback) { next_uninstall_external_web_app_results_[app_url];
bool result = next_uninstall_external_web_app_results_[app_url]; next_uninstall_external_web_app_results_.erase(app_url);
next_uninstall_external_web_app_results_.erase(app_url); std::move(callback).Run(result);
std::move(callback).Run(result); }));
}),
std::move(callback)));
} }
bool TestInstallFinalizer::CanCreateOsShortcuts() const { bool TestInstallFinalizer::CanCreateOsShortcuts() const {
......
...@@ -31,12 +31,11 @@ void TestWebAppUiDelegate::NotifyOnAllAppWindowsClosed( ...@@ -31,12 +31,11 @@ void TestWebAppUiDelegate::NotifyOnAllAppWindowsClosed(
const AppId& app_id, const AppId& app_id,
base::OnceClosure callback) { base::OnceClosure callback) {
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(base::BindLambdaForTesting( FROM_HERE, base::BindLambdaForTesting(
[&, app_id](base::OnceClosure callback) { [&, app_id, callback = std::move(callback)]() mutable {
app_id_to_num_windows_map_[app_id] = 0; app_id_to_num_windows_map_[app_id] = 0;
std::move(callback).Run(); std::move(callback).Run();
}), }));
std::move(callback)));
} }
} // namespace web_app } // namespace web_app
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