chromium/chrome/browser/apps/app_service/metrics/app_service_metrics.cc

// Copyright 2019 The Chromium Authors
// 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/metrics/app_service_metrics.h"

#include "ash/webui/mall/app_id.h"
#include "base/metrics/histogram_functions.h"
#include "base/notreached.h"
#include "base/time/time.h"
#include "build/branding_buildflags.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/web_applications/web_app_id_constants.h"
#include "chrome/common/extensions/extension_constants.h"
#include "components/app_constants/constants.h"
#include "components/services/app_service/public/cpp/app_launch_util.h"
#include "extensions/common/constants.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "ash/constants/ash_features.h"
#include "ash/public/cpp/app_list/internal_app_id_constants.h"
#include "ash/user_education/user_education_util.h"
#include "ash/user_education/welcome_tour/welcome_tour_metrics.h"
#include "ash/webui/projector_app/public/cpp/projector_app_constants.h"
#include "chrome/browser/ash/app_list/arc/arc_app_utils.h"
#include "chrome/browser/ash/file_manager/app_id.h"
#include "chrome/browser/ash/plugin_vm/plugin_vm_util.h"
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

namespace {

void RecordDefaultAppLaunch(apps::DefaultAppName default_app_name,
                            apps::LaunchSource launch_source) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
void RecordWelcomeTourInteraction(apps::DefaultAppName default_app_name,
                                  apps::LaunchSource launch_source) {
  // This metric is intended to capture actual user actions after the user
  // completed the Welcome Tour. Do not log automatically launched apps,
  // including apps that were automatically launched by the Welcome Tour.
  if (launch_source == apps::LaunchSource::kFromChromeInternal ||
      launch_source == apps::LaunchSource::kFromWelcomeTour) {
    return;
  }

  PrefService* prefs = ash::user_education_util::GetLastActiveUserPrefService();

  switch (default_app_name) {
    case apps::DefaultAppName::kFiles:
      ash::welcome_tour_metrics::RecordInteraction(
          prefs, ash::welcome_tour_metrics::Interaction::kFilesApp);
      break;
    case apps::DefaultAppName::kHelpApp:
      ash::welcome_tour_metrics::RecordInteraction(
          prefs, ash::welcome_tour_metrics::Interaction::kExploreApp);
      break;
    case apps::DefaultAppName::kSettings:
      ash::welcome_tour_metrics::RecordInteraction(
          prefs, ash::welcome_tour_metrics::Interaction::kSettingsApp);
      break;
    default:
      break;
  }
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace

namespace apps {

std::optional<apps::DefaultAppName> AppIdToName(const std::string& app_id) {}

void RecordAppLaunch(const std::string& app_id,
                     apps::LaunchSource launch_source) {}

const std::optional<apps::DefaultAppName> PreinstalledWebAppIdToName(
    const std::string& app_id) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
const std::optional<apps::DefaultAppName> SystemWebAppIdToName(
    const std::string& app_id) {
  // These apps should all have chrome:// URLs.
  if (app_id == web_app::kCameraAppId) {
    return apps::DefaultAppName::kCamera;
  } else if (app_id == web_app::kDiagnosticsAppId) {
    return apps::DefaultAppName::kDiagnosticsApp;
  } else if (app_id == file_manager::kFileManagerSwaAppId) {
    return apps::DefaultAppName::kFiles;
  } else if (app_id == web_app::kFirmwareUpdateAppId) {
    return apps::DefaultAppName::kFirmwareUpdateApp;
  } else if (app_id == web_app::kHelpAppId) {
    return apps::DefaultAppName::kHelpApp;
  } else if (app_id == ash::kMallSystemAppId) {
    return apps::DefaultAppName::kMall;
  } else if (app_id == web_app::kMediaAppId) {
    return apps::DefaultAppName::kMediaApp;
    // `MockSystemApp` is for tests only.
  } else if (app_id == web_app::kMockSystemAppId) {
    return apps::DefaultAppName::kMockSystemApp;
  } else if (app_id == web_app::kOsFeedbackAppId) {
    return apps::DefaultAppName::kOsFeedbackApp;
  } else if (app_id == web_app::kOsSettingsAppId) {
    return apps::DefaultAppName::kSettings;
  } else if (app_id == web_app::kPrintManagementAppId) {
    return apps::DefaultAppName::kPrintManagementApp;
  } else if (app_id == ash::kChromeUIUntrustedProjectorSwaAppId) {
    return apps::DefaultAppName::kProjector;
  } else if (app_id == web_app::kSanitizeAppId) {
    return apps::DefaultAppName::kSanitizeApp;
  } else if (app_id == web_app::kScanningAppId) {
    return apps::DefaultAppName::kScanningApp;
  } else if (app_id == web_app::kShimlessRMAAppId) {
    return apps::DefaultAppName::kShimlessRMAApp;
  } else if (app_id == web_app::kShortcutCustomizationAppId) {
    return apps::DefaultAppName::kShortcutCustomizationApp;
  } else {
    return std::nullopt;
  }
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace apps