Index: chrome/utility/media_galleries/iapps_xml_utils.cc |
diff --git a/chrome/utility/media_galleries/iapps_xml_utils.cc b/chrome/utility/media_galleries/iapps_xml_utils.cc |
index 987b6c193ecd7f1618b64840cb7773a65b3f1bf6..aed0ae92406b8cc6470990f7b104a12f3e275cd2 100644 |
--- a/chrome/utility/media_galleries/iapps_xml_utils.cc |
+++ b/chrome/utility/media_galleries/iapps_xml_utils.cc |
@@ -97,4 +97,64 @@ std::string ReadFileAsString(base::File file) { |
return result; |
} |
+XmlDictReader::XmlDictReader(XmlReader* reader) : reader_(reader) {} |
+ |
+XmlDictReader::~XmlDictReader() {} |
+ |
+bool XmlDictReader::Read() { |
+ if (reader_->NodeName() != "dict") |
+ return false; |
+ |
+ int dict_content_depth = reader_->Depth() + 1; |
+ // Advance past the dict node and into the body of the dictionary. |
+ if (!reader_->Read()) |
+ return false; |
+ |
+ while (reader_->Depth() >= dict_content_depth && ShouldLoop()) { |
+ if (!iapps::SeekToNodeAtCurrentDepth(reader_, "key")) |
+ break; |
+ std::string found_key; |
+ if (!reader_->ReadElementContent(&found_key)) |
+ break; |
+ DCHECK_EQ(dict_content_depth, reader_->Depth()); |
+ |
+ if (!HandleKey(found_key)) |
+ break; |
+ } |
+ // Seek to the end of the dictionary. Bail on end or error. |
+ while (reader_->Depth() >= dict_content_depth && reader_->Next()) { |
+ } |
+ return FinishedOk(); |
+} |
+ |
+bool XmlDictReader::ShouldLoop() { |
+ return true; |
+} |
+ |
+bool XmlDictReader::HandleKey(const std::string& key) { |
+ if (Found(key)) |
+ return AllowRepeats(); |
+ if (HandleKeyImpl(key)) { |
+ found_.insert(key); |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+bool XmlDictReader::AllowRepeats() { |
+ return false; |
+} |
+ |
+bool XmlDictReader::FinishedOk() { |
+ return true; |
+} |
+ |
+bool XmlDictReader::SkipToNext() { |
+ return SkipToNextElement(reader_) && reader_->Next(); |
+} |
+ |
+bool XmlDictReader::Found(const std::string& key) const { |
+ return ContainsKey(found_, key); |
+} |
+ |
} // namespace iapps |