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

Side by Side Diff: components/payments/address_normalizer.h

Issue 2713033004: Layered component for web payments (Closed)
Patch Set: Rebase Created 3 years, 9 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/OWNERS ('k') | components/payments/address_normalizer.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_ADDRESS_NORMALIZER_H_
6 #define COMPONENTS_PAYMENTS_ADDRESS_NORMALIZER_H_
7
8 #include "base/macros.h"
9 #include "components/autofill/core/browser/autofill_profile.h"
10 #include "third_party/libaddressinput/chromium/chrome_address_validator.h"
11
12 using autofill::AutofillProfile;
13
14 namespace payments {
15
16 // A class used to normalize addresses.
17 class AddressNormalizer : public autofill::LoadRulesListener {
18 public:
19 // The interface for the normalization delegates.
20 class Delegate {
21 public:
22 virtual void OnAddressNormalized(
23 const autofill::AutofillProfile& normalized_profile) = 0;
24
25 virtual void OnCouldNotNormalize(
26 const autofill::AutofillProfile& profile) = 0;
27
28 protected:
29 virtual ~Delegate() {}
30 };
31
32 // The interface for the normalization request.
33 class Request {
34 public:
35 virtual void OnRulesLoaded(bool success) = 0;
36 virtual ~Request() {}
37 };
38
39 AddressNormalizer(std::unique_ptr<i18n::addressinput::Source> source,
40 std::unique_ptr<i18n::addressinput::Storage> storage);
41 ~AddressNormalizer() override;
42
43 // Start loading the validation rules for the specified |region_code|.
44 virtual void LoadRulesForRegion(const std::string& region_code);
45
46 // Returns whether the rules for the specified |region_code| have finished
47 // loading.
48 bool AreRulesLoadedForRegion(const std::string& region_code);
49
50 // Starts the normalization of the |profile| based on the |region_code|. The
51 // normalized profile will be returned to the |requester| possibly
52 // asynchronously. If the normalization is not completed in |timeout_seconds|
53 // the requester will be informed and the request cancelled. This value should
54 // be greater or equal to 0, for which it means that the normalization should
55 // happen synchronously, or not at all if the rules are not already loaded.
56 // Will start loading the rules for the |region_code| if they had not started
57 // loading.
58 void StartAddressNormalization(const autofill::AutofillProfile& profile,
59 const std::string& region_code,
60 int timeout_seconds,
61 Delegate* requester);
62
63 private:
64 // Called when the validation rules for the |region_code| have finished
65 // loading. Implementation of the LoadRulesListener interface.
66 void OnAddressValidationRulesLoaded(const std::string& region_code,
67 bool success) override;
68
69 // Map associating a region code to pending normalizations.
70 std::map<std::string, std::vector<std::unique_ptr<Request>>>
71 pending_normalization_;
72
73 // The address validator used to normalize addresses.
74 autofill::AddressValidator address_validator_;
75
76 DISALLOW_COPY_AND_ASSIGN(AddressNormalizer);
77 };
78
79 } // namespace payments
80
81 #endif // COMPONENTS_PAYMENTS_ADDRESS_NORMALIZER_H_
OLDNEW
« no previous file with comments | « components/payments/OWNERS ('k') | components/payments/address_normalizer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698