Commit 3d019d5f authored by Jiaquan He's avatar Jiaquan He Committed by Commit Bot

app_list: decouple AppListService from mac.

AppList will be available only with Ash.

Some mac machines still have apps shortcut in the dock, and Apple do not
have an API to remove things from the Dock. This commit hard codes the
shim handler into AppShimHandler so that we can clean up AppListService
classes.

This commit:
- moves InitAppsPageLegacyShimHandler for mac out of AppListService;
- removes references to AppListService from mac.

Bug: 733662
Change-Id: I66bca8851bf2427a5cd16f3046680e304d1ee368
Reviewed-on: https://chromium-review.googlesource.com/963684Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Commit-Queue: Jiaquan He <hejq@google.com>
Cr-Commit-Position: refs/heads/master@{#543863}
parent 7214884d
......@@ -12,6 +12,8 @@ source_set("app_shim") {
"app_shim_host_mac.h",
"app_shim_host_manager_mac.h",
"app_shim_host_manager_mac.mm",
"apps_page_shim_handler.h",
"apps_page_shim_handler.mm",
"extension_app_shim_handler_mac.cc",
"extension_app_shim_handler_mac.h",
"unix_domain_socket_acceptor.cc",
......
......@@ -13,10 +13,11 @@
#include "base/memory/singleton.h"
#include "base/single_thread_task_runner.h"
#include "base/threading/thread_task_runner_handle.h"
#include "chrome/browser/apps/app_shim/apps_page_shim_handler.h"
#include "chrome/browser/apps/app_window_registry_util.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/lifetime/application_lifetime.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/common/mac/app_mode_common.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "content/public/browser/notification_service.h"
......@@ -28,7 +29,7 @@ namespace {
void TerminateIfNoAppWindows() {
bool app_windows_left =
AppWindowRegistryUtil::IsAppWindowVisibleInAnyProfile(0);
if (!app_windows_left && !AppListService::Get()->IsAppListVisible()) {
if (!app_windows_left) {
chrome::AttemptExit();
}
}
......@@ -91,6 +92,7 @@ class AppShimHandlerRegistry : public content::NotificationObserver {
registrar_.Add(
this, chrome::NOTIFICATION_BROWSER_CLOSE_CANCELLED,
content::NotificationService::AllBrowserContextsAndSources());
SetForAppMode(app_mode::kAppListModeId, &apps_page_shim_handler_);
}
~AppShimHandlerRegistry() override {}
......@@ -114,6 +116,7 @@ class AppShimHandlerRegistry : public content::NotificationObserver {
HandlerMap handlers_;
AppShimHandler* default_handler_;
AppsPageShimHandler apps_page_shim_handler_;
content::NotificationRegistrar registrar_;
bool browser_session_running_;
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/app_list/app_list_service_disabled_mac.h"
#ifndef CHROME_BROWSER_APPS_APP_SHIM_APPS_PAGE_SHIM_HANDLER_H_
#define CHROME_BROWSER_APPS_APP_SHIM_APPS_PAGE_SHIM_HANDLER_H_
#include "base/compiler_specific.h"
#import "base/mac/foundation_util.h"
#import "chrome/browser/app_controller_mac.h"
#include "chrome/browser/apps/app_shim/app_shim_handler_mac.h"
#include "chrome/common/mac/app_mode_common.h"
#include <vector>
namespace {
#include "base/macros.h"
#include "chrome/browser/apps/app_shim/app_shim_handler_mac.h"
// Stub handler for the old app_list shim that opens chrome://apps when a copy
// of the App Launcher .app bundle created with Chrome < m52 tries to connect.
class AppsPageShimHandler : public apps::AppShimHandler {
public:
explicit AppsPageShimHandler(void (*action)(Profile*)) : action_(action) {}
AppsPageShimHandler() {}
private:
// AppShimHandler:
void OnShimLaunch(apps::AppShimHandler::Host* host,
apps::AppShimLaunchType launch_type,
const std::vector<base::FilePath>& files) override {
AppController* controller =
base::mac::ObjCCastStrict<AppController>([NSApp delegate]);
action_([controller lastProfile]);
// Always close the shim process immediately.
host->OnAppLaunchComplete(apps::APP_SHIM_LAUNCH_DUPLICATE_HOST);
}
void OnShimClose(apps::AppShimHandler::Host* host) override {}
const std::vector<base::FilePath>& files) override;
void OnShimClose(apps::AppShimHandler::Host* host) override;
void OnShimFocus(apps::AppShimHandler::Host* host,
apps::AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) override {}
void OnShimSetHidden(apps::AppShimHandler::Host* host, bool hidden) override {
}
void OnShimQuit(apps::AppShimHandler::Host* host) override {}
void (*action_)(Profile*);
const std::vector<base::FilePath>& files) override;
void OnShimSetHidden(apps::AppShimHandler::Host* host, bool hidden) override;
void OnShimQuit(apps::AppShimHandler::Host* host) override;
private:
DISALLOW_COPY_AND_ASSIGN(AppsPageShimHandler);
};
} // namespace
void InitAppsPageLegacyShimHandler(void (*action)(Profile*)) {
static AppsPageShimHandler* handler = nullptr;
if (!handler) {
handler = new AppsPageShimHandler(action);
apps::AppShimHandler::RegisterHandler(app_mode::kAppListModeId, handler);
}
}
#endif // CHROME_BROWSER_APPS_APP_SHIM_APPS_PAGE_SHIM_HANDLER_H_
// Copyright 2013 The Chromium Authors. All rights reserved.
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "build/build_config.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/apps/app_shim/apps_page_shim_handler.h"
#if defined(TOOLKIT_VIEWS)
#include "base/command_line.h"
#import "base/mac/foundation_util.h"
#import "chrome/browser/app_controller_mac.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_manager.h"
......@@ -22,58 +19,9 @@
#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "ui/base/page_transition_types.h"
#endif
#if defined(OS_MACOSX)
#include "chrome/browser/ui/app_list/app_list_service_disabled_mac.h"
#endif
namespace {
class AppListServiceDisabled : public AppListService {
public:
static AppListServiceDisabled* GetInstance() {
return base::Singleton<
AppListServiceDisabled,
base::LeakySingletonTraits<AppListServiceDisabled>>::get();
}
private:
friend struct base::DefaultSingletonTraits<AppListServiceDisabled>;
AppListServiceDisabled() {}
// AppListService overrides:
void SetAppListNextPaintCallback(void (*callback)()) override {}
void Init(Profile* initial_profile) override {}
base::FilePath GetProfilePath(const base::FilePath& user_data_dir) override {
return base::FilePath();
}
void SetProfilePath(const base::FilePath& profile_path) override {}
void Show() override {}
void ShowForProfile(Profile* profile) override {}
void ShowForAppInstall(Profile* profile,
const std::string& extension_id,
bool start_discovery_tracking) override {}
void DismissAppList() override {}
Profile* GetCurrentAppListProfile() override { return nullptr; }
bool IsAppListVisible() const override { return false; }
bool GetTargetVisibility() const override { return false; }
void EnableAppList(Profile* initial_profile,
AppListEnableSource enable_source) override {}
AppListControllerDelegate* GetControllerDelegate() override {
return nullptr;
}
void CreateShortcut() override {}
void FlushForTesting() override {}
DISALLOW_COPY_AND_ASSIGN(AppListServiceDisabled);
};
#if defined(TOOLKIT_VIEWS)
bool IsProfileSignedOut(Profile* profile) {
ProfileAttributesEntry* entry;
bool has_entry =
......@@ -101,29 +49,29 @@ void OpenAppsPage(Profile* fallback_profile) {
ui::PAGE_TRANSITION_AUTO_BOOKMARK);
Navigate(&params);
}
#endif
} // namespace
// static
AppListService* AppListService::Get() {
return AppListServiceDisabled::GetInstance();
void AppsPageShimHandler::OnShimLaunch(
apps::AppShimHandler::Host* host,
apps::AppShimLaunchType launch_type,
const std::vector<base::FilePath>& files) {
AppController* controller =
base::mac::ObjCCastStrict<AppController>([NSApp delegate]);
OpenAppsPage([controller lastProfile]);
// Always close the shim process immediately.
host->OnAppLaunchComplete(apps::APP_SHIM_LAUNCH_DUPLICATE_HOST);
}
// static
void AppListService::RegisterPrefs(PrefRegistrySimple* registry) {}
void AppsPageShimHandler::OnShimClose(apps::AppShimHandler::Host* host) {}
// static
bool AppListService::HandleLaunchCommandLine(
const base::CommandLine& command_line,
Profile* launch_profile) {
#if defined(TOOLKIT_VIEWS)
if (!command_line.HasSwitch(switches::kShowAppList))
return false;
void AppsPageShimHandler::OnShimFocus(
apps::AppShimHandler::Host* host,
apps::AppShimFocusType focus_type,
const std::vector<base::FilePath>& files) {}
OpenAppsPage(launch_profile);
return true;
#else
return false;
#endif
}
void AppsPageShimHandler::OnShimSetHidden(apps::AppShimHandler::Host* host,
bool hidden) {}
void AppsPageShimHandler::OnShimQuit(apps::AppShimHandler::Host* host) {}
......@@ -6,6 +6,7 @@
#include <stddef.h>
#include <utility>
#include <vector>
#include "base/bind.h"
#include "base/lazy_instance.h"
......@@ -22,7 +23,6 @@
#include "chrome/browser/extensions/install_tracker.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/app_list/app_list_util.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/pref_names.h"
......@@ -496,9 +496,8 @@ WebstorePrivateEnableAppLauncherFunction::
ExtensionFunction::ResponseAction
WebstorePrivateEnableAppLauncherFunction::Run() {
AppListService* app_list_service = AppListService::Get();
app_list_service->EnableAppList(chrome_details_.GetProfile(),
AppListService::ENABLE_VIA_WEBSTORE_LINK);
// TODO(crbug.com/822900): Check if this API is still in use and whether we
// can remove it.
return RespondNow(NoArguments());
}
......
......@@ -54,7 +54,6 @@
#include "chrome/browser/signin/signin_manager_factory.h"
#include "chrome/browser/task_manager/task_manager_interface.h"
#include "chrome/browser/tracing/chrome_tracing_delegate.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/blocked_content/safe_browsing_triggered_popup_blocker.h"
#include "chrome/browser/ui/browser_ui_prefs.h"
#include "chrome/browser/ui/navigation_correction_tab_observer.h"
......@@ -349,7 +348,6 @@ void RegisterProfilePrefsForMigration(
void RegisterLocalState(PrefRegistrySimple* registry) {
// Please keep this list alphabetized.
AppListService::RegisterPrefs(registry);
browser_shutdown::RegisterPrefs(registry);
BrowserProcessImpl::RegisterPrefs(registry);
ChromeContentBrowserClient::RegisterLocalStatePrefs(registry);
......
......@@ -3609,13 +3609,6 @@ split_static_library("ui") {
]
deps += [ "//mash/common" ]
}
} else {
sources += [
"app_list/app_list_service.h",
"app_list/app_list_service_disabled.cc",
"app_list/app_list_service_disabled_mac.h",
"app_list/app_list_service_disabled_mac.mm",
]
}
if (enable_extensions) {
......
......@@ -36,7 +36,6 @@
#include "chrome/browser/profiles/profile_io_data.h"
#include "chrome/browser/sessions/session_service.h"
#include "chrome/browser/sessions/session_service_factory.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
......@@ -374,9 +373,6 @@ bool StartupBrowserCreatorImpl::Launch(Profile* profile,
DCHECK(profile);
profile_ = profile;
if (AppListService::HandleLaunchCommandLine(command_line_, profile))
return true;
if (command_line_.HasSwitch(switches::kAppId)) {
std::string app_id = command_line_.GetSwitchValueASCII(switches::kAppId);
const Extension* extension = GetPlatformApp(profile, app_id);
......
......@@ -33,7 +33,6 @@
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/local_auth.h"
#include "chrome/browser/signin/signin_util.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_finder.h"
......@@ -167,8 +166,8 @@ void UrlHashHelper::OnBrowserRemoved(Browser* browser) {
void UrlHashHelper::ExecuteUrlHash() {
if (hash_ == profiles::kUserManagerSelectProfileAppLauncher) {
AppListService* app_list_service = AppListService::Get();
app_list_service->ShowForProfile(profile_);
// TODO(crbug/821659): Clean up the desktop UserManager webui.
NOTIMPLEMENTED();
return;
}
......
......@@ -41,7 +41,6 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
#include "chrome/common/channel_info.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
......@@ -287,12 +286,9 @@ void UpdateAndLaunchShim(std::unique_ptr<web_app::ShortcutInfo> shortcut_info) {
void RebuildAppAndLaunch(std::unique_ptr<web_app::ShortcutInfo> shortcut_info) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (shortcut_info->extension_id == app_mode::kAppListModeId) {
AppListService* app_list_service = AppListService::Get();
app_list_service->CreateShortcut();
app_list_service->Show();
// TODO(crbug/821659): Clean up the desktop UserManager webui.
if (shortcut_info->extension_id == app_mode::kAppListModeId)
return;
}
ProfileManager* profile_manager = g_browser_process->profile_manager();
Profile* profile =
......
......@@ -5,11 +5,16 @@
#ifndef CHROME_COMMON_MAC_APP_MODE_COMMON_H_
#define CHROME_COMMON_MAC_APP_MODE_COMMON_H_
#import <Foundation/Foundation.h>
#include <CoreServices/CoreServices.h>
#include "base/files/file_path.h"
#include "base/strings/string16.h"
#ifdef __OBJC__
@class NSString;
#else
class NSString;
#endif
// This file contains constants, interfaces, etc. which are common to the
// browser application and the app mode loader (a.k.a. shim).
......
......@@ -4,6 +4,8 @@
#include "chrome/common/mac/app_mode_common.h"
#import <Foundation/Foundation.h>
#include "base/files/file_util.h"
namespace app_mode {
......
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