OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "components/payments/core/address_normalizer.h" | 5 #include "components/payments/core/address_normalizer_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
12 #include "base/cancelable_callback.h" | 12 #include "base/cancelable_callback.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 autofill::AddressValidator* address_validator_; | 116 autofill::AddressValidator* address_validator_; |
117 | 117 |
118 bool has_responded_; | 118 bool has_responded_; |
119 base::CancelableCallback<void()> on_timeout_; | 119 base::CancelableCallback<void()> on_timeout_; |
120 | 120 |
121 DISALLOW_COPY_AND_ASSIGN(AddressNormalizationRequest); | 121 DISALLOW_COPY_AND_ASSIGN(AddressNormalizationRequest); |
122 }; | 122 }; |
123 | 123 |
124 } // namespace | 124 } // namespace |
125 | 125 |
126 AddressNormalizer::AddressNormalizer(std::unique_ptr<Source> source, | 126 AddressNormalizerImpl::AddressNormalizerImpl(std::unique_ptr<Source> source, |
127 std::unique_ptr<Storage> storage) | 127 std::unique_ptr<Storage> storage) |
128 : address_validator_(std::move(source), std::move(storage), this) {} | 128 : address_validator_(std::move(source), std::move(storage), this) {} |
129 | 129 |
130 AddressNormalizer::~AddressNormalizer() {} | 130 AddressNormalizerImpl::~AddressNormalizerImpl() {} |
131 | 131 |
132 void AddressNormalizer::LoadRulesForRegion(const std::string& region_code) { | 132 void AddressNormalizerImpl::LoadRulesForRegion(const std::string& region_code) { |
133 address_validator_.LoadRules(region_code); | 133 address_validator_.LoadRules(region_code); |
134 } | 134 } |
135 | 135 |
136 bool AddressNormalizer::AreRulesLoadedForRegion( | 136 bool AddressNormalizerImpl::AreRulesLoadedForRegion( |
137 const std::string& region_code) { | 137 const std::string& region_code) { |
138 return address_validator_.AreRulesLoadedForRegion(region_code); | 138 return address_validator_.AreRulesLoadedForRegion(region_code); |
139 } | 139 } |
140 | 140 |
141 void AddressNormalizer::StartAddressNormalization( | 141 void AddressNormalizerImpl::StartAddressNormalization( |
142 const AutofillProfile& profile, | 142 const AutofillProfile& profile, |
143 const std::string& region_code, | 143 const std::string& region_code, |
144 int timeout_seconds, | 144 int timeout_seconds, |
145 AddressNormalizer::Delegate* requester) { | 145 AddressNormalizer::Delegate* requester) { |
146 DCHECK(timeout_seconds >= 0); | 146 DCHECK(timeout_seconds >= 0); |
147 | 147 |
148 std::unique_ptr<AddressNormalizationRequest> request( | 148 std::unique_ptr<AddressNormalizationRequest> request( |
149 base::MakeUnique<AddressNormalizationRequest>(profile, region_code, | 149 base::MakeUnique<AddressNormalizationRequest>(profile, region_code, |
150 timeout_seconds, requester, | 150 timeout_seconds, requester, |
151 &address_validator_)); | 151 &address_validator_)); |
(...skipping 14 matching lines...) Expand all Loading... |
166 } | 166 } |
167 | 167 |
168 it->second.push_back(std::move(request)); | 168 it->second.push_back(std::move(request)); |
169 | 169 |
170 // Start loading the rules for that region. If the rules were already in the | 170 // Start loading the rules for that region. If the rules were already in the |
171 // process of being loaded, this call will do nothing. | 171 // process of being loaded, this call will do nothing. |
172 LoadRulesForRegion(region_code); | 172 LoadRulesForRegion(region_code); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 void AddressNormalizer::OnAddressValidationRulesLoaded( | 176 void AddressNormalizerImpl::OnAddressValidationRulesLoaded( |
177 const std::string& region_code, | 177 const std::string& region_code, |
178 bool success) { | 178 bool success) { |
179 // Check if an address normalization is pending. | 179 // Check if an address normalization is pending. |
180 auto it = pending_normalization_.find(region_code); | 180 auto it = pending_normalization_.find(region_code); |
181 if (it != pending_normalization_.end()) { | 181 if (it != pending_normalization_.end()) { |
182 for (size_t i = 0; i < it->second.size(); ++i) { | 182 for (size_t i = 0; i < it->second.size(); ++i) { |
183 it->second[i]->OnRulesLoaded(success); | 183 it->second[i]->OnRulesLoaded(success); |
184 } | 184 } |
185 pending_normalization_.erase(it); | 185 pending_normalization_.erase(it); |
186 } | 186 } |
187 } | 187 } |
188 | 188 |
189 } // namespace payments | 189 } // namespace payments |
OLD | NEW |