#include "chrome/browser/metrics/extensions_metrics_provider.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <optional>
#include <set>
#include <vector>
#include "base/hash/legacy_hash.h"
#include "base/logging.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/chrome_content_browser_client_extensions_part.h"
#include "chrome/browser/extensions/extension_management.h"
#include "chrome/browser/extensions/install_verifier.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "components/metrics/metrics_log.h"
#include "components/metrics/metrics_state_manager.h"
#include "extensions/browser/blocklist_extension_prefs.h"
#include "extensions/browser/disable_reason.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_set.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_constants.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "third_party/metrics_proto/system_profile.pb.h"
Extension;
Manifest;
ManifestLocation;
ExtensionInstallProto;
namespace {
const size_t kExtensionListClientKeys = …;
const size_t kExtensionListBuckets = …;
enum ExtensionState { … };
metrics::SystemProfileProto::ExtensionsState ExtensionStateAsProto(
ExtensionState value) { … }
ExtensionState IsOffStoreExtension(const extensions::Extension& extension,
const extensions::InstallVerifier& verifier,
content::BrowserContext* context) { … }
ExtensionState CheckForOffStore(const extensions::ExtensionSet& extensions,
const extensions::InstallVerifier& verifier,
content::BrowserContext* context) { … }
ExtensionInstallProto::Type GetType(Manifest::Type type) { … }
ExtensionInstallProto::InstallLocation GetInstallLocation(
ManifestLocation location) { … }
ExtensionInstallProto::ActionType GetActionType(const Manifest& manifest) { … }
ExtensionInstallProto::BackgroundScriptType GetBackgroundScriptType(
const Extension& extension) { … }
static_assert …;
std::vector<ExtensionInstallProto::DisableReason> GetDisableReasons(
const extensions::ExtensionId& id,
extensions::ExtensionPrefs* prefs) { … }
ExtensionInstallProto::BlacklistState GetBlacklistState(
const extensions::ExtensionId& id,
extensions::ExtensionPrefs* prefs) { … }
metrics::ExtensionInstallProto ConstructInstallProto(
const extensions::Extension& extension,
extensions::ExtensionPrefs* prefs,
base::Time last_sample_time,
extensions::ExtensionManagement* extension_management) { … }
std::vector<metrics::ExtensionInstallProto> GetInstallsForProfile(
Profile* profile,
base::Time last_sample_time) { … }
}
ExtensionsMetricsProvider::ExtensionsMetricsProvider(
metrics::MetricsStateManager* metrics_state_manager)
: … { … }
ExtensionsMetricsProvider::~ExtensionsMetricsProvider() = default;
int ExtensionsMetricsProvider::HashExtension(const std::string& extension_id,
uint32_t client_key) { … }
std::optional<extensions::ExtensionSet>
ExtensionsMetricsProvider::GetInstalledExtensions(Profile* profile) { … }
uint64_t ExtensionsMetricsProvider::GetClientID() const { … }
void ExtensionsMetricsProvider::ProvideSystemProfileMetrics(
metrics::SystemProfileProto* system_profile) { … }
metrics::ExtensionInstallProto
ExtensionsMetricsProvider::ConstructInstallProtoForTesting(
const extensions::Extension& extension,
extensions::ExtensionPrefs* prefs,
base::Time last_sample_time,
Profile* profile) { … }
std::vector<metrics::ExtensionInstallProto>
ExtensionsMetricsProvider::GetInstallsForProfileForTesting(
Profile* profile,
base::Time last_sample_time) { … }
void ExtensionsMetricsProvider::ProvideOffStoreMetric(
metrics::SystemProfileProto* system_profile) { … }
void ExtensionsMetricsProvider::ProvideOccupiedBucketMetric(
metrics::SystemProfileProto* system_profile) { … }
void ExtensionsMetricsProvider::ProvideExtensionInstallsMetrics(
metrics::SystemProfileProto* system_profile) { … }