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

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

Issue 2879853003: [Payments] Code Refactoring for the Subkey Request (Closed)
Patch Set: requester not null 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
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 // 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 delegates.
20 class Delegate {
21 public:
22 virtual void OnSubKeysReceived(std::vector<std::string> sub_keys) = 0;
23 virtual ~Delegate() {}
24 };
25
26 // The interface for the subkey request.
27 class Request {
28 public:
29 virtual void OnRulesLoaded() = 0;
30 virtual ~Request() {}
31 };
32
33 SubKeyRequester(std::unique_ptr<i18n::addressinput::Source> source,
34 std::unique_ptr<i18n::addressinput::Storage> storage);
35 ~SubKeyRequester() override;
36
37 // If the rules for |region_code| are loaded, this gets the subkeys for the
38 // |region_code|, synchronously. If they are not loaded yet, it sets up a
39 // task to get the subkeys when the rules are loaded (asynchronous). If the
40 // loading has not yet started, it will also start loading the rules for the
41 // |region_code|. The received subkeys will be returned to the |requester|. If
42 // the subkeys are not received in |timeout_seconds|, then the requester will
43 // be informed and the request will be canceled. |requester| should never be
44 // null.
45 void StartRegionSubKeysRequest(const std::string& region_code,
46 int timeout_seconds,
47 Delegate* requester);
48
49 // Returns whether the rules for the specified |region_code| have finished
50 // loading.
51 bool AreRulesLoadedForRegion(const std::string& region_code);
52
53 // Start loading the rules for the specified |region_code|.
54 virtual void LoadRulesForRegion(const std::string& region_code);
55
56 // Cancels the pending subkey request task.
57 void CancelPendingGetSubKeys();
58
59 private:
60 // Called when the address rules for the |region_code| have finished
61 // loading. Implementation of the LoadRulesListener interface.
62 void OnAddressValidationRulesLoaded(const std::string& region_code,
63 bool success) override;
64
65 // The region code and the request for the pending subkey request.
66 std::unique_ptr<Request> pending_subkey_request_;
67 std::string pending_subkey_region_code_;
68
69 // The address validator used to load subkeys.
70 autofill::AddressValidator address_validator_;
71
72 DISALLOW_COPY_AND_ASSIGN(SubKeyRequester);
73 };
74
75 } // namespace payments
76
77 #endif // COMPONENTS_PAYMENTS_CORE_SUBKEY_REQUESTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698