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"
14 base::FilePath::StringType
FindLibraryLocationInPrefXml(
15 const std::string
& pref_xml_data
) {
17 base::FilePath::StringType result
;
19 if (!reader
.Load(pref_xml_data
))
22 // Find the plist node and then search within that tag.
23 if (!iapps::SeekToNodeAtCurrentDepth(&reader
, "plist"))
28 if (!iapps::SeekToNodeAtCurrentDepth(&reader
, "dict"))
31 if (!iapps::SeekInDict(&reader
, "User Preferences"))
34 if (!iapps::SeekToNodeAtCurrentDepth(&reader
, "dict"))
37 if (!iapps::SeekInDict(&reader
, "iTunes Library XML Location:1"))
40 if (!iapps::SeekToNodeAtCurrentDepth(&reader
, "data"))
43 std::string pref_value
;
44 if (!reader
.ReadElementContent(&pref_value
))
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*.
49 if (!base::Base64Decode(base::CollapseWhitespaceASCII(pref_value
, true),
52 return base::FilePath::StringType(
53 reinterpret_cast<const wchar_t*>(data
.data()), data
.size() / 2);