#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
namespace extensions {
ExtensionStatus;
FailureReason;
namespace {
constexpr base::TimeDelta kInstallationTimeout = …;
#if BUILDFLAG(IS_CHROMEOS_ASH)
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;
}
void ReportUserType(Profile* profile, bool is_stuck_in_initial_creation_stage) {
InstallStageTracker::UserInfo user_info =
InstallStageTracker::GetUserInfo(profile);
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
void ReportInstallationStageTimes(
const ExtensionId& extension_id,
const InstallStageTracker::InstallationData& installation) { … }
void ReportManifestFetchFailedErrorCodes(
const InstallStageTracker::InstallationData& installation,
bool is_from_store) { … }
void ReportCrxFetchFailedErrorCodes(
const InstallStageTracker::InstallationData& installation,
bool is_from_store) { … }
void ReportManifestFetchRetryErrorCodes(
const InstallStageTracker::InstallationData& installation,
bool is_from_store) { … }
void ReportCrxFetchRetryErrorCodes(
const InstallStageTracker::InstallationData& installation,
bool is_from_store) { … }
void ReportCurrentStage(
const InstallStageTracker::InstallationData& installation) { … }
void ReportDetailedFailureReasons(
Profile* profile,
const InstallStageTracker::InstallationData& installation,
const bool is_from_store) { … }
bool IsStatusGood(ExtensionStatus status) { … }
}
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) { … }
}