Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: components/autofill/core/browser/autofill_external_delegate.cc

Issue 1458903003: [Autofill] Deduplicate Autocomplete and Datalist suggestions, keeping the latter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/core/browser/autofill_external_delegate.h" 5 #include "components/autofill/core/browser/autofill_external_delegate.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "base/metrics/histogram_macros.h" 11 #include "base/metrics/histogram_macros.h"
12 #include "base/metrics/sparse_histogram.h" 12 #include "base/metrics/sparse_histogram.h"
13 #include "base/stl_util.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "components/autofill/core/browser/autocomplete_history_manager.h" 16 #include "components/autofill/core/browser/autocomplete_history_manager.h"
16 #include "components/autofill/core/browser/autofill_driver.h" 17 #include "components/autofill/core/browser/autofill_driver.h"
17 #include "components/autofill/core/browser/autofill_manager.h" 18 #include "components/autofill/core/browser/autofill_manager.h"
18 #include "components/autofill/core/browser/autofill_metrics.h" 19 #include "components/autofill/core/browser/autofill_metrics.h"
19 #include "components/autofill/core/browser/popup_item_ids.h" 20 #include "components/autofill/core/browser/popup_item_ids.h"
20 #include "components/autofill/core/common/autofill_util.h" 21 #include "components/autofill/core/common/autofill_util.h"
21 #include "grit/components_strings.h" 22 #include "grit/components_strings.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 suggestions->back().frontend_id = POPUP_ITEM_ID_AUTOFILL_OPTIONS; 303 suggestions->back().frontend_id = POPUP_ITEM_ID_AUTOFILL_OPTIONS;
303 if (IsKeyboardAccessoryEnabled()) 304 if (IsKeyboardAccessoryEnabled())
304 suggestions->back().icon = base::ASCIIToUTF16("settings"); 305 suggestions->back().icon = base::ASCIIToUTF16("settings");
305 } 306 }
306 307
307 void AutofillExternalDelegate::InsertDataListValues( 308 void AutofillExternalDelegate::InsertDataListValues(
308 std::vector<Suggestion>* suggestions) { 309 std::vector<Suggestion>* suggestions) {
309 if (data_list_values_.empty()) 310 if (data_list_values_.empty())
310 return; 311 return;
311 312
313 // Go through the list of autocomplete values and remove them if they are in
314 // the list of datalist values.
315 std::set<base::string16> data_list_set(data_list_values_.begin(),
316 data_list_values_.end());
317 suggestions->erase(
318 std::remove_if(suggestions->begin(), suggestions->end(),
319 [&data_list_set](const Suggestion& suggestion) {
320 return suggestion.frontend_id ==
321 POPUP_ITEM_ID_AUTOCOMPLETE_ENTRY &&
322 ContainsKey(data_list_set, suggestion.value);
323 }),
324 suggestions->end());
325
312 #if !defined(OS_ANDROID) 326 #if !defined(OS_ANDROID)
313 // Insert the separator between the datalist and Autofill values (if there 327 // Insert the separator between the datalist and Autofill/Autocomplete values
314 // are any). 328 // (if there are any).
315 if (!suggestions->empty()) { 329 if (!suggestions->empty()) {
316 suggestions->insert(suggestions->begin(), Suggestion()); 330 suggestions->insert(suggestions->begin(), Suggestion());
317 (*suggestions)[0].frontend_id = POPUP_ITEM_ID_SEPARATOR; 331 (*suggestions)[0].frontend_id = POPUP_ITEM_ID_SEPARATOR;
318 } 332 }
319 #endif 333 #endif
320 334
321 // Insert the datalist elements at the beginning. 335 // Insert the datalist elements at the beginning.
322 suggestions->insert(suggestions->begin(), data_list_values_.size(), 336 suggestions->insert(suggestions->begin(), data_list_values_.size(),
323 Suggestion()); 337 Suggestion());
324 for (size_t i = 0; i < data_list_values_.size(); i++) { 338 for (size_t i = 0; i < data_list_values_.size(); i++) {
325 (*suggestions)[i].value = data_list_values_[i]; 339 (*suggestions)[i].value = data_list_values_[i];
326 (*suggestions)[i].label = data_list_labels_[i]; 340 (*suggestions)[i].label = data_list_labels_[i];
327 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY; 341 (*suggestions)[i].frontend_id = POPUP_ITEM_ID_DATALIST_ENTRY;
328 } 342 }
329 } 343 }
330 344
331 } // namespace autofill 345 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698