Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: components/payments/core/subkey_requester.h

Issue 2879853003: [Payments] Code Refactoring for the Subkey Request (Closed)
Patch Set: Final nit Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/payments/core/BUILD.gn ('k') | components/payments/core/subkey_requester.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 using SubKeyReceiverCallback =
14 base::OnceCallback<void(const std::vector<std::string>&)>;
15
16 // 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 // corresponding subkeys is the list of that countries admin areas (states,
19 // provinces, ..).
20 class SubKeyRequester : public autofill::LoadRulesListener {
21 public:
22 // The interface for the subkey request.
23 class Request {
24 public:
25 virtual void OnRulesLoaded() = 0;
26 virtual ~Request() {}
27 };
28
29 SubKeyRequester(std::unique_ptr<i18n::addressinput::Source> source,
30 std::unique_ptr<i18n::addressinput::Storage> storage);
31 ~SubKeyRequester() override;
32
33 // 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 // 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 // |region_code|. The received subkeys will be returned to the |requester|. If
38 // 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 // null.
41 void StartRegionSubKeysRequest(const std::string& region_code,
42 int timeout_seconds,
43 SubKeyReceiverCallback cb);
44
45 // Returns whether the rules for the specified |region_code| have finished
46 // loading.
47 bool AreRulesLoadedForRegion(const std::string& region_code);
48
49 // Start loading the rules for the specified |region_code|.
50 virtual void LoadRulesForRegion(const std::string& region_code);
51
52 // Cancels the pending subkey request task.
53 void CancelPendingGetSubKeys();
54
55 private:
56 // Called when the address rules for the |region_code| have finished
57 // loading. Implementation of the LoadRulesListener interface.
58 void OnAddressValidationRulesLoaded(const std::string& region_code,
59 bool success) override;
60
61 // The region code and the request for the pending subkey request.
62 std::unique_ptr<Request> pending_subkey_request_;
63 std::string pending_subkey_region_code_;
64
65 // The address validator used to load subkeys.
66 autofill::AddressValidator address_validator_;
67
68 DISALLOW_COPY_AND_ASSIGN(SubKeyRequester);
69 };
70
71 } // namespace payments
72
73 #endif // COMPONENTS_PAYMENTS_CORE_SUBKEY_REQUESTER_H_
OLDNEW
« no previous file with comments | « components/payments/core/BUILD.gn ('k') | components/payments/core/subkey_requester.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698