#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/metrics/file_metrics_provider.h"
#include <stddef.h>
#include <memory>
#include <string_view>
#include <vector>
#include "base/command_line.h"
#include "base/containers/flat_map.h"
#include "base/debug/crash_logging.h"
#include "base/feature_list.h"
#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/metrics/histogram_base.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/persistent_histogram_allocator.h"
#include "base/metrics/persistent_memory_allocator.h"
#include "base/metrics/ranges_manager.h"
#include "base/strings/stringprintf.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/time/time.h"
#include "components/metrics/metrics_features.h"
#include "components/metrics/metrics_log.h"
#include "components/metrics/metrics_pref_names.h"
#include "components/metrics/metrics_service.h"
#include "components/metrics/persistent_histograms.h"
#include "components/metrics/persistent_system_profile.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
namespace metrics {
namespace {
struct SourceOptions { … };
constexpr int STD_OPEN = …;
constexpr SourceOptions kSourceOptions[] = …;
void DeleteFileWhenPossible(const base::FilePath& path) { … }
}
struct FileMetricsProvider::SourceInfo { … };
FileMetricsProvider::Params::Params(const base::FilePath& path,
SourceType type,
SourceAssociation association,
std::string_view prefs_key)
: … { … }
FileMetricsProvider::Params::~Params() = default;
FileMetricsProvider::FileMetricsProvider(PrefService* local_state)
: … { … }
FileMetricsProvider::~FileMetricsProvider() = default;
void FileMetricsProvider::RegisterSource(const Params& params,
bool metrics_reporting_enabled) { … }
void FileMetricsProvider::RegisterSourcePrefs(
PrefRegistrySimple* prefs,
const std::string_view prefs_key) { … }
void FileMetricsProvider::RegisterPrefs(PrefRegistrySimple* prefs) { … }
void FileMetricsProvider::RecordAccessResult(AccessResult result) { … }
bool FileMetricsProvider::LocateNextFileInDirectory(SourceInfo* source) { … }
void FileMetricsProvider::FinishedWithSource(SourceInfo* source,
AccessResult result) { … }
std::vector<size_t> FileMetricsProvider::CheckAndMergeMetricSourcesOnTaskRunner(
SourceInfoList* sources) { … }
FileMetricsProvider::AccessResult FileMetricsProvider::CheckAndMapMetricSource(
SourceInfo* source) { … }
size_t FileMetricsProvider::MergeHistogramDeltasFromSource(SourceInfo* source) { … }
void FileMetricsProvider::RecordHistogramSnapshotsFromSource(
base::HistogramSnapshotManager* snapshot_manager,
SourceInfo* source,
base::HistogramBase::Flags required_flags) { … }
FileMetricsProvider::AccessResult FileMetricsProvider::HandleFilterSource(
SourceInfo* source,
const base::FilePath& path) { … }
bool FileMetricsProvider::ProvideIndependentMetricsOnTaskRunner(
SourceInfo* source,
ChromeUserMetricsExtension* uma_proto,
base::HistogramSnapshotManager* snapshot_manager,
base::OnceClosure serialize_log_callback) { … }
void FileMetricsProvider::AppendToSamplesCountPref(
std::vector<size_t> samples_counts) { … }
size_t FileMetricsProvider::CollectFileMetadataFromSource(SourceInfo* source) { … }
void FileMetricsProvider::ScheduleSourcesCheck() { … }
void FileMetricsProvider::RecordSourcesChecked(
SourceInfoList* checked,
std::vector<size_t> samples_counts) { … }
void FileMetricsProvider::DeleteFileAsync(const base::FilePath& path) { … }
void FileMetricsProvider::RecordSourceAsRead(SourceInfo* source) { … }
void FileMetricsProvider::OnDidCreateMetricsLog() { … }
bool FileMetricsProvider::HasIndependentMetrics() { … }
void FileMetricsProvider::ProvideIndependentMetrics(
base::OnceClosure serialize_log_callback,
base::OnceCallback<void(bool)> done_callback,
ChromeUserMetricsExtension* uma_proto,
base::HistogramSnapshotManager* snapshot_manager) { … }
void FileMetricsProvider::ProvideIndependentMetricsCleanup(
base::OnceCallback<void(bool)> done_callback,
std::unique_ptr<SourceInfo> source,
bool success) { … }
bool FileMetricsProvider::HasPreviousSessionData() { … }
void FileMetricsProvider::RecordInitialHistogramSnapshots(
base::HistogramSnapshotManager* snapshot_manager) { … }
void FileMetricsProvider::MergeHistogramDeltas(
bool async,
base::OnceClosure done_callback) { … }
bool FileMetricsProvider::SimulateIndependentMetrics() { … }
}