Commit 31e62c27 authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

Desktop PWAs: Record web app manifest display load when launching

When a desktop PWA is launched in a window, we now record the
display mode that was requested in the manifest.




Bug: 1939127
Change-Id: I98b77e5eebd355add3cb38a97924fbcd457b99fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1939082
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#719853}
parent 9b1ecac8
...@@ -6,11 +6,27 @@ ...@@ -6,11 +6,27 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "chrome/browser/apps/platform_apps/platform_app_launch.h" #include "chrome/browser/apps/platform_apps/platform_app_launch.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/extensions/application_launch.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 "chrome/common/chrome_features.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
namespace apps { 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) ExtensionAppLaunchManager::ExtensionAppLaunchManager(Profile* profile)
: LaunchManager(profile) {} : LaunchManager(profile) {}
...@@ -18,6 +34,8 @@ ExtensionAppLaunchManager::~ExtensionAppLaunchManager() = default; ...@@ -18,6 +34,8 @@ ExtensionAppLaunchManager::~ExtensionAppLaunchManager() = default;
content::WebContents* ExtensionAppLaunchManager::OpenApplication( content::WebContents* ExtensionAppLaunchManager::OpenApplication(
const AppLaunchParams& params) { const AppLaunchParams& params) {
if (params.container == apps::mojom::LaunchContainer::kLaunchContainerWindow)
RecordBookmarkLaunch(profile(), params.app_id);
return ::OpenApplication(profile(), params); return ::OpenApplication(profile(), params);
} }
...@@ -25,6 +43,8 @@ bool ExtensionAppLaunchManager::OpenApplicationWindow( ...@@ -25,6 +43,8 @@ bool ExtensionAppLaunchManager::OpenApplicationWindow(
const std::string& app_id, const std::string& app_id,
const base::CommandLine& command_line, const base::CommandLine& command_line,
const base::FilePath& current_directory) { const base::FilePath& current_directory) {
RecordBookmarkLaunch(profile(), app_id);
return OpenExtensionApplicationWindow(profile(), app_id, command_line, return OpenExtensionApplicationWindow(profile(), app_id, command_line,
current_directory); current_directory);
} }
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/web_applications/app_browser_controller.h" #include "chrome/browser/ui/web_applications/app_browser_controller.h"
#include "chrome/browser/ui/web_applications/web_app_controller_browsertest.h" #include "chrome/browser/ui/web_applications/web_app_controller_browsertest.h"
...@@ -15,6 +16,8 @@ namespace { ...@@ -15,6 +16,8 @@ namespace {
constexpr const char kExampleURL[] = "http://example.org/"; constexpr const char kExampleURL[] = "http://example.org/";
constexpr char kLaunchWebAppDisplayModeHistogram[] = "Launch.WebAppDisplayMode";
} // namespace } // namespace
namespace web_app { namespace web_app {
...@@ -62,6 +65,7 @@ IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, HasMinimalUiButtons) { ...@@ -62,6 +65,7 @@ IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, HasMinimalUiButtons) {
int index = 0; int index = 0;
auto has_buttons = [this, &index](DisplayMode display_mode, auto has_buttons = [this, &index](DisplayMode display_mode,
bool open_as_window) -> bool { bool open_as_window) -> bool {
base::HistogramTester tester;
const std::string base_url = "https://example.com/path"; const std::string base_url = "https://example.com/path";
auto web_app_info = std::make_unique<WebApplicationInfo>(); auto web_app_info = std::make_unique<WebApplicationInfo>();
web_app_info->app_url = GURL(base_url + base::NumberToString(index++)); web_app_info->app_url = GURL(base_url + base::NumberToString(index++));
...@@ -70,6 +74,9 @@ IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, HasMinimalUiButtons) { ...@@ -70,6 +74,9 @@ IN_PROC_BROWSER_TEST_P(WebAppBrowserTest, HasMinimalUiButtons) {
web_app_info->open_as_window = open_as_window; web_app_info->open_as_window = open_as_window;
AppId app_id = InstallWebApp(std::move(web_app_info)); AppId app_id = InstallWebApp(std::move(web_app_info));
Browser* app_browser = LaunchWebAppBrowser(app_id); Browser* app_browser = LaunchWebAppBrowser(app_id);
tester.ExpectUniqueSample(kLaunchWebAppDisplayModeHistogram, display_mode,
1);
return app_browser->app_controller()->HasMinimalUiButtons(); return app_browser->app_controller()->HasMinimalUiButtons();
}; };
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/web_applications/system_web_app_ui_utils.h" #include "chrome/browser/ui/web_applications/system_web_app_ui_utils.h"
#include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h" #include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/components/web_app_install_utils.h" #include "chrome/browser/web_applications/components/web_app_install_utils.h"
#include "chrome/browser/web_applications/components/web_app_tab_helper.h" #include "chrome/browser/web_applications/components/web_app_tab_helper.h"
...@@ -96,6 +97,9 @@ content::WebContents* WebAppLaunchManager::OpenApplication( ...@@ -96,6 +97,9 @@ content::WebContents* WebAppLaunchManager::OpenApplication(
if (!provider_->registrar().IsInstalled(params.app_id)) if (!provider_->registrar().IsInstalled(params.app_id))
return nullptr; return nullptr;
if (params.container == apps::mojom::LaunchContainer::kLaunchContainerWindow)
RecordAppWindowLaunch(profile(), params.app_id);
const GURL url = params.override_url.is_empty() const GURL url = params.override_url.is_empty()
? provider_->registrar().GetAppLaunchURL(params.app_id) ? provider_->registrar().GetAppLaunchURL(params.app_id)
: params.override_url; : params.override_url;
...@@ -187,4 +191,18 @@ void WebAppLaunchManager::OpenWebApplication( ...@@ -187,4 +191,18 @@ void WebAppLaunchManager::OpenWebApplication(
OpenApplication(params); OpenApplication(params);
} }
void RecordAppWindowLaunch(Profile* profile, const std::string& app_id) {
WebAppProvider* provider = WebAppProvider::Get(profile);
if (!provider)
return;
DisplayMode display = provider->registrar().GetAppDisplayMode(app_id);
if (display == DisplayMode::kUndefined)
return;
DCHECK_LT(DisplayMode::kUndefined, display);
DCHECK_LE(display, DisplayMode::kMaxValue);
UMA_HISTOGRAM_ENUMERATION("Launch.WebAppDisplayMode", display);
}
} // namespace web_app } // namespace web_app
...@@ -44,6 +44,8 @@ class WebAppLaunchManager : public apps::LaunchManager { ...@@ -44,6 +44,8 @@ class WebAppLaunchManager : public apps::LaunchManager {
DISALLOW_COPY_AND_ASSIGN(WebAppLaunchManager); DISALLOW_COPY_AND_ASSIGN(WebAppLaunchManager);
}; };
void RecordAppWindowLaunch(Profile* profile, const std::string& app_id);
} // namespace web_app } // namespace web_app
#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_LAUNCH_MANAGER_H_ #endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_WEB_APP_LAUNCH_MANAGER_H_
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