| Index: components/autofill/core/browser/personal_data_manager.cc
 | 
| diff --git a/components/autofill/core/browser/personal_data_manager.cc b/components/autofill/core/browser/personal_data_manager.cc
 | 
| index 5441a475b7da657346d9603ce00b82bb4c6251dc..5391f9b79028c41f0acd7f23650b8bb552d95fae 100644
 | 
| --- a/components/autofill/core/browser/personal_data_manager.cc
 | 
| +++ b/components/autofill/core/browser/personal_data_manager.cc
 | 
| @@ -29,6 +29,7 @@
 | 
|  #include "components/autofill/core/browser/validation.h"
 | 
|  #include "components/autofill/core/common/autofill_pref_names.h"
 | 
|  #include "components/autofill/core/common/autofill_switches.h"
 | 
| +#include "components/autofill/core/common/autofill_util.h"
 | 
|  #include "components/signin/core/common/signin_pref_names.h"
 | 
|  #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h"
 | 
|  #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_formatter.h"
 | 
| @@ -229,6 +230,13 @@ bool RankByMfu(const AutofillDataModel* a, const AutofillDataModel* b) {
 | 
|    return a->use_date() > b->use_date();
 | 
|  }
 | 
|  
 | 
| +// Helper function to order prefix matched suggestions prior to substring
 | 
| +// matched.
 | 
| +bool OrderPrefixBeforeSubstring(const Suggestion& suggestion1,
 | 
| +                                const Suggestion& suggestion2) {
 | 
| +  return suggestion1.match < suggestion2.match;
 | 
| +}
 | 
| +
 | 
|  }  // namespace
 | 
|  
 | 
|  PersonalDataManager::PersonalDataManager(const std::string& app_locale)
 | 
| @@ -837,18 +845,29 @@ std::vector<Suggestion> PersonalDataManager::GetProfileSuggestions(
 | 
|        if (values[i].empty())
 | 
|          continue;
 | 
|  
 | 
| +      bool substring_token_matched = false;
 | 
|        base::string16 value_canon =
 | 
|            AutofillProfile::CanonicalizeProfileString(values[i]);
 | 
| -      if (StartsWith(value_canon, field_contents_canon, true)) {
 | 
| -        // Prefix match, add suggestion.
 | 
| +      if (StartsWith(value_canon, field_contents_canon, true) ||
 | 
| +          (substring_token_matched =
 | 
| +               IsFeatureSubstringMatchEnabled() &&
 | 
| +               IsContentsPrefixOfSuggestionToken(
 | 
| +                   value_canon, field_contents_canon, CASE_SENSITIVE))) {
 | 
|          matched_profiles.push_back(profile);
 | 
|          suggestions.push_back(Suggestion(values[i]));
 | 
|          suggestions.back().backend_id.guid = profile->guid();
 | 
|          suggestions.back().backend_id.variant = i;
 | 
| +        suggestions.back().match = substring_token_matched
 | 
| +                                       ? Suggestion::SUBSTRING_MATCH
 | 
| +                                       : Suggestion::PREFIX_MATCH;
 | 
|        }
 | 
|      }
 | 
|    }
 | 
|  
 | 
| +  // Now sort profiles with prefix matched suggestions order before substring
 | 
| +  // matched suggestions.
 | 
| +  std::sort(suggestions.begin(), suggestions.end(), OrderPrefixBeforeSubstring);
 | 
| +
 | 
|    // Don't show two suggestions if one is a subset of the other.
 | 
|    std::vector<AutofillProfile*> unique_matched_profiles;
 | 
|    std::vector<Suggestion> unique_suggestions;
 | 
| 
 |