OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "third_party/libaddressinput/chromium/chrome_address_validator.h" | 5 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 if (focused_field == POSTAL_CODE || | 106 if (focused_field == POSTAL_CODE || |
107 (focused_field >= ADMIN_AREA && focused_field <= DEPENDENT_LOCALITY)) { | 107 (focused_field >= ADMIN_AREA && focused_field <= DEPENDENT_LOCALITY)) { |
108 input_suggester_->GetSuggestions( | 108 input_suggester_->GetSuggestions( |
109 user_input, focused_field, suggestion_limit, suggestions); | 109 user_input, focused_field, suggestion_limit, suggestions); |
110 } | 110 } |
111 | 111 |
112 return SUCCESS; | 112 return SUCCESS; |
113 } | 113 } |
114 | 114 |
115 bool AddressValidator::CanonicalizeAdministrativeArea( | 115 bool AddressValidator::NormalizeAddress(AddressData* address) const { |
116 AddressData* address) const { | |
117 if (!supplier_->IsLoaded(address->region_code)) | 116 if (!supplier_->IsLoaded(address->region_code)) |
118 return false; | 117 return false; |
119 | 118 |
120 // TODO: It would probably be beneficial to use the full canonicalization. | 119 normalizer_->Normalize(address); |
121 AddressData tmp(*address); | 120 return true; |
122 normalizer_->Normalize(&tmp); | 121 } |
123 address->administrative_area = tmp.administrative_area; | |
124 | 122 |
125 return true; | 123 bool AddressValidator::AreRulesLoadedForRegion(const std::string& region_code) { |
| 124 return supplier_->IsLoaded(region_code); |
126 } | 125 } |
127 | 126 |
128 AddressValidator::AddressValidator() | 127 AddressValidator::AddressValidator() |
129 : load_rules_listener_(NULL), weak_factory_(this) {} | 128 : load_rules_listener_(NULL), weak_factory_(this) {} |
130 | 129 |
131 base::TimeDelta AddressValidator::GetBaseRetryPeriod() const { | 130 base::TimeDelta AddressValidator::GetBaseRetryPeriod() const { |
132 return base::TimeDelta::FromSeconds(8); | 131 return base::TimeDelta::FromSeconds(8); |
133 } | 132 } |
134 | 133 |
135 void AddressValidator::Validated(bool success, | 134 void AddressValidator::Validated(bool success, |
(...skipping 17 matching lines...) Expand all Loading... |
153 weak_factory_.GetWeakPtr(), region_code), | 152 weak_factory_.GetWeakPtr(), region_code), |
154 GetBaseRetryPeriod() * pow(2, attempts_number_[region_code]++)); | 153 GetBaseRetryPeriod() * pow(2, attempts_number_[region_code]++)); |
155 } | 154 } |
156 | 155 |
157 void AddressValidator::RetryLoadRules(const std::string& region_code) { | 156 void AddressValidator::RetryLoadRules(const std::string& region_code) { |
158 // Do not reset retry count. | 157 // Do not reset retry count. |
159 supplier_->LoadRules(region_code, *rules_loaded_); | 158 supplier_->LoadRules(region_code, *rules_loaded_); |
160 } | 159 } |
161 | 160 |
162 } // namespace autofill | 161 } // namespace autofill |
OLD | NEW |