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

Unified Diff: components/payments/address_validator_helper.h

Issue 2686613003: [Payments] Move address normalization code from android to native. (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: components/payments/address_validator_helper.h
diff --git a/components/payments/address_validator_helper.h b/components/payments/address_validator_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..8a84d48352e3fcb99bc2427ffc00562ae69e8a27
--- /dev/null
+++ b/components/payments/address_validator_helper.h
@@ -0,0 +1,68 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_PAYMENTS_ADDRESS_VALIDATOR_HELPER_H_
+#define COMPONENTS_PAYMENTS_ADDRESS_VALIDATOR_HELPER_H_
+
+#include "base/macros.h"
+#include "base/memory/weak_ptr.h"
+#include "components/autofill/core/browser/autofill_profile.h"
+#include "third_party/libaddressinput/chromium/chrome_address_validator.h"
+
+using autofill::AutofillProfile;
+
+namespace payments {
+
+// The interface for the normalization requesters.
+class AddressNormalizationRequester {
please use gerrit instead 2017/02/14 21:31:09 nit: AddressNormalizer::Delegate
sebsg 2017/02/15 16:18:31 Done.
+ public:
please use gerrit instead 2017/02/14 21:31:08 Need a virtual destructor with empty body.
sebsg 2017/02/15 16:18:31 Done.
+ virtual void OnAddressNormalized(
+ autofill::AutofillProfile normalized_profile) = 0;
+};
+
+// The interface for the normalization request.
+class NormalizationRequest {
please use gerrit instead 2017/02/14 21:31:09 nit: AddressNormalizer::Request
sebsg 2017/02/15 16:18:31 Done.
+ public:
+ virtual void OnRulesSuccessfullyLoaded() = 0;
+ virtual ~NormalizationRequest() {}
+};
+
+// A helper class to help with address validation and normalization.
+class AddressValidatorHelper
please use gerrit instead 2017/02/14 21:31:09 nit: AddressNormalizer, because it does not valida
sebsg 2017/02/15 16:18:31 Done.
+ : public autofill::LoadRulesListener,
+ public base::SupportsWeakPtr<AddressValidatorHelper> {
+ public:
+ AddressValidatorHelper(std::unique_ptr<i18n::addressinput::Source> source,
+ std::unique_ptr<i18n::addressinput::Storage> storage);
+ ~AddressValidatorHelper() override;
+
+ // Start loading the validation rules for the specified |region_code|.
+ void LoadRulesForRegion(const std::string& region_code);
+
+ // Returns whether the rules for the specified |region_code| have finished
+ // loading.
+ bool AreRulesLoadedForRegion(const std::string& region_code);
+
+ // Starts the normalization of the |profile| based on the |region_code|. The
+ // normalized profile will be returned to the |requester|. Returns true if the
+ // normalization will happen asynchronously.
+ bool StartAddressNormalization(autofill::AutofillProfile profile,
please use gerrit instead 2017/02/14 21:31:09 const-ref for profile You seem to have changed th
sebsg 2017/02/15 16:18:31 Done.
+ const std::string region_code,
please use gerrit instead 2017/02/14 21:31:09 const-ref for region_code
sebsg 2017/02/15 16:18:30 Done.
+ AddressNormalizationRequester* requester);
+
+ private:
+ void OnAddressValidationRulesLoaded(const std::string& region_code,
please use gerrit instead 2017/02/14 21:31:09 Specify the interface being implemented.
sebsg 2017/02/15 16:18:31 Done.
+ bool success) override;
+
+ // Map associating a region code to pending normalizations.
+ std::map<std::string, std::vector<std::unique_ptr<NormalizationRequest>>>
+ pending_normalization_;
+
+ // The address validator used to normalize addresses.
+ autofill::AddressValidator address_validator_;
+};
please use gerrit instead 2017/02/14 21:31:09 DISALLOW_COPY_AND_ASSIGN
sebsg 2017/02/15 16:18:31 Done.
+
+} // namespace payments
+
+#endif // COMPONENTS_PAYMENTS_ADDRESS_VALIDATOR_HELPER_H_

Powered by Google App Engine
This is Rietveld 408576698