Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 std::vector<std::pair<std::string, std::string>> subkeys_codes_names; | |
| 65 if (!AreRulesLoadedForRegion(region_code)) | 66 if (!AreRulesLoadedForRegion(region_code)) |
| 66 return std::vector<std::string>(); | 67 return subkeys_codes_names; |
| 67 | 68 |
| 68 auto rules = supplier_->GetRulesForRegion(region_code); | 69 auto rules = supplier_->GetRulesForRegion(region_code); |
| 69 auto rule_iterator = rules.find("data/" + region_code); | |
| 70 | 70 |
| 71 if (rule_iterator == rules.end() || !rule_iterator->second) | 71 std::string code_prefix = "data/" + region_code + "/"; |
| 72 return std::vector<std::string>(); | 72 size_t code_prefix_size = code_prefix.size(); |
|
Mathieu
2017/07/05 16:07:15
nit: code_prefix_size = region_code.size() + 6;
Parastoo
2017/07/07 15:53:23
Done.
| |
| 73 | 73 |
| 74 return rule_iterator->second->GetSubKeys(); | 74 for (auto r : rules) { |
| 75 if (r.first.size() <= code_prefix_size) | |
|
Mathieu
2017/07/05 16:07:15
Could we get in a situation where the key is data/
Parastoo
2017/07/07 15:53:23
Done.
| |
| 76 continue; | |
| 77 subkeys_codes_names.push_back( | |
| 78 std::make_pair(r.first.substr(code_prefix_size), r.second->GetName())); | |
| 79 } | |
| 80 return subkeys_codes_names; | |
| 75 } | 81 } |
| 76 | 82 |
| 77 AddressValidator::Status AddressValidator::ValidateAddress( | 83 AddressValidator::Status AddressValidator::ValidateAddress( |
| 78 const AddressData& address, | 84 const AddressData& address, |
| 79 const FieldProblemMap* filter, | 85 const FieldProblemMap* filter, |
| 80 FieldProblemMap* problems) const { | 86 FieldProblemMap* problems) const { |
| 81 if (supplier_->IsPending(address.region_code)) { | 87 if (supplier_->IsPending(address.region_code)) { |
| 82 if (problems) | 88 if (problems) |
| 83 addressinput::ValidateRequiredFields(address, filter, problems); | 89 addressinput::ValidateRequiredFields(address, filter, problems); |
| 84 return RULES_NOT_READY; | 90 return RULES_NOT_READY; |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 weak_factory_.GetWeakPtr(), region_code), | 174 weak_factory_.GetWeakPtr(), region_code), |
| 169 GetBaseRetryPeriod() * pow(2, attempts_number_[region_code]++)); | 175 GetBaseRetryPeriod() * pow(2, attempts_number_[region_code]++)); |
| 170 } | 176 } |
| 171 | 177 |
| 172 void AddressValidator::RetryLoadRules(const std::string& region_code) { | 178 void AddressValidator::RetryLoadRules(const std::string& region_code) { |
| 173 // Do not reset retry count. | 179 // Do not reset retry count. |
| 174 supplier_->LoadRules(region_code, *rules_loaded_); | 180 supplier_->LoadRules(region_code, *rules_loaded_); |
| 175 } | 181 } |
| 176 | 182 |
| 177 } // namespace autofill | 183 } // namespace autofill |
| OLD | NEW |