chromium/chrome/browser/extensions/forced_extensions/force_installed_metrics.cc

// Copyright 2020 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/extensions/forced_extensions/force_installed_metrics.h"

#include <set>

#include "base/functional/bind.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/forced_extensions/install_stage_tracker.h"
#include "chrome/browser/profiles/profile.h"
#include "components/prefs/pref_service.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/install/crx_install_error.h"
#include "extensions/browser/install/sandboxed_unpacker_failure_reason.h"
#include "extensions/browser/updater/extension_downloader.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/profiles/profile_helper.h"
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

namespace extensions {

ExtensionStatus;
FailureReason;

namespace {
// Timeout to report UMA if not all force-installed extension were loaded.
constexpr base::TimeDelta kInstallationTimeout =;

#if BUILDFLAG(IS_CHROMEOS_ASH)
// Converts user_manager::UserType to InstallStageTracker::UserType for
// histogram purposes.
ForceInstalledMetrics::UserType ConvertUserType(
    InstallStageTracker::UserInfo user_info) {
  switch (user_info.user_type) {
    case user_manager::UserType::kRegular: {
      if (user_info.is_new_user)
        return ForceInstalledMetrics::UserType::USER_TYPE_REGULAR_NEW;
      return ForceInstalledMetrics::UserType::USER_TYPE_REGULAR_EXISTING;
    }
    case user_manager::UserType::kGuest:
      return ForceInstalledMetrics::UserType::USER_TYPE_GUEST;
    case user_manager::UserType::kPublicAccount:
      return ForceInstalledMetrics::UserType::USER_TYPE_PUBLIC_ACCOUNT;
    case user_manager::UserType::kKioskApp:
      return ForceInstalledMetrics::UserType::USER_TYPE_KIOSK_APP;
    case user_manager::UserType::kChild:
      return ForceInstalledMetrics::UserType::USER_TYPE_CHILD;
    case user_manager::UserType::kWebKioskApp:
      return ForceInstalledMetrics::UserType::USER_TYPE_WEB_KIOSK_APP;
    default:
      NOTREACHED_IN_MIGRATION();
  }
  return ForceInstalledMetrics::UserType::kMaxValue;
}

// Reports type of user in case Force Installed Extensions fail to
// install only if there is a user corresponding to given profile.
void ReportUserType(Profile* profile, bool is_stuck_in_initial_creation_stage) {
  InstallStageTracker::UserInfo user_info =
      InstallStageTracker::GetUserInfo(profile);
  // There can be extensions on the login screen. There is no user on the login
  // screen and thus we would not report in that case.
  if (!user_info.is_user_present)
    return;

  ForceInstalledMetrics::UserType user_type = ConvertUserType(user_info);
  base::UmaHistogramEnumeration("Extensions.ForceInstalledFailureSessionType",
                                user_type);
  if (is_stuck_in_initial_creation_stage) {
    base::UmaHistogramEnumeration(
        "Extensions.ForceInstalledFailureSessionType."
        "ExtensionStuckInInitialCreationStage",
        user_type);
  }
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

// Reports time taken for force installed extension during different
// installation stages.
void ReportInstallationStageTimes(
    const ExtensionId& extension_id,
    const InstallStageTracker::InstallationData& installation) {}

// Reports the network error code, HTTP error code and number of fetch tries
// made when extension fails to install with MANIFEST_FETCH_FAILED.
void ReportManifestFetchFailedErrorCodes(
    const InstallStageTracker::InstallationData& installation,
    bool is_from_store) {}

// Reports the network error code, HTTP error code and number of fetch tries
// made when extension fails to install with CRX_FETCH_FAILED.
void ReportCrxFetchFailedErrorCodes(
    const InstallStageTracker::InstallationData& installation,
    bool is_from_store) {}

// Reports the network error code, HTTP error code and number of fetch tries
// made when extension is stuck in DOWNLOAD_MANIFEST_RETRY downloading stage.
void ReportManifestFetchRetryErrorCodes(
    const InstallStageTracker::InstallationData& installation,
    bool is_from_store) {}

// Reports the network error code, HTTP error code and number of fetch tries
// made when extension is stuck in DOWNLOAD_CRX_RETRY downloading stage.
void ReportCrxFetchRetryErrorCodes(
    const InstallStageTracker::InstallationData& installation,
    bool is_from_store) {}

// Reports installation stage and downloading stage for extensions which are
// currently in progress of the installation.
void ReportCurrentStage(
    const InstallStageTracker::InstallationData& installation) {}

// Reports detailed failure reason for the extensions which failed to install
// after 5 minutes.
void ReportDetailedFailureReasons(
    Profile* profile,
    const InstallStageTracker::InstallationData& installation,
    const bool is_from_store) {}

// Returns false if the extension status corresponds to a missing extension
// which is not yet installed or loaded.
bool IsStatusGood(ExtensionStatus status) {}

}  // namespace

ForceInstalledMetrics::ForceInstalledMetrics(
    ExtensionRegistry* registry,
    Profile* profile,
    ForceInstalledTracker* tracker,
    std::unique_ptr<base::OneShotTimer> timer)
    :{}

ForceInstalledMetrics::~ForceInstalledMetrics() = default;

void ForceInstalledMetrics::ReportDisableReason(
    const ExtensionId& extension_id) {}

void ForceInstalledMetrics::ReportMetricsOnExtensionsReady() {}

void ForceInstalledMetrics::ReportMetrics() {}

void ForceInstalledMetrics::OnForceInstalledExtensionsLoaded() {}

void ForceInstalledMetrics::OnForceInstalledExtensionsReady() {}

void ForceInstalledMetrics::OnExtensionDownloadCacheStatusRetrieved(
    const ExtensionId& id,
    ExtensionDownloaderDelegate::CacheStatus cache_status) {}

}  //  namespace extensions