Chromium Code Reviews| Index: third_party/libaddressinput/chromium/preload_address_validator.cc |
| diff --git a/third_party/libaddressinput/chromium/preload_address_validator.cc b/third_party/libaddressinput/chromium/preload_address_validator.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e1fb647ee795f0d1ec3234258b398f34cfffe3e4 |
| --- /dev/null |
| +++ b/third_party/libaddressinput/chromium/preload_address_validator.cc |
| @@ -0,0 +1,121 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <cstddef> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/scoped_ptr.h" |
| + |
| +#define I18N_ADDRESSINPUT_UTIL_BASICTYPES_H_ |
| +#include "third_party/libaddressinput/chromium/preload_address_validator.h" |
| +#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h" |
| +#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_validator.h" |
| +#include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h" |
| +#include "third_party/libaddressinput/src/cpp/include/libaddressinput/downloader.h" |
| +#include "third_party/libaddressinput/src/cpp/include/libaddressinput/preload_supplier.h" |
| +#include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h" |
| + |
| +namespace autofill { |
| + |
| +using ::i18n::addressinput::AddressData; |
| +using ::i18n::addressinput::AddressField; |
| +using ::i18n::addressinput::AddressValidator; |
| +using ::i18n::addressinput::BuildCallback; |
| +using ::i18n::addressinput::Downloader; |
| +using ::i18n::addressinput::FieldProblemMap; |
| +using ::i18n::addressinput::PreloadSupplier; |
| +using ::i18n::addressinput::Storage; |
| + |
| +PreloadAddressValidator::PreloadAddressValidator( |
| + scoped_ptr<Downloader> downloader, |
| + scoped_ptr<Storage> storage) |
| + : supplier_( |
| + new PreloadSupplier( |
| + I18N_ADDRESS_VALIDATION_DATA_URL, |
| + downloader.release(), |
| + storage.release())), |
| + validator_( |
| + new AddressValidator( |
| + supplier_.get())), |
| + validated_(BuildCallback(this, &PreloadAddressValidator::Validated)) { |
| +} |
| + |
| +PreloadAddressValidator::PreloadAddressValidator( |
| + const std::string& validation_data_url, |
| + scoped_ptr<Downloader> downloader, |
| + scoped_ptr<Storage> storage) |
| + : supplier_( |
| + new PreloadSupplier( |
| + validation_data_url, |
| + downloader.release(), |
| + storage.release())), |
| + validator_( |
| + new AddressValidator( |
| + supplier_.get())), |
| + validated_(BuildCallback(this, &PreloadAddressValidator::Validated)) { |
| +} |
| + |
| +PreloadAddressValidator::~PreloadAddressValidator() { |
| +} |
| + |
| +void PreloadAddressValidator::LoadRules(const std::string& region_code, |
| + const Callback& loaded) { |
| + assert(supplier_ != NULL); |
| + supplier_->LoadRules(region_code, loaded); |
| +} |
| + |
| +PreloadAddressValidator::Status PreloadAddressValidator::Validate( |
| + const AddressData& address, |
| + const FieldProblemMap* filter, |
| + FieldProblemMap* problems) const { |
| + assert(supplier_ != NULL); |
| + assert(validator_ != NULL); |
| + |
| + if (supplier_->IsPending(address.region_code)) { |
| + return RULES_NOT_READY; |
| + } |
| + |
| + if (!supplier_->IsLoaded(address.region_code)) { |
| + return RULES_UNAVAILABLE; |
| + } |
| + |
| + validator_->Validate( |
| + address, |
| + /*allow_postal*/ false, |
| + /*require_name*/ false, |
| + filter, |
| + problems, |
| + *validated_); |
| + |
| + return SUCCESS; |
| +} |
| + |
| +PreloadAddressValidator::Status PreloadAddressValidator::GetSuggestions( |
| + const AddressData& user_input, |
| + AddressField focused_field, |
| + size_t suggestion_limit, |
| + std::vector<AddressData>* suggestions) const { |
| + // Stub implementation. TODO: Implement! ;-) |
|
please use gerrit instead
2014/05/23 14:44:54
Need the suggestions implementation from Rouslan.
|
| + return RULES_UNAVAILABLE; |
| +} |
| + |
| +bool PreloadAddressValidator::CanonicalizeAdministrativeArea( |
| + AddressData* address_data) const { |
| + // Stub implementation. TODO: Implement! ;-) |
|
please use gerrit instead
2014/05/23 14:44:54
Need the synonym implementation from Rouslan.
|
| + return RULES_UNAVAILABLE; |
| +} |
| + |
| +void PreloadAddressValidator::Validated(bool success, |
| + const AddressData&, |
| + const FieldProblemMap&) { |
| + assert(success); |
| +} |
| + |
| +// Stub constructor for use by MockAddressValidator. |
| +PreloadAddressValidator::PreloadAddressValidator() { |
| +} |
| + |
| +} // namespace autofill |