| Index: chrome/utility/media_galleries/iapps_xml_utils.h
|
| diff --git a/chrome/utility/media_galleries/iapps_xml_utils.h b/chrome/utility/media_galleries/iapps_xml_utils.h
|
| index edee54bead9811416383506282676dd5cd4e55e4..d451878e9e001014a188de4327698ea2dda86fee 100644
|
| --- a/chrome/utility/media_galleries/iapps_xml_utils.h
|
| +++ b/chrome/utility/media_galleries/iapps_xml_utils.h
|
| @@ -5,9 +5,11 @@
|
| #ifndef CHROME_UTILITY_MEDIA_GALLERIES_IAPPS_XML_UTILS_H_
|
| #define CHROME_UTILITY_MEDIA_GALLERIES_IAPPS_XML_UTILS_H_
|
|
|
| +#include <set>
|
| #include <string>
|
|
|
| #include "base/files/file.h"
|
| +#include "base/stl_util.h"
|
|
|
| class XmlReader;
|
|
|
| @@ -34,6 +36,54 @@ bool ReadInteger(XmlReader* reader, uint64* result);
|
| // Read in the contents of the given library xml |file| and return as a string.
|
| std::string ReadFileAsString(base::File file);
|
|
|
| +// Contains the common code and main loop for reading the key/values
|
| +// of an XML dict. The derived class must implement |HandleKeyImpl()|
|
| +// which is called with each key, and may re-implement |ShouldLoop()|,
|
| +// |FinishedOk()| and/or |AllowRepeats()|.
|
| +class XmlDictReader {
|
| + public:
|
| + explicit XmlDictReader(XmlReader* reader);
|
| + virtual ~XmlDictReader();
|
| +
|
| + // The main loop of this class. Reads all the keys in the
|
| + // current element and calls |HandleKey()| with each.
|
| + bool Read();
|
| +
|
| + // Re-implemented by derived class if it should bail from the
|
| + // loop earlier, such as if it encountered all required fields.
|
| + virtual bool ShouldLoop();
|
| +
|
| + // Called by |Read()| with each key. Calls derived |HandleKeyImpl()|.
|
| + bool HandleKey(const std::string& key);
|
| +
|
| + virtual bool HandleKeyImpl(const std::string& key) = 0;
|
| +
|
| + // Re-implemented by the derived class (to return true) if
|
| + // it should allow fields to be repeated, but skipped.
|
| + virtual bool AllowRepeats();
|
| +
|
| + // Re-implemented by derived class if it should test for required
|
| + // fields instead of just returning true.
|
| + virtual bool FinishedOk();
|
| +
|
| + // A convenience function for the derived classes.
|
| + // Skips to next element.
|
| + bool SkipToNext();
|
| +
|
| + // A convenience function for the derived classes.
|
| + // Used to test if all required keys have been encountered.
|
| + bool Found(const std::string& key) const;
|
| +
|
| + protected:
|
| + XmlReader* reader_;
|
| +
|
| + private:
|
| + // The keys that the reader has run into in this element.
|
| + std::set<std::string> found_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(XmlDictReader);
|
| +};
|
| +
|
| } // namespace iapps
|
|
|
| #endif // CHROME_UTILITY_MEDIA_GALLERIES_IAPPS_XML_UTILS_H_
|
|
|