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

Side by Side Diff: third_party/libaddressinput/chromium/preload_address_validator.h

Issue 298863012: Use upstream libaddressinput in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merged in https://codereview.chromium.org/300303002/ Created 6 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_PRELOAD_ADDRESS_VALIDATOR_H_
6 #define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_PRELOAD_ADDRESS_VALIDATOR_H_
7
8 #include <cstddef>
9 #include <string>
10 #include <vector>
11
12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fi eld.h"
15 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_va lidator.h"
16 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h "
17
18 namespace i18n {
19 namespace addressinput {
20
21 class Downloader;
22 class PreloadSupplier;
23 class Storage;
24 class Synonyms;
25 struct AddressData;
26
27 } // namespace addressinput
28 } // namespace i18n
29
30 namespace autofill {
31
32 class Suggestions;
33
34 // Interface to the libaddressinput AddressValidator for Chromium Autofill.
35 class PreloadAddressValidator {
36 public:
37 typedef ::i18n::addressinput::Callback<std::string, int> Callback;
38
39 // The status of address validation.
40 enum Status {
41 // Address validation completed successfully. Check |problems| to see if any
42 // problems were found.
43 SUCCESS,
44
45 // The validation rules are not available, because LoadRules() was not
46 // called or failed. Reload the rules.
47 RULES_UNAVAILABLE,
48
49 // The validation rules are being loaded. Try again later.
50 RULES_NOT_READY
51 };
52
53 PreloadAddressValidator(
54 const std::string& validation_data_url,
55 scoped_ptr< ::i18n::addressinput::Downloader> downloader,
56 scoped_ptr< ::i18n::addressinput::Storage> storage);
57
58 virtual ~PreloadAddressValidator();
59
60 // Loads the generic validation rules for |region_code| and specific rules
61 // for the regions's administrative areas, localities, and dependent
62 // localities. A typical data size is 10KB. The largest is 250KB. If a region
63 // has language-specific validation rules, then these are also loaded.
64 //
65 // Example rule:
66 // https://i18napis.appspot.com/ssl-aggregate-address/data/US
67 //
68 // If the rules are already in progress of being loaded, it does nothing.
69 // Calls |loaded| when the loading has finished.
70 virtual void LoadRules(const std::string& region_code,
71 const Callback& loaded);
72
73 // Validates the |address| and populates |problems| with the validation
74 // problems, filtered according to the |filter| parameter.
75 //
76 // If the |filter| is empty, then all discovered validation problems are
77 // returned. If the |filter| contains problem elements, then only the problems
78 // in the |filter| may be returned.
79 virtual Status Validate(
80 const ::i18n::addressinput::AddressData& address,
81 const ::i18n::addressinput::FieldProblemMap* filter,
82 ::i18n::addressinput::FieldProblemMap* problems) const;
83
84 // Fills in |suggestions| for the partially typed in |user_input|, assuming
85 // the user is typing in the |focused_field|. If the number of |suggestions|
86 // is over the |suggestion_limit|, then returns no |suggestions| at all.
87 //
88 // If the |solutions| parameter is NULL, the checks whether the validation
89 // rules are available, but does not fill in suggestions.
90 //
91 // Sample user input 1:
92 // country code = "US"
93 // postal code = "90066"
94 // focused field = POSTAL_CODE
95 // suggestions limit = 1
96 // Suggestion:
97 // [{administrative_area: "CA"}]
98 //
99 // Sample user input 2:
100 // country code = "CN"
101 // dependent locality = "Zongyang"
102 // focused field = DEPENDENT_LOCALITY
103 // suggestions limit = 10
104 // Suggestion:
105 // [{dependent_locality: "Zongyang Xian",
106 // locality: "Anqing Shi",
107 // administrative_area: "Anhui Sheng"}]
108 virtual Status GetSuggestions(
109 const ::i18n::addressinput::AddressData& user_input,
110 ::i18n::addressinput::AddressField focused_field,
111 size_t suggestion_limit,
112 std::vector< ::i18n::addressinput::AddressData>* suggestions) const;
113
114 // Canonicalizes the administrative area in |address_data|. For example,
115 // "texas" changes to "TX". Returns true on success, otherwise leaves
116 // |address_data| alone and returns false.
117 virtual bool CanonicalizeAdministrativeArea(
118 ::i18n::addressinput::AddressData* address) const;
119
120 private:
121 void Validated(bool success,
122 const ::i18n::addressinput::AddressData&,
123 const ::i18n::addressinput::FieldProblemMap&);
124
125 const scoped_ptr< ::i18n::addressinput::PreloadSupplier> supplier_;
126 const scoped_ptr<Suggestions> suggestions_;
127 const scoped_ptr< ::i18n::addressinput::Synonyms> synonyms_;
128 const scoped_ptr<const ::i18n::addressinput::AddressValidator> validator_;
129 const scoped_ptr<const ::i18n::addressinput::AddressValidator::Callback>
130 validated_;
131
132 friend class MockAddressValidator;
133 PreloadAddressValidator();
134
135 DISALLOW_COPY_AND_ASSIGN(PreloadAddressValidator);
136 };
137
138 } // namespace autofill
139
140 #endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_PRELOAD_ADDRESS_VALIDATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698