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

Side by Side Diff: third_party/libaddressinput/chromium/chrome_address_validator.cc

Issue 2966103002: [Payments] Show admin area complete names on PR form. (Closed)
Patch Set: Show the name in the appropriate language. Created 3 years, 5 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #include "third_party/libaddressinput/chromium/chrome_address_validator.h" 5 #include "third_party/libaddressinput/chromium/chrome_address_validator.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 load_rules_listener_(load_rules_listener), 53 load_rules_listener_(load_rules_listener),
54 weak_factory_(this) {} 54 weak_factory_(this) {}
55 55
56 AddressValidator::~AddressValidator() {} 56 AddressValidator::~AddressValidator() {}
57 57
58 void AddressValidator::LoadRules(const std::string& region_code) { 58 void AddressValidator::LoadRules(const std::string& region_code) {
59 attempts_number_[region_code] = 0; 59 attempts_number_[region_code] = 0;
60 supplier_->LoadRules(region_code, *rules_loaded_); 60 supplier_->LoadRules(region_code, *rules_loaded_);
61 } 61 }
62 62
63 std::vector<std::string> AddressValidator::GetRegionSubKeys( 63 std::vector<std::pair<std::string, std::string>>
64 const std::string& region_code) { 64 AddressValidator::GetRegionSubKeys(const std::string& region_code,
65 const std::string& language) {
66 std::vector<std::pair<std::string, std::string>> subkeys_codes_names;
65 if (!AreRulesLoadedForRegion(region_code)) 67 if (!AreRulesLoadedForRegion(region_code))
66 return std::vector<std::string>(); 68 return subkeys_codes_names;
67 69
68 auto rules = supplier_->GetRulesForRegion(region_code); 70 auto rules = supplier_->GetRulesForRegion(region_code);
69 auto rule_iterator = rules.find("data/" + region_code); 71 auto rule_iterator = rules.find("data/" + region_code);
72 // this should never happen
Mathieu 2017/07/07 13:10:02 nit: Please add capital letters to sentences and e
Parastoo 2017/07/07 15:53:24 Done.
73 if (rule_iterator == rules.end() || !rule_iterator->second)
Mathieu 2017/07/07 13:10:02 Can this happen if the rules on the server are bad
Parastoo 2017/07/07 15:53:23 Yes, this can happen if the rules are bad, or not
74 return subkeys_codes_names;
70 75
71 if (rule_iterator == rules.end() || !rule_iterator->second) 76 auto subkeys_codes = rule_iterator->second->GetSubKeys();
72 return std::vector<std::string>();
73 77
74 return rule_iterator->second->GetSubKeys(); 78 // if the device language is available, show the names in that language.
79 // Otherwise, show the default names.
80 std::string lang_suffix = "";
81 if (rules.find("data/" + region_code + "--" + language) != rules.end())
82 lang_suffix = "--" + language; // exp: --fr
Mathieu 2017/07/07 13:10:02 exp -> ex:
Parastoo 2017/07/07 15:53:23 Done.
83
84 for (auto subkey_code : subkeys_codes) {
85 auto rule = rules.find("data/" + region_code + '/' + subkey_code +
86 lang_suffix); // exp: data/CA/QC--fr
87 // this should never happen
88 if (rule == rules.end() || !rule_iterator->second)
89 continue;
90 auto subkey_name = rule->second->GetName();
91 if (subkey_name.empty()) // For some cases, the name is not available.
92 subkey_name = subkey_code;
93 subkeys_codes_names.push_back(make_pair(subkey_code, subkey_name));
94 }
95 return subkeys_codes_names;
75 } 96 }
76 97
77 AddressValidator::Status AddressValidator::ValidateAddress( 98 AddressValidator::Status AddressValidator::ValidateAddress(
78 const AddressData& address, 99 const AddressData& address,
79 const FieldProblemMap* filter, 100 const FieldProblemMap* filter,
80 FieldProblemMap* problems) const { 101 FieldProblemMap* problems) const {
81 if (supplier_->IsPending(address.region_code)) { 102 if (supplier_->IsPending(address.region_code)) {
82 if (problems) 103 if (problems)
83 addressinput::ValidateRequiredFields(address, filter, problems); 104 addressinput::ValidateRequiredFields(address, filter, problems);
84 return RULES_NOT_READY; 105 return RULES_NOT_READY;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 weak_factory_.GetWeakPtr(), region_code), 189 weak_factory_.GetWeakPtr(), region_code),
169 GetBaseRetryPeriod() * pow(2, attempts_number_[region_code]++)); 190 GetBaseRetryPeriod() * pow(2, attempts_number_[region_code]++));
170 } 191 }
171 192
172 void AddressValidator::RetryLoadRules(const std::string& region_code) { 193 void AddressValidator::RetryLoadRules(const std::string& region_code) {
173 // Do not reset retry count. 194 // Do not reset retry count.
174 supplier_->LoadRules(region_code, *rules_loaded_); 195 supplier_->LoadRules(region_code, *rules_loaded_);
175 } 196 }
176 197
177 } // namespace autofill 198 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698