Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6938)

Unified Diff: chrome/browser/media_galleries/fileapi/itunes_xml_utils.cc

Issue 16231016: Extract track information from iTunes library xml file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix win test Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/media_galleries/fileapi/itunes_xml_utils.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media_galleries/fileapi/itunes_xml_utils.cc
diff --git a/chrome/browser/media_galleries/fileapi/itunes_xml_utils.cc b/chrome/browser/media_galleries/fileapi/itunes_xml_utils.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4b441da28abf1146402b21b37be11040bc232127
--- /dev/null
+++ b/chrome/browser/media_galleries/fileapi/itunes_xml_utils.cc
@@ -0,0 +1,57 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/media_galleries/fileapi/itunes_xml_utils.h"
+#include <string>
+
+#include "base/logging.h"
+#include "third_party/libxml/chromium/libxml_utils.h"
+
+namespace itunes {
+
+bool SkipToNextElement(XmlReader* reader) {
+ if (!reader->SkipToElement()) {
+ // SkipToElement returns false if the current node is an end element,
+ // try to advance to the next element and then try again.
+ if (!reader->Read() || !reader->SkipToElement())
+ return false;
+ }
+ return true;
+}
+
+bool SeekToNodeAtCurrentDepth(XmlReader* reader, const std::string& name) {
+ int depth = reader->Depth();
+ do {
+ if (!SkipToNextElement(reader))
+ return false;
+ DCHECK_EQ(depth, reader->Depth());
+ if (reader->NodeName() == name)
+ return true;
+ } while (reader->Next());
+
+ return false;
+}
+
+bool SeekInDict(XmlReader* reader, const std::string& key) {
+ DCHECK_EQ("dict", reader->NodeName());
+
+ 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) {
+ if (!SeekToNodeAtCurrentDepth(reader, "key"))
+ return false;
+ std::string found_key;
+ if (!reader->ReadElementContent(&found_key))
+ return false;
+ DCHECK_EQ(dict_content_depth, reader->Depth());
+ if (found_key == key)
+ return true;
+ }
+ return false;
+}
+
+} // namespace itunes
« no previous file with comments | « chrome/browser/media_galleries/fileapi/itunes_xml_utils.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698