Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/suggestion.h" | 5 #include "components/autofill/core/browser/suggestion.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "components/autofill/core/browser/autofill_profile.h" | 8 #include "components/autofill/core/browser/autofill_profile.h" |
| 9 #include "components/autofill/core/browser/credit_card.h" | 9 #include "components/autofill/core/browser/credit_card.h" |
| 10 | 10 |
| 11 namespace autofill { | 11 namespace autofill { |
| 12 | 12 |
| 13 Suggestion::Suggestion() | 13 Suggestion::Suggestion() |
| 14 : frontend_id(0) { | 14 : frontend_id(0), |
| 15 match(PREFIX_MATCH) { | |
| 15 } | 16 } |
| 16 | 17 |
| 17 Suggestion::Suggestion(const Suggestion& other) | 18 Suggestion::Suggestion(const Suggestion& other) |
| 18 : backend_id(other.backend_id), | 19 : backend_id(other.backend_id), |
| 19 frontend_id(other.frontend_id), | 20 frontend_id(other.frontend_id), |
| 20 value(other.value), | 21 value(other.value), |
| 21 label(other.label), | 22 label(other.label), |
| 22 icon(other.icon) { | 23 icon(other.icon), |
| 24 match(other.match) { | |
| 23 } | 25 } |
| 24 | 26 |
| 25 Suggestion::Suggestion(const base::string16& v) | 27 Suggestion::Suggestion(const base::string16& v) |
| 26 : frontend_id(0), | 28 : frontend_id(0), |
| 27 value(v) { | 29 value(v), |
| 30 match(PREFIX_MATCH) { | |
| 28 } | 31 } |
| 29 | 32 |
| 30 Suggestion::Suggestion(const std::string& v, | 33 Suggestion::Suggestion(const std::string& v, |
| 31 const std::string& l, | 34 const std::string& l, |
| 32 const std::string& i, | 35 const std::string& i, |
| 33 int fid) | 36 int fid) |
| 34 : frontend_id(fid), | 37 : frontend_id(fid), |
| 35 value(base::UTF8ToUTF16(v)), | 38 value(base::UTF8ToUTF16(v)), |
| 36 label(base::UTF8ToUTF16(l)), | 39 label(base::UTF8ToUTF16(l)), |
| 37 icon(base::UTF8ToUTF16(i)) { | 40 icon(base::UTF8ToUTF16(i)), |
| 41 match(PREFIX_MATCH) { | |
| 38 } | 42 } |
| 39 | 43 |
| 40 Suggestion::~Suggestion() { | 44 Suggestion::~Suggestion() { |
| 41 } | 45 } |
| 42 | 46 |
| 47 void OrderPrefixBeforeSubstring(std::vector<Suggestion>* suggestions) { | |
| 48 std::sort(suggestions->begin(), suggestions->end(), | |
| 49 [](const Suggestion& s1, const Suggestion& s2) { | |
| 50 return s1.match < s2.match; | |
|
Evan Stade
2015/06/08 23:23:38
You probably want std::stable_sort (because we don
Evan Stade
2015/06/08 23:24:34
actually, I would suggest just extending OrderByMf
Pritam Nikam
2015/06/09 11:39:06
Done.
Pritam Nikam
2015/06/09 11:39:06
Did you mean RankByMfu (Ref [1])?
This API does so
| |
| 51 }); | |
| 52 } | |
| 53 | |
| 43 } // namespace autofill | 54 } // namespace autofill |
| OLD | NEW |