Index: components/payments/core/address_normalization_manager.h |
diff --git a/components/payments/core/address_normalization_manager.h b/components/payments/core/address_normalization_manager.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..39aac077d34415681f72e3fecd5cd302d544bbad |
--- /dev/null |
+++ b/components/payments/core/address_normalization_manager.h |
@@ -0,0 +1,75 @@ |
+// 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_CORE_ADDRESS_NORMALIZATION_MANAGER_H_ |
+#define COMPONENTS_PAYMENTS_CORE_ADDRESS_NORMALIZATION_MANAGER_H_ |
+ |
+#include <memory> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/callback.h" |
+#include "base/threading/thread_checker.h" |
+ |
+namespace autofill { |
+class AutofillProfile; |
+} // namespace autofill |
+ |
+namespace payments { |
+ |
+class AddressNormalizer; |
+ |
+// Class to handle multiple concurrent address normalization requests. This |
+// class is not thread-safe. |
+class AddressNormalizationManager { |
+ public: |
+ // Initializes an AddressNormalizationManager. |default_country_code| will be |
+ // used if the country code in an AutofillProfile to normalize is not valid. |
+ // The AddressNormalizationManager takes ownership of |address_normalizer|. |
+ AddressNormalizationManager( |
+ std::unique_ptr<AddressNormalizer> address_normalizer, |
+ const std::string& default_country_code); |
+ |
+ ~AddressNormalizationManager(); |
+ |
+ // Stops accepting normalization requests. If all the address normalization |
+ // requests have already completed, |completion_callback| will be called |
+ // before this method returns. Otherwise, it will be called as soon as the |
+ // last pending request completes. |
+ void FinalizeWithCompletionCallback(base::OnceClosure completion_callback); |
+ |
+ // Normalizes the address in |profile|. This may or may not happen |
+ // asynchronously. On completion, the address in |profile| will be updated |
+ // with the normalized address. |
+ 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
|
+ |
+ private: |
+ class NormalizerDelegate; |
+ friend class NormalizerDelegate; |
+ |
+ // Runs the completion callback if all the delegates have completed. |
+ void MaybeRunCompletionCallback(); |
+ |
+ // Whether the AddressNormalizationManager is still accepting requests or not. |
+ bool accepting_requests_ = true; |
+ |
+ // The default country code to use if a profile does not have a valid country. |
+ const std::string default_country_code_; |
+ |
+ // The callback to execute when all addresses have been normalized. |
+ base::OnceClosure completion_callback_; |
+ |
+ // Storage for all the delegates that handle the normalization requests. |
+ std::vector<std::unique_ptr<NormalizerDelegate>> delegates_; |
+ |
+ // The AddressNormalizer to use. Owned by this class. |
+ std::unique_ptr<AddressNormalizer> address_normalizer_; |
+ |
+ THREAD_CHECKER(thread_checker_); |
+ DISALLOW_COPY_AND_ASSIGN(AddressNormalizationManager); |
+}; |
+ |
+} // namespace payments |
+ |
+#endif // COMPONENTS_PAYMENTS_CORE_ADDRESS_NORMALIZATION_MANAGER_H_ |