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 #ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_ADDRESS_VALIDATOR_H_ | 5 #ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_ADDRESS_VALIDATOR_H_ |
6 #define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_ADDRESS_VALIDATOR_H_ | 6 #define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_ADDRESS_VALIDATOR_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
| 11 #include <memory> |
11 #include <string> | 12 #include <string> |
12 #include <vector> | 13 #include <vector> |
13 | 14 |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "base/time/time.h" | 17 #include "base/time/time.h" |
18 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi
eld.h" | 18 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi
eld.h" |
19 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_va
lidator.h" | 19 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_va
lidator.h" |
20 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h
" | 20 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h
" |
21 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/preload_su
pplier.h" | 21 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/preload_su
pplier.h" |
22 | 22 |
23 namespace i18n { | 23 namespace i18n { |
24 namespace addressinput { | 24 namespace addressinput { |
25 class AddressNormalizer; | 25 class AddressNormalizer; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 | 69 |
70 // The validation rules are not available, because LoadRules() was not | 70 // The validation rules are not available, because LoadRules() was not |
71 // called or failed. Reload the rules. | 71 // called or failed. Reload the rules. |
72 RULES_UNAVAILABLE, | 72 RULES_UNAVAILABLE, |
73 | 73 |
74 // The validation rules are being loaded. Try again later. | 74 // The validation rules are being loaded. Try again later. |
75 RULES_NOT_READY | 75 RULES_NOT_READY |
76 }; | 76 }; |
77 | 77 |
78 // Takes ownership of |source| and |storage|. | 78 // Takes ownership of |source| and |storage|. |
79 AddressValidator(scoped_ptr< ::i18n::addressinput::Source> source, | 79 AddressValidator(std::unique_ptr<::i18n::addressinput::Source> source, |
80 scoped_ptr< ::i18n::addressinput::Storage> storage, | 80 std::unique_ptr<::i18n::addressinput::Storage> storage, |
81 LoadRulesListener* load_rules_listener); | 81 LoadRulesListener* load_rules_listener); |
82 | 82 |
83 virtual ~AddressValidator(); | 83 virtual ~AddressValidator(); |
84 | 84 |
85 // Loads the generic validation rules for |region_code| and specific rules | 85 // Loads the generic validation rules for |region_code| and specific rules |
86 // for the region's administrative areas, localities, and dependent | 86 // for the region's administrative areas, localities, and dependent |
87 // localities. A typical data size is 10KB. The largest is 250KB. If a region | 87 // localities. A typical data size is 10KB. The largest is 250KB. If a region |
88 // has language-specific validation rules, then these are also loaded. | 88 // has language-specific validation rules, then these are also loaded. |
89 // | 89 // |
90 // Example rule: | 90 // Example rule: |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 const ::i18n::addressinput::FieldProblemMap&); | 156 const ::i18n::addressinput::FieldProblemMap&); |
157 | 157 |
158 // Invokes the |load_rules_listener_|, if it's not NULL. Called by | 158 // Invokes the |load_rules_listener_|, if it's not NULL. Called by |
159 // |rules_loaded_| callback. | 159 // |rules_loaded_| callback. |
160 void RulesLoaded(bool success, const std::string& region_code, int); | 160 void RulesLoaded(bool success, const std::string& region_code, int); |
161 | 161 |
162 // Retries loading rules without resetting the retry counter. | 162 // Retries loading rules without resetting the retry counter. |
163 void RetryLoadRules(const std::string& region_code); | 163 void RetryLoadRules(const std::string& region_code); |
164 | 164 |
165 // Loads and stores aggregate rules at COUNTRY level. | 165 // Loads and stores aggregate rules at COUNTRY level. |
166 const scoped_ptr< ::i18n::addressinput::PreloadSupplier> supplier_; | 166 const std::unique_ptr<::i18n::addressinput::PreloadSupplier> supplier_; |
167 | 167 |
168 // Suggests addresses based on user input. | 168 // Suggests addresses based on user input. |
169 const scoped_ptr<InputSuggester> input_suggester_; | 169 const std::unique_ptr<InputSuggester> input_suggester_; |
170 | 170 |
171 // Normalizes addresses into a canonical form. | 171 // Normalizes addresses into a canonical form. |
172 const scoped_ptr< ::i18n::addressinput::AddressNormalizer> normalizer_; | 172 const std::unique_ptr<::i18n::addressinput::AddressNormalizer> normalizer_; |
173 | 173 |
174 // Validates addresses. | 174 // Validates addresses. |
175 const scoped_ptr<const ::i18n::addressinput::AddressValidator> validator_; | 175 const std::unique_ptr<const ::i18n::addressinput::AddressValidator> |
| 176 validator_; |
176 | 177 |
177 // The callback that |validator_| invokes when it finished validating an | 178 // The callback that |validator_| invokes when it finished validating an |
178 // address. | 179 // address. |
179 const scoped_ptr<const ::i18n::addressinput::AddressValidator::Callback> | 180 const std::unique_ptr<const ::i18n::addressinput::AddressValidator::Callback> |
180 validated_; | 181 validated_; |
181 | 182 |
182 // The callback that |supplier_| invokes when it finished loading rules. | 183 // The callback that |supplier_| invokes when it finished loading rules. |
183 const scoped_ptr<const ::i18n::addressinput::PreloadSupplier::Callback> | 184 const std::unique_ptr<const ::i18n::addressinput::PreloadSupplier::Callback> |
184 rules_loaded_; | 185 rules_loaded_; |
185 | 186 |
186 // Not owned delegate to invoke when |suppler_| finished loading rules. Can be | 187 // Not owned delegate to invoke when |suppler_| finished loading rules. Can be |
187 // NULL. | 188 // NULL. |
188 LoadRulesListener* const load_rules_listener_; | 189 LoadRulesListener* const load_rules_listener_; |
189 | 190 |
190 // A mapping of region codes to the number of attempts to retry loading rules. | 191 // A mapping of region codes to the number of attempts to retry loading rules. |
191 std::map<std::string, int> attempts_number_; | 192 std::map<std::string, int> attempts_number_; |
192 | 193 |
193 // Member variables should appear before the WeakPtrFactory, to ensure that | 194 // Member variables should appear before the WeakPtrFactory, to ensure that |
194 // any WeakPtrs to AddressValidator are invalidated before its members | 195 // any WeakPtrs to AddressValidator are invalidated before its members |
195 // variable's destructors are executed, rendering them invalid. | 196 // variable's destructors are executed, rendering them invalid. |
196 base::WeakPtrFactory<AddressValidator> weak_factory_; | 197 base::WeakPtrFactory<AddressValidator> weak_factory_; |
197 | 198 |
198 DISALLOW_COPY_AND_ASSIGN(AddressValidator); | 199 DISALLOW_COPY_AND_ASSIGN(AddressValidator); |
199 }; | 200 }; |
200 | 201 |
201 } // namespace autofill | 202 } // namespace autofill |
202 | 203 |
203 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_ADDRESS_VALIDATOR_H_ | 204 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_CHROME_ADDRESS_VALIDATOR_H_ |
OLD | NEW |