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..e9be7bcb2c67bb345cd10c438ec5b48c4bf791ba 100644 |
--- a/chrome/utility/media_galleries/iapps_xml_utils.cc |
+++ b/chrome/utility/media_galleries/iapps_xml_utils.cc |
@@ -97,4 +97,55 @@ std::string ReadFileAsString(base::File file) { |
return result; |
} |
+XmlDictReader::XmlDictReader(XmlReader* reader) : reader_(reader) {} |
+ |
+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 (Found(found_key) && AllowRepeats()) |
+ continue; |
+ |
+ 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()) |
Lei Zhang
2014/08/05 19:38:24
while (...) {}, rather than the semi-colon on the
Kevin Bailey
2014/08/05 21:52:05
Done.
|
+ ; |
+ return FinishedOk(); |
+} |
+ |
+bool XmlDictReader::ShouldLoop() { |
+ return true; |
+} |
+ |
+bool XmlDictReader::SkipToNext() { |
+ return SkipToNextElement(reader_) && reader_->Next(); |
+} |
+ |
+bool XmlDictReader::FinishedOk() { |
+ return true; |
+} |
+ |
+bool XmlDictReader::AllowRepeats() { |
+ return false; |
+} |
+ |
+XmlDictReader::~XmlDictReader() { |
+} |
+ |
} // namespace iapps |