autofill_type.h revision dc0f95d653279beabeb9817299e2902918ba123e
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 CONTACT_INFO, 23 ADDRESS_HOME, 24 ADDRESS_BILLING, 25 PHONE_HOME, 26 PHONE_FAX, 27 CREDIT_CARD, 28 }; 29 30 enum FieldTypeSubGroup { 31 NO_SUBGROUP, 32 // Address subgroups. 33 ADDRESS_LINE1, 34 ADDRESS_LINE2, 35 ADDRESS_APT_NUM, 36 ADDRESS_CITY, 37 ADDRESS_STATE, 38 ADDRESS_ZIP, 39 ADDRESS_COUNTRY, 40 41 // Phone subgroups. 42 PHONE_NUMBER, 43 PHONE_CITY_CODE, 44 PHONE_COUNTRY_CODE, 45 PHONE_CITY_AND_NUMBER, 46 PHONE_WHOLE_NUMBER 47 }; 48 49 struct AutofillTypeDefinition { 50 FieldTypeGroup group; 51 FieldTypeSubGroup subgroup; 52 }; 53 54 explicit AutofillType(AutofillFieldType field_type); 55 AutofillType(const AutofillType& autofill_type); 56 AutofillType& operator=(const AutofillType& autofill_type); 57 58 AutofillFieldType field_type() const; 59 FieldTypeGroup group() const; 60 FieldTypeSubGroup subgroup() const; 61 62 // Maps |field_type| to a field type that can be directly stored in a profile 63 // (in the sense that it makes sense to call |AutoFillProfile::SetInfo()| with 64 // the returned field type as the first parameter). 65 static AutofillFieldType GetEquivalentFieldType(AutofillFieldType field_type); 66 67 // Utilities for serializing and deserializing an |AutofillFieldType|. 68 static std::string FieldTypeToString(AutofillFieldType field_type); 69 static AutofillFieldType StringToFieldType(const std::string& str); 70 71 private: 72 AutofillFieldType field_type_; 73}; 74 75typedef AutofillType::FieldTypeGroup FieldTypeGroup; 76typedef AutofillType::FieldTypeSubGroup FieldTypeSubGroup; 77typedef std::set<AutofillFieldType> FieldTypeSet; 78typedef std::map<string16, AutofillFieldType> FieldTypeMap; 79 80#endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_TYPE_H_ 81