Chromium Code Reviews| 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_CORE_ADDRESS_NORMALIZATION_MANAGER_H_ | |
| 6 #define COMPONENTS_PAYMENTS_CORE_ADDRESS_NORMALIZATION_MANAGER_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/threading/thread_checker.h" | |
| 14 | |
| 15 namespace autofill { | |
| 16 class AutofillProfile; | |
| 17 } // namespace autofill | |
| 18 | |
| 19 namespace payments { | |
| 20 | |
| 21 class AddressNormalizer; | |
| 22 | |
| 23 // Class to handle multiple concurrent address normalization requests. This | |
| 24 // class is not thread-safe. | |
| 25 class AddressNormalizationManager { | |
| 26 public: | |
| 27 // Initializes an AddressNormalizationManager. |default_country_code| will be | |
| 28 // used if the country code in an AutofillProfile to normalize is not valid. | |
| 29 // The AddressNormalizationManager takes ownership of |address_normalizer|. | |
| 30 AddressNormalizationManager( | |
| 31 std::unique_ptr<AddressNormalizer> address_normalizer, | |
| 32 const std::string& default_country_code); | |
| 33 | |
| 34 ~AddressNormalizationManager(); | |
| 35 | |
| 36 // Stops accepting normalization requests. If all the address normalization | |
| 37 // requests have already completed, |completion_callback| will be called | |
| 38 // before this method returns. Otherwise, it will be called as soon as the | |
| 39 // last pending request completes. | |
| 40 void FinalizeWithCompletionCallback(base::OnceClosure completion_callback); | |
| 41 | |
| 42 // Normalizes the address in |profile|. This may or may not happen | |
| 43 // asynchronously. On completion, the address in |profile| will be updated | |
| 44 // with the normalized address. | |
| 45 void StartNormalizingAddress(autofill::AutofillProfile* profile); | |
|
sebsg
2017/05/17 19:30:23
My only concern is this modification of the profil
macourteau
2017/05/17 19:41:10
Ok, good to know. Will make sure the code using th
| |
| 46 | |
| 47 private: | |
| 48 class NormalizerDelegate; | |
| 49 friend class NormalizerDelegate; | |
| 50 | |
| 51 // Runs the completion callback if all the delegates have completed. | |
| 52 void MaybeRunCompletionCallback(); | |
| 53 | |
| 54 // Whether the AddressNormalizationManager is still accepting requests or not. | |
| 55 bool accepting_requests_ = true; | |
| 56 | |
| 57 // The default country code to use if a profile does not have a valid country. | |
| 58 const std::string default_country_code_; | |
| 59 | |
| 60 // The callback to execute when all addresses have been normalized. | |
| 61 base::OnceClosure completion_callback_; | |
| 62 | |
| 63 // Storage for all the delegates that handle the normalization requests. | |
| 64 std::vector<std::unique_ptr<NormalizerDelegate>> delegates_; | |
| 65 | |
| 66 // The AddressNormalizer to use. Owned by this class. | |
| 67 std::unique_ptr<AddressNormalizer> address_normalizer_; | |
| 68 | |
| 69 THREAD_CHECKER(thread_checker_); | |
| 70 DISALLOW_COPY_AND_ASSIGN(AddressNormalizationManager); | |
| 71 }; | |
| 72 | |
| 73 } // namespace payments | |
| 74 | |
| 75 #endif // COMPONENTS_PAYMENTS_CORE_ADDRESS_NORMALIZATION_MANAGER_H_ | |
| OLD | NEW |