#include "components/optimization_guide/core/prediction_model_store.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/task/thread_pool.h"
#include "base/uuid.h"
#include "components/optimization_guide/core/model_store_metadata_entry.h"
#include "components/optimization_guide/core/model_util.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/optimization_guide/core/optimization_guide_prefs.h"
#include "components/prefs/pref_service.h"
namespace optimization_guide {
namespace {
constexpr size_t kBytesPerMegabyte = …;
std::vector<base::FilePath> GetModelFilePaths(
const proto::ModelInfo& model_info,
const base::FilePath& base_model_dir) { … }
proto::OptimizationTarget ParseOptimizationTargetFromString(
const std::string& optimization_target_str) { … }
void RemoveInvalidModelDirs(const base::FilePath& base_store_dir,
std::set<base::FilePath> valid_model_dirs) { … }
void RecordModelStorageMetrics(const base::FilePath& base_store_dir) { … }
}
PredictionModelStore::PredictionModelStore()
: … { … }
PredictionModelStore::~PredictionModelStore() = default;
void PredictionModelStore::Initialize(const base::FilePath& base_store_dir) { … }
bool PredictionModelStore::HasModel(
proto::OptimizationTarget optimization_target,
const proto::ModelCacheKey& model_cache_key) const { … }
bool PredictionModelStore::HasModelWithVersion(
proto::OptimizationTarget optimization_target,
const proto::ModelCacheKey& model_cache_key,
int64_t version) { … }
void PredictionModelStore::LoadModel(
proto::OptimizationTarget optimization_target,
const proto::ModelCacheKey& model_cache_key,
PredictionModelLoadedCallback callback) { … }
std::unique_ptr<proto::PredictionModel>
PredictionModelStore::LoadAndVerifyModelInBackgroundThread(
proto::OptimizationTarget optimization_target,
const base::FilePath& base_model_dir) { … }
void PredictionModelStore::OnModelLoaded(
proto::OptimizationTarget optimization_target,
const proto::ModelCacheKey& model_cache_key,
PredictionModelLoadedCallback callback,
std::unique_ptr<proto::PredictionModel> model) { … }
void PredictionModelStore::UpdateMetadataForExistingModel(
proto::OptimizationTarget optimization_target,
const proto::ModelCacheKey& model_cache_key,
const proto::ModelInfo& model_info) { … }
void PredictionModelStore::UpdateModel(
proto::OptimizationTarget optimization_target,
const proto::ModelCacheKey& model_cache_key,
const proto::ModelInfo& model_info,
const base::FilePath& base_model_dir,
base::OnceClosure callback) { … }
void PredictionModelStore::OnModelUpdateVerified(
proto::OptimizationTarget optimization_target,
const proto::ModelCacheKey& model_cache_key,
base::OnceClosure callback,
bool model_paths_exist) { … }
base::FilePath PredictionModelStore::GetBaseModelDirForModelCacheKey(
proto::OptimizationTarget optimization_target,
const proto::ModelCacheKey& model_cache_key) { … }
void PredictionModelStore::UpdateModelCacheKeyMapping(
proto::OptimizationTarget optimization_target,
const proto::ModelCacheKey& client_model_cache_key,
const proto::ModelCacheKey& server_model_cache_key) { … }
void PredictionModelStore::RemoveModel(
proto::OptimizationTarget optimization_target,
const proto::ModelCacheKey& model_cache_key,
PredictionModelStoreModelRemovalReason model_remove_reason) { … }
void PredictionModelStore::ScheduleModelDirRemoval(
const base::FilePath& base_model_dir) { … }
void PredictionModelStore::PurgeInactiveModels() { … }
void PredictionModelStore::CleanUpOldModelFiles() { … }
void PredictionModelStore::OnFilePathDeleted(const std::string& path_to_delete,
bool success) { … }
base::FilePath PredictionModelStore::GetBaseStoreDirForTesting() const { … }
void PredictionModelStore::ResetForTesting() { … }
}