blob: 6a6d534462a3f97e8b7dbfd7d145141f9fc80b35 [file] [log] [blame]
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_UKM_APP_SOURCE_URL_RECORDER_H_
#define COMPONENTS_UKM_APP_SOURCE_URL_RECORDER_H_
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_source_id.h"
#include "base/feature_list.h"
#include <string>
class GURL;
namespace apps {
class AppPlatformMetrics;
}
namespace app_list {
class AppLaunchEventLogger;
} // namespace app_list
namespace arc::input_overlay {
class InputOverlayUkm;
} // namespace arc::input_overlay
namespace badging {
class BadgeManager;
} // namespace badging
namespace web_app {
class DesktopWebAppUkmRecorder;
} // namespace web_app
namespace webapk {
class WebApkUkmRecorder;
} // namespace webapk
namespace ukm {
BASE_FEATURE(kUkmAppLogging, "UkmAppLogging", base::FEATURE_ENABLED_BY_DEFAULT);
class AppSourceUrlRecorder {
private:
friend class apps::AppPlatformMetrics;
friend class AppSourceUrlRecorderTest;
friend class app_list::AppLaunchEventLogger;
friend class arc::input_overlay::InputOverlayUkm;
friend class badging::BadgeManager;
friend class web_app::DesktopWebAppUkmRecorder;
friend class webapk::WebApkUkmRecorder;
// Get a UKM SourceId using the URL generated by GetURLForChromeApp.
static SourceId GetSourceIdForChromeApp(const std::string& app_id);
// Returns the URL to be used for UKM for a Chrome app identified by `app_id`.
//
// This URL will be generated with the prefix "app://" for a Chrome app with
// `app_id`, a unique hash string to identify the app. For example,
// "mgndgikekgjfcpckkfioiadnlibdjbkf" is the `app_id` for Chrome browser, and
// the output SourceId is "app://mgndgikekgjfcpckkfioiadnlibdjbkf".
//
// This URL will be used to generate the SourceId for GetSourceIdForChromeApp.
static GURL GetURLForChromeApp(const std::string& app_id);
// Get a UKM SourceId using the URL generated by GetURLForChromeExtension.
static SourceId GetSourceIdForChromeExtension(const std::string& id);
// Returns the URL given an extension |id| to be used for UKM for a Chrome
// extension.
//
// This URL will be generated with the prefix "chrome-extension://" for a
// Chrome extension. For example, for `id`,
// "mhjfbmdgcfjbbpaeojofohoefgiehjai", the output SourceId is
// "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai".
//
//
// This string representation will be used to generate the SourceId
// for GetSourceIdForChromeExtension.
static GURL GetURLForChromeExtension(const std::string& id);
// Get a UKM SourceId using the URL generated by GetURLforArcPackageName.
static SourceId GetSourceIdForArcPackageName(const std::string& package_name);
// Returns the URL given a ARC app `package_name` to be used to identify the
// app for UKM.
//
// This URL will be generated with the prefix "app://" for an Arc app with
// `package_name`. For example, for `package_name`, "com.google.play", the
// output SourceId is "app://com.google.play".
//
// This URL will be used to generate the SourceId for
// GetSourceIdForArcPackageName.
static GURL GetURLForArcPackageName(const std::string& package_name);
// Get a UKM SourceId using the URL generated by GetURLForArc.
static SourceId GetSourceIdForArc(const std::string& package_name);
// Returns the URL given a ARC app hash `package_name` to be used to identify
// the app for UKM.
//
// This URL is generated with the prefix "app://play/" for an Arc app
// with a hash string for `package_name`. For example, for `package_name`,
// "com.google.play", the output SourceId is
// "app://play/pjhgmeephkiehhlkfcoginnkbphkdang".
//
// This URL will be used to generate the SourceId for GetSourceIdForArc.
static GURL GetURLForArc(const std::string& package_name);
// Get a UKM SourceId using URL generated by GetURLForPWA.
static SourceId GetSourceIdForPWA(const GURL& url);
// Returns the URL to be used to identify the PWA app given a `url` to be used
// in UKM.
static GURL GetURLForPWA(const GURL& url);
// Get a UKM SourceId using the URL generated by GetURLForBorealis.
static SourceId GetSourceIdForBorealis(const std::string& app);
// Returns the URL to be used to identify the Borealis app given name `app` in
// UKM.
//
// This URL is generated with the prefix "app://borealis/" for a Borealis app.
// `app` could be a numeric Borealis App ID, or a string identifying a
// special case such as the main client app or an unregistered app.
//
// This URL will be used to generate a SourceId for GetSourceIdForBorealis.
static GURL GetURLForBorealis(const std::string& app);
// Get a UKM SourceId using the URL generated by GetURLForCrostini.
static SourceId GetSourceIdForCrostini(const std::string& desktop_id,
const std::string& app_name);
// Returns the URL for the Crostini app to be used in UKM.
//
// This URL is generated with the prefix "app://" for a Crostini app with an
// XDG desktop id of `desktop_id` and app name of `app_name`.
//
// This URL will be used to generate a SourceId for GetSourceIdForCrostini.
static GURL GetURLForCrostini(const std::string& desktop_id,
const std::string& app_name);
// For internal use only. Generates a SourceId given a `url` generated by one
// of the `GetURLFor{AppType}` functions above.
static SourceId GetSourceIdForUrl(const GURL& url, const AppType);
// Informs UKM service that the source_id is no longer needed nor used by the
// end of the current reporting cycle, and thus can be deleted later.
static void MarkSourceForDeletion(SourceId source_id);
};
} // namespace ukm
#endif // COMPONENTS_UKM_APP_SOURCE_URL_RECORDER_H_