Commit 5c33ddf9 authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Do not call SyncInstallDelegate on empty arguments.

Fix WebAppSyncBridge::ApplySyncChangesToRegistrar: Do not call
SyncInstallDelegate methods if app sets are empty.

Add WebAppSyncBridge unit tests for ApplySyncChanges method.

These tests is a promised follow up for this CL:
https://chromium-review.googlesource.com/c/chromium/src/+/1830494

This code is disabled by default behind kDesktopPWAsWithoutExtensions and
kDesktopPWAsUSS base features.

In next CL:
Add WebAppSyncBridge::CommitUpdate unit tests (UpdateSync).

Change-Id: If5b20b3ef8490397a4e024e3237b0456e06667ab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1910985
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Cr-Commit-Position: refs/heads/master@{#714825}
parent e699a7c5
...@@ -57,6 +57,11 @@ void TestWebAppRegistryController::SetInstallWebAppsAfterSyncDelegate( ...@@ -57,6 +57,11 @@ void TestWebAppRegistryController::SetInstallWebAppsAfterSyncDelegate(
install_web_apps_after_sync_delegate_ = delegate; install_web_apps_after_sync_delegate_ = delegate;
} }
void TestWebAppRegistryController::SetUninstallWebAppsAfterSyncDelegate(
UninstallWebAppsAfterSyncDelegate delegate) {
uninstall_web_apps_after_sync_delegate_ = delegate;
}
void TestWebAppRegistryController::InstallWebAppsAfterSync( void TestWebAppRegistryController::InstallWebAppsAfterSync(
std::vector<WebApp*> web_apps, std::vector<WebApp*> web_apps,
RepeatingInstallCallback callback) { RepeatingInstallCallback callback) {
...@@ -71,8 +76,12 @@ void TestWebAppRegistryController::InstallWebAppsAfterSync( ...@@ -71,8 +76,12 @@ void TestWebAppRegistryController::InstallWebAppsAfterSync(
void TestWebAppRegistryController::UninstallWebAppsAfterSync( void TestWebAppRegistryController::UninstallWebAppsAfterSync(
std::vector<std::unique_ptr<WebApp>> web_apps, std::vector<std::unique_ptr<WebApp>> web_apps,
RepeatingUninstallCallback callback) { RepeatingUninstallCallback callback) {
for (const std::unique_ptr<WebApp>& web_app : web_apps) if (uninstall_web_apps_after_sync_delegate_) {
callback.Run(web_app->app_id(), /*uninstalled=*/true); uninstall_web_apps_after_sync_delegate_.Run(std::move(web_apps), callback);
} else {
for (const std::unique_ptr<WebApp>& web_app : web_apps)
callback.Run(web_app->app_id(), /*uninstalled=*/true);
}
} }
void TestWebAppRegistryController::DestroySubsystems() { void TestWebAppRegistryController::DestroySubsystems() {
......
...@@ -44,6 +44,12 @@ class TestWebAppRegistryController : public SyncInstallDelegate { ...@@ -44,6 +44,12 @@ class TestWebAppRegistryController : public SyncInstallDelegate {
void SetInstallWebAppsAfterSyncDelegate( void SetInstallWebAppsAfterSyncDelegate(
InstallWebAppsAfterSyncDelegate delegate); InstallWebAppsAfterSyncDelegate delegate);
using UninstallWebAppsAfterSyncDelegate = base::RepeatingCallback<void(
std::vector<std::unique_ptr<WebApp>> web_apps,
RepeatingUninstallCallback callback)>;
void SetUninstallWebAppsAfterSyncDelegate(
UninstallWebAppsAfterSyncDelegate delegate);
// SyncInstallDelegate: // SyncInstallDelegate:
void InstallWebAppsAfterSync(std::vector<WebApp*> web_apps, void InstallWebAppsAfterSync(std::vector<WebApp*> web_apps,
RepeatingInstallCallback callback) override; RepeatingInstallCallback callback) override;
...@@ -60,6 +66,7 @@ class TestWebAppRegistryController : public SyncInstallDelegate { ...@@ -60,6 +66,7 @@ class TestWebAppRegistryController : public SyncInstallDelegate {
private: private:
InstallWebAppsAfterSyncDelegate install_web_apps_after_sync_delegate_; InstallWebAppsAfterSyncDelegate install_web_apps_after_sync_delegate_;
UninstallWebAppsAfterSyncDelegate uninstall_web_apps_after_sync_delegate_;
std::unique_ptr<TestWebAppDatabaseFactory> database_factory_; std::unique_ptr<TestWebAppDatabaseFactory> database_factory_;
std::unique_ptr<WebAppRegistrarMutable> mutable_registrar_; std::unique_ptr<WebAppRegistrarMutable> mutable_registrar_;
......
...@@ -395,14 +395,18 @@ void WebAppSyncBridge::ApplySyncChangesToRegistrar( ...@@ -395,14 +395,18 @@ void WebAppSyncBridge::ApplySyncChangesToRegistrar(
// Do a full follow up install for all remote entities that don’t exist // Do a full follow up install for all remote entities that don’t exist
// locally. // locally.
install_delegate_->InstallWebAppsAfterSync(std::move(apps_to_install), if (!apps_to_install.empty()) {
base::DoNothing()); install_delegate_->InstallWebAppsAfterSync(std::move(apps_to_install),
base::DoNothing());
}
// Do a full follow up uninstall for all deleted remote entities that exist // Do a full follow up uninstall for all deleted remote entities that exist
// locally and not needed by other sources. We need to clean up disk data // locally and not needed by other sources. We need to clean up disk data
// (icons). // (icons).
install_delegate_->UninstallWebAppsAfterSync(std::move(apps_unregistered), if (!apps_unregistered.empty()) {
base::DoNothing()); install_delegate_->UninstallWebAppsAfterSync(std::move(apps_unregistered),
base::DoNothing());
}
} }
std::unique_ptr<syncer::MetadataChangeList> std::unique_ptr<syncer::MetadataChangeList>
......
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