#include "components/segmentation_platform/internal/execution/processing/custom_input_processor.h"
#include <string_view>
#include "base/rand_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/system/sys_info.h"
#include "base/task/sequenced_task_runner.h"
#include "components/segmentation_platform/internal/database/ukm_types.h"
#include "components/segmentation_platform/internal/execution/processing/feature_processor_state.h"
#include "components/segmentation_platform/internal/execution/processing/processing_utils.h"
#include "components/segmentation_platform/internal/metadata/metadata_utils.h"
#include "components/segmentation_platform/public/input_delegate.h"
#include "components/segmentation_platform/public/proto/model_metadata.pb.h"
#if BUILDFLAG(IS_ANDROID)
#include "components/segmentation_platform/internal/android/execution/processing/custom_device_utils.h"
#endif
namespace segmentation_platform::processing {
namespace {
std::optional<int> GetArgAsInt(
const google::protobuf::Map<std::string, std::string>& args,
const std::string& key) { … }
}
CustomInputProcessor::CustomInputProcessor(
const base::Time prediction_time,
InputDelegateHolder* input_delegate_holder)
: … { … }
CustomInputProcessor::CustomInputProcessor(
base::flat_map<FeatureIndex, Data>&& data,
const base::Time prediction_time,
InputDelegateHolder* input_delegate_holder)
: … { … }
CustomInputProcessor::~CustomInputProcessor() = default;
void CustomInputProcessor::Process(
FeatureProcessorState& feature_processor_state,
QueryProcessorCallback callback) { … }
template <typename IndexType>
void CustomInputProcessor::ProcessIndexType(
base::flat_map<IndexType, proto::CustomInput> custom_inputs,
FeatureProcessorState& feature_processor_state,
std::unique_ptr<base::flat_map<IndexType, Tensor>> result,
TemplateCallback<IndexType> callback) { … }
template <typename IndexType>
void CustomInputProcessor::OnGotProcessedValue(
base::flat_map<IndexType, proto::CustomInput> custom_inputs,
base::WeakPtr<FeatureProcessorState> feature_processor_state,
std::unique_ptr<base::flat_map<IndexType, Tensor>> result,
TemplateCallback<IndexType> callback,
IndexType current_index,
size_t current_tensor_length,
bool error,
Tensor current_value) { … }
SqlCustomInputIndex;
template void CustomInputProcessor::ProcessIndexType(
base::flat_map<SqlCustomInputIndex, proto::CustomInput> custom_inputs,
FeatureProcessorState& feature_processor_state,
std::unique_ptr<base::flat_map<SqlCustomInputIndex, Tensor>> result,
TemplateCallback<std::pair<int, int>> callback);
template void CustomInputProcessor::OnGotProcessedValue(
base::flat_map<SqlCustomInputIndex, proto::CustomInput> custom_inputs,
base::WeakPtr<FeatureProcessorState> feature_processor_state,
std::unique_ptr<base::flat_map<SqlCustomInputIndex, Tensor>> result,
TemplateCallback<SqlCustomInputIndex> callback,
SqlCustomInputIndex current_index,
size_t current_tensor_length,
bool success,
Tensor current_value);
QueryProcessor::Tensor CustomInputProcessor::ProcessSingleCustomInput(
const proto::CustomInput& custom_input,
FeatureProcessorState& feature_processor_state) { … }
bool CustomInputProcessor::AddFromInputContext(
const proto::CustomInput& custom_input,
FeatureProcessorState& feature_processor_state,
std::vector<ProcessedValue>& out_tensor) { … }
bool CustomInputProcessor::AddPredictionTime(
const proto::CustomInput& custom_input,
std::vector<ProcessedValue>& out_tensor) { … }
bool CustomInputProcessor::AddTimeRangeBeforePrediction(
const proto::CustomInput& custom_input,
std::vector<ProcessedValue>& out_tensor) { … }
bool CustomInputProcessor::AddDeviceRAMInMB(
const proto::CustomInput& custom_input,
std::vector<ProcessedValue>& out_tensor) { … }
bool CustomInputProcessor::AddDeviceOSVersionNumber(
const proto::CustomInput& custom_input,
std::vector<ProcessedValue>& out_tensor) { … }
bool CustomInputProcessor::AddDevicePPI(
const proto::CustomInput& custom_input,
std::vector<ProcessedValue>& out_tensor) { … }
bool CustomInputProcessor::AddRandom(const proto::CustomInput& custom_input,
std::vector<ProcessedValue>& out_tensor) { … }
}