Commit 750b5a49 authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

dpwa: IsInstalled() and GetAppById() should return false after profile deletion.

If profile is being marked for deletion,
IsInstalled() and GetAppById() must return
false for any given app_id.

The WebAppDatabase representation and manifest resources directories
will be deleted as a part of profile directory deletion.

Bug: 1080703, 1088434
Change-Id: I8c1c4767a67d6c1cead1c015e1137d7faf2aaa4c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2265700Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#782273}
parent eaedcc05
......@@ -12,8 +12,10 @@
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/components/web_app_id.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/browser/web_applications/extensions/bookmark_app_registrar.h"
#include "chrome/browser/web_applications/test/web_app_install_observer.h"
#include "chrome/browser/web_applications/test/web_app_test.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "content/public/test/browser_test.h"
#include "url/gurl.h"
......@@ -43,11 +45,30 @@ IN_PROC_BROWSER_TEST_P(WebAppProfileDeletionBrowserTest,
observer.SetWebAppProfileWillBeDeletedDelegate(
base::BindLambdaForTesting([&](const AppId& app_to_be_uninstalled) {
EXPECT_EQ(app_to_be_uninstalled, app_id);
if (GetParam() == ProviderType::kWebApps) {
EXPECT_TRUE(registrar().IsInstalled(app_id));
EXPECT_TRUE(registrar().AsWebAppRegistrar()->GetAppById(app_id));
} else if (GetParam() == ProviderType::kBookmarkApps) {
// IsInstalled() returns false here. This is a legacy behavior for
// bookmark apps:
EXPECT_FALSE(registrar().IsInstalled(app_id));
EXPECT_TRUE(
registrar().AsBookmarkAppRegistrar()->FindExtension(app_id));
}
run_loop.Quit();
}));
ScheduleCurrentProfileForDeletion();
run_loop.Run();
EXPECT_FALSE(registrar().IsInstalled(app_id));
if (GetParam() == ProviderType::kWebApps) {
EXPECT_FALSE(registrar().AsWebAppRegistrar()->GetAppById(app_id));
} else if (GetParam() == ProviderType::kBookmarkApps) {
EXPECT_FALSE(registrar().AsBookmarkAppRegistrar()->FindExtension(app_id));
}
}
INSTANTIATE_TEST_SUITE_P(All,
......
......@@ -22,6 +22,9 @@ WebAppRegistrar::WebAppRegistrar(Profile* profile) : AppRegistrar(profile) {}
WebAppRegistrar::~WebAppRegistrar() = default;
const WebApp* WebAppRegistrar::GetAppById(const AppId& app_id) const {
if (registry_profile_being_deleted_)
return nullptr;
auto it = registry_.find(app_id);
return it == registry_.end() ? nullptr : it->second.get();
}
......@@ -171,6 +174,11 @@ void WebAppRegistrar::OnProfileMarkedForPermanentDeletion(
for (const auto& app : AllApps())
NotifyWebAppProfileWillBeDeleted(app.app_id());
// We can't do registry_.clear() here because it makes in-memory registry
// diverged from the sync server registry and from the on-disk registry
// (WebAppDatabase/LevelDB and "Web Applications" profile directory).
registry_profile_being_deleted_ = true;
}
WebAppRegistrar::AppSet::AppSet(const WebAppRegistrar* registrar)
......
......@@ -122,6 +122,7 @@ class WebAppRegistrar : public AppRegistrar, public ProfileManagerObserver {
private:
Registry registry_;
bool registry_profile_being_deleted_ = false;
#if DCHECK_IS_ON()
size_t mutations_count_ = 0;
#endif
......
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