Commit 0d1cc1cd authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

MacPWAs BMO: Remove AppShimTerminationManager dep on platform_apps

Have AppShimTerminationManager call back into
AppShimManager::Delegate to determine if app windows are open.

This will allow us to remove all includes of platform_apps from
app_shim.

Bug: 1057195
Change-Id: I04d13efaca5f65fd507c0f949068e2a6d830e2fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2108003Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751389}
parent 1c5a8e68
......@@ -251,6 +251,10 @@ AppShimHost* AppShimManager::FindHost(Profile* profile,
return profile_state->GetHost();
}
bool AppShimManager::HasNonBookmarkAppWindowsOpen() {
return delegate_->HasNonBookmarkAppWindowsOpen();
}
AppShimHost* AppShimManager::GetHostForRemoteCocoaBrowser(Browser* browser) {
const std::string app_id =
web_app::GetAppIdFromApplicationName(browser->app_name());
......
......@@ -131,6 +131,10 @@ class AppShimManager : public AppShimHostBootstrap::Client,
// Terminate Chrome if Chrome attempted to quit, but was prevented from
// quitting due to apps being open.
virtual void MaybeTerminate() = 0;
// Return true if any app windows are open. This is eventually invoked
// by MaybeTerminate. It does not apply to bookmark apps.
virtual bool HasNonBookmarkAppWindowsOpen() = 0;
};
// Helper function to get the instance on the browser process. This will be
......@@ -151,6 +155,9 @@ class AppShimManager : public AppShimHostBootstrap::Client,
// finishes launching.
AppShimHost* GetHostForRemoteCocoaBrowser(Browser* browser);
// Return true if any non-bookmark app windows open.
bool HasNonBookmarkAppWindowsOpen();
// AppShimHostBootstrap::Client:
void OnShimProcessConnected(
std::unique_ptr<AppShimHostBootstrap> bootstrap) override;
......
......@@ -90,6 +90,7 @@ class MockDelegate : public AppShimManager::Delegate {
MOCK_METHOD0(LaunchUserManager, void());
MOCK_METHOD0(MaybeTerminate, void());
MOCK_METHOD0(HasNonBookmarkAppWindowsOpen, bool());
void SetAppCanCreateHost(bool should_create_host) {
allow_shim_to_connect_ = should_create_host;
......
......@@ -11,7 +11,7 @@
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/apps/platform_apps/app_window_registry_util.h"
#include "chrome/browser/apps/app_shim/app_shim_manager_mac.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/common/mac/app_mode_common.h"
......@@ -24,11 +24,9 @@ namespace apps {
namespace {
void TerminateIfNoAppWindows() {
bool app_windows_left =
AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0);
if (!app_windows_left) {
auto* app_shim_manager = AppShimManager::Get();
if (app_shim_manager && !app_shim_manager->HasNonBookmarkAppWindowsOpen())
chrome::AttemptExit();
}
}
class AppShimTerminationManagerImpl : public AppShimTerminationManager,
......
......@@ -7,6 +7,7 @@
#include "apps/launcher.h"
#include "chrome/browser/apps/app_shim/app_shim_termination_manager.h"
#include "chrome/browser/apps/launch_service/launch_service.h"
#include "chrome/browser/apps/platform_apps/app_window_registry_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/launch_util.h"
#include "chrome/browser/profiles/profile_manager.h"
......@@ -284,4 +285,8 @@ void ExtensionAppShimManagerDelegate::MaybeTerminate() {
apps::AppShimTerminationManager::Get()->MaybeTerminate();
}
bool ExtensionAppShimManagerDelegate::HasNonBookmarkAppWindowsOpen() {
return AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0);
}
} // namespace apps
......@@ -11,86 +11,42 @@ namespace apps {
class ExtensionAppShimManagerDelegate : public AppShimManager::Delegate {
public:
// AppShimManager::Delegate:
ExtensionAppShimManagerDelegate();
~ExtensionAppShimManagerDelegate() override;
// Return the profile for |path|, only if it is already loaded.
Profile* ProfileForPath(const base::FilePath& path) override;
// Load a profile and call |callback| when completed or failed.
void LoadProfileAsync(const base::FilePath& path,
base::OnceCallback<void(Profile*)> callback) override;
// Return true if the specified path is for a valid profile that is also
// locked.
bool IsProfileLockedForPath(const base::FilePath& path) override;
// Show all app windows (for non-PWA apps). Return true if there existed any
// windows.
bool ShowAppWindows(Profile* profile, const web_app::AppId& app_id) override;
// Close all app windows (for non-PWA apps).
void CloseAppWindows(Profile* profile, const web_app::AppId& app_id) override;
// Return true iff |app_id| corresponds to an app that is installed for
// |profile|.
bool AppIsInstalled(Profile* profile, const web_app::AppId& app_id) override;
// Return true iff the specified app can create an AppShimHost, which will
// keep the app shim process connected (as opposed to, e.g, a bookmark app
// that opens in a tab, which will immediately close).
bool AppCanCreateHost(Profile* profile,
const web_app::AppId& app_id) override;
// Return true if Cocoa windows for this app should be hosted in the app
// shim process.
bool AppUsesRemoteCocoa(Profile* profile,
const web_app::AppId& app_id) override;
// Return true if a single app shim is used for all profiles (as opposed to
// one shim per profile).
bool AppIsMultiProfile(Profile* profile,
const web_app::AppId& app_id) override;
// Create an AppShimHost for the specified parameters (intercept-able for
// tests).
std::unique_ptr<AppShimHost> CreateHost(AppShimHost::Client* client,
const base::FilePath& profile_path,
const web_app::AppId& app_id,
bool use_remote_cocoa) override;
// Open a dialog to enable the specified extension. Call |callback| after
// the dialog is executed.
void EnableExtension(Profile* profile,
const std::string& extension_id,
base::OnceCallback<void()> callback) override;
// Launch the app in Chrome. This will (often) create a new window.
void LaunchApp(Profile* profile,
const web_app::AppId& app_id,
const std::vector<base::FilePath>& files) override;
// Open the specified URL in a new Chrome window. This is the fallback when
// an app shim exists, but there is no profile or extension for it. If
// |profile_path| is specified, then that profile is preferred, otherwise,
// the last used profile is used.
void OpenAppURLInBrowserWindow(const base::FilePath& profile_path,
const GURL& url) override;
// Launch the shim process for an app.
void LaunchShim(Profile* profile,
const web_app::AppId& app_id,
bool recreate_shims,
ShimLaunchedCallback launched_callback,
ShimTerminatedCallback terminated_callback) override;
// Launch the user manager (in response to attempting to access a locked
// profile).
void LaunchUserManager() override;
// Terminate Chrome if Chrome attempted to quit, but was prevented from
// quitting due to apps being open.
void MaybeTerminate() override;
bool HasNonBookmarkAppWindowsOpen() override;
};
} // namespace apps
......
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