Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Side by Side Diff: chrome/browser/autofill/phone_number.cc

Issue 11360055: [Autofill] Rename GetInfo and SetInfo to GetRawInfo and SetRawInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase harder Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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/phone_number.h" 5 #include "chrome/browser/autofill/phone_number.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 void PhoneNumber::GetSupportedTypes(FieldTypeSet* supported_types) const { 54 void PhoneNumber::GetSupportedTypes(FieldTypeSet* supported_types) const {
55 supported_types->insert(PHONE_HOME_WHOLE_NUMBER); 55 supported_types->insert(PHONE_HOME_WHOLE_NUMBER);
56 supported_types->insert(PHONE_HOME_NUMBER); 56 supported_types->insert(PHONE_HOME_NUMBER);
57 supported_types->insert(PHONE_HOME_CITY_CODE); 57 supported_types->insert(PHONE_HOME_CITY_CODE);
58 supported_types->insert(PHONE_HOME_CITY_AND_NUMBER); 58 supported_types->insert(PHONE_HOME_CITY_AND_NUMBER);
59 supported_types->insert(PHONE_HOME_COUNTRY_CODE); 59 supported_types->insert(PHONE_HOME_COUNTRY_CODE);
60 } 60 }
61 61
62 string16 PhoneNumber::GetInfo(AutofillFieldType type) const { 62 string16 PhoneNumber::GetRawInfo(AutofillFieldType type) const {
63 if (type == PHONE_HOME_WHOLE_NUMBER) 63 if (type == PHONE_HOME_WHOLE_NUMBER)
64 return number_; 64 return number_;
65 65
66 UpdateCacheIfNeeded(); 66 UpdateCacheIfNeeded();
67 if (!cached_parsed_phone_.IsValidNumber()) 67 if (!cached_parsed_phone_.IsValidNumber())
68 return string16(); 68 return string16();
69 69
70 if (type == PHONE_HOME_NUMBER) 70 if (type == PHONE_HOME_NUMBER)
71 return cached_parsed_phone_.GetNumber(); 71 return cached_parsed_phone_.GetNumber();
72 72
73 if (type == PHONE_HOME_CITY_CODE) 73 if (type == PHONE_HOME_CITY_CODE)
74 return cached_parsed_phone_.GetCityCode(); 74 return cached_parsed_phone_.GetCityCode();
75 75
76 if (type == PHONE_HOME_COUNTRY_CODE) 76 if (type == PHONE_HOME_COUNTRY_CODE)
77 return cached_parsed_phone_.GetCountryCode(); 77 return cached_parsed_phone_.GetCountryCode();
78 78
79 if (type == PHONE_HOME_CITY_AND_NUMBER) { 79 if (type == PHONE_HOME_CITY_AND_NUMBER) {
80 string16 city_and_local(cached_parsed_phone_.GetCityCode()); 80 string16 city_and_local(cached_parsed_phone_.GetCityCode());
81 city_and_local.append(cached_parsed_phone_.GetNumber()); 81 city_and_local.append(cached_parsed_phone_.GetNumber());
82 return city_and_local; 82 return city_and_local;
83 } 83 }
84 84
85 return string16(); 85 return string16();
86 } 86 }
87 87
88 void PhoneNumber::SetInfo(AutofillFieldType type, const string16& value) { 88 void PhoneNumber::SetRawInfo(AutofillFieldType type, const string16& value) {
89 if (type != PHONE_HOME_CITY_AND_NUMBER && 89 if (type != PHONE_HOME_CITY_AND_NUMBER &&
90 type != PHONE_HOME_WHOLE_NUMBER) { 90 type != PHONE_HOME_WHOLE_NUMBER) {
91 // Only full phone numbers should be set directly. The remaining field 91 // Only full phone numbers should be set directly. The remaining field
92 // field types are read-only. 92 // field types are read-only.
93 return; 93 return;
94 } 94 }
95 95
96 number_ = value; 96 number_ = value;
97 cached_parsed_phone_ = autofill_i18n::PhoneObject(number_, GetLocale()); 97 cached_parsed_phone_ = autofill_i18n::PhoneObject(number_, GetLocale());
98 } 98 }
99 99
100 // Normalize phones if |type| is a whole number: 100 // Normalize phones if |type| is a whole number:
101 // (650)2345678 -> 6502345678 101 // (650)2345678 -> 6502345678
102 // 1-800-FLOWERS -> 18003569377 102 // 1-800-FLOWERS -> 18003569377
103 // If the phone cannot be normalized, returns the stored value verbatim. 103 // If the phone cannot be normalized, returns the stored value verbatim.
104 string16 PhoneNumber::GetCanonicalizedInfo(AutofillFieldType type) const { 104 string16 PhoneNumber::GetCanonicalizedInfo(AutofillFieldType type) const {
105 string16 phone = GetInfo(type); 105 string16 phone = GetRawInfo(type);
106 if (type != PHONE_HOME_WHOLE_NUMBER) 106 if (type != PHONE_HOME_WHOLE_NUMBER)
107 return phone; 107 return phone;
108 108
109 string16 normalized_phone = autofill_i18n::NormalizePhoneNumber(phone, 109 string16 normalized_phone = autofill_i18n::NormalizePhoneNumber(phone,
110 GetLocale()); 110 GetLocale());
111 if (!normalized_phone.empty()) 111 if (!normalized_phone.empty())
112 return normalized_phone; 112 return normalized_phone;
113 113
114 return phone; 114 return phone;
115 } 115 }
116 116
117 bool PhoneNumber::SetCanonicalizedInfo(AutofillFieldType type, 117 bool PhoneNumber::SetCanonicalizedInfo(AutofillFieldType type,
118 const string16& value) { 118 const string16& value) {
119 string16 number = value; 119 string16 number = value;
120 StripPunctuation(&number); 120 StripPunctuation(&number);
121 SetInfo(type, number); 121 SetRawInfo(type, number);
122 122
123 return NormalizePhone(); 123 return NormalizePhone();
124 } 124 }
125 125
126 void PhoneNumber::GetMatchingTypes(const string16& text, 126 void PhoneNumber::GetMatchingTypes(const string16& text,
127 FieldTypeSet* matching_types) const { 127 FieldTypeSet* matching_types) const {
128 string16 stripped_text = text; 128 string16 stripped_text = text;
129 StripPunctuation(&stripped_text); 129 StripPunctuation(&stripped_text);
130 FormGroup::GetMatchingTypes(stripped_text, matching_types); 130 FormGroup::GetMatchingTypes(stripped_text, matching_types);
131 131
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 country_, city_, phone_, 218 country_, city_, phone_,
219 locale, 219 locale,
220 (country_.empty() ? 220 (country_.empty() ?
221 autofill_i18n::NATIONAL : autofill_i18n::INTERNATIONAL), 221 autofill_i18n::NATIONAL : autofill_i18n::INTERNATIONAL),
222 value); 222 value);
223 } 223 }
224 224
225 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { 225 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const {
226 return phone_.empty() && whole_number_.empty(); 226 return phone_.empty() && whole_number_.empty();
227 } 227 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/phone_number.h ('k') | chrome/browser/autofill/select_control_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698