Commit 31976e73 authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Extract InstallFinalizer::CanSkipAppUpdateForSync method.

Plumb InstallFinalizer to BookmarkAppInstallManager.

CanSkipAppUpdateForSync will be reused in WebAppInstallManager.

Bug: 915043
Change-Id: Ied37333203e3d972accecde5bd8ee3d157862959
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1585744
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654792}
parent af33df0e
...@@ -10,13 +10,13 @@ ...@@ -10,13 +10,13 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/callback.h" #include "base/callback.h"
#include "base/scoped_observer.h" #include "base/scoped_observer.h"
#include "base/strings/utf_string_conversions.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/extensions/bookmark_app_helper.h" #include "chrome/browser/extensions/bookmark_app_helper.h"
#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/tab_helper.h" #include "chrome/browser/extensions/tab_helper.h"
#include "chrome/browser/installable/installable_metrics.h" #include "chrome/browser/installable/installable_metrics.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/components/install_finalizer.h"
#include "chrome/browser/web_applications/components/install_manager_observer.h" #include "chrome/browser/web_applications/components/install_manager_observer.h"
#include "chrome/browser/web_applications/components/install_options.h" #include "chrome/browser/web_applications/components/install_options.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "extensions/browser/extension_system.h" #include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
namespace extensions { namespace extensions {
...@@ -252,8 +251,10 @@ void OnGetWebApplicationInfo(const BookmarkAppInstallManager* install_manager, ...@@ -252,8 +251,10 @@ void OnGetWebApplicationInfo(const BookmarkAppInstallManager* install_manager,
} // namespace } // namespace
BookmarkAppInstallManager::BookmarkAppInstallManager(Profile* profile) BookmarkAppInstallManager::BookmarkAppInstallManager(
: InstallManager(profile) { Profile* profile,
web_app::InstallFinalizer* finalizer)
: InstallManager(profile), finalizer_(finalizer) {
bookmark_app_helper_factory_ = base::BindRepeating( bookmark_app_helper_factory_ = base::BindRepeating(
[](Profile* profile, const WebApplicationInfo& web_app_info, [](Profile* profile, const WebApplicationInfo& web_app_info,
content::WebContents* web_contents, content::WebContents* web_contents,
...@@ -380,23 +381,14 @@ void BookmarkAppInstallManager::InstallOrUpdateWebAppFromSync( ...@@ -380,23 +381,14 @@ void BookmarkAppInstallManager::InstallOrUpdateWebAppFromSync(
ExtensionSystem::Get(profile())->extension_service(); ExtensionSystem::Get(profile())->extension_service();
DCHECK(extension_service); DCHECK(extension_service);
const Extension* extension = extension_service->GetInstalledExtension(app_id); if (finalizer_->CanSkipAppUpdateForSync(app_id, *web_application_info))
// Return if there are no bookmark app details that need updating.
const std::string extension_sync_data_name =
base::UTF16ToUTF8(web_application_info->title);
const std::string bookmark_app_description =
base::UTF16ToUTF8(web_application_info->description);
if (extension &&
extension->non_localized_name() == extension_sync_data_name &&
extension->description() == bookmark_app_description) {
return; return;
}
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
const bool is_locally_installed = true; bool is_locally_installed = true;
#else #else
const bool is_locally_installed = extension != nullptr; bool is_locally_installed =
extension_service->GetInstalledExtension(app_id) != nullptr;
#endif #endif
CreateOrUpdateBookmarkApp(extension_service, web_application_info.get(), CreateOrUpdateBookmarkApp(extension_service, web_application_info.get(),
......
...@@ -20,6 +20,7 @@ class WebContents; ...@@ -20,6 +20,7 @@ class WebContents;
} }
namespace web_app { namespace web_app {
class InstallFinalizer;
class WebAppDataRetriever; class WebAppDataRetriever;
} }
...@@ -31,7 +32,8 @@ class BookmarkAppHelper; ...@@ -31,7 +32,8 @@ class BookmarkAppHelper;
// crbug.com/915043. // crbug.com/915043.
class BookmarkAppInstallManager final : public web_app::InstallManager { class BookmarkAppInstallManager final : public web_app::InstallManager {
public: public:
explicit BookmarkAppInstallManager(Profile* profile); BookmarkAppInstallManager(Profile* profile,
web_app::InstallFinalizer* finalizer);
~BookmarkAppInstallManager() override; ~BookmarkAppInstallManager() override;
// InstallManager: // InstallManager:
...@@ -83,6 +85,7 @@ class BookmarkAppInstallManager final : public web_app::InstallManager { ...@@ -83,6 +85,7 @@ class BookmarkAppInstallManager final : public web_app::InstallManager {
private: private:
BookmarkAppHelperFactory bookmark_app_helper_factory_; BookmarkAppHelperFactory bookmark_app_helper_factory_;
DataRetrieverFactory data_retriever_factory_; DataRetrieverFactory data_retriever_factory_;
web_app::InstallFinalizer* finalizer_;
DISALLOW_COPY_AND_ASSIGN(BookmarkAppInstallManager); DISALLOW_COPY_AND_ASSIGN(BookmarkAppInstallManager);
}; };
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/web_applications/components/install_options.h" #include "chrome/browser/web_applications/components/install_options.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/test/test_data_retriever.h" #include "chrome/browser/web_applications/test/test_data_retriever.h"
#include "chrome/browser/web_applications/test/test_install_finalizer.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h" #include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_profile.h" #include "chrome/test/base/testing_profile.h"
...@@ -33,7 +34,9 @@ class BookmarkAppInstallManagerTest : public ChromeRenderViewHostTestHarness { ...@@ -33,7 +34,9 @@ class BookmarkAppInstallManagerTest : public ChromeRenderViewHostTestHarness {
void SetUp() override { void SetUp() override {
ChromeRenderViewHostTestHarness::SetUp(); ChromeRenderViewHostTestHarness::SetUp();
install_manager_ = std::make_unique<BookmarkAppInstallManager>(profile()); install_finalizer_ = std::make_unique<web_app::TestInstallFinalizer>();
install_manager_ = std::make_unique<BookmarkAppInstallManager>(
profile(), install_finalizer_.get());
extensions::TestExtensionSystem* test_extension_system = extensions::TestExtensionSystem* test_extension_system =
static_cast<extensions::TestExtensionSystem*>( static_cast<extensions::TestExtensionSystem*>(
...@@ -69,6 +72,7 @@ class BookmarkAppInstallManagerTest : public ChromeRenderViewHostTestHarness { ...@@ -69,6 +72,7 @@ class BookmarkAppInstallManagerTest : public ChromeRenderViewHostTestHarness {
} }
protected: protected:
std::unique_ptr<web_app::TestInstallFinalizer> install_finalizer_;
std::unique_ptr<BookmarkAppInstallManager> install_manager_; std::unique_ptr<BookmarkAppInstallManager> install_manager_;
}; };
......
...@@ -60,6 +60,10 @@ class InstallFinalizer { ...@@ -60,6 +60,10 @@ class InstallFinalizer {
virtual bool CanRevealAppShim() const = 0; virtual bool CanRevealAppShim() const = 0;
virtual void RevealAppShim(const AppId& app_id) = 0; virtual void RevealAppShim(const AppId& app_id) = 0;
virtual bool CanSkipAppUpdateForSync(
const AppId& app_id,
const WebApplicationInfo& web_app_info) const = 0;
virtual ~InstallFinalizer() = default; virtual ~InstallFinalizer() = default;
}; };
......
...@@ -9,8 +9,10 @@ ...@@ -9,8 +9,10 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/extensions/bookmark_app_extension_util.h" #include "chrome/browser/extensions/bookmark_app_extension_util.h"
#include "chrome/browser/extensions/crx_installer.h" #include "chrome/browser/extensions/crx_installer.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/launch_util.h" #include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
...@@ -19,6 +21,7 @@ ...@@ -19,6 +21,7 @@
#include "chrome/common/extensions/manifest_handlers/app_launch_info.h" #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/install/crx_install_error.h" #include "extensions/browser/install/crx_install_error.h"
#include "extensions/common/extension.h" #include "extensions/common/extension.h"
#include "extensions/common/extension_id.h" #include "extensions/common/extension_id.h"
...@@ -165,6 +168,31 @@ void BookmarkAppInstallFinalizer::RevealAppShim(const web_app::AppId& app_id) { ...@@ -165,6 +168,31 @@ void BookmarkAppInstallFinalizer::RevealAppShim(const web_app::AppId& app_id) {
BookmarkAppRevealAppShim(profile_, app); BookmarkAppRevealAppShim(profile_, app);
} }
bool BookmarkAppInstallFinalizer::CanSkipAppUpdateForSync(
const web_app::AppId& app_id,
const WebApplicationInfo& web_app_info) const {
ExtensionService* extension_service =
ExtensionSystem::Get(profile_)->extension_service();
DCHECK(extension_service);
const Extension* extension = extension_service->GetInstalledExtension(app_id);
if (!extension)
return false;
// We can skip if there are no bookmark app details that need updating.
// TODO(loyso): We need to check more data fields. crbug.com/949427.
const std::string extension_sync_data_name =
base::UTF16ToUTF8(web_app_info.title);
const std::string bookmark_app_description =
base::UTF16ToUTF8(web_app_info.description);
if (extension->non_localized_name() == extension_sync_data_name &&
extension->description() == bookmark_app_description) {
return true;
}
return false;
}
void BookmarkAppInstallFinalizer::SetCrxInstallerFactoryForTesting( void BookmarkAppInstallFinalizer::SetCrxInstallerFactoryForTesting(
CrxInstallerFactory crx_installer_factory) { CrxInstallerFactory crx_installer_factory) {
crx_installer_factory_ = crx_installer_factory; crx_installer_factory_ = crx_installer_factory;
......
...@@ -41,6 +41,9 @@ class BookmarkAppInstallFinalizer : public web_app::InstallFinalizer { ...@@ -41,6 +41,9 @@ class BookmarkAppInstallFinalizer : public web_app::InstallFinalizer {
content::WebContents* web_contents) override; content::WebContents* web_contents) override;
bool CanRevealAppShim() const override; bool CanRevealAppShim() const override;
void RevealAppShim(const web_app::AppId& app_id) override; void RevealAppShim(const web_app::AppId& app_id) override;
bool CanSkipAppUpdateForSync(
const web_app::AppId& app_id,
const WebApplicationInfo& web_app_info) const override;
using CrxInstallerFactory = using CrxInstallerFactory =
base::RepeatingCallback<scoped_refptr<CrxInstaller>(Profile*)>; base::RepeatingCallback<scoped_refptr<CrxInstaller>(Profile*)>;
......
...@@ -297,4 +297,41 @@ TEST_F(BookmarkAppInstallFinalizerTest, ForceLaunchContainer) { ...@@ -297,4 +297,41 @@ TEST_F(BookmarkAppInstallFinalizerTest, ForceLaunchContainer) {
run_loop.Run(); run_loop.Run();
} }
TEST_F(BookmarkAppInstallFinalizerTest, CanSkipAppUpdateForSync) {
BookmarkAppInstallFinalizer installer(profile());
auto info = std::make_unique<WebApplicationInfo>();
info->app_url = GURL(kWebAppUrl);
info->title = base::ASCIIToUTF16("Title1");
info->description = base::ASCIIToUTF16("Description1");
const web_app::AppId app_id = web_app::GenerateAppIdFromURL(info->app_url);
EXPECT_FALSE(installer.CanSkipAppUpdateForSync(app_id, *info));
base::RunLoop run_loop;
web_app::InstallFinalizer::FinalizeOptions options;
installer.FinalizeInstall(
*info, options,
base::BindLambdaForTesting([&](const web_app::AppId& installed_app_id,
web_app::InstallResultCode code) {
EXPECT_EQ(web_app::InstallResultCode::kSuccess, code);
EXPECT_EQ(app_id, installed_app_id);
run_loop.Quit();
}));
run_loop.Run();
EXPECT_TRUE(installer.CanSkipAppUpdateForSync(app_id, *info));
WebApplicationInfo info_with_diff_title = *info;
info_with_diff_title.title = base::ASCIIToUTF16("Title2");
EXPECT_FALSE(installer.CanSkipAppUpdateForSync(app_id, info_with_diff_title));
WebApplicationInfo info_with_diff_description = *info;
info_with_diff_description.title = base::ASCIIToUTF16("Description2");
EXPECT_FALSE(
installer.CanSkipAppUpdateForSync(app_id, info_with_diff_description));
}
} // namespace extensions } // namespace extensions
...@@ -82,6 +82,12 @@ void TestInstallFinalizer::RevealAppShim(const AppId& app_id) { ...@@ -82,6 +82,12 @@ void TestInstallFinalizer::RevealAppShim(const AppId& app_id) {
++num_reveal_appshim_calls_; ++num_reveal_appshim_calls_;
} }
bool TestInstallFinalizer::CanSkipAppUpdateForSync(
const AppId& app_id,
const WebApplicationInfo& web_app_info) const {
return false;
}
void TestInstallFinalizer::SetNextFinalizeInstallResult( void TestInstallFinalizer::SetNextFinalizeInstallResult(
const AppId& app_id, const AppId& app_id,
InstallResultCode code) { InstallResultCode code) {
......
...@@ -36,6 +36,9 @@ class TestInstallFinalizer final : public InstallFinalizer { ...@@ -36,6 +36,9 @@ class TestInstallFinalizer final : public InstallFinalizer {
content::WebContents* web_contents) override; content::WebContents* web_contents) override;
bool CanRevealAppShim() const override; bool CanRevealAppShim() const override;
void RevealAppShim(const AppId& app_id) override; void RevealAppShim(const AppId& app_id) override;
bool CanSkipAppUpdateForSync(
const AppId& app_id,
const WebApplicationInfo& web_app_info) const override;
void SetNextFinalizeInstallResult(const AppId& app_id, void SetNextFinalizeInstallResult(const AppId& app_id,
InstallResultCode code); InstallResultCode code);
......
...@@ -149,4 +149,11 @@ void WebAppInstallFinalizer::RevealAppShim(const AppId& app_id) { ...@@ -149,4 +149,11 @@ void WebAppInstallFinalizer::RevealAppShim(const AppId& app_id) {
NOTIMPLEMENTED(); NOTIMPLEMENTED();
} }
bool WebAppInstallFinalizer::CanSkipAppUpdateForSync(
const AppId& app_id,
const WebApplicationInfo& web_app_info) const {
NOTIMPLEMENTED();
return true;
}
} // namespace web_app } // namespace web_app
...@@ -41,6 +41,9 @@ class WebAppInstallFinalizer final : public InstallFinalizer { ...@@ -41,6 +41,9 @@ class WebAppInstallFinalizer final : public InstallFinalizer {
content::WebContents* web_contents) override; content::WebContents* web_contents) override;
bool CanRevealAppShim() const override; bool CanRevealAppShim() const override;
void RevealAppShim(const AppId& app_id) override; void RevealAppShim(const AppId& app_id) override;
bool CanSkipAppUpdateForSync(
const AppId& app_id,
const WebApplicationInfo& web_app_info) const override;
private: private:
void OnDataWritten(InstallFinalizedCallback callback, void OnDataWritten(InstallFinalizedCallback callback,
......
...@@ -130,8 +130,8 @@ void WebAppProvider::CreateBookmarkAppsSubsystems(Profile* profile) { ...@@ -130,8 +130,8 @@ void WebAppProvider::CreateBookmarkAppsSubsystems(Profile* profile) {
install_manager_ = std::make_unique<WebAppInstallManager>( install_manager_ = std::make_unique<WebAppInstallManager>(
profile, install_finalizer_.get()); profile, install_finalizer_.get());
} else { } else {
install_manager_ = install_manager_ = std::make_unique<extensions::BookmarkAppInstallManager>(
std::make_unique<extensions::BookmarkAppInstallManager>(profile); profile, install_finalizer_.get());
} }
pending_app_manager_ = pending_app_manager_ =
......
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