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

Unified Diff: third_party/libaddressinput/chromium/cpp/src/country_rules_retriever.h

Issue 109323011: [rac] Download all rules for a country code in libaddressinput. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 6 years, 11 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/cpp/src/country_rules_retriever.h
diff --git a/third_party/libaddressinput/chromium/cpp/src/country_rules_retriever.h b/third_party/libaddressinput/chromium/cpp/src/country_rules_retriever.h
new file mode 100644
index 0000000000000000000000000000000000000000..750f12e399600f44fa3266ba78b4f0af5ecd4ce1
--- /dev/null
+++ b/third_party/libaddressinput/chromium/cpp/src/country_rules_retriever.h
@@ -0,0 +1,98 @@
+// Copyright (C) 2014 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.
+
+#ifndef I18N_ADDRESSINPUT_COUNTRY_RULES_RETRIEVER_H_
+#define I18N_ADDRESSINPUT_COUNTRY_RULES_RETRIEVER_H_
+
+#include <libaddressinput/callback.h>
+#include <libaddressinput/util/basictypes.h>
+#include <libaddressinput/util/scoped_ptr.h>
+
+#include <map>
+#include <string>
+#include <vector>
+
+namespace i18n {
+namespace addressinput {
+
+class Retriever;
+class Ruleset;
+
+// Retrieves a ruleset for a country. Sample usage:
+// class MyClass {
+// public:
+// MyClass() : retriever_(scoped_ptr<const Retriever>(...)) {}
+//
+// ~MyClass() {}
+//
+// void GetRuleset(const std::string& country_code) {
+// retriever_.RetrieveRules(
+// country_code,
+// BuildScopedPtrCallback(this, &MyClass::OnRulesetReady));
+// }
+//
+// void OnRulesetReady(bool success,
+// const std::string& country_code,
+// scoped_ptr<Ruleset> ruleset) {
+// ...
+// }
+//
+// private:
+// CountryRulesRetriever retriever_;
+//
+// DISALLOW_COPY_AND_ASSIGN(CountryRulesRetriever);
+// };
+class CountryRulesRetriever {
+ public:
+ typedef i18n::addressinput::ScopedPtrCallback<std::string, Ruleset> Callback;
+
+ explicit CountryRulesRetriever(scoped_ptr<Retriever> retriever);
+
+ ~CountryRulesRetriever();
+
+ // Recursively retrieves all of the rules for |country_code| and its
+ // administrative areas, localities, and dependent localities. Invokes the
+ // |rules_ready| callback when finished.
+ void RetrieveRules(const std::string& country_code,
+ scoped_ptr<Callback> rules_ready);
+
+ private:
+ class RulesetData;
+ struct RequestData;
+
+ // Callback for Retriever::Retrieve() method.
+ void OnDataReady(bool success,
+ const std::string& key,
+ const std::string& data);
+
+ // The data retriever that can download serialized rules for one sub-region at
+ // a time.
+ scoped_ptr<Retriever> retriever_;
+
+ // A mapping of data keys (e.g., "data/CA/AB--fr") to information that helps
+ // to parse the response data and place it the correct location in the
+ // rulesets.
+ std::map<std::string, RequestData> requests_;
+
+ // A list of rulesets that are being retrieved and information that is helpful
+ // in parsing and organizing the retrieved data.
+ std::vector<RulesetData*> rulesets_;
+
+ DISALLOW_COPY_AND_ASSIGN(CountryRulesRetriever);
+};
+
+} // namespace addressinput
+} // namespace i18n
+
+#endif // I18N_ADDRESSINPUT_COUNTRY_RULES_RETRIEVER_H_

Powered by Google App Engine
This is Rietveld 408576698