blob: 17eb036aadc725b4617ea8111df0ef811db100df [file] [log] [blame]
Ben Murdocheb525c52013-07-10 11:40:50 +01001// 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 Murdoch32409262013-08-07 11:04:47 +01007#include "components/autofill/core/browser/autofill_type.h"
8
Ben Murdocheb525c52013-07-10 11:40:50 +01009namespace autofill {
10
11void FormGroup::GetMatchingTypes(const base::string16& text,
12 const std::string& app_locale,
Ben Murdoch32409262013-08-07 11:04:47 +010013 ServerFieldTypeSet* matching_types) const {
Ben Murdocheb525c52013-07-10 11:40:50 +010014 if (text.empty()) {
15 matching_types->insert(EMPTY_TYPE);
16 return;
17 }
18
Ben Murdoch32409262013-08-07 11:04:47 +010019 ServerFieldTypeSet types;
Ben Murdocheb525c52013-07-10 11:40:50 +010020 GetSupportedTypes(&types);
Ben Murdoch32409262013-08-07 11:04:47 +010021 for (ServerFieldTypeSet::const_iterator type = types.begin();
Ben Murdocheb525c52013-07-10 11:40:50 +010022 type != types.end(); ++type) {
Ben Murdoch32409262013-08-07 11:04:47 +010023 if (GetInfo(AutofillType(*type), app_locale) == text)
Ben Murdocheb525c52013-07-10 11:40:50 +010024 matching_types->insert(*type);
25 }
26}
27
28void FormGroup::GetNonEmptyTypes(const std::string& app_locale,
Ben Murdoch32409262013-08-07 11:04:47 +010029 ServerFieldTypeSet* non_empty_types) const {
30 ServerFieldTypeSet types;
Ben Murdocheb525c52013-07-10 11:40:50 +010031 GetSupportedTypes(&types);
Ben Murdoch32409262013-08-07 11:04:47 +010032 for (ServerFieldTypeSet::const_iterator type = types.begin();
Ben Murdocheb525c52013-07-10 11:40:50 +010033 type != types.end(); ++type) {
Ben Murdoch32409262013-08-07 11:04:47 +010034 if (!GetInfo(AutofillType(*type), app_locale).empty())
Ben Murdocheb525c52013-07-10 11:40:50 +010035 non_empty_types->insert(*type);
36 }
37}
38
Ben Murdoch32409262013-08-07 11:04:47 +010039base::string16 FormGroup::GetInfo(const AutofillType& type,
40 const std::string& app_locale) const {
Ben Murdochbb1529c2013-08-08 10:24:53 +010041 return GetRawInfo(type.GetStorableType());
Ben Murdocheb525c52013-07-10 11:40:50 +010042}
43
Ben Murdoch32409262013-08-07 11:04:47 +010044bool FormGroup::SetInfo(const AutofillType& type,
Ben Murdocheb525c52013-07-10 11:40:50 +010045 const base::string16& value,
46 const std::string& app_locale) {
Ben Murdochbb1529c2013-08-08 10:24:53 +010047 SetRawInfo(type.GetStorableType(), value);
Ben Murdocheb525c52013-07-10 11:40:50 +010048 return true;
49}
50
51} // namespace autofill