#include "components/optimization_guide/core/model_execution/on_device_model_adaptation_loader.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/strcat.h"
#include "base/task/thread_pool.h"
#include "components/optimization_guide/core/model_execution/feature_keys.h"
#include "components/optimization_guide/core/model_execution/model_execution_features.h"
#include "components/optimization_guide/core/model_execution/model_execution_util.h"
#include "components/optimization_guide/core/model_execution/on_device_model_feature_adapter.h"
#include "components/optimization_guide/core/model_execution/on_device_model_service_controller.h"
#include "components/optimization_guide/core/optimization_guide_constants.h"
#include "components/optimization_guide/core/optimization_guide_enums.h"
#include "components/optimization_guide/core/optimization_guide_model_provider.h"
#include "components/optimization_guide/core/optimization_guide_switches.h"
#include "components/optimization_guide/proto/common_types.pb.h"
#include "components/optimization_guide/proto/on_device_base_model_metadata.pb.h"
#include "components/prefs/pref_service.h"
#include "services/on_device_model/public/cpp/model_assets.h"
namespace optimization_guide {
namespace {
void RecordAdaptationModelAvailability(
ModelBasedCapabilityKey feature,
OnDeviceModelAdaptationAvailability availability) { … }
base::expected<std::unique_ptr<OnDeviceModelAdaptationMetadata>,
OnDeviceModelAdaptationAvailability>
CreateAdaptatonMetadataFromModelExecutionConfig(
ModelBasedCapabilityKey feature,
std::unique_ptr<on_device_model::AdaptationAssetPaths> asset_paths,
int64_t version,
std::unique_ptr<proto::OnDeviceModelExecutionConfig> execution_config) { … }
std::unique_ptr<OnDeviceModelAdaptationMetadata>
OnDeviceModelAdaptationMetadataCreated(
ModelBasedCapabilityKey feature,
base::expected<std::unique_ptr<OnDeviceModelAdaptationMetadata>,
OnDeviceModelAdaptationAvailability> metadata) { … }
}
std::unique_ptr<OnDeviceModelAdaptationMetadata>
OnDeviceModelAdaptationMetadata::New(
on_device_model::AdaptationAssetPaths* asset_paths,
int64_t version,
scoped_refptr<OnDeviceModelFeatureAdapter> adapter) { … }
OnDeviceModelAdaptationMetadata::OnDeviceModelAdaptationMetadata(
on_device_model::AdaptationAssetPaths* asset_paths,
int64_t version,
scoped_refptr<OnDeviceModelFeatureAdapter> adapter)
: … { … }
OnDeviceModelAdaptationMetadata::OnDeviceModelAdaptationMetadata(
const OnDeviceModelAdaptationMetadata&) = default;
OnDeviceModelAdaptationMetadata::~OnDeviceModelAdaptationMetadata() = default;
OnDeviceModelAdaptationLoader::OnDeviceModelAdaptationLoader(
ModelBasedCapabilityKey feature,
OptimizationGuideModelProvider* model_provider,
base::WeakPtr<OnDeviceModelComponentStateManager>
on_device_component_state_manager,
PrefService* local_state,
OnLoadFn on_load_fn)
: … { … }
OnDeviceModelAdaptationLoader::~OnDeviceModelAdaptationLoader() { … }
void OnDeviceModelAdaptationLoader::StateChanged(
const OnDeviceModelComponentState* state) { … }
void OnDeviceModelAdaptationLoader::OnModelUpdated(
proto::OptimizationTarget optimization_target,
base::optional_ref<const ModelInfo> model_info) { … }
base::expected<std::unique_ptr<on_device_model::AdaptationAssetPaths>,
OnDeviceModelAdaptationAvailability>
OnDeviceModelAdaptationLoader::ProcessModelUpdate(
base::optional_ref<const optimization_guide::ModelInfo> model_info) { … }
}