Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / utility / media_galleries / iapps_xml_utils.h
blobd451878e9e001014a188de4327698ea2dda86fee
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_UTILITY_MEDIA_GALLERIES_IAPPS_XML_UTILS_H_
6 #define CHROME_UTILITY_MEDIA_GALLERIES_IAPPS_XML_UTILS_H_
8 #include <set>
9 #include <string>
11 #include "base/files/file.h"
12 #include "base/stl_util.h"
14 class XmlReader;
16 namespace iapps {
18 // Like XmlReader::SkipToElement, but will advance to the next open tag if the
19 // cursor is on a close tag.
20 bool SkipToNextElement(XmlReader* reader);
22 // Traverse |reader| looking for a node named |name| at the current depth
23 // of |reader|.
24 bool SeekToNodeAtCurrentDepth(XmlReader* reader, const std::string& name);
26 // Search within a "dict" node for |key|. The cursor must be on the starting
27 // "dict" node when entering this function.
28 bool SeekInDict(XmlReader* reader, const std::string& key);
30 // Get the value out of a string node.
31 bool ReadString(XmlReader* reader, std::string* result);
33 // Get the value out of an integer node.
34 bool ReadInteger(XmlReader* reader, uint64* result);
36 // Read in the contents of the given library xml |file| and return as a string.
37 std::string ReadFileAsString(base::File file);
39 // Contains the common code and main loop for reading the key/values
40 // of an XML dict. The derived class must implement |HandleKeyImpl()|
41 // which is called with each key, and may re-implement |ShouldLoop()|,
42 // |FinishedOk()| and/or |AllowRepeats()|.
43 class XmlDictReader {
44 public:
45 explicit XmlDictReader(XmlReader* reader);
46 virtual ~XmlDictReader();
48 // The main loop of this class. Reads all the keys in the
49 // current element and calls |HandleKey()| with each.
50 bool Read();
52 // Re-implemented by derived class if it should bail from the
53 // loop earlier, such as if it encountered all required fields.
54 virtual bool ShouldLoop();
56 // Called by |Read()| with each key. Calls derived |HandleKeyImpl()|.
57 bool HandleKey(const std::string& key);
59 virtual bool HandleKeyImpl(const std::string& key) = 0;
61 // Re-implemented by the derived class (to return true) if
62 // it should allow fields to be repeated, but skipped.
63 virtual bool AllowRepeats();
65 // Re-implemented by derived class if it should test for required
66 // fields instead of just returning true.
67 virtual bool FinishedOk();
69 // A convenience function for the derived classes.
70 // Skips to next element.
71 bool SkipToNext();
73 // A convenience function for the derived classes.
74 // Used to test if all required keys have been encountered.
75 bool Found(const std::string& key) const;
77 protected:
78 XmlReader* reader_;
80 private:
81 // The keys that the reader has run into in this element.
82 std::set<std::string> found_;
84 DISALLOW_COPY_AND_ASSIGN(XmlDictReader);
87 } // namespace iapps
89 #endif // CHROME_UTILITY_MEDIA_GALLERIES_IAPPS_XML_UTILS_H_