| // Copyright 2023 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "components/autofill/core/browser/heuristic_source.h" |
| |
| #include "base/feature_list.h" |
| #include "base/notreached.h" |
| #include "components/autofill/core/browser/form_parsing/autofill_parsing_utils.h" |
| #include "components/autofill/core/browser/form_parsing/regex_patterns.h" |
| #include "components/autofill/core/common/autofill_features.h" |
| #include "components/autofill/core/common/dense_set.h" |
| |
| namespace autofill { |
| |
| HeuristicSource GetActiveHeuristicSource() { |
| if (base::FeatureList::IsEnabled(features::kAutofillModelPredictions) && |
| features::kAutofillModelPredictionsAreActive.Get()) { |
| return HeuristicSource::kMachineLearning; |
| } |
| #if BUILDFLAG(USE_INTERNAL_AUTOFILL_PATTERNS) |
| return GetActiveRegexFeatures().empty() ? HeuristicSource::kDefault |
| : HeuristicSource::kExperimental; |
| #else |
| return HeuristicSource::kLegacy; |
| #endif |
| } |
| |
| std::optional<PatternSource> HeuristicSourceToPatternSource( |
| HeuristicSource source) { |
| switch (source) { |
| #if !BUILDFLAG(USE_INTERNAL_AUTOFILL_PATTERNS) |
| case HeuristicSource::kLegacy: |
| return PatternSource::kLegacy; |
| #else |
| case HeuristicSource::kDefault: |
| case HeuristicSource::kExperimental: |
| return PatternSource::kDefault; |
| case HeuristicSource::kPredictionImprovements: |
| return PatternSource::kPredictionImprovements; |
| #endif |
| case autofill::HeuristicSource::kMachineLearning: |
| return std::nullopt; |
| } |
| NOTREACHED(); |
| } |
| |
| } // namespace autofill |