Commit 15b9c735 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Move IsWebAppInstalledForUrl into AppBannerManager

AppBannerManager is the only callsite, and it has platform-specific
implementations. IsWebAppInstalledForUrl has platform-specific
implementations as well. Thus it fits nicely into
AppBannerManager{Desktop,Android}.

The rest of installable_utils is not needed by WebLayer, so this
crosses one more file off the componentization TODO list.

Bug: 1147268
Change-Id: I783942d31c993d67bc57ed08b4f2f2541ce911ad
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2537925
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828599}
parent 81bbd067
......@@ -20,7 +20,6 @@
#include "chrome/browser/banners/app_banner_settings_helper.h"
#include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/installable/installable_metrics.h"
#include "chrome/browser/installable/installable_utils.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/browser/back_forward_cache.h"
......@@ -292,11 +291,6 @@ bool AppBannerManager::IsExternallyInstalledWebApp() {
return false;
}
bool AppBannerManager::IsWebAppConsideredInstalled() {
return IsWebAppInstalledForUrl(web_contents()->GetBrowserContext(),
manifest_.start_url);
}
bool AppBannerManager::ShouldAllowWebAppReplacementInstall() {
return false;
}
......
......@@ -229,8 +229,12 @@ class AppBannerManager : public content::WebContentsObserver,
const blink::Manifest::RelatedApplication& related_app) const = 0;
// Returns whether the current page is already installed as a web app, or
// should be considered as installed.
virtual bool IsWebAppConsideredInstalled();
// should be considered as installed. Returns true if there is an installed
// web app within the BrowserContext of |web_contents()| that contains |url|
// within its scope, and false otherwise. For example, the URL
// https://example.com/a/b/c/d.html is contained within a web app with scope
// https://example.com/a/b/.
virtual bool IsWebAppConsideredInstalled() const = 0;
// Returns whether the installed web app at the current page can be
// overwritten with a new app install for the current page.
......
......@@ -174,15 +174,6 @@ std::string AppBannerManagerAndroid::GetBannerType() {
: "play";
}
bool AppBannerManagerAndroid::IsWebAppConsideredInstalled() {
// Also check if a WebAPK is currently being installed. Installation may take
// some time, so ensure we don't accidentally allow a new installation whilst
// one is in flight for the current site.
return AppBannerManager::IsWebAppConsideredInstalled() ||
WebApkInstallService::Get(web_contents()->GetBrowserContext())
->IsInstallInProgress(manifest_url_);
}
InstallableParams
AppBannerManagerAndroid::ParamsToPerformInstallableWebAppCheck() {
InstallableParams params =
......@@ -556,6 +547,16 @@ bool AppBannerManagerAndroid::IsRelatedNonWebAppInstalled(
return false;
}
bool AppBannerManagerAndroid::IsWebAppConsideredInstalled() const {
// Also check if a WebAPK is currently being installed. Installation may take
// some time, so ensure we don't accidentally allow a new installation whilst
// one is in flight for the current site.
return ShortcutHelper::IsWebApkInstalled(web_contents()->GetBrowserContext(),
manifest_.start_url) ||
WebApkInstallService::Get(web_contents()->GetBrowserContext())
->IsInstallInProgress(manifest_url_);
}
base::WeakPtr<AppBannerManager> AppBannerManagerAndroid::GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
......
......@@ -86,7 +86,6 @@ class AppBannerManagerAndroid
// AppBannerManager overrides.
std::string GetAppIdentifier() override;
std::string GetBannerType() override;
bool IsWebAppConsideredInstalled() override;
void PerformInstallableChecks() override;
InstallableParams ParamsToPerformInstallableWebAppCheck() override;
void PerformInstallableWebAppCheck() override;
......@@ -101,6 +100,7 @@ class AppBannerManagerAndroid
const base::string16& platform) const override;
bool IsRelatedNonWebAppInstalled(
const blink::Manifest::RelatedApplication& related_app) const override;
bool IsWebAppConsideredInstalled() const override;
private:
friend class content::WebContentsUserData<AppBannerManagerAndroid>;
......
......@@ -142,6 +142,8 @@ class AppBannerManagerTest : public AppBannerManager {
"installed-extension-id");
}
bool IsWebAppConsideredInstalled() const override { return false; }
private:
base::OnceClosure on_done_;
......
......@@ -145,6 +145,13 @@ bool AppBannerManagerDesktop::IsRelatedNonWebAppInstalled(
return false;
}
bool AppBannerManagerDesktop::IsWebAppConsideredInstalled() const {
return web_app::FindInstalledAppWithUrlInScope(
Profile::FromBrowserContext(web_contents()->GetBrowserContext()),
manifest_.start_url)
.has_value();
}
web_app::AppRegistrar& AppBannerManagerDesktop::registrar() {
auto* provider = web_app::WebAppProviderBase::GetProviderBase(
Profile::FromBrowserContext(web_contents()->GetBrowserContext()));
......
......@@ -62,6 +62,7 @@ class AppBannerManagerDesktop
const base::string16& platform) const override;
bool IsRelatedNonWebAppInstalled(
const blink::Manifest::RelatedApplication& related_app) const override;
bool IsWebAppConsideredInstalled() const override;
// Called when the web app install initiated by a banner has completed.
virtual void DidFinishCreatingWebApp(const web_app::AppId& app_id,
......
......@@ -12,26 +12,12 @@
#else
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_provider_factory.h"
#include "url/gurl.h"
#include "url/url_constants.h"
#endif
bool IsWebAppInstalledForUrl(content::BrowserContext* browser_context,
const GURL& url) {
#if defined(OS_ANDROID)
// This will still detect the presence of a WebAPK even if Chrome's data is
// cleared
return ShortcutHelper::IsWebApkInstalled(browser_context, url);
#else
return web_app::FindInstalledAppWithUrlInScope(
Profile::FromBrowserContext(browser_context), url)
.has_value();
#endif
}
bool DoesOriginContainAnyInstalledWebApp(
content::BrowserContext* browser_context,
const GURL& origin) {
......
......@@ -13,13 +13,6 @@ class BrowserContext;
class GURL;
// Returns true if there is an installed web app within |browser_context| that
// contains |url| within its scope, and false otherwise. For example, the URL
// https://example.com/a/b/c/d.html is contained within a web app with scope
// https://example.com/a/b/.
bool IsWebAppInstalledForUrl(content::BrowserContext* browser_context,
const GURL& url);
// Returns true if there is any installed web app within |browser_context|
// contained within |origin|. For example, a web app at https://example.com/a/b
// is contained within the origin https://example.com.
......
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