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_SUBKEY_REQUESTER_H_ | |
6 #define COMPONENTS_PAYMENTS_CORE_SUBKEY_REQUESTER_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" | |
10 | |
11 namespace payments { | |
12 | |
13 // SubKeyRequester Loads Rules from the server and extracts the subkeys. | |
14 // For a given key (region code for a country, such as US), the list of its | |
15 // corresponding subkeys is the list of that countries admin areas (states, | |
16 // provinces, ..). | |
17 class SubKeyRequester : public autofill::LoadRulesListener { | |
18 public: | |
19 // The interface for the subkey request. | |
20 class Request { | |
21 public: | |
22 virtual void OnRulesLoaded() = 0; | |
23 virtual ~Request() {} | |
24 }; | |
25 | |
26 SubKeyRequester(std::unique_ptr<i18n::addressinput::Source> source, | |
27 std::unique_ptr<i18n::addressinput::Storage> storage); | |
28 ~SubKeyRequester() override; | |
29 | |
30 // If the rules for |region_code| are loaded, this gets the subkeys for the | |
31 // |region_code|, synchronously. If they are not loaded yet, it sets up a | |
32 // task to get the subkeys when the rules are loaded (asynchronous). If the | |
33 // loading has not yet started, it will also start loading the rules for the | |
34 // |region_code|. The received subkeys will be returned to the |requester|. If | |
35 // the subkeys are not received in |timeout_seconds|, then the requester will | |
36 // be informed and the request will be canceled. |requester| should never be | |
37 // null. | |
38 void StartRegionSubKeysRequest( | |
39 const std::string& region_code, | |
40 int timeout_seconds, | |
41 base::OnceCallback<void(std::vector<std::string>)> cb); | |
David Trainor- moved to gerrit
2017/05/23 21:03:59
Why not const & on the vector? If it doesn't work
Parastoo
2017/05/24 14:57:20
Done.
| |
42 | |
43 // Returns whether the rules for the specified |region_code| have finished | |
44 // loading. | |
45 bool AreRulesLoadedForRegion(const std::string& region_code); | |
46 | |
47 // Start loading the rules for the specified |region_code|. | |
48 virtual void LoadRulesForRegion(const std::string& region_code); | |
49 | |
50 // Cancels the pending subkey request task. | |
51 void CancelPendingGetSubKeys(); | |
52 | |
53 private: | |
54 // Called when the address rules for the |region_code| have finished | |
55 // loading. Implementation of the LoadRulesListener interface. | |
56 void OnAddressValidationRulesLoaded(const std::string& region_code, | |
57 bool success) override; | |
58 | |
59 // The region code and the request for the pending subkey request. | |
60 std::unique_ptr<Request> pending_subkey_request_; | |
61 std::string pending_subkey_region_code_; | |
62 | |
63 // The address validator used to load subkeys. | |
64 autofill::AddressValidator address_validator_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(SubKeyRequester); | |
67 }; | |
68 | |
69 } // namespace payments | |
70 | |
71 #endif // COMPONENTS_PAYMENTS_CORE_SUBKEY_REQUESTER_H_ | |
OLD | NEW |