#include "components/segmentation_platform/internal/selection/segment_selector_impl.h"
#include "base/containers/contains.h"
#include "base/containers/flat_map.h"
#include "base/logging.h"
#include "base/task/single_thread_task_runner.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "components/segmentation_platform/internal/data_collection/training_data_collector.h"
#include "components/segmentation_platform/internal/database/segment_info_database.h"
#include "components/segmentation_platform/internal/database/signal_storage_config.h"
#include "components/segmentation_platform/internal/metadata/metadata_utils.h"
#include "components/segmentation_platform/internal/platform_options.h"
#include "components/segmentation_platform/internal/proto/model_prediction.pb.h"
#include "components/segmentation_platform/internal/selection/experimental_group_recorder.h"
#include "components/segmentation_platform/internal/selection/segment_result_provider.h"
#include "components/segmentation_platform/internal/selection/segmentation_result_prefs.h"
#include "components/segmentation_platform/internal/stats.h"
#include "components/segmentation_platform/public/config.h"
#include "components/segmentation_platform/public/field_trial_register.h"
#include "components/segmentation_platform/public/proto/model_metadata.pb.h"
#include "components/segmentation_platform/public/segment_selection_result.h"
namespace segmentation_platform {
namespace {
stats::SegmentationSelectionFailureReason GetFailureReason(
SegmentResultProvider::ResultState result_state) { … }
SegmentSelectionResult MakeResultFromSelection(
const SelectedSegment& selection) { … }
}
SegmentId_Name;
SegmentSelectorImpl::SegmentSelectorImpl(
SegmentInfoDatabase* segment_database,
SignalStorageConfig* signal_storage_config,
PrefService* pref_service,
const Config* config,
FieldTrialRegister* field_trial_register,
base::Clock* clock,
const PlatformOptions& platform_options)
: … { … }
SegmentSelectorImpl::SegmentSelectorImpl(
SegmentInfoDatabase* segment_database,
SignalStorageConfig* signal_storage_config,
std::unique_ptr<SegmentationResultPrefs> prefs,
const Config* config,
FieldTrialRegister* field_trial_register,
base::Clock* clock,
const PlatformOptions& platform_options)
: … { … }
SegmentSelectorImpl::~SegmentSelectorImpl() = default;
void SegmentSelectorImpl::OnPlatformInitialized(
ExecutionService* execution_service) { … }
void SegmentSelectorImpl::GetSelectedSegment(
SegmentSelectionCallback callback) { … }
SegmentSelectionResult SegmentSelectorImpl::GetCachedSegmentResult() { … }
void SegmentSelectorImpl::OnModelExecutionCompleted(SegmentId segment_id) { … }
bool SegmentSelectorImpl::IsPreviousSelectionInvalid() { … }
void SegmentSelectorImpl::SelectSegmentAndStoreToPrefs() { … }
void SegmentSelectorImpl::GetRankForNextSegment(
std::unique_ptr<SegmentRanks> ranks,
scoped_refptr<InputContext> input_context,
SegmentSelectionCallback callback) { … }
void SegmentSelectorImpl::OnGetResultForSegmentSelection(
std::unique_ptr<SegmentRanks> ranks,
scoped_refptr<InputContext> input_context,
SegmentSelectionCallback callback,
SegmentId current_segment_id,
std::unique_ptr<SegmentResultProvider::SegmentResult> result) { … }
std::pair<SegmentId, float> SegmentSelectorImpl::FindBestSegment(
const SegmentRanks& segment_results) { … }
void SegmentSelectorImpl::UpdateSelectedSegment(SegmentId new_selection,
float rank) { … }
void SegmentSelectorImpl::RecordFieldTrials() const { … }
void SegmentSelectorImpl::CallbackWrapper(
base::Time start_time,
SegmentSelectionCallback callback,
const SegmentSelectionResult& result) { … }
}