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

Unified Diff: third_party/libaddressinput/chromium/preload_address_validator.cc

Issue 389733002: Reland "Use upstream libaddressinput in Chrome." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix GN build. Created 6 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 side-by-side diff with in-line comments
Download patch
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
deleted file mode 100644
index 816e3a5d522702e1ee041d3e33ab866dc4256185..0000000000000000000000000000000000000000
--- a/third_party/libaddressinput/chromium/preload_address_validator.cc
+++ /dev/null
@@ -1,144 +0,0 @@
-// 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/chromium/suggestions.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"
-#include "third_party/libaddressinput/src/cpp/include/libaddressinput/synonyms.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;
-using ::i18n::addressinput::Synonyms;
-
-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())),
- suggestions_(
- new Suggestions(
- supplier_.get())),
- synonyms_(
- new Synonyms(
- supplier_.get())),
- 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 {
- assert(suggestions_ != NULL);
- assert(supplier_ != NULL);
-
- if (supplier_->IsPending(user_input.region_code)) {
- return RULES_NOT_READY;
- }
-
- if (!supplier_->IsLoaded(user_input.region_code)) {
- return RULES_UNAVAILABLE;
- }
-
- suggestions_->GetSuggestions(
- user_input,
- focused_field,
- suggestion_limit,
- suggestions);
-
- return SUCCESS;
-}
-
-bool PreloadAddressValidator::CanonicalizeAdministrativeArea(
- AddressData* address) const {
- assert(address != NULL);
- assert(supplier_ != NULL);
- assert(synonyms_ != NULL);
-
- if (!supplier_->IsLoaded(address->region_code)) {
- return false;
- }
-
- // TODO: It would probably be beneficial to use the full canonicalization.
- AddressData tmp(*address);
- synonyms_->NormalizeForDisplay(&tmp);
- address->administrative_area = tmp.administrative_area;
-
- return true;
-}
-
-void PreloadAddressValidator::Validated(bool success,
- const AddressData&,
- const FieldProblemMap&) {
- assert(success);
-}
-
-// Stub constructor for use by MockAddressValidator.
-PreloadAddressValidator::PreloadAddressValidator() {
-}
-
-} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698