Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "components/autofill/core/browser/form_group.h" |
| 6 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 7 | #include "components/autofill/core/browser/autofill_type.h" |
| 8 | |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 9 | namespace autofill { |
| 10 | |
| 11 | void FormGroup::GetMatchingTypes(const base::string16& text, |
| 12 | const std::string& app_locale, |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 13 | ServerFieldTypeSet* matching_types) const { |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 14 | if (text.empty()) { |
| 15 | matching_types->insert(EMPTY_TYPE); |
| 16 | return; |
| 17 | } |
| 18 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 19 | ServerFieldTypeSet types; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 20 | GetSupportedTypes(&types); |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 21 | for (ServerFieldTypeSet::const_iterator type = types.begin(); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 22 | type != types.end(); ++type) { |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 23 | if (GetInfo(AutofillType(*type), app_locale) == text) |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 24 | matching_types->insert(*type); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | void FormGroup::GetNonEmptyTypes(const std::string& app_locale, |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 29 | ServerFieldTypeSet* non_empty_types) const { |
| 30 | ServerFieldTypeSet types; |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 31 | GetSupportedTypes(&types); |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 32 | for (ServerFieldTypeSet::const_iterator type = types.begin(); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 33 | type != types.end(); ++type) { |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 34 | if (!GetInfo(AutofillType(*type), app_locale).empty()) |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 35 | non_empty_types->insert(*type); |
| 36 | } |
| 37 | } |
| 38 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 39 | base::string16 FormGroup::GetInfo(const AutofillType& type, |
| 40 | const std::string& app_locale) const { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 41 | return GetRawInfo(type.GetStorableType()); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 42 | } |
| 43 | |
Ben Murdoch | 3240926 | 2013-08-07 11:04:47 +0100 | [diff] [blame] | 44 | bool FormGroup::SetInfo(const AutofillType& type, |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 45 | const base::string16& value, |
| 46 | const std::string& app_locale) { |
Ben Murdoch | bb1529c | 2013-08-08 10:24:53 +0100 | [diff] [blame^] | 47 | SetRawInfo(type.GetStorableType(), value); |
Ben Murdoch | eb525c5 | 2013-07-10 11:40:50 +0100 | [diff] [blame] | 48 | return true; |
| 49 | } |
| 50 | |
| 51 | } // namespace autofill |