OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/utility/media_galleries/iphoto_library_parser.h" | 5 #include "chrome/utility/media_galleries/iphoto_library_parser.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include <string> | 9 #include <string> |
8 | 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
11 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
13 #include "chrome/utility/media_galleries/iapps_xml_utils.h" | 15 #include "chrome/utility/media_galleries/iapps_xml_utils.h" |
14 #include "third_party/libxml/chromium/libxml_utils.h" | 16 #include "third_party/libxml/chromium/libxml_utils.h" |
15 | 17 |
16 namespace iphoto { | 18 namespace iphoto { |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 struct PhotoInfo { | 22 struct PhotoInfo { |
21 uint64 id; | 23 uint64_t id; |
22 base::FilePath location; | 24 base::FilePath location; |
23 base::FilePath original_location; | 25 base::FilePath original_location; |
24 }; | 26 }; |
25 | 27 |
26 struct AlbumInfo { | 28 struct AlbumInfo { |
27 std::set<uint64> photo_ids; | 29 std::set<uint64_t> photo_ids; |
28 std::string name; | 30 std::string name; |
29 uint64 id; | 31 uint64_t id; |
30 }; | 32 }; |
31 | 33 |
32 class PhotosXmlDictReader : public iapps::XmlDictReader { | 34 class PhotosXmlDictReader : public iapps::XmlDictReader { |
33 public: | 35 public: |
34 PhotosXmlDictReader(XmlReader* reader, PhotoInfo* photo_info) | 36 PhotosXmlDictReader(XmlReader* reader, PhotoInfo* photo_info) |
35 : iapps::XmlDictReader(reader), photo_info_(photo_info) {} | 37 : iapps::XmlDictReader(reader), photo_info_(photo_info) {} |
36 | 38 |
37 bool HandleKeyImpl(const std::string& key) override { | 39 bool HandleKeyImpl(const std::string& key) override { |
38 if (key == "ImagePath") { | 40 if (key == "ImagePath") { |
39 std::string value; | 41 std::string value; |
(...skipping 16 matching lines...) Expand all Loading... |
56 private: | 58 private: |
57 PhotoInfo* photo_info_; | 59 PhotoInfo* photo_info_; |
58 }; | 60 }; |
59 | 61 |
60 // Contents of the album 'KeyList' key are | 62 // Contents of the album 'KeyList' key are |
61 // <array> | 63 // <array> |
62 // <string>1</string> | 64 // <string>1</string> |
63 // <string>2</string> | 65 // <string>2</string> |
64 // <string>3</string> | 66 // <string>3</string> |
65 // </array> | 67 // </array> |
66 bool ReadStringArray(XmlReader* reader, std::set<uint64>* photo_ids) { | 68 bool ReadStringArray(XmlReader* reader, std::set<uint64_t>* photo_ids) { |
67 if (reader->NodeName() != "array") | 69 if (reader->NodeName() != "array") |
68 return false; | 70 return false; |
69 | 71 |
70 // Advance past the array node and into the body of the array. | 72 // Advance past the array node and into the body of the array. |
71 if (!reader->Read()) | 73 if (!reader->Read()) |
72 return false; | 74 return false; |
73 | 75 |
74 int array_content_depth = reader->Depth(); | 76 int array_content_depth = reader->Depth(); |
75 | 77 |
76 while (iapps::SeekToNodeAtCurrentDepth(reader, "string")) { | 78 while (iapps::SeekToNodeAtCurrentDepth(reader, "string")) { |
77 if (reader->Depth() != array_content_depth) | 79 if (reader->Depth() != array_content_depth) |
78 return false; | 80 return false; |
79 std::string photo_id; | 81 std::string photo_id; |
80 if (!iapps::ReadString(reader, &photo_id)) | 82 if (!iapps::ReadString(reader, &photo_id)) |
81 continue; | 83 continue; |
82 uint64 id; | 84 uint64_t id; |
83 if (!base::StringToUint64(photo_id, &id)) | 85 if (!base::StringToUint64(photo_id, &id)) |
84 continue; | 86 continue; |
85 photo_ids->insert(id); | 87 photo_ids->insert(id); |
86 } | 88 } |
87 | 89 |
88 return true; | 90 return true; |
89 } | 91 } |
90 | 92 |
91 class AlbumXmlDictReader : public iapps::XmlDictReader { | 93 class AlbumXmlDictReader : public iapps::XmlDictReader { |
92 public: | 94 public: |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 bool errors = false; | 147 bool errors = false; |
146 while (reader->Depth() >= photos_dict_depth) { | 148 while (reader->Depth() >= photos_dict_depth) { |
147 if (!iapps::SeekToNodeAtCurrentDepth(reader, "key")) | 149 if (!iapps::SeekToNodeAtCurrentDepth(reader, "key")) |
148 break; | 150 break; |
149 | 151 |
150 std::string key; | 152 std::string key; |
151 if (!reader->ReadElementContent(&key)) { | 153 if (!reader->ReadElementContent(&key)) { |
152 errors = true; | 154 errors = true; |
153 break; | 155 break; |
154 } | 156 } |
155 uint64 id; | 157 uint64_t id; |
156 bool id_valid = base::StringToUint64(key, &id); | 158 bool id_valid = base::StringToUint64(key, &id); |
157 | 159 |
158 if (!id_valid || | 160 if (!id_valid || |
159 reader->Depth() != photos_dict_depth) { | 161 reader->Depth() != photos_dict_depth) { |
160 errors = true; | 162 errors = true; |
161 break; | 163 break; |
162 } | 164 } |
163 if (!iapps::SeekToNodeAtCurrentDepth(reader, "dict")) { | 165 if (!iapps::SeekToNodeAtCurrentDepth(reader, "dict")) { |
164 errors = true; | 166 errors = true; |
165 break; | 167 break; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 return false; | 256 return false; |
255 | 257 |
256 if (!iapps::SeekToNodeAtCurrentDepth(&reader, "dict")) | 258 if (!iapps::SeekToNodeAtCurrentDepth(&reader, "dict")) |
257 return false; | 259 return false; |
258 | 260 |
259 IPhotoLibraryXmlDictReader dict_reader(&reader, &library_); | 261 IPhotoLibraryXmlDictReader dict_reader(&reader, &library_); |
260 return dict_reader.Read(); | 262 return dict_reader.Read(); |
261 } | 263 } |
262 | 264 |
263 } // namespace iphoto | 265 } // namespace iphoto |
OLD | NEW |