OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/autofill/contact_info.h" | 5 #include "chrome/browser/autofill/contact_info.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/autofill/autofill_type.h" | 9 #include "chrome/browser/autofill/autofill_type.h" |
10 #include "chrome/browser/autofill/field_types.h" | 10 #include "chrome/browser/autofill/field_types.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 static const size_t kAutoFillContactInfoLength = | 22 static const size_t kAutoFillContactInfoLength = |
23 arraysize(kAutoFillContactInfoTypes); | 23 arraysize(kAutoFillContactInfoTypes); |
24 | 24 |
25 FormGroup* ContactInfo::Clone() const { | 25 FormGroup* ContactInfo::Clone() const { |
26 return new ContactInfo(*this); | 26 return new ContactInfo(*this); |
27 } | 27 } |
28 | 28 |
29 void ContactInfo::GetPossibleFieldTypes(const string16& text, | 29 void ContactInfo::GetPossibleFieldTypes(const string16& text, |
30 FieldTypeSet* possible_types) const { | 30 FieldTypeSet* possible_types) const { |
| 31 DCHECK(possible_types); |
| 32 |
31 if (IsFirstName(text)) | 33 if (IsFirstName(text)) |
32 possible_types->insert(NAME_FIRST); | 34 possible_types->insert(NAME_FIRST); |
33 | 35 |
34 if (IsMiddleName(text)) | 36 if (IsMiddleName(text)) |
35 possible_types->insert(NAME_MIDDLE); | 37 possible_types->insert(NAME_MIDDLE); |
36 | 38 |
37 if (IsLastName(text)) | 39 if (IsLastName(text)) |
38 possible_types->insert(NAME_LAST); | 40 possible_types->insert(NAME_LAST); |
39 | 41 |
40 if (IsMiddleInitial(text)) | 42 if (IsMiddleInitial(text)) |
41 possible_types->insert(NAME_MIDDLE_INITIAL); | 43 possible_types->insert(NAME_MIDDLE_INITIAL); |
42 | 44 |
43 if (IsSuffix(text)) | 45 if (IsSuffix(text)) |
44 possible_types->insert(NAME_SUFFIX); | 46 possible_types->insert(NAME_SUFFIX); |
45 | 47 |
46 if (IsFullName(text)) | 48 if (IsFullName(text)) |
47 possible_types->insert(NAME_FULL); | 49 possible_types->insert(NAME_FULL); |
48 | 50 |
49 if (email_ == text) | 51 if (email_ == text) |
50 possible_types->insert(EMAIL_ADDRESS); | 52 possible_types->insert(EMAIL_ADDRESS); |
51 | 53 |
52 if (company_name_ == text) | 54 if (company_name_ == text) |
53 possible_types->insert(COMPANY_NAME); | 55 possible_types->insert(COMPANY_NAME); |
54 } | 56 } |
55 | 57 |
| 58 void ContactInfo::GetAvailableFieldTypes(FieldTypeSet* available_types) const { |
| 59 DCHECK(available_types); |
| 60 |
| 61 if (!first().empty()) |
| 62 available_types->insert(NAME_FIRST); |
| 63 |
| 64 if (!middle().empty()) |
| 65 available_types->insert(NAME_MIDDLE); |
| 66 |
| 67 if (!last().empty()) |
| 68 available_types->insert(NAME_LAST); |
| 69 |
| 70 if (!MiddleInitial().empty()) |
| 71 available_types->insert(NAME_MIDDLE_INITIAL); |
| 72 |
| 73 if (!FullName().empty()) |
| 74 available_types->insert(NAME_FULL); |
| 75 |
| 76 if (!suffix().empty()) |
| 77 available_types->insert(NAME_SUFFIX); |
| 78 |
| 79 if (!email().empty()) |
| 80 available_types->insert(EMAIL_ADDRESS); |
| 81 |
| 82 if (!company_name().empty()) |
| 83 available_types->insert(COMPANY_NAME); |
| 84 } |
| 85 |
56 void ContactInfo::FindInfoMatches(const AutoFillType& type, | 86 void ContactInfo::FindInfoMatches(const AutoFillType& type, |
57 const string16& info, | 87 const string16& info, |
58 std::vector<string16>* matched_text) const { | 88 std::vector<string16>* matched_text) const { |
59 if (matched_text == NULL) { | 89 DCHECK(matched_text); |
60 DLOG(ERROR) << "NULL matched vector passed in"; | |
61 return; | |
62 } | |
63 | 90 |
64 string16 match; | 91 string16 match; |
65 if (type.field_type() == UNKNOWN_TYPE) { | 92 if (type.field_type() == UNKNOWN_TYPE) { |
66 for (size_t i = 0; i < kAutoFillContactInfoLength; i++) { | 93 for (size_t i = 0; i < kAutoFillContactInfoLength; i++) { |
67 if (FindInfoMatchesHelper(kAutoFillContactInfoTypes[i], info, &match)) | 94 if (FindInfoMatchesHelper(kAutoFillContactInfoTypes[i], info, &match)) |
68 matched_text->push_back(match); | 95 matched_text->push_back(match); |
69 } | 96 } |
70 } else if (FindInfoMatchesHelper(type.field_type(), info, &match)) { | 97 } else if (FindInfoMatchesHelper(type.field_type(), info, &match)) { |
71 matched_text->push_back(match); | 98 matched_text->push_back(match); |
72 } | 99 } |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 SetLast(full_name_tokens.back()); | 403 SetLast(full_name_tokens.back()); |
377 if (full_name_tokens.size() > 2) { | 404 if (full_name_tokens.size() > 2) { |
378 full_name_tokens.erase(full_name_tokens.begin()); | 405 full_name_tokens.erase(full_name_tokens.begin()); |
379 full_name_tokens.pop_back(); | 406 full_name_tokens.pop_back(); |
380 SetMiddle(JoinString(full_name_tokens, ' ')); | 407 SetMiddle(JoinString(full_name_tokens, ' ')); |
381 } | 408 } |
382 } | 409 } |
383 } | 410 } |
384 } | 411 } |
385 | 412 |
OLD | NEW |