Commit 3dda524e authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Make sure that UI Manager works in the provider ready scope.

NotifyOnAllAppWindowsClosed API should not cause notifications
before Start or after Shutdown.

Bug: 1084939
Change-Id: I18b1299bd0cc1115a7024bd6ac8fc37a02a3e30a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2214459Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771510}
parent 30fc823a
...@@ -40,7 +40,16 @@ WebAppUiManagerImpl* WebAppUiManagerImpl::Get(Profile* profile) { ...@@ -40,7 +40,16 @@ WebAppUiManagerImpl* WebAppUiManagerImpl::Get(Profile* profile) {
return provider ? provider->ui_manager().AsImpl() : nullptr; return provider ? provider->ui_manager().AsImpl() : nullptr;
} }
WebAppUiManagerImpl::WebAppUiManagerImpl(Profile* profile) : profile_(profile) { WebAppUiManagerImpl::WebAppUiManagerImpl(Profile* profile)
: dialog_manager_(std::make_unique<WebAppDialogManager>(profile)),
profile_(profile) {}
WebAppUiManagerImpl::~WebAppUiManagerImpl() = default;
void WebAppUiManagerImpl::Start() {
DCHECK(!started_);
started_ = true;
for (Browser* browser : *BrowserList::GetInstance()) { for (Browser* browser : *BrowserList::GetInstance()) {
if (!IsBrowserForInstalledApp(browser)) if (!IsBrowserForInstalledApp(browser))
continue; continue;
...@@ -49,12 +58,11 @@ WebAppUiManagerImpl::WebAppUiManagerImpl(Profile* profile) : profile_(profile) { ...@@ -49,12 +58,11 @@ WebAppUiManagerImpl::WebAppUiManagerImpl(Profile* profile) : profile_(profile) {
} }
BrowserList::AddObserver(this); BrowserList::AddObserver(this);
dialog_manager_ = std::make_unique<WebAppDialogManager>(profile);
} }
WebAppUiManagerImpl::~WebAppUiManagerImpl() { void WebAppUiManagerImpl::Shutdown() {
BrowserList::RemoveObserver(this); BrowserList::RemoveObserver(this);
started_ = false;
} }
WebAppDialogManager& WebAppUiManagerImpl::dialog_manager() { WebAppDialogManager& WebAppUiManagerImpl::dialog_manager() {
...@@ -66,6 +74,8 @@ WebAppUiManagerImpl* WebAppUiManagerImpl::AsImpl() { ...@@ -66,6 +74,8 @@ WebAppUiManagerImpl* WebAppUiManagerImpl::AsImpl() {
} }
size_t WebAppUiManagerImpl::GetNumWindowsForApp(const AppId& app_id) { size_t WebAppUiManagerImpl::GetNumWindowsForApp(const AppId& app_id) {
DCHECK(started_);
auto it = num_windows_for_apps_map_.find(app_id); auto it = num_windows_for_apps_map_.find(app_id);
if (it == num_windows_for_apps_map_.end()) if (it == num_windows_for_apps_map_.end())
return 0; return 0;
...@@ -76,6 +86,8 @@ size_t WebAppUiManagerImpl::GetNumWindowsForApp(const AppId& app_id) { ...@@ -76,6 +86,8 @@ size_t WebAppUiManagerImpl::GetNumWindowsForApp(const AppId& app_id) {
void WebAppUiManagerImpl::NotifyOnAllAppWindowsClosed( void WebAppUiManagerImpl::NotifyOnAllAppWindowsClosed(
const AppId& app_id, const AppId& app_id,
base::OnceClosure callback) { base::OnceClosure callback) {
DCHECK(started_);
const size_t num_windows_for_app = GetNumWindowsForApp(app_id); const size_t num_windows_for_app = GetNumWindowsForApp(app_id);
if (num_windows_for_app == 0) { if (num_windows_for_app == 0) {
base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE,
...@@ -167,17 +179,17 @@ void WebAppUiManagerImpl::ReparentAppTabToWindow(content::WebContents* contents, ...@@ -167,17 +179,17 @@ void WebAppUiManagerImpl::ReparentAppTabToWindow(content::WebContents* contents,
} }
void WebAppUiManagerImpl::OnBrowserAdded(Browser* browser) { void WebAppUiManagerImpl::OnBrowserAdded(Browser* browser) {
if (!IsBrowserForInstalledApp(browser)) { DCHECK(started_);
if (!IsBrowserForInstalledApp(browser))
return; return;
}
++num_windows_for_apps_map_[GetAppIdForBrowser(browser)]; ++num_windows_for_apps_map_[GetAppIdForBrowser(browser)];
} }
void WebAppUiManagerImpl::OnBrowserRemoved(Browser* browser) { void WebAppUiManagerImpl::OnBrowserRemoved(Browser* browser) {
if (!IsBrowserForInstalledApp(browser)) { DCHECK(started_);
if (!IsBrowserForInstalledApp(browser))
return; return;
}
const auto& app_id = GetAppIdForBrowser(browser); const auto& app_id = GetAppIdForBrowser(browser);
......
...@@ -34,6 +34,9 @@ class WebAppUiManagerImpl : public BrowserListObserver, public WebAppUiManager { ...@@ -34,6 +34,9 @@ class WebAppUiManagerImpl : public BrowserListObserver, public WebAppUiManager {
explicit WebAppUiManagerImpl(Profile* profile); explicit WebAppUiManagerImpl(Profile* profile);
~WebAppUiManagerImpl() override; ~WebAppUiManagerImpl() override;
void Start() override;
void Shutdown() override;
WebAppDialogManager& dialog_manager(); WebAppDialogManager& dialog_manager();
// WebAppUiManager: // WebAppUiManager:
...@@ -73,6 +76,7 @@ class WebAppUiManagerImpl : public BrowserListObserver, public WebAppUiManager { ...@@ -73,6 +76,7 @@ class WebAppUiManagerImpl : public BrowserListObserver, public WebAppUiManager {
std::map<AppId, std::vector<base::OnceClosure>> windows_closed_requests_map_; std::map<AppId, std::vector<base::OnceClosure>> windows_closed_requests_map_;
std::map<AppId, size_t> num_windows_for_apps_map_; std::map<AppId, size_t> num_windows_for_apps_map_;
bool started_ = false;
base::WeakPtrFactory<WebAppUiManagerImpl> weak_ptr_factory_{this}; base::WeakPtrFactory<WebAppUiManagerImpl> weak_ptr_factory_{this};
......
...@@ -30,6 +30,9 @@ class WebAppUiManager { ...@@ -30,6 +30,9 @@ class WebAppUiManager {
virtual ~WebAppUiManager() = default; virtual ~WebAppUiManager() = default;
virtual void Start() = 0;
virtual void Shutdown() = 0;
// A safe downcast. // A safe downcast.
virtual WebAppUiManagerImpl* AsImpl() = 0; virtual WebAppUiManagerImpl* AsImpl() = 0;
......
...@@ -17,6 +17,10 @@ TestWebAppUiManager::TestWebAppUiManager() = default; ...@@ -17,6 +17,10 @@ TestWebAppUiManager::TestWebAppUiManager() = default;
TestWebAppUiManager::~TestWebAppUiManager() = default; TestWebAppUiManager::~TestWebAppUiManager() = default;
void TestWebAppUiManager::Start() {}
void TestWebAppUiManager::Shutdown() {}
void TestWebAppUiManager::SetNumWindowsForApp(const AppId& app_id, void TestWebAppUiManager::SetNumWindowsForApp(const AppId& app_id,
size_t num_windows_for_app) { size_t num_windows_for_app) {
app_id_to_num_windows_map_[app_id] = num_windows_for_app; app_id_to_num_windows_map_[app_id] = num_windows_for_app;
......
...@@ -17,6 +17,9 @@ class TestWebAppUiManager : public WebAppUiManager { ...@@ -17,6 +17,9 @@ class TestWebAppUiManager : public WebAppUiManager {
TestWebAppUiManager(); TestWebAppUiManager();
~TestWebAppUiManager() override; ~TestWebAppUiManager() override;
void Start() override;
void Shutdown() override;
void SetNumWindowsForApp(const AppId& app_id, size_t num_windows_for_app); void SetNumWindowsForApp(const AppId& app_id, size_t num_windows_for_app);
bool DidUninstallAndReplace(const AppId& from_app, const AppId& to_app); bool DidUninstallAndReplace(const AppId& from_app, const AppId& to_app);
......
...@@ -329,11 +329,7 @@ bool WebAppInstallFinalizer::WasExternalAppUninstalledByUser( ...@@ -329,11 +329,7 @@ bool WebAppInstallFinalizer::WasExternalAppUninstalledByUser(
void WebAppInstallFinalizer::FinalizeUpdate( void WebAppInstallFinalizer::FinalizeUpdate(
const WebApplicationInfo& web_app_info, const WebApplicationInfo& web_app_info,
InstallFinalizedCallback callback) { InstallFinalizedCallback callback) {
if (!started_) { CHECK(started_);
std::move(callback).Run(AppId(),
InstallResultCode::kWebAppProviderNotReady);
return;
}
const AppId app_id = GenerateAppIdFromURL(web_app_info.app_url); const AppId app_id = GenerateAppIdFromURL(web_app_info.app_url);
const WebApp* existing_web_app = GetWebAppRegistrar().GetAppById(app_id); const WebApp* existing_web_app = GetWebAppRegistrar().GetAppById(app_id);
......
...@@ -149,6 +149,7 @@ SystemWebAppManager& WebAppProvider::system_web_app_manager() { ...@@ -149,6 +149,7 @@ SystemWebAppManager& WebAppProvider::system_web_app_manager() {
} }
void WebAppProvider::Shutdown() { void WebAppProvider::Shutdown() {
ui_manager_->Shutdown();
shortcut_manager_->Shutdown(); shortcut_manager_->Shutdown();
pending_app_manager_->Shutdown(); pending_app_manager_->Shutdown();
install_manager_->Shutdown(); install_manager_->Shutdown();
...@@ -277,6 +278,7 @@ void WebAppProvider::OnRegistryControllerReady() { ...@@ -277,6 +278,7 @@ void WebAppProvider::OnRegistryControllerReady() {
shortcut_manager_->Start(); shortcut_manager_->Start();
manifest_update_manager_->Start(); manifest_update_manager_->Start();
file_handler_manager_->Start(); file_handler_manager_->Start();
ui_manager_->Start();
on_registry_ready_.Signal(); on_registry_ready_.Signal();
} }
......
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