| Index: components/autofill/core/browser/autocomplete_history_manager.cc
 | 
| diff --git a/components/autofill/core/browser/autocomplete_history_manager.cc b/components/autofill/core/browser/autocomplete_history_manager.cc
 | 
| index acfb47df60fbf963abdbc98e9dfc45dc3b891fc1..e72f24ace41e4f97d6d0b84c081b64ae322b9608 100644
 | 
| --- a/components/autofill/core/browser/autocomplete_history_manager.cc
 | 
| +++ b/components/autofill/core/browser/autocomplete_history_manager.cc
 | 
| @@ -9,12 +9,14 @@
 | 
|  #include "base/prefs/pref_service.h"
 | 
|  #include "base/profiler/scoped_tracker.h"
 | 
|  #include "base/strings/string16.h"
 | 
| +#include "base/strings/string_util.h"
 | 
|  #include "base/strings/utf_string_conversions.h"
 | 
|  #include "components/autofill/core/browser/autofill_client.h"
 | 
|  #include "components/autofill/core/browser/autofill_driver.h"
 | 
|  #include "components/autofill/core/browser/autofill_external_delegate.h"
 | 
|  #include "components/autofill/core/browser/validation.h"
 | 
|  #include "components/autofill/core/common/autofill_pref_names.h"
 | 
| +#include "components/autofill/core/common/autofill_util.h"
 | 
|  #include "components/autofill/core/common/form_data.h"
 | 
|  
 | 
|  namespace autofill {
 | 
| @@ -81,7 +83,21 @@ void AutocompleteHistoryManager::OnWebDataServiceRequestDone(
 | 
|    const WDResult<std::vector<base::string16> >* autofill_result =
 | 
|        static_cast<const WDResult<std::vector<base::string16> >*>(result);
 | 
|    std::vector<base::string16> suggestions = autofill_result->GetValue();
 | 
| -  SendSuggestions(&suggestions);
 | 
| +
 | 
| +  if (!IsFeatureSubstringMatchEnabled() || pending_query_prefix_.empty()) {
 | 
| +    SendSuggestions(&suggestions);
 | 
| +  } else {
 | 
| +    std::vector<base::string16> preferred_suggestions;
 | 
| +    for (base::string16 suggestion : suggestions) {
 | 
| +      if (StartsWith(suggestion, pending_query_prefix_, false) ||
 | 
| +          IsContentsPrefixOfSuggestionToken(suggestion, pending_query_prefix_,
 | 
| +                                            false)) {
 | 
| +        preferred_suggestions.push_back(suggestion);
 | 
| +      }
 | 
| +    }
 | 
| +
 | 
| +    SendSuggestions(&preferred_suggestions);
 | 
| +  }
 | 
|  }
 | 
|  
 | 
|  void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
 | 
| @@ -101,8 +117,10 @@ void AutocompleteHistoryManager::OnGetAutocompleteSuggestions(
 | 
|    }
 | 
|  
 | 
|    if (database_.get()) {
 | 
| +    pending_query_prefix_ = prefix;
 | 
|      pending_query_handle_ = database_->GetFormValuesForElementName(
 | 
| -        name, prefix, kMaxAutocompleteMenuItems, this);
 | 
| +        name, IsFeatureSubstringMatchEnabled() ? base::string16() : prefix,
 | 
| +        kMaxAutocompleteMenuItems, this);
 | 
|    }
 | 
|  }
 | 
|  
 | 
| 
 |