Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "components/autofill/core/browser/address.h" | 5 #include "components/autofill/core/browser/address.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 line1_ = address.line1_; | 37 line1_ = address.line1_; |
| 38 line2_ = address.line2_; | 38 line2_ = address.line2_; |
| 39 city_ = address.city_; | 39 city_ = address.city_; |
| 40 state_ = address.state_; | 40 state_ = address.state_; |
| 41 country_code_ = address.country_code_; | 41 country_code_ = address.country_code_; |
| 42 zip_code_ = address.zip_code_; | 42 zip_code_ = address.zip_code_; |
| 43 return *this; | 43 return *this; |
| 44 } | 44 } |
| 45 | 45 |
| 46 base::string16 Address::GetRawInfo(NativeFieldType type) const { | 46 base::string16 Address::GetRawInfo(NativeFieldType type) const { |
| 47 type = AutofillType::GetEquivalentFieldType(type); | 47 // TODO(isherman): Is GetEquivalentNativeType even necessary? |
|
Evan Stade
2013/08/05 18:47:24
I'm assuming you mean you could just switch on |ty
Ilya Sherman
2013/08/06 05:05:39
Yeah. This requires fixing up a couple of call si
| |
| 48 if (type == ADDRESS_HOME_LINE1) | 48 switch (AutofillType(type).GetEquivalentNativeType()) { |
| 49 return line1_; | 49 case ADDRESS_HOME_LINE1: |
| 50 return line1_; | |
| 50 | 51 |
| 51 if (type == ADDRESS_HOME_LINE2) | 52 case ADDRESS_HOME_LINE2: |
| 52 return line2_; | 53 return line2_; |
| 53 | 54 |
| 54 if (type == ADDRESS_HOME_CITY) | 55 case ADDRESS_HOME_CITY: |
| 55 return city_; | 56 return city_; |
| 56 | 57 |
| 57 if (type == ADDRESS_HOME_STATE) | 58 case ADDRESS_HOME_STATE: |
| 58 return state_; | 59 return state_; |
| 59 | 60 |
| 60 if (type == ADDRESS_HOME_ZIP) | 61 case ADDRESS_HOME_ZIP: |
| 61 return zip_code_; | 62 return zip_code_; |
| 62 | 63 |
| 63 if (type == ADDRESS_HOME_COUNTRY) | 64 case ADDRESS_HOME_COUNTRY: |
| 64 return country_code_; | 65 return country_code_; |
| 65 | 66 |
| 66 return base::string16(); | 67 default: |
| 68 return base::string16(); | |
| 69 } | |
| 67 } | 70 } |
| 68 | 71 |
| 69 void Address::SetRawInfo(NativeFieldType type, const base::string16& value) { | 72 void Address::SetRawInfo(NativeFieldType type, const base::string16& value) { |
| 70 type = AutofillType::GetEquivalentFieldType(type); | 73 // TODO(isherman): Is GetEquivalentNativeType even necessary? |
| 71 if (type == ADDRESS_HOME_LINE1) { | 74 switch (AutofillType(type).GetEquivalentNativeType()) { |
| 72 line1_ = value; | 75 case ADDRESS_HOME_LINE1: |
| 73 } else if (type == ADDRESS_HOME_LINE2) { | 76 line1_ = value; |
| 74 line2_ = value; | 77 break; |
| 75 } else if (type == ADDRESS_HOME_CITY) { | 78 |
| 76 city_ = value; | 79 case ADDRESS_HOME_LINE2: |
| 77 } else if (type == ADDRESS_HOME_STATE) { | 80 line2_ = value; |
| 78 state_ = value; | 81 break; |
| 79 } else if (type == ADDRESS_HOME_COUNTRY) { | 82 |
| 80 DCHECK(value.empty() || value.length() == 2u); | 83 case ADDRESS_HOME_CITY: |
| 81 country_code_ = value; | 84 city_ = value; |
| 82 } else if (type == ADDRESS_HOME_ZIP) { | 85 break; |
| 83 zip_code_ = value; | 86 |
| 84 } else { | 87 case ADDRESS_HOME_STATE: |
| 85 NOTREACHED(); | 88 state_ = value; |
| 89 break; | |
| 90 | |
| 91 case ADDRESS_HOME_COUNTRY: | |
| 92 DCHECK(value.empty() || value.length() == 2u); | |
| 93 country_code_ = value; | |
| 94 break; | |
| 95 | |
| 96 case ADDRESS_HOME_ZIP: | |
| 97 zip_code_ = value; | |
| 98 break; | |
| 99 | |
| 100 default: | |
| 101 NOTREACHED(); | |
| 86 } | 102 } |
| 87 } | 103 } |
| 88 | 104 |
| 89 base::string16 Address::GetInfo(const AutofillType& type, | 105 base::string16 Address::GetInfo(const AutofillType& type, |
| 90 const std::string& app_locale) const { | 106 const std::string& app_locale) const { |
| 91 NativeFieldType native_type = | 107 NativeFieldType native_type = type.GetEquivalentNativeType(); |
| 92 AutofillType::GetEquivalentFieldType(type.native_type()); | |
| 93 if (native_type == ADDRESS_HOME_COUNTRY && !country_code_.empty()) | 108 if (native_type == ADDRESS_HOME_COUNTRY && !country_code_.empty()) |
| 94 return AutofillCountry(UTF16ToASCII(country_code_), app_locale).name(); | 109 return AutofillCountry(UTF16ToASCII(country_code_), app_locale).name(); |
| 95 | 110 |
| 96 return GetRawInfo(native_type); | 111 return GetRawInfo(native_type); |
| 97 } | 112 } |
| 98 | 113 |
| 99 bool Address::SetInfo(const AutofillType& type, | 114 bool Address::SetInfo(const AutofillType& type, |
| 100 const base::string16& value, | 115 const base::string16& value, |
| 101 const std::string& app_locale) { | 116 const std::string& app_locale) { |
| 102 NativeFieldType native_type = | 117 NativeFieldType native_type = type.GetEquivalentNativeType(); |
| 103 AutofillType::GetEquivalentFieldType(type.native_type()); | |
| 104 if (native_type == ADDRESS_HOME_COUNTRY && !value.empty()) { | 118 if (native_type == ADDRESS_HOME_COUNTRY && !value.empty()) { |
| 105 country_code_ = | 119 country_code_ = |
| 106 ASCIIToUTF16(AutofillCountry::GetCountryCode(value, app_locale)); | 120 ASCIIToUTF16(AutofillCountry::GetCountryCode(value, app_locale)); |
| 107 return !country_code_.empty(); | 121 return !country_code_.empty(); |
| 108 } | 122 } |
| 109 | 123 |
| 110 SetRawInfo(native_type, value); | 124 SetRawInfo(native_type, value); |
| 111 return true; | 125 return true; |
| 112 } | 126 } |
| 113 | 127 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 125 void Address::GetSupportedTypes(NativeFieldTypeSet* supported_types) const { | 139 void Address::GetSupportedTypes(NativeFieldTypeSet* supported_types) const { |
| 126 supported_types->insert(ADDRESS_HOME_LINE1); | 140 supported_types->insert(ADDRESS_HOME_LINE1); |
| 127 supported_types->insert(ADDRESS_HOME_LINE2); | 141 supported_types->insert(ADDRESS_HOME_LINE2); |
| 128 supported_types->insert(ADDRESS_HOME_CITY); | 142 supported_types->insert(ADDRESS_HOME_CITY); |
| 129 supported_types->insert(ADDRESS_HOME_STATE); | 143 supported_types->insert(ADDRESS_HOME_STATE); |
| 130 supported_types->insert(ADDRESS_HOME_ZIP); | 144 supported_types->insert(ADDRESS_HOME_ZIP); |
| 131 supported_types->insert(ADDRESS_HOME_COUNTRY); | 145 supported_types->insert(ADDRESS_HOME_COUNTRY); |
| 132 } | 146 } |
| 133 | 147 |
| 134 } // namespace autofill | 148 } // namespace autofill |
| OLD | NEW |