OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_PAYMENTS_CORE_SUBKEY_REQUESTER_H_ | 5 #ifndef COMPONENTS_PAYMENTS_CORE_SUBKEY_REQUESTER_H_ |
6 #define COMPONENTS_PAYMENTS_CORE_SUBKEY_REQUESTER_H_ | 6 #define COMPONENTS_PAYMENTS_CORE_SUBKEY_REQUESTER_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" | 9 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" |
10 | 10 |
11 namespace payments { | 11 namespace payments { |
12 | 12 |
13 using SubKeyReceiverCallback = | 13 using SubKeyReceiverCallback = |
14 base::OnceCallback<void(const std::vector<std::string>&)>; | 14 base::OnceCallback<void(const std::vector<std::string>&, |
15 const std::vector<std::string>&)>; | |
15 | 16 |
16 // SubKeyRequester Loads Rules from the server and extracts the subkeys. | 17 // SubKeyRequester Loads Rules from the server and extracts the subkeys. |
17 // For a given key (region code for a country, such as US), the list of its | 18 // For a given key (region code for a country, such as US), the list of its |
18 // corresponding subkeys is the list of that countries admin areas (states, | 19 // corresponding subkeys is the list of that countries admin areas (states, |
19 // provinces, ..). | 20 // provinces, ..). |
20 class SubKeyRequester : public autofill::LoadRulesListener { | 21 class SubKeyRequester : public autofill::LoadRulesListener { |
21 public: | 22 public: |
22 // The interface for the subkey request. | 23 // The interface for the subkey request. |
23 class Request { | 24 class Request { |
24 public: | 25 public: |
25 virtual void OnRulesLoaded() = 0; | 26 virtual void OnRulesLoaded() = 0; |
26 virtual ~Request() {} | 27 virtual ~Request() {} |
27 }; | 28 }; |
28 | 29 |
29 SubKeyRequester(std::unique_ptr<i18n::addressinput::Source> source, | 30 SubKeyRequester(std::unique_ptr<i18n::addressinput::Source> source, |
30 std::unique_ptr<i18n::addressinput::Storage> storage); | 31 std::unique_ptr<i18n::addressinput::Storage> storage); |
31 ~SubKeyRequester() override; | 32 ~SubKeyRequester() override; |
32 | 33 |
33 // If the rules for |region_code| are loaded, this gets the subkeys for the | 34 // If the rules for |region_code| are loaded, this gets the subkeys for the |
34 // |region_code|, synchronously. If they are not loaded yet, it sets up a | 35 // |region_code|, synchronously. If they are not loaded yet, it sets up a |
35 // task to get the subkeys when the rules are loaded (asynchronous). If the | 36 // task to get the subkeys when the rules are loaded (asynchronous). If the |
36 // loading has not yet started, it will also start loading the rules for the | 37 // loading has not yet started, it will also start loading the rules for the |
37 // |region_code|. The received subkeys will be returned to the |requester|. If | 38 // |region_code|. The received subkeys will be returned to the |requester|. If |
Mathieu
2017/07/07 13:10:01
add a comment about the format of |language| (or a
Parastoo
2017/07/07 15:53:23
Done.
| |
38 // the subkeys are not received in |timeout_seconds|, then the requester will | 39 // the subkeys are not received in |timeout_seconds|, then the requester will |
39 // be informed and the request will be canceled. |requester| should never be | 40 // be informed and the request will be canceled. |requester| should never be |
40 // null. | 41 // null. |
41 void StartRegionSubKeysRequest(const std::string& region_code, | 42 void StartRegionSubKeysRequest(const std::string& region_code, |
43 const std::string& language, | |
42 int timeout_seconds, | 44 int timeout_seconds, |
43 SubKeyReceiverCallback cb); | 45 SubKeyReceiverCallback cb); |
44 | 46 |
45 // Returns whether the rules for the specified |region_code| have finished | 47 // Returns whether the rules for the specified |region_code| have finished |
46 // loading. | 48 // loading. |
47 bool AreRulesLoadedForRegion(const std::string& region_code); | 49 bool AreRulesLoadedForRegion(const std::string& region_code); |
48 | 50 |
49 // Start loading the rules for the specified |region_code|. | 51 // Start loading the rules for the specified |region_code|. |
50 virtual void LoadRulesForRegion(const std::string& region_code); | 52 virtual void LoadRulesForRegion(const std::string& region_code); |
51 | 53 |
(...skipping 12 matching lines...) Expand all Loading... | |
64 | 66 |
65 // The address validator used to load subkeys. | 67 // The address validator used to load subkeys. |
66 autofill::AddressValidator address_validator_; | 68 autofill::AddressValidator address_validator_; |
67 | 69 |
68 DISALLOW_COPY_AND_ASSIGN(SubKeyRequester); | 70 DISALLOW_COPY_AND_ASSIGN(SubKeyRequester); |
69 }; | 71 }; |
70 | 72 |
71 } // namespace payments | 73 } // namespace payments |
72 | 74 |
73 #endif // COMPONENTS_PAYMENTS_CORE_SUBKEY_REQUESTER_H_ | 75 #endif // COMPONENTS_PAYMENTS_CORE_SUBKEY_REQUESTER_H_ |
OLD | NEW |