Commit 07670151 authored by Christopher Cameron's avatar Christopher Cameron Committed by Commit Bot

Remove AppShimHandler::Host interface and access AppShimHost directly

This has been a longstanding TODO. Pending work will require adding
more methods to route to AppShimHost, so just delete this rather than
adding more methods to it.

TBR=mgiuca

Bug: 896917
Change-Id: Idd8f55c7b6f549354441e28832e292ce693b9363
Reviewed-on: https://chromium-review.googlesource.com/c/1357574Reviewed-by: default avatarccameron <ccameron@chromium.org>
Commit-Queue: ccameron <ccameron@chromium.org>
Cr-Commit-Position: refs/heads/master@{#612938}
parent 9db07132
...@@ -12,10 +12,7 @@ ...@@ -12,10 +12,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "chrome/common/mac/app_shim_launch.h" #include "chrome/common/mac/app_shim_launch.h"
namespace views { class AppShimHost;
class BridgeFactoryHost;
} // namespace views
class AppShimHostBootstrap; class AppShimHostBootstrap;
namespace apps { namespace apps {
...@@ -24,40 +21,6 @@ namespace apps { ...@@ -24,40 +21,6 @@ namespace apps {
// shim processes. // shim processes.
class AppShimHandler { class AppShimHandler {
public: public:
// TODO(ccameron): Remove this virtual interface and always use AppShimHost
// directly.
// https://crbug.com/896917
class Host {
public:
// Returns true if an AppShimHostBootstrap has already connected to this
// host.
virtual bool HasBootstrapConnected() const = 0;
// Invoked when the app shim process has finished launching. The |bootstrap|
// object owns the lifetime of the app shim process.
virtual void OnBootstrapConnected(
std::unique_ptr<AppShimHostBootstrap> bootstrap) = 0;
// Invoked when the app is successfully launched.
virtual void OnAppLaunchComplete(AppShimLaunchResult result) = 0;
// Invoked when the app is closed in the browser process.
virtual void OnAppClosed() = 0;
// Invoked when the app should be hidden.
virtual void OnAppHide() = 0;
// Invoked when a window becomes visible while the app is hidden. Ensures
// the shim's "Hide/Show" state is updated correctly and the app can be
// re-hidden.
virtual void OnAppUnhideWithoutActivation() = 0;
// Invoked when the app is requesting user attention.
virtual void OnAppRequestUserAttention(AppShimAttentionType type) = 0;
// Allows the handler to determine which app this host corresponds to.
virtual base::FilePath GetProfilePath() const = 0;
virtual std::string GetAppId() const = 0;
virtual views::BridgeFactoryHost* GetViewsBridgeFactoryHost() const = 0;
protected:
virtual ~Host() {}
};
// Register a handler for an |app_mode_id|. // Register a handler for an |app_mode_id|.
static void RegisterHandler(const std::string& app_mode_id, static void RegisterHandler(const std::string& app_mode_id,
AppShimHandler* handler); AppShimHandler* handler);
...@@ -92,20 +55,20 @@ class AppShimHandler { ...@@ -92,20 +55,20 @@ class AppShimHandler {
std::unique_ptr<AppShimHostBootstrap> bootstrap) = 0; std::unique_ptr<AppShimHostBootstrap> bootstrap) = 0;
// Invoked by the shim host when the connection to the shim process is closed. // Invoked by the shim host when the connection to the shim process is closed.
virtual void OnShimClose(Host* host) = 0; virtual void OnShimClose(AppShimHost* host) = 0;
// Invoked by the shim host when the shim process receives a focus event. // Invoked by the shim host when the shim process receives a focus event.
// |files|, if non-empty, holds an array of files dragged onto the app bundle // |files|, if non-empty, holds an array of files dragged onto the app bundle
// or dock icon. // or dock icon.
virtual void OnShimFocus(Host* host, virtual void OnShimFocus(AppShimHost* host,
AppShimFocusType focus_type, AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) = 0; const std::vector<base::FilePath>& files) = 0;
// Invoked by the shim host when the shim process is hidden or shown. // Invoked by the shim host when the shim process is hidden or shown.
virtual void OnShimSetHidden(Host* host, bool hidden) = 0; virtual void OnShimSetHidden(AppShimHost* host, bool hidden) = 0;
// Invoked by the shim host when the shim process receives a quit event. // Invoked by the shim host when the shim process receives a quit event.
virtual void OnShimQuit(Host* host) = 0; virtual void OnShimQuit(AppShimHost* host) = 0;
protected: protected:
AppShimHandler() {} AppShimHandler() {}
......
...@@ -141,9 +141,6 @@ void AppShimHost::QuitApp() { ...@@ -141,9 +141,6 @@ void AppShimHost::QuitApp() {
handler->OnShimQuit(this); handler->OnShimQuit(this);
} }
////////////////////////////////////////////////////////////////////////////////
// AppShimHost, apps::AppShimHandler::Host
void AppShimHost::OnAppLaunchComplete(apps::AppShimLaunchResult result) { void AppShimHost::OnAppLaunchComplete(apps::AppShimLaunchResult result) {
DCHECK(!has_sent_on_launch_complete_); DCHECK(!has_sent_on_launch_complete_);
launch_result_.emplace(result); launch_result_.emplace(result);
......
...@@ -30,23 +30,33 @@ class AppShimHostBootstrap; ...@@ -30,23 +30,33 @@ class AppShimHostBootstrap;
// chrome/app/chrome_main_app_mode_mac.mm. The AppShimHost owns itself, and is // chrome/app/chrome_main_app_mode_mac.mm. The AppShimHost owns itself, and is
// destroyed when the app it corresponds to is closed or when the channel // destroyed when the app it corresponds to is closed or when the channel
// connected to the app shim is closed. // connected to the app shim is closed.
class AppShimHost : public chrome::mojom::AppShimHost, class AppShimHost : public chrome::mojom::AppShimHost {
public apps::AppShimHandler::Host {
public: public:
AppShimHost(const std::string& app_id, const base::FilePath& profile_path); AppShimHost(const std::string& app_id, const base::FilePath& profile_path);
// apps::AppShimHandler::Host overrides: // Returns true if an AppShimHostBootstrap has already connected to this
bool HasBootstrapConnected() const override; // host.
void OnBootstrapConnected( bool HasBootstrapConnected() const;
std::unique_ptr<AppShimHostBootstrap> bootstrap) override; // Invoked when the app is successfully launched.
void OnAppLaunchComplete(apps::AppShimLaunchResult result) override; void OnBootstrapConnected(std::unique_ptr<AppShimHostBootstrap> bootstrap);
void OnAppClosed() override; // Invoked when the app is closed in the browser process. Virtual for tests.
void OnAppHide() override; virtual void OnAppLaunchComplete(apps::AppShimLaunchResult result);
void OnAppUnhideWithoutActivation() override; // Invoked when the app is closed in the browser process.
void OnAppRequestUserAttention(apps::AppShimAttentionType type) override; void OnAppClosed();
base::FilePath GetProfilePath() const override; // Invoked when the app should be hidden.
std::string GetAppId() const override; void OnAppHide();
views::BridgeFactoryHost* GetViewsBridgeFactoryHost() const override; // Invoked when a window becomes visible while the app is hidden. Ensures
// the shim's "Hide/Show" state is updated correctly and the app can be
// re-hidden.
void OnAppUnhideWithoutActivation();
// Invoked when the app is requesting user attention.
void OnAppRequestUserAttention(apps::AppShimAttentionType type);
// Functions to allow the handler to determine which app this host corresponds
// to.
base::FilePath GetProfilePath() const;
std::string GetAppId() const;
views::BridgeFactoryHost* GetViewsBridgeFactoryHost() const;
protected: protected:
// AppShimHost is owned by itself. It will delete itself in Close (called on // AppShimHost is owned by itself. It will delete itself in Close (called on
......
...@@ -118,7 +118,7 @@ class AppShimHostTest : public testing::Test, ...@@ -118,7 +118,7 @@ class AppShimHostTest : public testing::Test,
scoped_refptr<base::SingleThreadTaskRunner> task_runner() { scoped_refptr<base::SingleThreadTaskRunner> task_runner() {
return task_runner_; return task_runner_;
} }
apps::AppShimHandler::Host* host() { return host_.get(); } AppShimHost* host() { return host_.get(); }
chrome::mojom::AppShimHost* GetMojoHost() { return host_ptr_.get(); } chrome::mojom::AppShimHost* GetMojoHost() { return host_ptr_.get(); }
void LaunchApp(apps::AppShimLaunchType launch_type) { void LaunchApp(apps::AppShimLaunchType launch_type) {
...@@ -151,17 +151,17 @@ class AppShimHostTest : public testing::Test, ...@@ -151,17 +151,17 @@ class AppShimHostTest : public testing::Test,
host_->OnAppLaunchComplete(launch_result_); host_->OnAppLaunchComplete(launch_result_);
} }
void OnShimClose(Host* host) override { ++close_count_; } void OnShimClose(AppShimHost* host) override { ++close_count_; }
void OnShimFocus(Host* host, void OnShimFocus(AppShimHost* host,
apps::AppShimFocusType focus_type, apps::AppShimFocusType focus_type,
const std::vector<base::FilePath>& file) override { const std::vector<base::FilePath>& file) override {
++focus_count_; ++focus_count_;
} }
void OnShimSetHidden(Host* host, bool hidden) override {} void OnShimSetHidden(AppShimHost* host, bool hidden) override {}
void OnShimQuit(Host* host) override { ++quit_count_; } void OnShimQuit(AppShimHost* host) override { ++quit_count_; }
apps::AppShimLaunchResult launch_result_ = apps::APP_SHIM_LAUNCH_SUCCESS; apps::AppShimLaunchResult launch_result_ = apps::APP_SHIM_LAUNCH_SUCCESS;
int launch_count_ = 0; int launch_count_ = 0;
......
...@@ -116,13 +116,12 @@ class AppShimHostManagerBrowserTest : public InProcessBrowserTest, ...@@ -116,13 +116,12 @@ class AppShimHostManagerBrowserTest : public InProcessBrowserTest,
// AppShimHandler overrides: // AppShimHandler overrides:
void OnShimLaunch(std::unique_ptr<AppShimHostBootstrap> bootstrap) override; void OnShimLaunch(std::unique_ptr<AppShimHostBootstrap> bootstrap) override;
void OnShimClose(apps::AppShimHandler::Host* host) override {} void OnShimClose(::AppShimHost* host) override {}
void OnShimFocus(apps::AppShimHandler::Host* host, void OnShimFocus(::AppShimHost* host,
apps::AppShimFocusType focus_type, apps::AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) override {} const std::vector<base::FilePath>& files) override {}
void OnShimSetHidden(apps::AppShimHandler::Host* host, bool hidden) override { void OnShimSetHidden(::AppShimHost* host, bool hidden) override {}
} void OnShimQuit(::AppShimHost* host) override {}
void OnShimQuit(apps::AppShimHandler::Host* host) override {}
std::unique_ptr<TestShimClient> test_client_; std::unique_ptr<TestShimClient> test_client_;
std::vector<base::FilePath> last_launch_files_; std::vector<base::FilePath> last_launch_files_;
......
...@@ -107,12 +107,12 @@ class WindowedAppShimLaunchObserver : public apps::AppShimHandler { ...@@ -107,12 +107,12 @@ class WindowedAppShimLaunchObserver : public apps::AppShimHandler {
if (run_loop_.get()) if (run_loop_.get())
run_loop_->Quit(); run_loop_->Quit();
} }
void OnShimClose(Host* host) override {} void OnShimClose(AppShimHost* host) override {}
void OnShimFocus(Host* host, void OnShimFocus(AppShimHost* host,
apps::AppShimFocusType focus_type, apps::AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) override {} const std::vector<base::FilePath>& files) override {}
void OnShimSetHidden(Host* host, bool hidden) override {} void OnShimSetHidden(AppShimHost* host, bool hidden) override {}
void OnShimQuit(Host* host) override {} void OnShimQuit(AppShimHost* host) override {}
private: private:
std::string app_mode_id_; std::string app_mode_id_;
......
...@@ -18,12 +18,12 @@ class AppsPageShimHandler : public apps::AppShimHandler { ...@@ -18,12 +18,12 @@ class AppsPageShimHandler : public apps::AppShimHandler {
// AppShimHandler: // AppShimHandler:
void OnShimLaunch(std::unique_ptr<AppShimHostBootstrap> bootstrap) override; void OnShimLaunch(std::unique_ptr<AppShimHostBootstrap> bootstrap) override;
void OnShimClose(apps::AppShimHandler::Host* host) override; void OnShimClose(AppShimHost* host) override;
void OnShimFocus(apps::AppShimHandler::Host* host, void OnShimFocus(AppShimHost* host,
apps::AppShimFocusType focus_type, apps::AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) override; const std::vector<base::FilePath>& files) override;
void OnShimSetHidden(apps::AppShimHandler::Host* host, bool hidden) override; void OnShimSetHidden(AppShimHost* host, bool hidden) override;
void OnShimQuit(apps::AppShimHandler::Host* host) override; void OnShimQuit(AppShimHost* host) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(AppsPageShimHandler); DISALLOW_COPY_AND_ASSIGN(AppsPageShimHandler);
......
...@@ -63,14 +63,13 @@ void AppsPageShimHandler::OnShimLaunch( ...@@ -63,14 +63,13 @@ void AppsPageShimHandler::OnShimLaunch(
bootstrap->OnLaunchAppFailed(apps::APP_SHIM_LAUNCH_DUPLICATE_HOST); bootstrap->OnLaunchAppFailed(apps::APP_SHIM_LAUNCH_DUPLICATE_HOST);
} }
void AppsPageShimHandler::OnShimClose(apps::AppShimHandler::Host* host) {} void AppsPageShimHandler::OnShimClose(AppShimHost* host) {}
void AppsPageShimHandler::OnShimFocus( void AppsPageShimHandler::OnShimFocus(
apps::AppShimHandler::Host* host, AppShimHost* host,
apps::AppShimFocusType focus_type, apps::AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) {} const std::vector<base::FilePath>& files) {}
void AppsPageShimHandler::OnShimSetHidden(apps::AppShimHandler::Host* host, void AppsPageShimHandler::OnShimSetHidden(AppShimHost* host, bool hidden) {}
bool hidden) {}
void AppsPageShimHandler::OnShimQuit(apps::AppShimHandler::Host* host) {} void AppsPageShimHandler::OnShimQuit(AppShimHost* host) {}
...@@ -200,7 +200,7 @@ const Extension* ExtensionAppShimHandler::Delegate::MaybeGetAppExtension( ...@@ -200,7 +200,7 @@ const Extension* ExtensionAppShimHandler::Delegate::MaybeGetAppExtension(
return ExtensionAppShimHandler::MaybeGetAppExtension(context, extension_id); return ExtensionAppShimHandler::MaybeGetAppExtension(context, extension_id);
} }
AppShimHandler::Host* ExtensionAppShimHandler::Delegate::CreateHost( AppShimHost* ExtensionAppShimHandler::Delegate::CreateHost(
const std::string& app_id, const std::string& app_id,
const base::FilePath& profile_path) { const base::FilePath& profile_path) {
return new AppShimHost(app_id, profile_path); return new AppShimHost(app_id, profile_path);
...@@ -271,17 +271,16 @@ ExtensionAppShimHandler::~ExtensionAppShimHandler() { ...@@ -271,17 +271,16 @@ ExtensionAppShimHandler::~ExtensionAppShimHandler() {
BrowserList::RemoveObserver(this); BrowserList::RemoveObserver(this);
} }
AppShimHandler::Host* ExtensionAppShimHandler::FindHost( AppShimHost* ExtensionAppShimHandler::FindHost(Profile* profile,
Profile* profile, const std::string& app_id) {
const std::string& app_id) {
HostMap::iterator it = hosts_.find(make_pair(profile, app_id)); HostMap::iterator it = hosts_.find(make_pair(profile, app_id));
return it == hosts_.end() ? NULL : it->second; return it == hosts_.end() ? NULL : it->second;
} }
AppShimHandler::Host* ExtensionAppShimHandler::FindOrCreateHost( AppShimHost* ExtensionAppShimHandler::FindOrCreateHost(
Profile* profile, Profile* profile,
const std::string& app_id) { const std::string& app_id) {
Host*& host = hosts_[make_pair(profile, app_id)]; AppShimHost*& host = hosts_[make_pair(profile, app_id)];
if (!host) if (!host)
host = delegate_->CreateHost(app_id, profile->GetPath()); host = delegate_->CreateHost(app_id, profile->GetPath());
return host; return host;
...@@ -295,7 +294,7 @@ ExtensionAppShimHandler::GetViewsBridgeFactoryHostForBrowser(Browser* browser) { ...@@ -295,7 +294,7 @@ ExtensionAppShimHandler::GetViewsBridgeFactoryHostForBrowser(Browser* browser) {
const Extension* extension = const Extension* extension =
apps::ExtensionAppShimHandler::MaybeGetAppForBrowser(browser); apps::ExtensionAppShimHandler::MaybeGetAppForBrowser(browser);
if (extension && extension->is_hosted_app()) { if (extension && extension->is_hosted_app()) {
Host* host = FindOrCreateHost( AppShimHost* host = FindOrCreateHost(
Profile::FromBrowserContext(browser->profile()), extension->id()); Profile::FromBrowserContext(browser->profile()), extension->id());
return host->GetViewsBridgeFactoryHost(); return host->GetViewsBridgeFactoryHost();
} }
...@@ -348,7 +347,7 @@ const Extension* ExtensionAppShimHandler::MaybeGetAppForBrowser( ...@@ -348,7 +347,7 @@ const Extension* ExtensionAppShimHandler::MaybeGetAppForBrowser(
} }
void ExtensionAppShimHandler::QuitAppForWindow(AppWindow* app_window) { void ExtensionAppShimHandler::QuitAppForWindow(AppWindow* app_window) {
Host* host = AppShimHost* host =
FindHost(Profile::FromBrowserContext(app_window->browser_context()), FindHost(Profile::FromBrowserContext(app_window->browser_context()),
app_window->extension_id()); app_window->extension_id());
if (host) { if (host) {
...@@ -364,7 +363,7 @@ void ExtensionAppShimHandler::QuitAppForWindow(AppWindow* app_window) { ...@@ -364,7 +363,7 @@ void ExtensionAppShimHandler::QuitAppForWindow(AppWindow* app_window) {
void ExtensionAppShimHandler::QuitHostedAppForWindow( void ExtensionAppShimHandler::QuitHostedAppForWindow(
Profile* profile, Profile* profile,
const std::string& app_id) { const std::string& app_id) {
Host* host = FindHost(Profile::FromBrowserContext(profile), app_id); AppShimHost* host = FindHost(Profile::FromBrowserContext(profile), app_id);
if (host) if (host)
OnShimQuit(host); OnShimQuit(host);
else else
...@@ -373,7 +372,7 @@ void ExtensionAppShimHandler::QuitHostedAppForWindow( ...@@ -373,7 +372,7 @@ void ExtensionAppShimHandler::QuitHostedAppForWindow(
void ExtensionAppShimHandler::HideAppForWindow(AppWindow* app_window) { void ExtensionAppShimHandler::HideAppForWindow(AppWindow* app_window) {
Profile* profile = Profile::FromBrowserContext(app_window->browser_context()); Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
Host* host = FindHost(profile, app_window->extension_id()); AppShimHost* host = FindHost(profile, app_window->extension_id());
if (host) if (host)
host->OnAppHide(); host->OnAppHide();
else else
...@@ -382,7 +381,7 @@ void ExtensionAppShimHandler::HideAppForWindow(AppWindow* app_window) { ...@@ -382,7 +381,7 @@ void ExtensionAppShimHandler::HideAppForWindow(AppWindow* app_window) {
void ExtensionAppShimHandler::HideHostedApp(Profile* profile, void ExtensionAppShimHandler::HideHostedApp(Profile* profile,
const std::string& app_id) { const std::string& app_id) {
Host* host = FindHost(profile, app_id); AppShimHost* host = FindHost(profile, app_id);
if (host) if (host)
host->OnAppHide(); host->OnAppHide();
else else
...@@ -392,7 +391,7 @@ void ExtensionAppShimHandler::HideHostedApp(Profile* profile, ...@@ -392,7 +391,7 @@ void ExtensionAppShimHandler::HideHostedApp(Profile* profile,
void ExtensionAppShimHandler::FocusAppForWindow(AppWindow* app_window) { void ExtensionAppShimHandler::FocusAppForWindow(AppWindow* app_window) {
Profile* profile = Profile::FromBrowserContext(app_window->browser_context()); Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
const std::string& app_id = app_window->extension_id(); const std::string& app_id = app_window->extension_id();
Host* host = FindHost(profile, app_id); AppShimHost* host = FindHost(profile, app_id);
if (host) { if (host) {
OnShimFocus(host, APP_SHIM_FOCUS_NORMAL, std::vector<base::FilePath>()); OnShimFocus(host, APP_SHIM_FOCUS_NORMAL, std::vector<base::FilePath>());
} else { } else {
...@@ -403,7 +402,7 @@ void ExtensionAppShimHandler::FocusAppForWindow(AppWindow* app_window) { ...@@ -403,7 +402,7 @@ void ExtensionAppShimHandler::FocusAppForWindow(AppWindow* app_window) {
void ExtensionAppShimHandler::UnhideWithoutActivationForWindow( void ExtensionAppShimHandler::UnhideWithoutActivationForWindow(
AppWindow* app_window) { AppWindow* app_window) {
Profile* profile = Profile::FromBrowserContext(app_window->browser_context()); Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
Host* host = FindHost(profile, app_window->extension_id()); AppShimHost* host = FindHost(profile, app_window->extension_id());
if (host) if (host)
host->OnAppUnhideWithoutActivation(); host->OnAppUnhideWithoutActivation();
} }
...@@ -412,7 +411,7 @@ void ExtensionAppShimHandler::RequestUserAttentionForWindow( ...@@ -412,7 +411,7 @@ void ExtensionAppShimHandler::RequestUserAttentionForWindow(
AppWindow* app_window, AppWindow* app_window,
AppShimAttentionType attention_type) { AppShimAttentionType attention_type) {
Profile* profile = Profile::FromBrowserContext(app_window->browser_context()); Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
Host* host = FindHost(profile, app_window->extension_id()); AppShimHost* host = FindHost(profile, app_window->extension_id());
if (host) if (host)
host->OnAppRequestUserAttention(attention_type); host->OnAppRequestUserAttention(attention_type);
} }
...@@ -481,7 +480,7 @@ ExtensionAppShimHandler* ExtensionAppShimHandler::Get() { ...@@ -481,7 +480,7 @@ ExtensionAppShimHandler* ExtensionAppShimHandler::Get() {
} }
const Extension* ExtensionAppShimHandler::MaybeGetExtensionOrCloseHost( const Extension* ExtensionAppShimHandler::MaybeGetExtensionOrCloseHost(
Host* host, AppShimHost* host,
Profile** profile_out) { Profile** profile_out) {
DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath())); DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath()));
Profile* profile = delegate_->ProfileForPath(host->GetProfilePath()); Profile* profile = delegate_->ProfileForPath(host->GetProfilePath());
...@@ -515,7 +514,7 @@ void ExtensionAppShimHandler::OnProfileLoaded( ...@@ -515,7 +514,7 @@ void ExtensionAppShimHandler::OnProfileLoaded(
AppShimLaunchType launch_type = bootstrap->GetLaunchType(); AppShimLaunchType launch_type = bootstrap->GetLaunchType();
const std::vector<base::FilePath>& files = bootstrap->GetLaunchFiles(); const std::vector<base::FilePath>& files = bootstrap->GetLaunchFiles();
Host* host = FindOrCreateHost(profile, app_id); AppShimHost* host = FindOrCreateHost(profile, app_id);
if (host->HasBootstrapConnected()) { if (host->HasBootstrapConnected()) {
// If another app shim process has already connected to this (profile, // If another app shim process has already connected to this (profile,
// app_id) pair, then focus the windows for the existing process, and // app_id) pair, then focus the windows for the existing process, and
...@@ -572,7 +571,7 @@ void ExtensionAppShimHandler::OnExtensionEnabled( ...@@ -572,7 +571,7 @@ void ExtensionAppShimHandler::OnExtensionEnabled(
// If the profile doesn't exist, it may have been deleted during the enable // If the profile doesn't exist, it may have been deleted during the enable
// prompt. In this case, NOTIFICATION_PROFILE_DESTROYED may not be fired // prompt. In this case, NOTIFICATION_PROFILE_DESTROYED may not be fired
// until later, so respond to the host now. // until later, so respond to the host now.
Host* host = FindHost(profile, app_id); AppShimHost* host = FindHost(profile, app_id);
if (host) if (host)
host->OnAppLaunchComplete(APP_SHIM_LAUNCH_APP_NOT_FOUND); host->OnAppLaunchComplete(APP_SHIM_LAUNCH_APP_NOT_FOUND);
return; return;
...@@ -581,8 +580,7 @@ void ExtensionAppShimHandler::OnExtensionEnabled( ...@@ -581,8 +580,7 @@ void ExtensionAppShimHandler::OnExtensionEnabled(
delegate_->LaunchApp(profile, extension, files); delegate_->LaunchApp(profile, extension, files);
} }
void ExtensionAppShimHandler::OnShimClose(AppShimHost* host) {
void ExtensionAppShimHandler::OnShimClose(Host* host) {
// This might be called when shutting down. Don't try to look up the profile // This might be called when shutting down. Don't try to look up the profile
// since profile_manager might not be around. // since profile_manager might not be around.
for (HostMap::iterator it = hosts_.begin(); it != hosts_.end(); ) { for (HostMap::iterator it = hosts_.begin(); it != hosts_.end(); ) {
...@@ -593,7 +591,7 @@ void ExtensionAppShimHandler::OnShimClose(Host* host) { ...@@ -593,7 +591,7 @@ void ExtensionAppShimHandler::OnShimClose(Host* host) {
} }
void ExtensionAppShimHandler::OnShimFocus( void ExtensionAppShimHandler::OnShimFocus(
Host* host, AppShimHost* host,
AppShimFocusType focus_type, AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) { const std::vector<base::FilePath>& files) {
Profile* profile; Profile* profile;
...@@ -623,7 +621,7 @@ void ExtensionAppShimHandler::OnShimFocus( ...@@ -623,7 +621,7 @@ void ExtensionAppShimHandler::OnShimFocus(
delegate_->LaunchApp(profile, extension, files); delegate_->LaunchApp(profile, extension, files);
} }
void ExtensionAppShimHandler::OnShimSetHidden(Host* host, bool hidden) { void ExtensionAppShimHandler::OnShimSetHidden(AppShimHost* host, bool hidden) {
Profile* profile; Profile* profile;
const Extension* extension = MaybeGetExtensionOrCloseHost(host, &profile); const Extension* extension = MaybeGetExtensionOrCloseHost(host, &profile);
if (!extension) if (!extension)
...@@ -635,7 +633,7 @@ void ExtensionAppShimHandler::OnShimSetHidden(Host* host, bool hidden) { ...@@ -635,7 +633,7 @@ void ExtensionAppShimHandler::OnShimSetHidden(Host* host, bool hidden) {
SetAppHidden(profile, host->GetAppId(), hidden); SetAppHidden(profile, host->GetAppId(), hidden);
} }
void ExtensionAppShimHandler::OnShimQuit(Host* host) { void ExtensionAppShimHandler::OnShimQuit(AppShimHost* host) {
DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath())); DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath()));
Profile* profile = delegate_->ProfileForPath(host->GetProfilePath()); Profile* profile = delegate_->ProfileForPath(host->GetProfilePath());
...@@ -690,7 +688,7 @@ void ExtensionAppShimHandler::Observe( ...@@ -690,7 +688,7 @@ void ExtensionAppShimHandler::Observe(
// OnShimClose and invalidate the iterator. // OnShimClose and invalidate the iterator.
HostMap::iterator current = it++; HostMap::iterator current = it++;
if (profile->IsSameProfile(current->first.first)) { if (profile->IsSameProfile(current->first.first)) {
Host* host = current->second; AppShimHost* host = current->second;
host->OnAppClosed(); host->OnAppClosed();
} }
} }
...@@ -727,7 +725,7 @@ void ExtensionAppShimHandler::OnAppActivated(content::BrowserContext* context, ...@@ -727,7 +725,7 @@ void ExtensionAppShimHandler::OnAppActivated(content::BrowserContext* context,
return; return;
Profile* profile = static_cast<Profile*>(context); Profile* profile = static_cast<Profile*>(context);
Host* host = FindHost(profile, app_id); AppShimHost* host = FindHost(profile, app_id);
if (host && host->HasBootstrapConnected()) { if (host && host->HasBootstrapConnected()) {
// If there is a connected app shim process, notify it of success and focus // If there is a connected app shim process, notify it of success and focus
// the app windows. // the app windows.
...@@ -741,7 +739,7 @@ void ExtensionAppShimHandler::OnAppActivated(content::BrowserContext* context, ...@@ -741,7 +739,7 @@ void ExtensionAppShimHandler::OnAppActivated(content::BrowserContext* context,
void ExtensionAppShimHandler::OnAppDeactivated(content::BrowserContext* context, void ExtensionAppShimHandler::OnAppDeactivated(content::BrowserContext* context,
const std::string& app_id) { const std::string& app_id) {
Host* host = FindHost(static_cast<Profile*>(context), app_id); AppShimHost* host = FindHost(static_cast<Profile*>(context), app_id);
if (host) if (host)
host->OnAppClosed(); host->OnAppClosed();
......
...@@ -69,8 +69,8 @@ class ExtensionAppShimHandler : public AppShimHandler, ...@@ -69,8 +69,8 @@ class ExtensionAppShimHandler : public AppShimHandler,
virtual const extensions::Extension* MaybeGetAppExtension( virtual const extensions::Extension* MaybeGetAppExtension(
content::BrowserContext* context, content::BrowserContext* context,
const std::string& extension_id); const std::string& extension_id);
virtual Host* CreateHost(const std::string& app_id, virtual AppShimHost* CreateHost(const std::string& app_id,
const base::FilePath& profile_path); const base::FilePath& profile_path);
virtual void EnableExtension(Profile* profile, virtual void EnableExtension(Profile* profile,
const std::string& extension_id, const std::string& extension_id,
const base::Callback<void()>& callback); const base::Callback<void()>& callback);
...@@ -93,13 +93,11 @@ class ExtensionAppShimHandler : public AppShimHandler, ...@@ -93,13 +93,11 @@ class ExtensionAppShimHandler : public AppShimHandler,
// Get the host corresponding to a profile and app id, or null if there is // Get the host corresponding to a profile and app id, or null if there is
// none. Virtual for tests. // none. Virtual for tests.
virtual AppShimHandler::Host* FindHost(Profile* profile, virtual AppShimHost* FindHost(Profile* profile, const std::string& app_id);
const std::string& app_id);
// Return the host corresponding to |profile| and |app_id|, or create one if // Return the host corresponding to |profile| and |app_id|, or create one if
// needed. // needed.
AppShimHandler::Host* FindOrCreateHost(Profile* profile, AppShimHost* FindOrCreateHost(Profile* profile, const std::string& app_id);
const std::string& app_id);
// Get the ViewBridgeFactoryHost, which may be used to create remote // Get the ViewBridgeFactoryHost, which may be used to create remote
// NSWindows, corresponding to a browser instance (or nullptr if none exists). // NSWindows, corresponding to a browser instance (or nullptr if none exists).
...@@ -135,12 +133,12 @@ class ExtensionAppShimHandler : public AppShimHandler, ...@@ -135,12 +133,12 @@ class ExtensionAppShimHandler : public AppShimHandler,
// AppShimHandler overrides: // AppShimHandler overrides:
void OnShimLaunch(std::unique_ptr<AppShimHostBootstrap> bootstrap) override; void OnShimLaunch(std::unique_ptr<AppShimHostBootstrap> bootstrap) override;
void OnShimClose(Host* host) override; void OnShimClose(AppShimHost* host) override;
void OnShimFocus(Host* host, void OnShimFocus(AppShimHost* host,
AppShimFocusType focus_type, AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) override; const std::vector<base::FilePath>& files) override;
void OnShimSetHidden(Host* host, bool hidden) override; void OnShimSetHidden(AppShimHost* host, bool hidden) override;
void OnShimQuit(Host* host) override; void OnShimQuit(AppShimHost* host) override;
// AppLifetimeMonitor::Observer overrides: // AppLifetimeMonitor::Observer overrides:
void OnAppStart(content::BrowserContext* context, void OnAppStart(content::BrowserContext* context,
...@@ -162,8 +160,7 @@ class ExtensionAppShimHandler : public AppShimHandler, ...@@ -162,8 +160,7 @@ class ExtensionAppShimHandler : public AppShimHandler,
void OnBrowserRemoved(Browser* browser) override; void OnBrowserRemoved(Browser* browser) override;
protected: protected:
typedef std::map<std::pair<Profile*, std::string>, AppShimHandler::Host*> typedef std::map<std::pair<Profile*, std::string>, AppShimHost*> HostMap;
HostMap;
typedef std::set<Browser*> BrowserSet; typedef std::set<Browser*> BrowserSet;
typedef std::map<std::string, BrowserSet> AppBrowserMap; typedef std::map<std::string, BrowserSet> AppBrowserMap;
...@@ -178,7 +175,7 @@ class ExtensionAppShimHandler : public AppShimHandler, ...@@ -178,7 +175,7 @@ class ExtensionAppShimHandler : public AppShimHandler,
// and receiving the quit confirmation). If the extension has been uninstalled // and receiving the quit confirmation). If the extension has been uninstalled
// or disabled, the host is immediately closed. If non-nil, the Extension's // or disabled, the host is immediately closed. If non-nil, the Extension's
// Profile will be set in |profile|. // Profile will be set in |profile|.
const extensions::Extension* MaybeGetExtensionOrCloseHost(Host* host, const extensions::Extension* MaybeGetExtensionOrCloseHost(AppShimHost* host,
Profile** profile); Profile** profile);
// Closes all browsers associated with an app. // Closes all browsers associated with an app.
......
...@@ -63,12 +63,11 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate { ...@@ -63,12 +63,11 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate {
MOCK_METHOD0(MaybeTerminate, void()); MOCK_METHOD0(MaybeTerminate, void());
void SetHostForCreate(AppShimHandler::Host* host_for_create) { void SetHostForCreate(AppShimHost* host_for_create) {
host_for_create_ = host_for_create; host_for_create_ = host_for_create;
} }
AppShimHandler::Host* CreateHost( AppShimHost* CreateHost(const std::string& app_id,
const std::string& app_id, const base::FilePath& profile_path) override {
const base::FilePath& profile_path) override {
DCHECK(host_for_create_); DCHECK(host_for_create_);
auto* result = host_for_create_; auto* result = host_for_create_;
host_for_create_ = nullptr; host_for_create_ = nullptr;
...@@ -93,7 +92,7 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate { ...@@ -93,7 +92,7 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate {
private: private:
std::map<base::FilePath, base::OnceCallback<void(Profile*)>> callbacks_; std::map<base::FilePath, base::OnceCallback<void(Profile*)>> callbacks_;
AppShimHandler::Host* host_for_create_ = nullptr; AppShimHost* host_for_create_ = nullptr;
}; };
class TestingExtensionAppShimHandler : public ExtensionAppShimHandler { class TestingExtensionAppShimHandler : public ExtensionAppShimHandler {
...@@ -104,18 +103,17 @@ class TestingExtensionAppShimHandler : public ExtensionAppShimHandler { ...@@ -104,18 +103,17 @@ class TestingExtensionAppShimHandler : public ExtensionAppShimHandler {
virtual ~TestingExtensionAppShimHandler() {} virtual ~TestingExtensionAppShimHandler() {}
MOCK_METHOD3(OnShimFocus, MOCK_METHOD3(OnShimFocus,
void(Host* host, void(AppShimHost* host,
AppShimFocusType, AppShimFocusType,
const std::vector<base::FilePath>& files)); const std::vector<base::FilePath>& files));
void RealOnShimFocus(Host* host, void RealOnShimFocus(AppShimHost* host,
AppShimFocusType focus_type, AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) { const std::vector<base::FilePath>& files) {
ExtensionAppShimHandler::OnShimFocus(host, focus_type, files); ExtensionAppShimHandler::OnShimFocus(host, focus_type, files);
} }
AppShimHandler::Host* FindHost(Profile* profile, AppShimHost* FindHost(Profile* profile, const std::string& app_id) {
const std::string& app_id) {
HostMap::const_iterator it = hosts().find(make_pair(profile, app_id)); HostMap::const_iterator it = hosts().find(make_pair(profile, app_id));
return it == hosts().end() ? NULL : it->second; return it == hosts().end() ? NULL : it->second;
} }
......
...@@ -165,7 +165,7 @@ class MockExtensionAppShimHandler : public apps::ExtensionAppShimHandler { ...@@ -165,7 +165,7 @@ class MockExtensionAppShimHandler : public apps::ExtensionAppShimHandler {
} }
~MockExtensionAppShimHandler() override {} ~MockExtensionAppShimHandler() override {}
MOCK_METHOD2(FindHost, AppShimHandler::Host*(Profile*, const std::string&)); MOCK_METHOD2(FindHost, AppShimHost*(Profile*, const std::string&));
}; };
} // namespace } // namespace
......
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