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

Side by Side Diff: third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h

Issue 109323011: [rac] Download all rules for a country code in libaddressinput. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address data Created 6 years, 11 months 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) 2013 Google Inc. 1 // Copyright (C) 2013 Google Inc.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #ifndef I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_ 15 #ifndef I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_
16 #define I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_ 16 #define I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_
17 17
18 #include <libaddressinput/address_field.h> 18 #include <libaddressinput/address_field.h>
19 #include <libaddressinput/address_problem.h> 19 #include <libaddressinput/address_problem.h>
20 #include <libaddressinput/util/basictypes.h>
21 #include <libaddressinput/util/scoped_ptr.h> 20 #include <libaddressinput/util/scoped_ptr.h>
22 21
23 #include <map> 22 #include <map>
24 #include <string> 23 #include <string>
25 #include <vector> 24 #include <vector>
26 25
27 namespace i18n { 26 namespace i18n {
28 namespace addressinput { 27 namespace addressinput {
29 28
30 class Downloader; 29 class Downloader;
31 class LoadRulesDelegate; 30 class LoadRulesDelegate;
32 class Localization; 31 class Localization;
33 class Retriever;
34 class Storage; 32 class Storage;
35 struct AddressData; 33 struct AddressData;
36 34
37 typedef std::vector<AddressProblem> AddressProblems; 35 typedef std::vector<AddressProblem> AddressProblems;
38 typedef std::multimap<AddressField, AddressProblem::Type> AddressProblemFilter; 36 typedef std::multimap<AddressField, AddressProblem::Type> AddressProblemFilter;
39 37
40 // Validates an AddressData structure. Sample usage: 38 // Validates an AddressData structure. Sample usage:
41 // class MyClass : public LoadRulesDelegate { 39 // class MyClass : public LoadRulesDelegate {
42 // public: 40 // public:
43 // MyClass() : validator_(new MyDownloader, new MyStorage, this) { 41 // MyClass() : validator_(new MyDownloader, new MyStorage, this) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 SUCCESS, 75 SUCCESS,
78 76
79 // The validation rules are not available, because LoadRules() was not 77 // The validation rules are not available, because LoadRules() was not
80 // called or failed. Reload the rules. 78 // called or failed. Reload the rules.
81 RULES_UNAVAILABLE, 79 RULES_UNAVAILABLE,
82 80
83 // The validation rules are being loaded. Try again later. 81 // The validation rules are being loaded. Try again later.
84 RULES_NOT_READY 82 RULES_NOT_READY
85 }; 83 };
86 84
87 // Does not take ownership of |load_rules_delegate|, which can be NULL. 85 virtual ~AddressValidator();
88 AddressValidator(scoped_ptr<const Downloader> downloader, 86
89 scoped_ptr<Storage> storage, 87 // Builds an address validator. Takes ownership of |downloader| and |storage|,
90 LoadRulesDelegate* load_rules_delegate); 88 // which cannot be NULL. Does not take ownership of |load_rules_delegate|,
91 ~AddressValidator(); 89 // which can be NULL. The caller owns the result.
90 static scoped_ptr<AddressValidator> Build(
91 scoped_ptr<const Downloader> downloader,
92 scoped_ptr<Storage> storage,
93 LoadRulesDelegate* load_rules_delegate);
92 94
93 // Loads the generic validation rules for |country_code| and specific rules 95 // Loads the generic validation rules for |country_code| and specific rules
94 // for the country's administrative areas, localities, and dependent 96 // for the country's administrative areas, localities, and dependent
95 // localities. A typical data size is 10KB. The largest is 250KB. If a country 97 // localities. A typical data size is 10KB. The largest is 250KB. If a country
96 // has language-specific validation rules, then these are also loaded. 98 // has language-specific validation rules, then these are also loaded.
97 // 99 //
98 // If the rules were loaded successfully before, then does nothing. Notifies 100 // Example rule:
99 // |load_rules_delegate| when the loading finishes. 101 // https://i18napis.appspot.com/ssl-address/data/US
100 void LoadRules(const std::string& country_code); 102 //
103 // If the rules were loaded successfully before or are still being loaded,
104 // then does nothing. Notifies |load_rules_delegate| when the loading
105 // finishes.
106 virtual void LoadRules(const std::string& country_code) = 0;
101 107
102 // Validates the |address| and populates |problems| with the validation 108 // Validates the |address| and populates |problems| with the validation
103 // problems, filtered according to the |filter| parameter. 109 // problems, filtered according to the |filter| parameter.
104 // 110 //
105 // If the |filter| is empty, then all discovered validation problems are 111 // If the |filter| is empty, then all discovered validation problems are
106 // returned. If the |filter| contains problem elements, then only the problems 112 // returned. If the |filter| contains problem elements, then only the problems
107 // in the |filter| may be returned. 113 // in the |filter| may be returned.
108 // 114 //
109 // If the |problems| parameter is NULL, then checks whether the validation 115 // If the |problems| parameter is NULL, then checks whether the validation
110 // rules are available, but does not validate the |address|. 116 // rules are available, but does not validate the |address|.
111 Status ValidateAddress(const AddressData& address, 117 virtual Status ValidateAddress(const AddressData& address,
112 const AddressProblemFilter& filter, 118 const AddressProblemFilter& filter,
113 const Localization& localization, 119 const Localization& localization,
114 AddressProblems* problems) const; 120 AddressProblems* problems) const = 0;
115 private:
116 scoped_ptr<Retriever> retriever_;
117 LoadRulesDelegate* load_rules_delegate_;
118
119 DISALLOW_COPY_AND_ASSIGN(AddressValidator);
120 }; 121 };
121 122
122 } // namespace addressinput 123 } // namespace addressinput
123 } // namespace i18n 124 } // namespace i18n
124 125
125 #endif // I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_ 126 #endif // I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698