OLD | NEW |
---|---|
(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 #include <cstddef> | |
6 #include <string> | |
7 #include <vector> | |
8 | |
9 #include "base/basictypes.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 | |
12 #define I18N_ADDRESSINPUT_UTIL_BASICTYPES_H_ | |
13 #include "third_party/libaddressinput/chromium/preload_address_validator.h" | |
14 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.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 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/downloader .h" | |
18 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/preload_su pplier.h" | |
19 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h" | |
20 | |
21 namespace autofill { | |
22 | |
23 using ::i18n::addressinput::AddressData; | |
24 using ::i18n::addressinput::AddressField; | |
25 using ::i18n::addressinput::AddressValidator; | |
26 using ::i18n::addressinput::BuildCallback; | |
27 using ::i18n::addressinput::Downloader; | |
28 using ::i18n::addressinput::FieldProblemMap; | |
29 using ::i18n::addressinput::PreloadSupplier; | |
30 using ::i18n::addressinput::Storage; | |
31 | |
32 PreloadAddressValidator::PreloadAddressValidator( | |
33 scoped_ptr<Downloader> downloader, | |
34 scoped_ptr<Storage> storage) | |
35 : supplier_( | |
36 new PreloadSupplier( | |
37 I18N_ADDRESS_VALIDATION_DATA_URL, | |
38 downloader.release(), | |
39 storage.release())), | |
40 validator_( | |
41 new AddressValidator( | |
42 supplier_.get())), | |
43 validated_(BuildCallback(this, &PreloadAddressValidator::Validated)) { | |
44 } | |
45 | |
46 PreloadAddressValidator::PreloadAddressValidator( | |
47 const std::string& validation_data_url, | |
48 scoped_ptr<Downloader> downloader, | |
49 scoped_ptr<Storage> storage) | |
50 : supplier_( | |
51 new PreloadSupplier( | |
52 validation_data_url, | |
53 downloader.release(), | |
54 storage.release())), | |
55 validator_( | |
56 new AddressValidator( | |
57 supplier_.get())), | |
58 validated_(BuildCallback(this, &PreloadAddressValidator::Validated)) { | |
59 } | |
60 | |
61 PreloadAddressValidator::~PreloadAddressValidator() { | |
62 } | |
63 | |
64 void PreloadAddressValidator::LoadRules(const std::string& region_code, | |
65 const Callback& loaded) { | |
66 assert(supplier_ != NULL); | |
67 supplier_->LoadRules(region_code, loaded); | |
68 } | |
69 | |
70 PreloadAddressValidator::Status PreloadAddressValidator::Validate( | |
71 const AddressData& address, | |
72 const FieldProblemMap* filter, | |
73 FieldProblemMap* problems) const { | |
74 assert(supplier_ != NULL); | |
75 assert(validator_ != NULL); | |
76 | |
77 if (supplier_->IsPending(address.region_code)) { | |
78 return RULES_NOT_READY; | |
79 } | |
80 | |
81 if (!supplier_->IsLoaded(address.region_code)) { | |
82 return RULES_UNAVAILABLE; | |
83 } | |
84 | |
85 validator_->Validate( | |
86 address, | |
87 /*allow_postal*/ false, | |
88 /*require_name*/ false, | |
89 filter, | |
90 problems, | |
91 *validated_); | |
92 | |
93 return SUCCESS; | |
94 } | |
95 | |
96 PreloadAddressValidator::Status PreloadAddressValidator::GetSuggestions( | |
97 const AddressData& user_input, | |
98 AddressField focused_field, | |
99 size_t suggestion_limit, | |
100 std::vector<AddressData>* suggestions) const { | |
101 // Stub implementation. TODO: Implement! ;-) | |
please use gerrit instead
2014/05/23 14:44:54
Need the suggestions implementation from Rouslan.
| |
102 return RULES_UNAVAILABLE; | |
103 } | |
104 | |
105 bool PreloadAddressValidator::CanonicalizeAdministrativeArea( | |
106 AddressData* address_data) const { | |
107 // Stub implementation. TODO: Implement! ;-) | |
please use gerrit instead
2014/05/23 14:44:54
Need the synonym implementation from Rouslan.
| |
108 return RULES_UNAVAILABLE; | |
109 } | |
110 | |
111 void PreloadAddressValidator::Validated(bool success, | |
112 const AddressData&, | |
113 const FieldProblemMap&) { | |
114 assert(success); | |
115 } | |
116 | |
117 // Stub constructor for use by MockAddressValidator. | |
118 PreloadAddressValidator::PreloadAddressValidator() { | |
119 } | |
120 | |
121 } // namespace autofill | |
OLD | NEW |