1// Copyright (c) 2011 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#ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_TYPE_H_ 6#define CHROME_BROWSER_AUTOFILL_AUTOFILL_TYPE_H_ 7#pragma once 8 9#include <map> 10#include <set> 11#include <string> 12 13#include "base/string16.h" 14#include "chrome/browser/autofill/field_types.h" 15 16// The high-level description of Autofill types, used to categorize form fields 17// and for associating form fields with form values in the Web Database. 18class AutofillType { 19 public: 20 enum FieldTypeGroup { 21 NO_GROUP, 22 NAME, 23 EMAIL, 24 COMPANY, 25 ADDRESS_HOME, 26 ADDRESS_BILLING, 27 PHONE_HOME, 28 PHONE_FAX, 29 CREDIT_CARD, 30 }; 31 32 enum FieldTypeSubGroup { 33 NO_SUBGROUP, 34 // Address subgroups. 35 ADDRESS_LINE1, 36 ADDRESS_LINE2, 37 ADDRESS_APT_NUM, 38 ADDRESS_CITY, 39 ADDRESS_STATE, 40 ADDRESS_ZIP, 41 ADDRESS_COUNTRY, 42 43 // Phone subgroups. 44 PHONE_NUMBER, 45 PHONE_CITY_CODE, 46 PHONE_COUNTRY_CODE, 47 PHONE_CITY_AND_NUMBER, 48 PHONE_WHOLE_NUMBER 49 }; 50 51 struct AutofillTypeDefinition { 52 FieldTypeGroup group; 53 FieldTypeSubGroup subgroup; 54 }; 55 56 explicit AutofillType(AutofillFieldType field_type); 57 AutofillType(const AutofillType& autofill_type); 58 AutofillType& operator=(const AutofillType& autofill_type); 59 60 AutofillFieldType field_type() const; 61 FieldTypeGroup group() const; 62 FieldTypeSubGroup subgroup() const; 63 64 // Maps |field_type| to a field type that can be directly stored in a profile 65 // (in the sense that it makes sense to call |AutofillProfile::SetInfo()| with 66 // the returned field type as the first parameter). 67 static AutofillFieldType GetEquivalentFieldType(AutofillFieldType field_type); 68 69 // Utilities for serializing and deserializing an |AutofillFieldType|. 70 static std::string FieldTypeToString(AutofillFieldType field_type); 71 static AutofillFieldType StringToFieldType(const std::string& str); 72 73 private: 74 AutofillFieldType field_type_; 75}; 76 77typedef AutofillType::FieldTypeGroup FieldTypeGroup; 78typedef AutofillType::FieldTypeSubGroup FieldTypeSubGroup; 79typedef std::set<AutofillFieldType> FieldTypeSet; 80typedef std::map<string16, AutofillFieldType> FieldTypeMap; 81 82#endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_TYPE_H_ 83