Commit c4c43642 authored by Alice Boxhall's avatar Alice Boxhall Committed by Commit Bot

Revert "Reland "Remove launch service.""

This reverts commit a7c7613c.

Reason for revert: Sorry, this seems to be causing test failures: https://ci.chromium.org/p/chromium/builders/ci/chromeos-kevin-rel/24801

Original change's description:
> Reland "Remove launch service."
> 
> This is a reland of d07c4196
> 
> TBR=ericwilligers@chromium.org
> TBR=dominickn@chromium.org
> 
> Original change's description:
> > Remove launch service.
> >
> > BUG=1061843
> >
> > Change-Id: I12efd2899403cb9cc5e9dafc04300a7156342ed9
> > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2116156
> > Commit-Queue: Nancy Wang <nancylingwang@chromium.org>
> > Reviewed-by: Nancy Wang <nancylingwang@chromium.org>
> > Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
> > Reviewed-by: Eric Willigers <ericwilligers@chromium.org>
> > Reviewed-by: Dominick Ng <dominickn@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#756170}
> 
> Bug: 1061843
> Change-Id: I020be92154b0f5fad0d45f1f5c83f2d8539684d0
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2134036
> Reviewed-by: Xiyuan Xia <xiyuan@chromium.org>
> Reviewed-by: Eric Willigers <ericwilligers@chromium.org>
> Reviewed-by: Nancy Wang <nancylingwang@chromium.org>
> Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#756556}

TBR=xiyuan@chromium.org,ericwilligers@chromium.org,dominickn@chromium.org,nancylingwang@chromium.org

Change-Id: I5d1c9b2e82f3bbca4d482ab0909639ca553c81a2
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 1061843
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2137099Reviewed-by: default avatarAlice Boxhall <aboxhall@chromium.org>
Commit-Queue: Alice Boxhall <aboxhall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#756559}
parent 8f87b0bc
......@@ -3127,6 +3127,14 @@ jumbo_static_library("browser") {
"apps/intent_helper/intent_picker_auto_display_service_factory.h",
"apps/intent_helper/page_transition_util.cc",
"apps/intent_helper/page_transition_util.h",
"apps/launch_service/extension_app_launch_manager.cc",
"apps/launch_service/extension_app_launch_manager.h",
"apps/launch_service/launch_manager.cc",
"apps/launch_service/launch_manager.h",
"apps/launch_service/launch_service.cc",
"apps/launch_service/launch_service.h",
"apps/launch_service/launch_service_factory.cc",
"apps/launch_service/launch_service_factory.h",
"background/background_contents.cc",
"background/background_contents.h",
"background/background_contents_service_observer.h",
......
......@@ -21,6 +21,7 @@
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/app_service/launch_utils.h"
#include "chrome/browser/apps/app_service/menu_util.h"
#include "chrome/browser/apps/launch_service/launch_service.h"
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/arc/arc_web_contents_data.h"
#include "chrome/browser/chromeos/crostini/crostini_util.h"
......
ericwilligers@chromium.org
loyso@chromium.org
The Launch Service provides browser-specific functions for launching
application.
For example, Chrome Apps (platform apps and legacy packaged apps),
and BMO-based Desktop PWAs can be launched using this service.
The intent is to merge LaunchService into the AppService,
specifically AppServiceProxy.
See `//chrome/services/app_service/README.md` for a description of the
App Service.
// Copyright 2019 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/launch_service/extension_app_launch_manager.h"
#include "base/feature_list.h"
#include "chrome/browser/apps/app_service/launch_utils.h"
#include "chrome/browser/apps/platform_apps/platform_app_launch.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.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 {
namespace {
void RecordBookmarkLaunch(Profile* profile, const std::string& app_id) {
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(profile)->GetInstalledExtension(
app_id);
if (extension && extension->from_bookmark())
web_app::RecordAppWindowLaunch(profile, app_id);
}
} // namespace
ExtensionAppLaunchManager::ExtensionAppLaunchManager(Profile* profile)
: LaunchManager(profile) {}
ExtensionAppLaunchManager::~ExtensionAppLaunchManager() = default;
content::WebContents* ExtensionAppLaunchManager::OpenApplication(
const AppLaunchParams& params) {
if (params.container == apps::mojom::LaunchContainer::kLaunchContainerWindow)
RecordBookmarkLaunch(profile(), params.app_id);
return ::OpenApplication(profile(), params);
}
} // namespace apps
// Copyright 2019 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_LAUNCH_SERVICE_EXTENSION_APP_LAUNCH_MANAGER_H_
#define CHROME_BROWSER_APPS_LAUNCH_SERVICE_EXTENSION_APP_LAUNCH_MANAGER_H_
#include "base/macros.h"
#include "chrome/browser/apps/launch_service/launch_manager.h"
#include "chrome/services/app_service/public/mojom/types.mojom.h"
namespace apps {
// Handles launch requests for extension-backed apps,
// including Chrome Apps (platform apps and legacy packaged apps) and hosted
// apps (including desktop PWAs until BMO is ready).
class ExtensionAppLaunchManager final : public LaunchManager {
public:
explicit ExtensionAppLaunchManager(Profile* profile);
~ExtensionAppLaunchManager() override;
// apps::LaunchManager:
content::WebContents* OpenApplication(const AppLaunchParams& params) override;
private:
DISALLOW_COPY_AND_ASSIGN(ExtensionAppLaunchManager);
};
} // namespace apps
#endif // CHROME_BROWSER_APPS_LAUNCH_SERVICE_EXTENSION_APP_LAUNCH_MANAGER_H_
// Copyright 2019 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/launch_service/launch_manager.h"
namespace apps {
LaunchManager::LaunchManager(Profile* profile) : profile_(profile) {}
LaunchManager::~LaunchManager() = default;
} // namespace apps
// Copyright 2019 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_LAUNCH_SERVICE_LAUNCH_MANAGER_H_
#define CHROME_BROWSER_APPS_LAUNCH_SERVICE_LAUNCH_MANAGER_H_
#include <string>
#include "base/macros.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
class Profile;
namespace content {
class WebContents;
}
namespace apps {
struct AppLaunchParams;
// A LaunchManager handles launch requests for a given type of apps.
class LaunchManager {
public:
virtual ~LaunchManager();
// Open the application in a way specified by |params|.
virtual content::WebContents* OpenApplication(
const AppLaunchParams& params) = 0;
protected:
explicit LaunchManager(Profile*);
Profile* profile() { return profile_; }
private:
Profile* const profile_;
DISALLOW_COPY_AND_ASSIGN(LaunchManager);
};
} // namespace apps
#endif // CHROME_BROWSER_APPS_LAUNCH_SERVICE_LAUNCH_MANAGER_H_
// Copyright 2019 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/launch_service/launch_service.h"
#include "base/feature_list.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/launch_service/extension_app_launch_manager.h"
#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/common/chrome_features.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
namespace apps {
// static
LaunchService* LaunchService::Get(Profile* profile) {
return LaunchServiceFactory::GetForProfile(profile);
}
LaunchService::LaunchService(Profile* profile) : profile_(profile) {
DCHECK(profile_);
// LaunchService must have only one instance in original profile,
// apart from guest mode where the off-the-record profile is used.
DCHECK_EQ(profile_->IsGuestSession(), profile_->IsOffTheRecord());
extension_app_launch_manager_ =
std::make_unique<ExtensionAppLaunchManager>(profile);
if (base::FeatureList::IsEnabled(features::kDesktopPWAsWithoutExtensions) ||
base::FeatureList::IsEnabled(features::kDesktopPWAsUnifiedLaunch)) {
web_app_launch_manager_ =
std::make_unique<web_app::WebAppLaunchManager>(profile);
} else {
web_app_launch_manager_ =
std::make_unique<ExtensionAppLaunchManager>(profile);
}
}
LaunchService::~LaunchService() {}
content::WebContents* LaunchService::OpenApplication(
const AppLaunchParams& params) {
return GetLaunchManagerForApp(params.app_id).OpenApplication(params);
}
LaunchManager& LaunchService::GetLaunchManagerForApp(
const std::string& app_id) {
// --app old-style app shortcuts
if (app_id.empty())
return *extension_app_launch_manager_;
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension(
app_id);
return (!extension || extension->from_bookmark())
? *web_app_launch_manager_
: *extension_app_launch_manager_;
}
} // namespace apps
// Copyright 2019 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_LAUNCH_SERVICE_LAUNCH_SERVICE_H_
#define CHROME_BROWSER_APPS_LAUNCH_SERVICE_LAUNCH_SERVICE_H_
#include <memory>
#include <string>
#include "base/macros.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
class Profile;
namespace content {
class WebContents;
}
namespace apps {
class LaunchManager;
struct AppLaunchParams;
// This KeyedService receives app launch requests and forwards them
// to the appropriate LaunchManager, based on the type of app.
//
// It is expected to merge into the App Service (Proxy) when that service
// stabilizes. Launch requests will be forwarded through App publishers to App
// providers, and the LaunchManager classes will be retired. See
// chrome/services/app_service/README.md
class LaunchService : public KeyedService {
public:
static LaunchService* Get(Profile* profile);
explicit LaunchService(Profile* profile);
~LaunchService() override;
// Open the application in a way specified by |params|.
content::WebContents* OpenApplication(const AppLaunchParams& params);
private:
LaunchManager& GetLaunchManagerForApp(const std::string& app_id);
Profile* const profile_;
std::unique_ptr<LaunchManager> extension_app_launch_manager_;
std::unique_ptr<LaunchManager> web_app_launch_manager_;
DISALLOW_COPY_AND_ASSIGN(LaunchService);
};
} // namespace apps
#endif // CHROME_BROWSER_APPS_LAUNCH_SERVICE_LAUNCH_SERVICE_H_
// Copyright 2019 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/launch_service/launch_service_factory.h"
#include "chrome/browser/apps/launch_service/launch_service.h"
#include "chrome/browser/extensions/extension_system_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
namespace apps {
// static
LaunchService* LaunchServiceFactory::GetForProfile(Profile* profile) {
return static_cast<LaunchService*>(
LaunchServiceFactory::GetInstance()->GetServiceForBrowserContext(
profile, true /* create */));
}
// static
LaunchServiceFactory* LaunchServiceFactory::GetInstance() {
return base::Singleton<LaunchServiceFactory>::get();
}
LaunchServiceFactory::LaunchServiceFactory()
: BrowserContextKeyedServiceFactory(
"LaunchService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(extensions::ExtensionSystemFactory::GetInstance());
}
LaunchServiceFactory::~LaunchServiceFactory() = default;
KeyedService* LaunchServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
return new LaunchService(Profile::FromBrowserContext(context));
}
bool LaunchServiceFactory::ServiceIsCreatedWithBrowserContext() const {
return true;
}
content::BrowserContext* LaunchServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
Profile* const profile = Profile::FromBrowserContext(context);
if (profile->IsGuestSession()) {
// In guest mode, only off-the-record browsers may be opened.
return profile->GetOffTheRecordProfile();
}
// Do not create secondary instance for incognito WebContents with
// off-the-record profiles for non-guest sessions. Redirect to the instance
// from the original profile part.
return profile->GetOriginalProfile();
}
} // namespace apps
// Copyright 2019 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_LAUNCH_SERVICE_LAUNCH_SERVICE_FACTORY_H_
#define CHROME_BROWSER_APPS_LAUNCH_SERVICE_LAUNCH_SERVICE_FACTORY_H_
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "components/keyed_service/content/browser_context_keyed_service_factory.h"
namespace content {
class BrowserContext;
}
class Profile;
namespace apps {
class LaunchService;
// A factory which associates LaunchService instance with its profile instance.
class LaunchServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static LaunchService* GetForProfile(Profile* profile);
static LaunchServiceFactory* GetInstance();
private:
friend struct base::DefaultSingletonTraits<LaunchServiceFactory>;
LaunchServiceFactory();
~LaunchServiceFactory() override;
// BrowserContextKeyedServiceFactory
KeyedService* BuildServiceInstanceFor(
content::BrowserContext* context) const override;
bool ServiceIsCreatedWithBrowserContext() const override;
content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const override;
DISALLOW_COPY_AND_ASSIGN(LaunchServiceFactory);
};
} // namespace apps
#endif // CHROME_BROWSER_APPS_LAUNCH_SERVICE_LAUNCH_SERVICE_FACTORY_H_
......@@ -20,6 +20,7 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/app_service/app_service_metrics.h"
#include "chrome/browser/apps/launch_service/launch_service.h"
#include "chrome/browser/chromeos/crostini/crostini_features.h"
#include "chrome/browser/chromeos/drive/file_system_util.h"
#include "chrome/browser/chromeos/extensions/default_web_app_ids.h"
......
......@@ -18,6 +18,7 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/apps/app_service/app_service_metrics.h"
#include "chrome/browser/apps/launch_service/launch_service.h"
#include "chrome/browser/chromeos/plugin_vm/plugin_vm_util.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
......
......@@ -9,6 +9,7 @@
#include "base/strings/utf_string_conversions.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/launch_service/launch_service.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/arc/arc_util.h"
#include "chrome/browser/chromeos/arc/session/arc_session_manager.h"
......
......@@ -4,15 +4,12 @@
#include "chrome/browser/ui/web_applications/web_app_launch_manager.h"
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/metrics/histogram_macros.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/banners/app_banner_settings_helper.h"
#include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h"
......@@ -101,7 +98,7 @@ content::WebContents* NavigateWebApplicationWindow(
}
WebAppLaunchManager::WebAppLaunchManager(Profile* profile)
: profile_(profile), provider_(WebAppProvider::Get(profile)) {}
: apps::LaunchManager(profile), provider_(WebAppProvider::Get(profile)) {}
WebAppLaunchManager::~WebAppLaunchManager() = default;
......@@ -111,7 +108,7 @@ content::WebContents* WebAppLaunchManager::OpenApplication(
return nullptr;
if (params.container == apps::mojom::LaunchContainer::kLaunchContainerWindow)
RecordAppWindowLaunch(profile_, params.app_id);
RecordAppWindowLaunch(profile(), params.app_id);
web_app::FileHandlerManager& file_handler_manager =
provider_->file_handler_manager();
......@@ -125,10 +122,10 @@ content::WebContents* WebAppLaunchManager::OpenApplication(
// System Web Apps go through their own launch path.
base::Optional<SystemAppType> system_app_type =
GetSystemWebAppTypeForAppId(profile_, params.app_id);
GetSystemWebAppTypeForAppId(profile(), params.app_id);
if (system_app_type) {
Browser* browser =
LaunchSystemWebApp(profile_, *system_app_type, url, params);
LaunchSystemWebApp(profile(), *system_app_type, url, params);
return browser->tab_strip_model()->GetActiveWebContents();
}
......@@ -136,19 +133,19 @@ content::WebContents* WebAppLaunchManager::OpenApplication(
WindowOpenDisposition disposition = WindowOpenDisposition::NEW_FOREGROUND_TAB;
if (params.container == apps::mojom::LaunchContainer::kLaunchContainerTab) {
browser = chrome::FindTabbedBrowser(
profile_, /*match_original_profiles=*/false, params.display_id);
profile(), /*match_original_profiles=*/false, params.display_id);
if (browser) {
// For existing browser, ensure its window is activated.
browser->window()->Activate();
disposition = params.disposition;
} else {
browser =
new Browser(Browser::CreateParams(Browser::TYPE_NORMAL, profile_,
new Browser(Browser::CreateParams(Browser::TYPE_NORMAL, profile(),
/*user_gesture=*/true));
}
} else {
browser =
CreateWebApplicationWindow(profile_, params.app_id, params.disposition);
browser = CreateWebApplicationWindow(profile(), params.app_id,
params.disposition);
}
content::WebContents* web_contents;
......@@ -197,8 +194,8 @@ content::WebContents* WebAppLaunchManager::OpenApplication(
// Record the launch time in the site engagement service. A recent web
// app launch will provide an engagement boost to the origin.
SiteEngagementService::Get(profile_)->SetLastShortcutLaunchTime(web_contents,
url);
SiteEngagementService::Get(profile())->SetLastShortcutLaunchTime(web_contents,
url);
// Refresh the app banner added to homescreen event. The user may have
// cleared their browsing data since installing the app, which removes the
......@@ -251,7 +248,7 @@ void WebAppLaunchManager::LaunchWebApplication(
DCHECK(browser);
} else {
// Open an empty browser window as the app_id is invalid.
browser = apps::CreateBrowserWithNewTabPage(profile_);
browser = apps::CreateBrowserWithNewTabPage(profile());
params.container = apps::mojom::LaunchContainer::kLaunchContainerNone;
}
std::move(callback).Run(browser, params.container);
......
......@@ -7,12 +7,11 @@
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/services/app_service/public/mojom/types.mojom.h"
#include "chrome/browser/apps/launch_service/launch_manager.h"
class Browser;
enum class WindowOpenDisposition;
class GURL;
class Profile;
namespace apps {
struct AppLaunchParams;
......@@ -33,13 +32,14 @@ class WebAppProvider;
// Handles launch requests for Desktop PWAs and bookmark apps.
// Web applications have type AppType::kWeb in the app registry.
class WebAppLaunchManager {
class WebAppLaunchManager : public apps::LaunchManager {
public:
explicit WebAppLaunchManager(Profile* profile);
~WebAppLaunchManager();
~WebAppLaunchManager() override;
// apps::LaunchManager:
content::WebContents* OpenApplication(const apps::AppLaunchParams& params);
content::WebContents* OpenApplication(
const apps::AppLaunchParams& params) override;
void LaunchApplication(
const std::string& app_id,
......@@ -56,7 +56,6 @@ class WebAppLaunchManager {
apps::mojom::LaunchContainer container)>
callback);
Profile* const profile_;
WebAppProvider* const provider_;
base::WeakPtrFactory<WebAppLaunchManager> weak_ptr_factory_{this};
......
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