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..e9ca1565ae69466598391d1cf269b1ae2e07efa1 |
--- /dev/null |
+++ b/components/payments/core/address_normalization_manager.h |
@@ -0,0 +1,80 @@ |
+// 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: |
+ // Callback that is called when all the address normalization requests have |
+ // completed. |
+ using CompletionCallback = |
+ base::OnceCallback<void(const AddressNormalizationManager&)>; |
Mathieu
2017/05/17 16:45:14
can this be a base::OnceClosure()? If so, perhaps
macourteau
2017/05/17 18:38:40
Done.
|
+ |
+ // 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, |
Mathieu
2017/05/17 16:45:14
can we remove the std::unique_ptr?
macourteau
2017/05/17 18:38:40
The alternative would be for the caller to own the
|
+ 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. |
Mathieu
2017/05/17 16:45:14
you should mention how to get the normalized addre
macourteau
2017/05/17 18:38:40
This is mentioned in the documentation for StartNo
|
+ void FinalizeWithCompletionCallback(CompletionCallback 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); |
+ |
+ private: |
+ class NormalizerDelegate; |
Mathieu
2017/05/17 16:45:14
why not declare the whole class here?
macourteau
2017/05/17 18:38:40
Figured it was an implementation detail, and users
Mathieu
2017/05/17 19:47:33
Yeah, I don't see this pattern a lot so I would pr
macourteau
2017/05/17 19:52:04
Done.
|
+ 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. |
+ std::string default_country_code_; |
Mathieu
2017/05/17 16:45:14
nit: const?
macourteau
2017/05/17 18:38:40
Done.
|
+ |
+ // The callback to execute when all addresses have been normalized. |
+ CompletionCallback 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_ |