form_group.cc revision 3240926e260ce088908e02ac07a6cf7b0c0cbf44
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
7#include "components/autofill/core/browser/autofill_type.h"
8
9namespace autofill {
10
11void FormGroup::GetMatchingTypes(const base::string16& text,
12                                 const std::string& app_locale,
13                                 ServerFieldTypeSet* matching_types) const {
14  if (text.empty()) {
15    matching_types->insert(EMPTY_TYPE);
16    return;
17  }
18
19  ServerFieldTypeSet types;
20  GetSupportedTypes(&types);
21  for (ServerFieldTypeSet::const_iterator type = types.begin();
22       type != types.end(); ++type) {
23    if (GetInfo(AutofillType(*type), app_locale) == text)
24      matching_types->insert(*type);
25  }
26}
27
28void FormGroup::GetNonEmptyTypes(const std::string& app_locale,
29                                 ServerFieldTypeSet* non_empty_types) const {
30  ServerFieldTypeSet types;
31  GetSupportedTypes(&types);
32  for (ServerFieldTypeSet::const_iterator type = types.begin();
33       type != types.end(); ++type) {
34    if (!GetInfo(AutofillType(*type), app_locale).empty())
35      non_empty_types->insert(*type);
36  }
37}
38
39base::string16 FormGroup::GetInfo(const AutofillType& type,
40                                  const std::string& app_locale) const {
41  return GetRawInfo(type.server_type());
42}
43
44bool FormGroup::SetInfo(const AutofillType& type,
45                        const base::string16& value,
46                        const std::string& app_locale) {
47  SetRawInfo(type.server_type(), value);
48  return true;
49}
50
51}  // namespace autofill
52