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 // Callback that is called when all the address normalization requests have | |
28 // completed. | |
29 using CompletionCallback = | |
30 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.
| |
31 | |
32 // Initializes an AddressNormalizationManager. |default_country_code| will be | |
33 // used if the country code in an AutofillProfile to normalize is not valid. | |
34 // The AddressNormalizationManager takes ownership of |address_normalizer|. | |
35 AddressNormalizationManager( | |
36 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
| |
37 const std::string& default_country_code); | |
38 | |
39 ~AddressNormalizationManager(); | |
40 | |
41 // Stops accepting normalization requests. If all the address normalization | |
42 // requests have already completed, |completion_callback| will be called | |
43 // before this method returns. Otherwise, it will be called as soon as the | |
44 // 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
| |
45 void FinalizeWithCompletionCallback(CompletionCallback completion_callback); | |
46 | |
47 // Normalizes the address in |profile|. This may or may not happen | |
48 // asynchronously. On completion, the address in |profile| will be updated | |
49 // with the normalized address. | |
50 void StartNormalizingAddress(autofill::AutofillProfile* profile); | |
51 | |
52 private: | |
53 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.
| |
54 friend class NormalizerDelegate; | |
55 | |
56 // Runs the completion callback if all the delegates have completed. | |
57 void MaybeRunCompletionCallback(); | |
58 | |
59 // Whether the AddressNormalizationManager is still accepting requests or not. | |
60 bool accepting_requests_ = true; | |
61 | |
62 // The default country code to use if a profile does not have a valid country. | |
63 std::string default_country_code_; | |
Mathieu
2017/05/17 16:45:14
nit: const?
macourteau
2017/05/17 18:38:40
Done.
| |
64 | |
65 // The callback to execute when all addresses have been normalized. | |
66 CompletionCallback completion_callback_; | |
67 | |
68 // Storage for all the delegates that handle the normalization requests. | |
69 std::vector<std::unique_ptr<NormalizerDelegate>> delegates_; | |
70 | |
71 // The AddressNormalizer to use. Owned by this class. | |
72 std::unique_ptr<AddressNormalizer> address_normalizer_; | |
73 | |
74 THREAD_CHECKER(thread_checker_); | |
75 DISALLOW_COPY_AND_ASSIGN(AddressNormalizationManager); | |
76 }; | |
77 | |
78 } // namespace payments | |
79 | |
80 #endif // COMPONENTS_PAYMENTS_CORE_ADDRESS_NORMALIZATION_MANAGER_H_ | |
OLD | NEW |