Commit 804e4980 authored by nancy's avatar nancy Committed by Commit Bot

Move LaunchApplication to extensions application launch.

Launch service will be integrated to AppService, and removed, so this CL
is used to migrate ExtensionAppLaunchManager::LaunchApplication to
extensions application_launch.

Based on the design go/integrating-launch-service-to-app-service, add
BrowserAppLauncher class to AppService to handle the launch requests,
and forward to extensions application_launch or WebAppLaunchManager.

LaunchService->LaunchApplication is replaced with AppServiceProxy's
new interface LaunchAppWithCallback.

Follow up:
1. Get command line from the current process in
GetLaunchFilesFromCommandLine:
https://source.chromium.org/chromium/chromium/src/+/master:chrome/browser/apps/app_service/launch_utils.cc;l=87
Remove command_line from interfaces parameters, and remove
command_line from AppLaunchParams:
https://source.chromium.org/chromium/chromium/src/+/master:chrome/browser/apps/app_service/app_launch_params.h;l=57

2. Move ExtensionAppLaunchManager's OpenApplication function to
AppService BrowserAppLauncher and remove ExtensionAppLaunchManager.

3. Modify web_app::WebAppLaunchManager to remove the dependency on
LaunchManager.

4. Remove LaunchManager.

Note: We can't name AppService's BrowserAppLauncher to LaunchService
based on design now, because launch_service/launch_service hasn't been
removed yet, and they are both in apps namespace, so rename it to
BrowserAppLauncher.

BUG=1061843

Change-Id: If5a36a9fe6b8ea265ed198d52fdddab477fe58a5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2119344Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#753830}
parent 767c700c
......@@ -3106,6 +3106,8 @@ jumbo_static_library("browser") {
"apps/app_service/app_service_proxy.h",
"apps/app_service/app_service_proxy_factory.cc",
"apps/app_service/app_service_proxy_factory.h",
"apps/app_service/browser_app_launcher.cc",
"apps/app_service/browser_app_launcher.h",
"apps/app_service/dip_px_util.cc",
"apps/app_service/dip_px_util.h",
"apps/app_service/launch_utils.cc",
......
......@@ -119,6 +119,8 @@ void AppServiceProxy::Initialize() {
return;
}
browser_app_launcher_ = std::make_unique<apps::BrowserAppLauncher>(profile_);
app_service_impl_ =
std::make_unique<apps::AppServiceImpl>(profile_->GetPrefs());
app_service_impl_->BindReceiver(app_service_.BindNewPipeAndPassReceiver());
......@@ -174,6 +176,10 @@ apps::InstanceRegistry& AppServiceProxy::InstanceRegistry() {
}
#endif
BrowserAppLauncher& AppServiceProxy::BrowserAppLauncher() {
return *browser_app_launcher_;
}
apps::PreferredApps& AppServiceProxy::PreferredApps() {
return preferred_apps_;
}
......
......@@ -13,6 +13,7 @@
#include "base/containers/unique_ptr_adapters.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/apps/app_service/browser_app_launcher.h"
#include "chrome/services/app_service/public/cpp/app_registry_cache.h"
#include "chrome/services/app_service/public/cpp/icon_cache.h"
#include "chrome/services/app_service/public/cpp/icon_coalescer.h"
......@@ -73,12 +74,15 @@ class AppServiceProxy : public KeyedService,
mojo::Remote<apps::mojom::AppService>& AppService();
apps::AppRegistryCache& AppRegistryCache();
apps::PreferredApps& PreferredApps();
#if defined(OS_CHROMEOS)
apps::InstanceRegistry& InstanceRegistry();
#endif
BrowserAppLauncher& BrowserAppLauncher();
apps::PreferredApps& PreferredApps();
// apps::IconLoader overrides.
apps::mojom::IconKeyPtr GetIconKey(const std::string& app_id) override;
std::unique_ptr<IconLoader::Releaser> LoadIconFromIconKey(
......@@ -364,6 +368,11 @@ class AppServiceProxy : public KeyedService,
Profile* profile_;
// TODO(crbug.com/1061843): Remove BrowserAppLauncher and merge the interfaces
// to AppServiceProxy when publishers(ExtensionApps and WebApps) can run on
// Chrome.
std::unique_ptr<apps::BrowserAppLauncher> browser_app_launcher_;
using UninstallDialogs = std::set<std::unique_ptr<apps::UninstallDialog>,
base::UniquePtrComparator>;
UninstallDialogs uninstall_dialogs_;
......
// Copyright 2020 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/apps/app_service/browser_app_launcher.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/files/file_path.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/web_applications/web_app_launch_manager.h"
#include "chrome/common/chrome_features.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
namespace apps {
BrowserAppLauncher::BrowserAppLauncher(Profile* profile) : profile_(profile) {
if (base::FeatureList::IsEnabled(features::kDesktopPWAsWithoutExtensions) ||
base::FeatureList::IsEnabled(features::kDesktopPWAsUnifiedLaunch)) {
web_app_launch_manager_ =
std::make_unique<web_app::WebAppLaunchManager>(profile);
}
}
BrowserAppLauncher::~BrowserAppLauncher() = default;
void BrowserAppLauncher::LaunchAppWithCallback(
const std::string& app_id,
const base::FilePath& current_directory,
base::OnceCallback<void(Browser* browser,
apps::mojom::LaunchContainer container)> callback) {
// TODO(crbug.com/1061843): Remove command_line from AppLaunchParams, and get
// command line from the current process in GetLaunchFilesFromCommandLine
auto& command_line = *base::CommandLine::ForCurrentProcess();
// old-style app shortcuts
if (app_id.empty()) {
::LaunchAppWithCallback(profile_, app_id, command_line, current_directory,
std::move(callback));
return;
}
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension(
app_id);
if ((!extension || extension->from_bookmark()) && web_app_launch_manager_) {
web_app_launch_manager_->LaunchApplication(
app_id, command_line, current_directory, std::move(callback));
return;
}
::LaunchAppWithCallback(profile_, app_id, command_line, current_directory,
std::move(callback));
}
} // namespace apps
// Copyright 2020 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.
#ifndef CHROME_BROWSER_APPS_APP_SERVICE_BROWSER_APP_LAUNCHER_H_
#define CHROME_BROWSER_APPS_APP_SERVICE_BROWSER_APP_LAUNCHER_H_
#include <memory>
#include <string>
#include "base/callback.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
class Browser;
class Profile;
namespace base {
class FilePath;
} // namespace base
namespace web_app {
class WebAppLaunchManager;
} // namespace web_app
namespace apps {
// BrowserAppLauncher receives app launch requests and forwards them to
// extensions or WebAppLaunchManager, based on the app type.
//
// TODO(crbug.com/1061843): Remove BrowserAppLauncher and merge the interfaces
// to AppServiceProxy when publishers(ExtensionApps and WebApps) can run on
// Chrome.
class BrowserAppLauncher {
public:
explicit BrowserAppLauncher(Profile* profile);
~BrowserAppLauncher();
BrowserAppLauncher(const BrowserAppLauncher&) = delete;
BrowserAppLauncher& operator=(const BrowserAppLauncher&) = delete;
// Attempt to open |app_id| in a new window or tab. Open an empty browser
// window if unsuccessful. The user's preferred launch container for the app
// (standalone window or browser tab) is used. |callback| will be called with
// the container type used to open the app, kLaunchContainerNone if an empty
// browser window was opened.
void LaunchAppWithCallback(
const std::string& app_id,
const base::FilePath& current_directory,
base::OnceCallback<void(Browser* browser,
apps::mojom::LaunchContainer container)>
callback);
private:
Profile* const profile_;
std::unique_ptr<web_app::WebAppLaunchManager> web_app_launch_manager_;
};
} // namespace apps
#endif // CHROME_BROWSER_APPS_APP_SERVICE_BROWSER_APP_LAUNCHER_H_
......@@ -43,26 +43,4 @@ content::WebContents* ExtensionAppLaunchManager::OpenApplication(
return ::OpenApplication(profile(), params);
}
void ExtensionAppLaunchManager::LaunchApplication(
const std::string& app_id,
const base::CommandLine& command_line,
const base::FilePath& current_directory,
base::OnceCallback<void(Browser* browser,
apps::mojom::LaunchContainer container)> callback) {
apps::mojom::LaunchContainer container;
if (OpenExtensionApplicationWindow(profile(), app_id, command_line,
current_directory)) {
RecordBookmarkLaunch(profile(), app_id);
container = apps::mojom::LaunchContainer::kLaunchContainerWindow;
} else if (OpenExtensionApplicationTab(profile(), app_id)) {
container = apps::mojom::LaunchContainer::kLaunchContainerTab;
} else {
// Open an empty browser window as the app_id is invalid.
CreateBrowserWithNewTabPage(profile());
container = apps::mojom::LaunchContainer::kLaunchContainerNone;
}
std::move(callback).Run(BrowserList::GetInstance()->GetLastActive(),
container);
}
} // namespace apps
......@@ -22,14 +22,6 @@ class ExtensionAppLaunchManager final : public LaunchManager {
// apps::LaunchManager:
content::WebContents* OpenApplication(const AppLaunchParams& params) override;
void LaunchApplication(
const std::string& app_id,
const base::CommandLine& command_line,
const base::FilePath& current_directory,
base::OnceCallback<void(Browser* browser,
apps::mojom::LaunchContainer container)> callback)
override;
private:
DISALLOW_COPY_AND_ASSIGN(ExtensionAppLaunchManager);
};
......
......@@ -6,20 +6,12 @@
#define CHROME_BROWSER_APPS_LAUNCH_SERVICE_LAUNCH_MANAGER_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/macros.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
class Browser;
class Profile;
namespace base {
class CommandLine;
class FilePath;
} // namespace base
namespace content {
class WebContents;
}
......@@ -37,19 +29,6 @@ class LaunchManager {
virtual content::WebContents* OpenApplication(
const AppLaunchParams& params) = 0;
// Attempt to open |app_id| in a new window or tab. Open an empty browser
// window if unsuccessful. The user's preferred launch container for the app
// (standalone window or browser tab) is used. |callback| will be called with
// the container type used to open the app, kLaunchContainerNone if an empty
// browser window was opened.
virtual void LaunchApplication(
const std::string& app_id,
const base::CommandLine& command_line,
const base::FilePath& current_directory,
base::OnceCallback<void(Browser* browser,
apps::mojom::LaunchContainer container)>
callback) = 0;
protected:
explicit LaunchManager(Profile*);
Profile* profile() { return profile_; }
......
......@@ -10,7 +10,6 @@
#include "chrome/browser/apps/launch_service/launch_service_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/web_applications/web_app_launch_manager.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/chrome_features.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
......@@ -48,16 +47,6 @@ content::WebContents* LaunchService::OpenApplication(
return GetLaunchManagerForApp(params.app_id).OpenApplication(params);
}
void LaunchService::LaunchApplication(
const std::string& app_id,
const base::CommandLine& command_line,
const base::FilePath& current_directory,
base::OnceCallback<void(Browser* browser,
apps::mojom::LaunchContainer container)> callback) {
GetLaunchManagerForApp(app_id).LaunchApplication(
app_id, command_line, current_directory, std::move(callback));
}
LaunchManager& LaunchService::GetLaunchManagerForApp(
const std::string& app_id) {
// --app old-style app shortcuts
......
......@@ -8,19 +8,12 @@
#include <memory>
#include <string>
#include "base/callback.h"
#include "base/macros.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
class Browser;
class Profile;
namespace base {
class CommandLine;
class FilePath;
} // namespace base
namespace content {
class WebContents;
}
......@@ -47,19 +40,6 @@ class LaunchService : public KeyedService {
// Open the application in a way specified by |params|.
content::WebContents* OpenApplication(const AppLaunchParams& params);
// Attempt to open |app_id| in a new window or tab. Open an empty browser
// window if unsuccessful. The user's preferred launch container for the app
// (standalone window or browser tab) is used. |callback| will be called with
// the container type used to open the app, kLaunchContainerNone if an empty
// browser window was opened.
void LaunchApplication(
const std::string& app_id,
const base::CommandLine& command_line,
const base::FilePath& current_directory,
base::OnceCallback<void(Browser* browser,
apps::mojom::LaunchContainer container)>
callback);
private:
LaunchManager& GetLaunchManagerForApp(const std::string& app_id);
......
......@@ -6,15 +6,20 @@
#include <memory>
#include <string>
#include <utility>
#include "apps/launcher.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/metrics/histogram_macros.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/app_mode/app_mode_utils.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/app_service/launch_utils.h"
#include "chrome/browser/apps/platform_apps/platform_app_launch.h"
#include "chrome/browser/banners/app_banner_settings_helper.h"
#include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/extensions/extension_service.h"
......@@ -25,12 +30,14 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/extension_enable_flow.h"
#include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
#include "chrome/browser/ui/web_applications/system_web_app_ui_utils.h"
#include "chrome/browser/ui/web_applications/web_app_launch_manager.h"
#include "chrome/browser/ui/web_applications/web_app_launch_utils.h"
#include "chrome/browser/web_applications/components/file_handler_manager.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h"
......@@ -515,3 +522,32 @@ bool CanLaunchViaEvent(const extensions::Extension* extension) {
extensions::FeatureProvider::GetAPIFeature("app.runtime");
return feature && feature->IsAvailableToExtension(extension).is_available();
}
void LaunchAppWithCallback(
Profile* profile,
const std::string& app_id,
const base::CommandLine& command_line,
const base::FilePath& current_directory,
base::OnceCallback<void(Browser* browser,
apps::mojom::LaunchContainer container)> callback) {
apps::mojom::LaunchContainer container;
if (apps::OpenExtensionApplicationWindow(profile, app_id, command_line,
current_directory)) {
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(profile)->GetInstalledExtension(
app_id);
// TODO(crbug.com/1061843): Remove this when BMO launches.
if (extension && extension->from_bookmark())
web_app::RecordAppWindowLaunch(profile, app_id);
container = apps::mojom::LaunchContainer::kLaunchContainerWindow;
} else if (apps::OpenExtensionApplicationTab(profile, app_id)) {
container = apps::mojom::LaunchContainer::kLaunchContainerTab;
} else {
// Open an empty browser window as the app_id is invalid.
apps::CreateBrowserWithNewTabPage(profile);
container = apps::mojom::LaunchContainer::kLaunchContainerNone;
}
std::move(callback).Run(BrowserList::GetInstance()->GetLastActive(),
container);
}
......@@ -11,6 +11,11 @@
class Browser;
class Profile;
namespace base {
class CommandLine;
class FilePath;
} // namespace base
namespace content {
class WebContents;
}
......@@ -59,4 +64,17 @@ content::WebContents* OpenAppShortcutWindow(Profile* profile,
// chrome.app.runtime.onLaunched event.
bool CanLaunchViaEvent(const extensions::Extension* extension);
// Attempt to open |app_id| in a new window or tab. Open an empty browser
// window if unsuccessful. The user's preferred launch container for the app
// (standalone window or browser tab) is used. |callback| will be called with
// the container type used to open the app, kLaunchContainerNone if an empty
// browser window was opened.
void LaunchAppWithCallback(
Profile* profile,
const std::string& app_id,
const base::CommandLine& command_line,
const base::FilePath& current_directory,
base::OnceCallback<void(Browser* browser,
apps::mojom::LaunchContainer container)> callback);
#endif // CHROME_BROWSER_UI_EXTENSIONS_APPLICATION_LAUNCH_H_
......@@ -25,8 +25,9 @@
#include "base/version.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/apps_launch.h"
#include "chrome/browser/apps/launch_service/launch_service.h"
#include "chrome/browser/apps/platform_apps/install_chrome_app.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
......@@ -580,8 +581,10 @@ bool StartupBrowserCreatorImpl::MaybeLaunchApplication(Profile* profile) {
if (!app_id.empty()) {
// Opens an empty browser window if the app_id is invalid.
apps::LaunchService::Get(profile)->LaunchApplication(
app_id, command_line_, cur_dir_, base::BindOnce(&FinalizeWebAppLaunch));
apps::AppServiceProxyFactory::GetForProfile(profile)
->BrowserAppLauncher()
.LaunchAppWithCallback(app_id, cur_dir_,
base::BindOnce(&FinalizeWebAppLaunch));
return true;
}
......
......@@ -17,6 +17,11 @@ namespace apps {
struct AppLaunchParams;
} // namespace apps
namespace base {
class CommandLine;
class FilePath;
} // namespace base
namespace content {
class WebContents;
} // namespace content
......@@ -41,8 +46,8 @@ class WebAppLaunchManager : public apps::LaunchManager {
const base::CommandLine& command_line,
const base::FilePath& current_directory,
base::OnceCallback<void(Browser* browser,
apps::mojom::LaunchContainer container)> callback)
override;
apps::mojom::LaunchContainer container)>
callback);
private:
void LaunchWebApplication(
......
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