Commit bd3a8a3b authored by Jeremy Roman's avatar Jeremy Roman Committed by Chromium LUCI CQ

optimization_guide: Fix sequence checker in PredictionManager.

Change-Id: Ie987f109f3a1c243270246b1f13469c57dac33a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2607544
Auto-Submit: Jeremy Roman <jbroman@chromium.org>
Commit-Queue: Sophie Chang <sophiechang@chromium.org>
Reviewed-by: default avatarSophie Chang <sophiechang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#839783}
parent 8eb672d8
...@@ -274,7 +274,7 @@ void PredictionManager::UpdateFCPSessionStatistics(base::TimeDelta fcp) { ...@@ -274,7 +274,7 @@ void PredictionManager::UpdateFCPSessionStatistics(base::TimeDelta fcp) {
void PredictionManager::RegisterOptimizationTargets( void PredictionManager::RegisterOptimizationTargets(
const std::vector<proto::OptimizationTarget>& optimization_targets) { const std::vector<proto::OptimizationTarget>& optimization_targets) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (optimization_targets.empty()) if (optimization_targets.empty())
return; return;
...@@ -348,7 +348,7 @@ base::Optional<float> PredictionManager::GetValueForClientFeature( ...@@ -348,7 +348,7 @@ base::Optional<float> PredictionManager::GetValueForClientFeature(
content::NavigationHandle* navigation_handle, content::NavigationHandle* navigation_handle,
const base::flat_map<proto::ClientModelFeature, float>& const base::flat_map<proto::ClientModelFeature, float>&
override_client_model_feature_values) const { override_client_model_feature_values) const {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
proto::ClientModelFeature client_model_feature; proto::ClientModelFeature client_model_feature;
if (!proto::ClientModelFeature_Parse(model_feature, &client_model_feature)) if (!proto::ClientModelFeature_Parse(model_feature, &client_model_feature))
...@@ -437,7 +437,7 @@ base::flat_map<std::string, float> PredictionManager::BuildFeatureMap( ...@@ -437,7 +437,7 @@ base::flat_map<std::string, float> PredictionManager::BuildFeatureMap(
const base::flat_set<std::string>& model_features, const base::flat_set<std::string>& model_features,
const base::flat_map<proto::ClientModelFeature, float>& const base::flat_map<proto::ClientModelFeature, float>&
override_client_model_feature_values) { override_client_model_feature_values) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
base::flat_map<std::string, float> feature_map; base::flat_map<std::string, float> feature_map;
if (model_features.size() == 0) if (model_features.size() == 0)
return feature_map; return feature_map;
...@@ -479,7 +479,7 @@ OptimizationTargetDecision PredictionManager::ShouldTargetNavigation( ...@@ -479,7 +479,7 @@ OptimizationTargetDecision PredictionManager::ShouldTargetNavigation(
proto::OptimizationTarget optimization_target, proto::OptimizationTarget optimization_target,
const base::flat_map<proto::ClientModelFeature, float>& const base::flat_map<proto::ClientModelFeature, float>&
override_client_model_feature_values) { override_client_model_feature_values) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(navigation_handle->GetURL().SchemeIsHTTPOrHTTPS()); DCHECK(navigation_handle->GetURL().SchemeIsHTTPOrHTTPS());
OptimizationGuideNavigationData* navigation_data = OptimizationGuideNavigationData* navigation_data =
...@@ -558,7 +558,7 @@ OptimizationTargetDecision PredictionManager::ShouldTargetNavigation( ...@@ -558,7 +558,7 @@ OptimizationTargetDecision PredictionManager::ShouldTargetNavigation(
void PredictionManager::OnEffectiveConnectionTypeChanged( void PredictionManager::OnEffectiveConnectionTypeChanged(
net::EffectiveConnectionType effective_connection_type) { net::EffectiveConnectionType effective_connection_type) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
current_effective_connection_type_ = effective_connection_type; current_effective_connection_type_ = effective_connection_type;
} }
...@@ -588,7 +588,7 @@ void PredictionManager::SetPredictionModelDownloadManagerForTesting( ...@@ -588,7 +588,7 @@ void PredictionManager::SetPredictionModelDownloadManagerForTesting(
} }
void PredictionManager::FetchModelsAndHostModelFeatures() { void PredictionManager::FetchModelsAndHostModelFeatures() {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!ShouldFetchModelsAndHostModelFeatures(profile_)) if (!ShouldFetchModelsAndHostModelFeatures(profile_))
return; return;
...@@ -689,7 +689,7 @@ void PredictionManager::FetchModelsAndHostModelFeatures() { ...@@ -689,7 +689,7 @@ void PredictionManager::FetchModelsAndHostModelFeatures() {
void PredictionManager::OnModelsAndHostFeaturesFetched( void PredictionManager::OnModelsAndHostFeaturesFetched(
base::Optional<std::unique_ptr<proto::GetModelsResponse>> base::Optional<std::unique_ptr<proto::GetModelsResponse>>
get_models_response_data) { get_models_response_data) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!get_models_response_data) if (!get_models_response_data)
return; return;
...@@ -713,7 +713,7 @@ void PredictionManager::OnModelsAndHostFeaturesFetched( ...@@ -713,7 +713,7 @@ void PredictionManager::OnModelsAndHostFeaturesFetched(
void PredictionManager::UpdateHostModelFeatures( void PredictionManager::UpdateHostModelFeatures(
const google::protobuf::RepeatedPtrField<proto::HostModelFeatures>& const google::protobuf::RepeatedPtrField<proto::HostModelFeatures>&
host_model_features) { host_model_features) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::unique_ptr<StoreUpdateData> host_model_features_update_data = std::unique_ptr<StoreUpdateData> host_model_features_update_data =
StoreUpdateData::CreateHostModelFeaturesStoreUpdateData( StoreUpdateData::CreateHostModelFeaturesStoreUpdateData(
/*update_time=*/clock_->Now() + kUpdateModelsAndFeaturesDelay, /*update_time=*/clock_->Now() + kUpdateModelsAndFeaturesDelay,
...@@ -734,7 +734,7 @@ void PredictionManager::UpdateHostModelFeatures( ...@@ -734,7 +734,7 @@ void PredictionManager::UpdateHostModelFeatures(
std::unique_ptr<PredictionModel> PredictionManager::CreatePredictionModel( std::unique_ptr<PredictionModel> PredictionManager::CreatePredictionModel(
const proto::PredictionModel& model) const { const proto::PredictionModel& model) const {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return PredictionModel::Create( return PredictionModel::Create(
std::make_unique<proto::PredictionModel>(model)); std::make_unique<proto::PredictionModel>(model));
} }
...@@ -742,7 +742,7 @@ std::unique_ptr<PredictionModel> PredictionManager::CreatePredictionModel( ...@@ -742,7 +742,7 @@ std::unique_ptr<PredictionModel> PredictionManager::CreatePredictionModel(
void PredictionManager::UpdatePredictionModels( void PredictionManager::UpdatePredictionModels(
const google::protobuf::RepeatedPtrField<proto::PredictionModel>& const google::protobuf::RepeatedPtrField<proto::PredictionModel>&
prediction_models) { prediction_models) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
std::unique_ptr<StoreUpdateData> prediction_model_update_data = std::unique_ptr<StoreUpdateData> prediction_model_update_data =
StoreUpdateData::CreatePredictionModelStoreUpdateData(); StoreUpdateData::CreatePredictionModelStoreUpdateData();
bool has_models_to_update = false; bool has_models_to_update = false;
...@@ -813,13 +813,13 @@ void PredictionManager::NotifyObserversOfNewModelPath( ...@@ -813,13 +813,13 @@ void PredictionManager::NotifyObserversOfNewModelPath(
} }
void PredictionManager::OnPredictionModelsStored() { void PredictionManager::OnPredictionModelsStored() {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
LOCAL_HISTOGRAM_BOOLEAN( LOCAL_HISTOGRAM_BOOLEAN(
"OptimizationGuide.PredictionManager.PredictionModelsStored", true); "OptimizationGuide.PredictionManager.PredictionModelsStored", true);
} }
void PredictionManager::OnHostModelFeaturesStored() { void PredictionManager::OnHostModelFeaturesStored() {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
LOCAL_HISTOGRAM_BOOLEAN( LOCAL_HISTOGRAM_BOOLEAN(
"OptimizationGuide.PredictionManager.HostModelFeaturesStored", true); "OptimizationGuide.PredictionManager.HostModelFeaturesStored", true);
...@@ -838,7 +838,7 @@ void PredictionManager::OnHostModelFeaturesStored() { ...@@ -838,7 +838,7 @@ void PredictionManager::OnHostModelFeaturesStored() {
} }
void PredictionManager::OnStoreInitialized() { void PredictionManager::OnStoreInitialized() {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
store_is_ready_ = true; store_is_ready_ = true;
// Only load host model features if there are optimization targets registered. // Only load host model features if there are optimization targets registered.
...@@ -855,7 +855,7 @@ void PredictionManager::OnStoreInitialized() { ...@@ -855,7 +855,7 @@ void PredictionManager::OnStoreInitialized() {
} }
void PredictionManager::LoadHostModelFeatures() { void PredictionManager::LoadHostModelFeatures() {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// Load the host model features first, each prediction model requires the set // Load the host model features first, each prediction model requires the set
// of host model features to be known before creation. // of host model features to be known before creation.
model_and_features_store_->LoadAllHostModelFeatures( model_and_features_store_->LoadAllHostModelFeatures(
...@@ -866,7 +866,7 @@ void PredictionManager::LoadHostModelFeatures() { ...@@ -866,7 +866,7 @@ void PredictionManager::LoadHostModelFeatures() {
void PredictionManager::OnLoadHostModelFeatures( void PredictionManager::OnLoadHostModelFeatures(
std::unique_ptr<std::vector<proto::HostModelFeatures>> std::unique_ptr<std::vector<proto::HostModelFeatures>>
all_host_model_features) { all_host_model_features) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
// If the store returns an empty vector of host model features, the store // If the store returns an empty vector of host model features, the store
// contains no host model features. However, the load is otherwise complete // contains no host model features. However, the load is otherwise complete
// and prediction models can be loaded but they will require no host model // and prediction models can be loaded but they will require no host model
...@@ -887,7 +887,7 @@ void PredictionManager::OnLoadHostModelFeatures( ...@@ -887,7 +887,7 @@ void PredictionManager::OnLoadHostModelFeatures(
void PredictionManager::LoadPredictionModels( void PredictionManager::LoadPredictionModels(
const base::flat_set<proto::OptimizationTarget>& optimization_targets) { const base::flat_set<proto::OptimizationTarget>& optimization_targets) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(host_model_features_loaded_); DCHECK(host_model_features_loaded_);
OptimizationGuideStore::EntryKey model_entry_key; OptimizationGuideStore::EntryKey model_entry_key;
...@@ -911,7 +911,7 @@ void PredictionManager::LoadPredictionModels( ...@@ -911,7 +911,7 @@ void PredictionManager::LoadPredictionModels(
void PredictionManager::OnLoadPredictionModel( void PredictionManager::OnLoadPredictionModel(
std::unique_ptr<proto::PredictionModel> model) { std::unique_ptr<proto::PredictionModel> model) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!model) if (!model)
return; return;
...@@ -922,7 +922,7 @@ void PredictionManager::OnLoadPredictionModel( ...@@ -922,7 +922,7 @@ void PredictionManager::OnLoadPredictionModel(
void PredictionManager::OnProcessLoadedModel( void PredictionManager::OnProcessLoadedModel(
std::unique_ptr<proto::PredictionModel> model, std::unique_ptr<proto::PredictionModel> model,
bool success) { bool success) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (success) { if (success) {
base::UmaHistogramSparse( base::UmaHistogramSparse(
"OptimizationGuide.PredictionModelLoadedVersion." + "OptimizationGuide.PredictionModelLoadedVersion." +
...@@ -943,7 +943,7 @@ void PredictionManager::OnProcessLoadedModel( ...@@ -943,7 +943,7 @@ void PredictionManager::OnProcessLoadedModel(
bool PredictionManager::ProcessAndStoreLoadedModel( bool PredictionManager::ProcessAndStoreLoadedModel(
const proto::PredictionModel& model) { const proto::PredictionModel& model) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!model.model_info().has_optimization_target()) if (!model.model_info().has_optimization_target())
return false; return false;
if (!model.model_info().has_version()) if (!model.model_info().has_version())
...@@ -993,7 +993,7 @@ bool PredictionManager::ProcessAndStoreLoadedModel( ...@@ -993,7 +993,7 @@ bool PredictionManager::ProcessAndStoreLoadedModel(
bool PredictionManager::ShouldUpdateStoredModelForTarget( bool PredictionManager::ShouldUpdateStoredModelForTarget(
proto::OptimizationTarget optimization_target, proto::OptimizationTarget optimization_target,
int64_t new_version) const { int64_t new_version) const {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
auto model_file_it = auto model_file_it =
optimization_target_prediction_model_file_map_.find(optimization_target); optimization_target_prediction_model_file_map_.find(optimization_target);
...@@ -1011,7 +1011,7 @@ bool PredictionManager::ShouldUpdateStoredModelForTarget( ...@@ -1011,7 +1011,7 @@ bool PredictionManager::ShouldUpdateStoredModelForTarget(
void PredictionManager::StoreLoadedPredictionModelFile( void PredictionManager::StoreLoadedPredictionModelFile(
proto::OptimizationTarget optimization_target, proto::OptimizationTarget optimization_target,
std::unique_ptr<PredictionModelFile> prediction_model_file) { std::unique_ptr<PredictionModelFile> prediction_model_file) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
bool has_model_for_target = bool has_model_for_target =
optimization_target_prediction_model_map_.contains(optimization_target); optimization_target_prediction_model_map_.contains(optimization_target);
...@@ -1036,7 +1036,7 @@ void PredictionManager::StoreLoadedPredictionModelFile( ...@@ -1036,7 +1036,7 @@ void PredictionManager::StoreLoadedPredictionModelFile(
void PredictionManager::StoreLoadedPredictionModel( void PredictionManager::StoreLoadedPredictionModel(
proto::OptimizationTarget optimization_target, proto::OptimizationTarget optimization_target,
std::unique_ptr<PredictionModel> prediction_model) { std::unique_ptr<PredictionModel> prediction_model) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
bool has_model_file_for_target = bool has_model_file_for_target =
optimization_target_prediction_model_file_map_.contains( optimization_target_prediction_model_file_map_.contains(
...@@ -1053,7 +1053,7 @@ void PredictionManager::StoreLoadedPredictionModel( ...@@ -1053,7 +1053,7 @@ void PredictionManager::StoreLoadedPredictionModel(
bool PredictionManager::ProcessAndStoreHostModelFeatures( bool PredictionManager::ProcessAndStoreHostModelFeatures(
const proto::HostModelFeatures& host_model_features) { const proto::HostModelFeatures& host_model_features) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!host_model_features.has_host()) if (!host_model_features.has_host())
return false; return false;
if (host_model_features.model_features_size() == 0) if (host_model_features.model_features_size() == 0)
...@@ -1104,7 +1104,7 @@ void PredictionManager::MaybeScheduleModelAndHostModelFeaturesFetch() { ...@@ -1104,7 +1104,7 @@ void PredictionManager::MaybeScheduleModelAndHostModelFeaturesFetch() {
} }
base::Time PredictionManager::GetLastFetchAttemptTime() const { base::Time PredictionManager::GetLastFetchAttemptTime() const {
SEQUENCE_CHECKER(squence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return base::Time::FromDeltaSinceWindowsEpoch( return base::Time::FromDeltaSinceWindowsEpoch(
base::TimeDelta::FromMicroseconds( base::TimeDelta::FromMicroseconds(
pref_service_->GetInt64(prefs::kModelAndFeaturesLastFetchAttempt))); pref_service_->GetInt64(prefs::kModelAndFeaturesLastFetchAttempt)));
...@@ -1133,7 +1133,7 @@ void PredictionManager::ScheduleModelsAndHostModelFeaturesFetch() { ...@@ -1133,7 +1133,7 @@ void PredictionManager::ScheduleModelsAndHostModelFeaturesFetch() {
void PredictionManager::SetLastModelAndFeaturesFetchAttemptTime( void PredictionManager::SetLastModelAndFeaturesFetchAttemptTime(
base::Time last_attempt_time) { base::Time last_attempt_time) {
SEQUENCE_CHECKER(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
pref_service_->SetInt64( pref_service_->SetInt64(
prefs::kModelAndFeaturesLastFetchAttempt, prefs::kModelAndFeaturesLastFetchAttempt,
last_attempt_time.ToDeltaSinceWindowsEpoch().InMicroseconds()); last_attempt_time.ToDeltaSinceWindowsEpoch().InMicroseconds());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment