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

Unified Diff: third_party/libaddressinput/chromium/cpp/src/rule.cc

Issue 109323011: [rac] Download all rules for a country code in libaddressinput. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge smaller patches. Created 7 years 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/rule.cc
diff --git a/third_party/libaddressinput/chromium/cpp/src/rule.cc b/third_party/libaddressinput/chromium/cpp/src/rule.cc
index 15d13443de680420e50729ae32a8ad90096dd443..a8aba1d8101c63c72ae133dbfaa8e1b0b02599cf 100644
--- a/third_party/libaddressinput/chromium/cpp/src/rule.cc
+++ b/third_party/libaddressinput/chromium/cpp/src/rule.cc
@@ -24,6 +24,7 @@
#include "address_field_util.h"
#include "grit.h"
#include "messages.h"
+#include "region_data_constants.h"
#include "util/json.h"
#include "util/string_split.h"
@@ -98,6 +99,15 @@ int GetMessageIdFromName(const std::string& name,
return it != message_ids.end() ? it->second : INVALID_MESSAGE_ID;
}
+// Parses the default region data into the static Rule object and returns a
+// constant reference to this object. Cannot return a copy of the object,
+// because Rule objects are not copyable.
+const Rule& InitDefaultRule() {
+ static Rule rule;
+ rule.ParseSerializedRule(RegionDataConstants::GetDefaultRegionData());
+ return rule;
+}
+
} // namespace
Rule::Rule()
@@ -110,6 +120,16 @@ Rule::Rule()
Rule::~Rule() {}
+// static
+const Rule& Rule::GetDefault() {
+ // Returns the constant reference to the Rule object from InitDefaultRule().
+ // The static object is in InitDefaultRule(), but this function maintains a
+ // constant static reference to it. The constant static reference avoids
+ // re-parsing the default region data.
+ static const Rule& kDefaultRule(InitDefaultRule());
+ return kDefaultRule;
+}
+
void Rule::CopyFrom(const Rule& rule) {
format_ = rule.format_;
sub_keys_ = rule.sub_keys_;

Powered by Google App Engine
This is Rietveld 408576698