Index: third_party/libaddressinput/chromium/preload_address_validator.h |
diff --git a/third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h b/third_party/libaddressinput/chromium/preload_address_validator.h |
similarity index 39% |
copy from third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h |
copy to third_party/libaddressinput/chromium/preload_address_validator.h |
index a9285f2f73c8b537cd6940bc69cc5a7d0f0fee49..8b22040b912a95e5bbb60569bb6f160855d0a039 100644 |
--- a/third_party/libaddressinput/chromium/cpp/include/libaddressinput/address_validator.h |
+++ b/third_party/libaddressinput/chromium/preload_address_validator.h |
@@ -1,75 +1,41 @@ |
-// Copyright (C) 2013 Google Inc. |
-// |
-// Licensed under the Apache License, Version 2.0 (the "License"); |
-// you may not use this file except in compliance with the License. |
-// You may obtain a copy of the License at |
-// |
-// http://www.apache.org/licenses/LICENSE-2.0 |
-// |
-// Unless required by applicable law or agreed to in writing, software |
-// distributed under the License is distributed on an "AS IS" BASIS, |
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
-// See the License for the specific language governing permissions and |
-// limitations under the License. |
+// 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. |
-#ifndef I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_ |
-#define I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_ |
+#ifndef THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_PRELOAD_ADDRESS_VALIDATOR_H_ |
+#define THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_PRELOAD_ADDRESS_VALIDATOR_H_ |
-#include <libaddressinput/address_field.h> |
-#include <libaddressinput/address_problem.h> |
-#include <libaddressinput/util/scoped_ptr.h> |
- |
-#include <map> |
+#include <cstddef> |
#include <string> |
#include <vector> |
+#include "base/macros.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_field.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_validator.h" |
+#include "third_party/libaddressinput/src/cpp/include/libaddressinput/callback.h" |
+ |
namespace i18n { |
namespace addressinput { |
class Downloader; |
-class LoadRulesDelegate; |
+class PreloadSupplier; |
class Storage; |
+class Synonyms; |
struct AddressData; |
-typedef std::vector<AddressProblem> AddressProblems; |
-typedef std::multimap<AddressField, AddressProblem::Type> AddressProblemFilter; |
+} // namespace addressinput |
+} // namespace i18n |
-// Validates an AddressData structure. Sample usage: |
-// class MyClass : public LoadRulesDelegate { |
-// public: |
-// MyClass() : validator_(AddressValidator::Build( |
-// scoped_ptr<Downloader>(new MyDownloader), |
-// scoped_ptr<Storage>(new MyStorage), |
-// this)) { |
-// validator_->LoadRules("US"); |
-// } |
-// |
-// virtual ~MyClass() {} |
-// |
-// virtual void OnAddressValidationRulesLoaded( |
-// const std::string& country_code, |
-// bool success) { |
-// ... |
-// } |
-// |
-// void ValidateAddress() { |
-// AddressData address; |
-// address.country_code = "US"; |
-// address.administrative_area = "CA"; |
-// AddressProblems problems; |
-// AddressProblemFilter filter; |
-// AddressValidator::Status status = |
-// validator_->ValidateAddress(address, filter, &problems); |
-// if (status == AddressValidator::SUCCESS) { |
-// Process(problems); |
-// } |
-// } |
-// |
-// private: |
-// scoped_ptr<AddressValidator> validator_; |
-// }; |
-class AddressValidator { |
+namespace autofill { |
+ |
+class Suggestions; |
+ |
+// Interface to the libaddressinput AddressValidator for Chromium Autofill. |
+class PreloadAddressValidator { |
public: |
+ typedef ::i18n::addressinput::Callback<std::string, int> Callback; |
+ |
// The status of address validation. |
enum Status { |
// Address validation completed successfully. Check |problems| to see if any |
@@ -84,28 +50,26 @@ class AddressValidator { |
RULES_NOT_READY |
}; |
- virtual ~AddressValidator(); |
+ // Takes ownership of |downloader| and |storage|. |
+ PreloadAddressValidator( |
+ const std::string& validation_data_url, |
+ scoped_ptr< ::i18n::addressinput::Downloader> downloader, |
+ scoped_ptr< ::i18n::addressinput::Storage> storage); |
- // Builds an address validator. Takes ownership of |downloader| and |storage|, |
- // which cannot be NULL. Does not take ownership of |load_rules_delegate|, |
- // which can be NULL. The caller owns the result. |
- static scoped_ptr<AddressValidator> Build( |
- scoped_ptr<Downloader> downloader, |
- scoped_ptr<Storage> storage, |
- LoadRulesDelegate* load_rules_delegate); |
+ virtual ~PreloadAddressValidator(); |
- // Loads the generic validation rules for |country_code| and specific rules |
- // for the country's administrative areas, localities, and dependent |
- // localities. A typical data size is 10KB. The largest is 250KB. If a country |
+ // Loads the generic validation rules for |region_code| and specific rules |
+ // for the regions's administrative areas, localities, and dependent |
+ // localities. A typical data size is 10KB. The largest is 250KB. If a region |
// has language-specific validation rules, then these are also loaded. |
// |
// Example rule: |
// https://i18napis.appspot.com/ssl-aggregate-address/data/US |
// |
- // If the rules were loaded successfully before or are still being loaded, |
- // then does nothing. Notifies |load_rules_delegate| when the loading |
- // finishes. |
- virtual void LoadRules(const std::string& country_code) = 0; |
+ // If the rules are already in progress of being loaded, it does nothing. |
+ // Calls |loaded| when the loading has finished. |
+ virtual void LoadRules(const std::string& region_code, |
+ const Callback& loaded); |
// Validates the |address| and populates |problems| with the validation |
// problems, filtered according to the |filter| parameter. |
@@ -113,12 +77,10 @@ class AddressValidator { |
// If the |filter| is empty, then all discovered validation problems are |
// returned. If the |filter| contains problem elements, then only the problems |
// in the |filter| may be returned. |
- // |
- // If the |problems| parameter is NULL, then checks whether the validation |
- // rules are available, but does not validate the |address|. |
- virtual Status ValidateAddress(const AddressData& address, |
- const AddressProblemFilter& filter, |
- AddressProblems* problems) const = 0; |
+ virtual Status Validate( |
+ const ::i18n::addressinput::AddressData& address, |
+ const ::i18n::addressinput::FieldProblemMap* filter, |
+ ::i18n::addressinput::FieldProblemMap* problems) const; |
// Fills in |suggestions| for the partially typed in |user_input|, assuming |
// the user is typing in the |focused_field|. If the number of |suggestions| |
@@ -145,19 +107,35 @@ class AddressValidator { |
// locality: "Anqing Shi", |
// administrative_area: "Anhui Sheng"}] |
virtual Status GetSuggestions( |
- const AddressData& user_input, |
- AddressField focused_field, |
+ const ::i18n::addressinput::AddressData& user_input, |
+ ::i18n::addressinput::AddressField focused_field, |
size_t suggestion_limit, |
- std::vector<AddressData>* suggestions) const = 0; |
+ std::vector< ::i18n::addressinput::AddressData>* suggestions) const; |
// Canonicalizes the administrative area in |address_data|. For example, |
// "texas" changes to "TX". Returns true on success, otherwise leaves |
// |address_data| alone and returns false. |
- virtual bool CanonicalizeAdministrativeArea(AddressData* address_data) |
- const = 0; |
+ virtual bool CanonicalizeAdministrativeArea( |
+ ::i18n::addressinput::AddressData* address) const; |
+ |
+ private: |
+ void Validated(bool success, |
+ const ::i18n::addressinput::AddressData&, |
+ const ::i18n::addressinput::FieldProblemMap&); |
+ |
+ const scoped_ptr< ::i18n::addressinput::PreloadSupplier> supplier_; |
+ const scoped_ptr<Suggestions> suggestions_; |
+ const scoped_ptr< ::i18n::addressinput::Synonyms> synonyms_; |
+ const scoped_ptr<const ::i18n::addressinput::AddressValidator> validator_; |
+ const scoped_ptr<const ::i18n::addressinput::AddressValidator::Callback> |
+ validated_; |
+ |
+ friend class MockAddressValidator; |
+ PreloadAddressValidator(); |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PreloadAddressValidator); |
}; |
-} // namespace addressinput |
-} // namespace i18n |
+} // namespace autofill |
-#endif // I18N_ADDRESSINPUT_ADDRESS_VALIDATOR_H_ |
+#endif // THIRD_PARTY_LIBADDRESSINPUT_CHROMIUM_PRELOAD_ADDRESS_VALIDATOR_H_ |