+std::string MakeElementPath(const std::string& parent,
+ const std::string& element) {
+ std::vector<std::string> parts;
+ parts.push_back(parent);
+ parts.push_back(element);
+ return JoinString(parts, '.');
+}
+
+bool AddDictionary(const std::string& key,
+ scoped_ptr<base::DictionaryValue> child, base::DictionaryValue* parent) {
+ if (key.empty() || !child || !parent)
+ return false;
+
+ scoped_ptr<base::Value> existing_child;
+ base::DictionaryValue* unused;
+ if (parent->GetDictionary(key, &unused)) {
+ if (!parent->Remove(key, &existing_child))
+ return false;
+ }
+
+ if (existing_child) {
+ scoped_ptr<base::ListValue> list(new base::ListValue);
+ list->Set(list->GetSize(), existing_child.release());
+ list->Set(list->GetSize(), child.release());
+ parent->Set(key, list.release());
+ } else {
+ base::ListValue* list;
+ if (parent->GetList(key, &list))
+ list->Set(list->GetSize(), child.release());
+ else
+ parent->Set(key, child.release());
+ }
+
+ return true;
+}
+