| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_PAYMENTS_ADDRESS_NORMALIZER_H_ |
| 6 #define COMPONENTS_PAYMENTS_ADDRESS_NORMALIZER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/weak_ptr.h" |
| 10 #include "components/autofill/core/browser/autofill_profile.h" |
| 11 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" |
| 12 |
| 13 using autofill::AutofillProfile; |
| 14 |
| 15 namespace payments { |
| 16 |
| 17 // A class used to normalize addresses. |
| 18 class AddressNormalizer : public autofill::LoadRulesListener, |
| 19 public base::SupportsWeakPtr<AddressNormalizer> { |
| 20 public: |
| 21 // The interface for the normalization delegates. |
| 22 class Delegate { |
| 23 public: |
| 24 virtual void OnAddressNormalized( |
| 25 const autofill::AutofillProfile& normalized_profile) = 0; |
| 26 |
| 27 virtual void OnCouldNotNormalize( |
| 28 const autofill::AutofillProfile& profile) = 0; |
| 29 |
| 30 protected: |
| 31 virtual ~Delegate() {} |
| 32 }; |
| 33 |
| 34 // The interface for the normalization request. |
| 35 class Request { |
| 36 public: |
| 37 virtual void OnRulesLoaded(bool success) = 0; |
| 38 virtual ~Request() {} |
| 39 }; |
| 40 |
| 41 AddressNormalizer(std::unique_ptr<i18n::addressinput::Source> source, |
| 42 std::unique_ptr<i18n::addressinput::Storage> storage); |
| 43 ~AddressNormalizer() override; |
| 44 |
| 45 // Start loading the validation rules for the specified |region_code|. |
| 46 void LoadRulesForRegion(const std::string& region_code); |
| 47 |
| 48 // Returns whether the rules for the specified |region_code| have finished |
| 49 // loading. |
| 50 bool AreRulesLoadedForRegion(const std::string& region_code); |
| 51 |
| 52 // Starts the normalization of the |profile| based on the |region_code|. The |
| 53 // normalized profile will be returned to the |requester| possibly |
| 54 // asynchronously. |
| 55 void StartAddressNormalization(const autofill::AutofillProfile& profile, |
| 56 const std::string& region_code, |
| 57 Delegate* requester); |
| 58 |
| 59 private: |
| 60 // Called when the validation rules for the |region_code| have finished |
| 61 // loading. Implementation of the LoadRulesListener interface. |
| 62 void OnAddressValidationRulesLoaded(const std::string& region_code, |
| 63 bool success) override; |
| 64 |
| 65 // Map associating a region code to pending normalizations. |
| 66 std::map<std::string, std::vector<std::unique_ptr<Request>>> |
| 67 pending_normalization_; |
| 68 |
| 69 // The address validator used to normalize addresses. |
| 70 autofill::AddressValidator address_validator_; |
| 71 |
| 72 DISALLOW_COPY_AND_ASSIGN(AddressNormalizer); |
| 73 }; |
| 74 |
| 75 } // namespace payments |
| 76 |
| 77 #endif // COMPONENTS_PAYMENTS_ADDRESS_NORMALIZER_H_ |
| OLD | NEW |