Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / utility / media_galleries / itunes_pref_parser_win.cc
blob77e8cc6c64054eb0cb69ba87e945a4bb123f6336
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 #include "chrome/utility/media_galleries/itunes_pref_parser_win.h"
7 #include "base/base64.h"
8 #include "base/strings/string_util.h"
9 #include "chrome/utility/media_galleries/iapps_xml_utils.h"
10 #include "third_party/libxml/chromium/libxml_utils.h"
12 namespace itunes {
14 base::FilePath::StringType FindLibraryLocationInPrefXml(
15 const std::string& pref_xml_data) {
16 XmlReader reader;
17 base::FilePath::StringType result;
19 if (!reader.Load(pref_xml_data))
20 return result;
22 // Find the plist node and then search within that tag.
23 if (!iapps::SeekToNodeAtCurrentDepth(&reader, "plist"))
24 return result;
25 if (!reader.Read())
26 return result;
28 if (!iapps::SeekToNodeAtCurrentDepth(&reader, "dict"))
29 return result;
31 if (!iapps::SeekInDict(&reader, "User Preferences"))
32 return result;
34 if (!iapps::SeekToNodeAtCurrentDepth(&reader, "dict"))
35 return result;
37 if (!iapps::SeekInDict(&reader, "iTunes Library XML Location:1"))
38 return result;
40 if (!iapps::SeekToNodeAtCurrentDepth(&reader, "data"))
41 return result;
43 std::string pref_value;
44 if (!reader.ReadElementContent(&pref_value))
45 return result;
46 // The data is a base64 encoded wchar_t*. Because Base64Decode uses
47 // std::strings, the result has to be casted to a wchar_t*.
48 std::string data;
49 if (!base::Base64Decode(base::CollapseWhitespaceASCII(pref_value, true),
50 &data))
51 return result;
52 return base::FilePath::StringType(
53 reinterpret_cast<const wchar_t*>(data.data()), data.size() / 2);
56 } // namespace itunes