Commit 7ae9c365 authored by Guido Urdaneta's avatar Guido Urdaneta Committed by Commit Bot

Revert "Remove AppShimHandler::Host interface and access AppShimHost directly"

This reverts commit 07670151.

Reason for revert: Suspect of introducing consistent failure on Mac12.12 Tests bot.
https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Mac10.12%20Tests

First failure: https://ci.chromium.org/p/chromium/builders/luci.chromium.ci/Mac10.12%20Tests/17211


Sample logs

[ RUN      ] NativeAppWindowCocoaBrowserTest.HideShowWithAppWithShim
[12598:61443:1201/114417.410054:WARNING:notification_platform_bridge_mac.mm(521)] AlertNotificationService: XPC connection invalidated.
../../chrome/browser/ui/cocoa/apps/native_app_window_cocoa_browsertest.mm:198: Failure
Actual function call count doesn't match EXPECT_CALL(*mock_host, OnAppUnhideWithoutActivation())...
         Expected: to be called once
           Actual: never called - unsatisfied and active
Stack trace:
0   browser_tests                       0x000000010ca5edbb testing::internal::UnitTestImpl::CurrentOsStackTraceExceptTop(int) + 91
1   browser_tests                       0x000000010ca5e779 testing::internal::AssertHelper::operator=(testing::Message const&) const + 89
2   browser_tests                       0x000000010ca4dd61 testing::internal::GoogleTestFailureReporter::ReportFailure(testing::internal::FailureReporterInterface::FailureType, char const*, int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 97
3   browser_tests                       0x000000010ca52a28 testing::internal::UntypedFunctionMockerBase::VerifyAndClearExpectationsLocked() + 584
4   browser_tests                       0x000000010ca53399 testing::Mock::VerifyAndClearExpectationsLocked(void*) + 393
5   browser_tests                       0x000000010ca531f1 testing::Mock::VerifyAndClearExpectations(void*) + 33
6   browser_tests                       0x000000010c75e4cd NativeAppWindowCocoaBrowserTest_HideShowWithAppWithShim_Test::RunTestOnMainThread() + 3117
7   browser_tests                       0x000000010ff002bb content::BrowserTestBase::ProxyRunTestOnMainThreadLoop() + 491
8   browser_tests                       0x000000010f944014 ChromeBrowserMainParts::PreMainMessageLoopRunImpl() + 4372
9   browser_tests                       0x000000010f942e3d ChromeBrowserMainParts::PreMainMessageLoopRun() + 45
10  browser_tests                       0x000000010daaedc2 content::BrowserMainLoop::PreMainMessageLoopRun() + 50
11  browser_tests                       0x000000010df0f397 content::StartupTaskRunner::RunAllTasksNow() + 39
12  browser_tests                       0x000000010daad9fb content::BrowserMainLoop::CreateStartupTasks() + 683
13  browser_tests                       0x000000010dab1065 content::BrowserMainRunnerImpl::Initialize(content::MainFunctionParams const&) + 85
14  browser_tests                       0x000000010daabde2 content::BrowserMain(content::MainFunctionParams const&) + 178
15  browser_tests                       0x000000010f3cc601 content::ContentMainRunnerImpl::RunServiceManager(content::MainFunctionParams&, bool) + 241
16  browser_tests                       0x000000010f3cc4e4 content::ContentMainRunnerImpl::Run(bool) + 292
17  browser_tests                       0x00000001127318cb service_manager::Main(service_manager::MainParams const&) + 3051
18  browser_tests                       0x000000010f3cb684 content::ContentMain(content::ContentMainParams const&) + 68
19  browser_tests                       0x000000010fefff0d content::BrowserTestBase::SetUp() + 2829
20  browser_tests                       0x000000010f8b75f1 InProcessBrowserTest::SetUp() + 529

Original change's description:
> 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/1357574
> Reviewed-by: ccameron <ccameron@chromium.org>
> Commit-Queue: ccameron <ccameron@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#612938}

TBR=ccameron@chromium.org,mgiuca@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: 896917
Change-Id: I0e4314f3a0d9b1241ecdde333a4d02b327a06917
Reviewed-on: https://chromium-review.googlesource.com/c/1358431Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#613064}
parent 7aa08198
...@@ -12,7 +12,10 @@ ...@@ -12,7 +12,10 @@
#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"
class AppShimHost; namespace views {
class BridgeFactoryHost;
} // namespace views
class AppShimHostBootstrap; class AppShimHostBootstrap;
namespace apps { namespace apps {
...@@ -21,6 +24,40 @@ namespace apps { ...@@ -21,6 +24,40 @@ 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);
...@@ -55,20 +92,20 @@ class AppShimHandler { ...@@ -55,20 +92,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(AppShimHost* host) = 0; virtual void OnShimClose(Host* 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(AppShimHost* host, virtual void OnShimFocus(Host* 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(AppShimHost* host, bool hidden) = 0; virtual void OnShimSetHidden(Host* 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(AppShimHost* host) = 0; virtual void OnShimQuit(Host* host) = 0;
protected: protected:
AppShimHandler() {} AppShimHandler() {}
......
...@@ -141,6 +141,9 @@ void AppShimHost::QuitApp() { ...@@ -141,6 +141,9 @@ 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,33 +30,23 @@ class AppShimHostBootstrap; ...@@ -30,33 +30,23 @@ 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);
// Returns true if an AppShimHostBootstrap has already connected to this // apps::AppShimHandler::Host overrides:
// host. bool HasBootstrapConnected() const override;
bool HasBootstrapConnected() const; void OnBootstrapConnected(
// Invoked when the app is successfully launched. std::unique_ptr<AppShimHostBootstrap> bootstrap) override;
void OnBootstrapConnected(std::unique_ptr<AppShimHostBootstrap> bootstrap); void OnAppLaunchComplete(apps::AppShimLaunchResult result) override;
// Invoked when the app is closed in the browser process. Virtual for tests. void OnAppClosed() override;
virtual void OnAppLaunchComplete(apps::AppShimLaunchResult result); void OnAppHide() override;
// Invoked when the app is closed in the browser process. void OnAppUnhideWithoutActivation() override;
void OnAppClosed(); void OnAppRequestUserAttention(apps::AppShimAttentionType type) override;
// Invoked when the app should be hidden. base::FilePath GetProfilePath() const override;
void OnAppHide(); std::string GetAppId() const override;
// Invoked when a window becomes visible while the app is hidden. Ensures views::BridgeFactoryHost* GetViewsBridgeFactoryHost() const override;
// 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_;
} }
AppShimHost* host() { return host_.get(); } apps::AppShimHandler::Host* 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(AppShimHost* host) override { ++close_count_; } void OnShimClose(Host* host) override { ++close_count_; }
void OnShimFocus(AppShimHost* host, void OnShimFocus(Host* 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(AppShimHost* host, bool hidden) override {} void OnShimSetHidden(Host* host, bool hidden) override {}
void OnShimQuit(AppShimHost* host) override { ++quit_count_; } void OnShimQuit(Host* 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,12 +116,13 @@ class AppShimHostManagerBrowserTest : public InProcessBrowserTest, ...@@ -116,12 +116,13 @@ 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(::AppShimHost* host) override {} void OnShimClose(apps::AppShimHandler::Host* host) override {}
void OnShimFocus(::AppShimHost* host, void OnShimFocus(apps::AppShimHandler::Host* 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(::AppShimHost* host, bool hidden) override {} void OnShimSetHidden(apps::AppShimHandler::Host* 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(AppShimHost* host) override {} void OnShimClose(Host* host) override {}
void OnShimFocus(AppShimHost* host, void OnShimFocus(Host* 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(AppShimHost* host, bool hidden) override {} void OnShimSetHidden(Host* host, bool hidden) override {}
void OnShimQuit(AppShimHost* host) override {} void OnShimQuit(Host* 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(AppShimHost* host) override; void OnShimClose(apps::AppShimHandler::Host* host) override;
void OnShimFocus(AppShimHost* host, void OnShimFocus(apps::AppShimHandler::Host* 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(AppShimHost* host, bool hidden) override; void OnShimSetHidden(apps::AppShimHandler::Host* host, bool hidden) override;
void OnShimQuit(AppShimHost* host) override; void OnShimQuit(apps::AppShimHandler::Host* host) override;
private: private:
DISALLOW_COPY_AND_ASSIGN(AppsPageShimHandler); DISALLOW_COPY_AND_ASSIGN(AppsPageShimHandler);
......
...@@ -63,13 +63,14 @@ void AppsPageShimHandler::OnShimLaunch( ...@@ -63,13 +63,14 @@ void AppsPageShimHandler::OnShimLaunch(
bootstrap->OnLaunchAppFailed(apps::APP_SHIM_LAUNCH_DUPLICATE_HOST); bootstrap->OnLaunchAppFailed(apps::APP_SHIM_LAUNCH_DUPLICATE_HOST);
} }
void AppsPageShimHandler::OnShimClose(AppShimHost* host) {} void AppsPageShimHandler::OnShimClose(apps::AppShimHandler::Host* host) {}
void AppsPageShimHandler::OnShimFocus( void AppsPageShimHandler::OnShimFocus(
AppShimHost* host, apps::AppShimHandler::Host* host,
apps::AppShimFocusType focus_type, apps::AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) {} const std::vector<base::FilePath>& files) {}
void AppsPageShimHandler::OnShimSetHidden(AppShimHost* host, bool hidden) {} void AppsPageShimHandler::OnShimSetHidden(apps::AppShimHandler::Host* host,
bool hidden) {}
void AppsPageShimHandler::OnShimQuit(AppShimHost* host) {} void AppsPageShimHandler::OnShimQuit(apps::AppShimHandler::Host* 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);
} }
AppShimHost* ExtensionAppShimHandler::Delegate::CreateHost( AppShimHandler::Host* 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,16 +271,17 @@ ExtensionAppShimHandler::~ExtensionAppShimHandler() { ...@@ -271,16 +271,17 @@ ExtensionAppShimHandler::~ExtensionAppShimHandler() {
BrowserList::RemoveObserver(this); BrowserList::RemoveObserver(this);
} }
AppShimHost* ExtensionAppShimHandler::FindHost(Profile* profile, AppShimHandler::Host* ExtensionAppShimHandler::FindHost(
const std::string& app_id) { Profile* profile,
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;
} }
AppShimHost* ExtensionAppShimHandler::FindOrCreateHost( AppShimHandler::Host* ExtensionAppShimHandler::FindOrCreateHost(
Profile* profile, Profile* profile,
const std::string& app_id) { const std::string& app_id) {
AppShimHost*& host = hosts_[make_pair(profile, app_id)]; Host*& 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;
...@@ -294,7 +295,7 @@ ExtensionAppShimHandler::GetViewsBridgeFactoryHostForBrowser(Browser* browser) { ...@@ -294,7 +295,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()) {
AppShimHost* host = FindOrCreateHost( Host* host = FindOrCreateHost(
Profile::FromBrowserContext(browser->profile()), extension->id()); Profile::FromBrowserContext(browser->profile()), extension->id());
return host->GetViewsBridgeFactoryHost(); return host->GetViewsBridgeFactoryHost();
} }
...@@ -347,7 +348,7 @@ const Extension* ExtensionAppShimHandler::MaybeGetAppForBrowser( ...@@ -347,7 +348,7 @@ const Extension* ExtensionAppShimHandler::MaybeGetAppForBrowser(
} }
void ExtensionAppShimHandler::QuitAppForWindow(AppWindow* app_window) { void ExtensionAppShimHandler::QuitAppForWindow(AppWindow* app_window) {
AppShimHost* host = Host* 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) {
...@@ -363,7 +364,7 @@ void ExtensionAppShimHandler::QuitAppForWindow(AppWindow* app_window) { ...@@ -363,7 +364,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) {
AppShimHost* host = FindHost(Profile::FromBrowserContext(profile), app_id); Host* host = FindHost(Profile::FromBrowserContext(profile), app_id);
if (host) if (host)
OnShimQuit(host); OnShimQuit(host);
else else
...@@ -372,7 +373,7 @@ void ExtensionAppShimHandler::QuitHostedAppForWindow( ...@@ -372,7 +373,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());
AppShimHost* host = FindHost(profile, app_window->extension_id()); Host* host = FindHost(profile, app_window->extension_id());
if (host) if (host)
host->OnAppHide(); host->OnAppHide();
else else
...@@ -381,7 +382,7 @@ void ExtensionAppShimHandler::HideAppForWindow(AppWindow* app_window) { ...@@ -381,7 +382,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) {
AppShimHost* host = FindHost(profile, app_id); Host* host = FindHost(profile, app_id);
if (host) if (host)
host->OnAppHide(); host->OnAppHide();
else else
...@@ -391,7 +392,7 @@ void ExtensionAppShimHandler::HideHostedApp(Profile* profile, ...@@ -391,7 +392,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();
AppShimHost* host = FindHost(profile, app_id); Host* 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 {
...@@ -402,7 +403,7 @@ void ExtensionAppShimHandler::FocusAppForWindow(AppWindow* app_window) { ...@@ -402,7 +403,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());
AppShimHost* host = FindHost(profile, app_window->extension_id()); Host* host = FindHost(profile, app_window->extension_id());
if (host) if (host)
host->OnAppUnhideWithoutActivation(); host->OnAppUnhideWithoutActivation();
} }
...@@ -411,7 +412,7 @@ void ExtensionAppShimHandler::RequestUserAttentionForWindow( ...@@ -411,7 +412,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());
AppShimHost* host = FindHost(profile, app_window->extension_id()); Host* host = FindHost(profile, app_window->extension_id());
if (host) if (host)
host->OnAppRequestUserAttention(attention_type); host->OnAppRequestUserAttention(attention_type);
} }
...@@ -480,7 +481,7 @@ ExtensionAppShimHandler* ExtensionAppShimHandler::Get() { ...@@ -480,7 +481,7 @@ ExtensionAppShimHandler* ExtensionAppShimHandler::Get() {
} }
const Extension* ExtensionAppShimHandler::MaybeGetExtensionOrCloseHost( const Extension* ExtensionAppShimHandler::MaybeGetExtensionOrCloseHost(
AppShimHost* host, Host* 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());
...@@ -514,7 +515,7 @@ void ExtensionAppShimHandler::OnProfileLoaded( ...@@ -514,7 +515,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();
AppShimHost* host = FindOrCreateHost(profile, app_id); Host* 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
...@@ -571,7 +572,7 @@ void ExtensionAppShimHandler::OnExtensionEnabled( ...@@ -571,7 +572,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.
AppShimHost* host = FindHost(profile, app_id); Host* 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;
...@@ -580,7 +581,8 @@ void ExtensionAppShimHandler::OnExtensionEnabled( ...@@ -580,7 +581,8 @@ 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(); ) {
...@@ -591,7 +593,7 @@ void ExtensionAppShimHandler::OnShimClose(AppShimHost* host) { ...@@ -591,7 +593,7 @@ void ExtensionAppShimHandler::OnShimClose(AppShimHost* host) {
} }
void ExtensionAppShimHandler::OnShimFocus( void ExtensionAppShimHandler::OnShimFocus(
AppShimHost* host, Host* host,
AppShimFocusType focus_type, AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) { const std::vector<base::FilePath>& files) {
Profile* profile; Profile* profile;
...@@ -621,7 +623,7 @@ void ExtensionAppShimHandler::OnShimFocus( ...@@ -621,7 +623,7 @@ void ExtensionAppShimHandler::OnShimFocus(
delegate_->LaunchApp(profile, extension, files); delegate_->LaunchApp(profile, extension, files);
} }
void ExtensionAppShimHandler::OnShimSetHidden(AppShimHost* host, bool hidden) { void ExtensionAppShimHandler::OnShimSetHidden(Host* host, bool hidden) {
Profile* profile; Profile* profile;
const Extension* extension = MaybeGetExtensionOrCloseHost(host, &profile); const Extension* extension = MaybeGetExtensionOrCloseHost(host, &profile);
if (!extension) if (!extension)
...@@ -633,7 +635,7 @@ void ExtensionAppShimHandler::OnShimSetHidden(AppShimHost* host, bool hidden) { ...@@ -633,7 +635,7 @@ void ExtensionAppShimHandler::OnShimSetHidden(AppShimHost* host, bool hidden) {
SetAppHidden(profile, host->GetAppId(), hidden); SetAppHidden(profile, host->GetAppId(), hidden);
} }
void ExtensionAppShimHandler::OnShimQuit(AppShimHost* host) { void ExtensionAppShimHandler::OnShimQuit(Host* host) {
DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath())); DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath()));
Profile* profile = delegate_->ProfileForPath(host->GetProfilePath()); Profile* profile = delegate_->ProfileForPath(host->GetProfilePath());
...@@ -688,7 +690,7 @@ void ExtensionAppShimHandler::Observe( ...@@ -688,7 +690,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)) {
AppShimHost* host = current->second; Host* host = current->second;
host->OnAppClosed(); host->OnAppClosed();
} }
} }
...@@ -725,7 +727,7 @@ void ExtensionAppShimHandler::OnAppActivated(content::BrowserContext* context, ...@@ -725,7 +727,7 @@ void ExtensionAppShimHandler::OnAppActivated(content::BrowserContext* context,
return; return;
Profile* profile = static_cast<Profile*>(context); Profile* profile = static_cast<Profile*>(context);
AppShimHost* host = FindHost(profile, app_id); Host* 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.
...@@ -739,7 +741,7 @@ void ExtensionAppShimHandler::OnAppActivated(content::BrowserContext* context, ...@@ -739,7 +741,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) {
AppShimHost* host = FindHost(static_cast<Profile*>(context), app_id); Host* 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 AppShimHost* CreateHost(const std::string& app_id, virtual Host* 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,11 +93,13 @@ class ExtensionAppShimHandler : public AppShimHandler, ...@@ -93,11 +93,13 @@ 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 AppShimHost* FindHost(Profile* profile, const std::string& app_id); virtual AppShimHandler::Host* FindHost(Profile* profile,
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.
AppShimHost* FindOrCreateHost(Profile* profile, const std::string& app_id); AppShimHandler::Host* FindOrCreateHost(Profile* profile,
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).
...@@ -133,12 +135,12 @@ class ExtensionAppShimHandler : public AppShimHandler, ...@@ -133,12 +135,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(AppShimHost* host) override; void OnShimClose(Host* host) override;
void OnShimFocus(AppShimHost* host, void OnShimFocus(Host* host,
AppShimFocusType focus_type, AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) override; const std::vector<base::FilePath>& files) override;
void OnShimSetHidden(AppShimHost* host, bool hidden) override; void OnShimSetHidden(Host* host, bool hidden) override;
void OnShimQuit(AppShimHost* host) override; void OnShimQuit(Host* host) override;
// AppLifetimeMonitor::Observer overrides: // AppLifetimeMonitor::Observer overrides:
void OnAppStart(content::BrowserContext* context, void OnAppStart(content::BrowserContext* context,
...@@ -160,7 +162,8 @@ class ExtensionAppShimHandler : public AppShimHandler, ...@@ -160,7 +162,8 @@ class ExtensionAppShimHandler : public AppShimHandler,
void OnBrowserRemoved(Browser* browser) override; void OnBrowserRemoved(Browser* browser) override;
protected: protected:
typedef std::map<std::pair<Profile*, std::string>, AppShimHost*> HostMap; typedef std::map<std::pair<Profile*, std::string>, AppShimHandler::Host*>
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;
...@@ -175,7 +178,7 @@ class ExtensionAppShimHandler : public AppShimHandler, ...@@ -175,7 +178,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(AppShimHost* host, const extensions::Extension* MaybeGetExtensionOrCloseHost(Host* host,
Profile** profile); Profile** profile);
// Closes all browsers associated with an app. // Closes all browsers associated with an app.
......
...@@ -63,11 +63,12 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate { ...@@ -63,11 +63,12 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate {
MOCK_METHOD0(MaybeTerminate, void()); MOCK_METHOD0(MaybeTerminate, void());
void SetHostForCreate(AppShimHost* host_for_create) { void SetHostForCreate(AppShimHandler::Host* host_for_create) {
host_for_create_ = host_for_create; host_for_create_ = host_for_create;
} }
AppShimHost* CreateHost(const std::string& app_id, AppShimHandler::Host* CreateHost(
const base::FilePath& profile_path) override { const std::string& app_id,
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;
...@@ -92,7 +93,7 @@ class MockDelegate : public ExtensionAppShimHandler::Delegate { ...@@ -92,7 +93,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_;
AppShimHost* host_for_create_ = nullptr; AppShimHandler::Host* host_for_create_ = nullptr;
}; };
class TestingExtensionAppShimHandler : public ExtensionAppShimHandler { class TestingExtensionAppShimHandler : public ExtensionAppShimHandler {
...@@ -103,17 +104,18 @@ class TestingExtensionAppShimHandler : public ExtensionAppShimHandler { ...@@ -103,17 +104,18 @@ class TestingExtensionAppShimHandler : public ExtensionAppShimHandler {
virtual ~TestingExtensionAppShimHandler() {} virtual ~TestingExtensionAppShimHandler() {}
MOCK_METHOD3(OnShimFocus, MOCK_METHOD3(OnShimFocus,
void(AppShimHost* host, void(Host* host,
AppShimFocusType, AppShimFocusType,
const std::vector<base::FilePath>& files)); const std::vector<base::FilePath>& files));
void RealOnShimFocus(AppShimHost* host, void RealOnShimFocus(Host* 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);
} }
AppShimHost* FindHost(Profile* profile, const std::string& app_id) { AppShimHandler::Host* FindHost(Profile* profile,
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, AppShimHost*(Profile*, const std::string&)); MOCK_METHOD2(FindHost, AppShimHandler::Host*(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