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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 std::set<uint64> photo_ids; | 27 std::set<uint64> photo_ids; |
28 std::string name; | 28 std::string name; |
29 uint64 id; | 29 uint64 id; |
30 }; | 30 }; |
31 | 31 |
32 class PhotosXmlDictReader : public iapps::XmlDictReader { | 32 class PhotosXmlDictReader : public iapps::XmlDictReader { |
33 public: | 33 public: |
34 PhotosXmlDictReader(XmlReader* reader, PhotoInfo* photo_info) | 34 PhotosXmlDictReader(XmlReader* reader, PhotoInfo* photo_info) |
35 : iapps::XmlDictReader(reader), photo_info_(photo_info) {} | 35 : iapps::XmlDictReader(reader), photo_info_(photo_info) {} |
36 | 36 |
37 virtual bool HandleKeyImpl(const std::string& key) OVERRIDE { | 37 virtual bool HandleKeyImpl(const std::string& key) override { |
38 if (key == "ImagePath") { | 38 if (key == "ImagePath") { |
39 std::string value; | 39 std::string value; |
40 if (!iapps::ReadString(reader_, &value)) | 40 if (!iapps::ReadString(reader_, &value)) |
41 return false; | 41 return false; |
42 photo_info_->location = base::FilePath(value); | 42 photo_info_->location = base::FilePath(value); |
43 } else if (key == "OriginalPath") { | 43 } else if (key == "OriginalPath") { |
44 std::string value; | 44 std::string value; |
45 if (!iapps::ReadString(reader_, &value)) | 45 if (!iapps::ReadString(reader_, &value)) |
46 return false; | 46 return false; |
47 photo_info_->original_location = base::FilePath(value); | 47 photo_info_->original_location = base::FilePath(value); |
48 } else if (!SkipToNext()) { | 48 } else if (!SkipToNext()) { |
49 return false; | 49 return false; |
50 } | 50 } |
51 return true; | 51 return true; |
52 } | 52 } |
53 | 53 |
54 virtual bool FinishedOk() OVERRIDE { | 54 virtual bool FinishedOk() override { |
55 return Found("ImagePath"); | 55 return Found("ImagePath"); |
56 } | 56 } |
57 | 57 |
58 private: | 58 private: |
59 PhotoInfo* photo_info_; | 59 PhotoInfo* photo_info_; |
60 }; | 60 }; |
61 | 61 |
62 // Contents of the album 'KeyList' key are | 62 // Contents of the album 'KeyList' key are |
63 // <array> | 63 // <array> |
64 // <string>1</string> | 64 // <string>1</string> |
(...skipping 23 matching lines...) Expand all Loading... |
88 } | 88 } |
89 | 89 |
90 return true; | 90 return true; |
91 } | 91 } |
92 | 92 |
93 class AlbumXmlDictReader : public iapps::XmlDictReader { | 93 class AlbumXmlDictReader : public iapps::XmlDictReader { |
94 public: | 94 public: |
95 AlbumXmlDictReader(XmlReader* reader, AlbumInfo* album_info) | 95 AlbumXmlDictReader(XmlReader* reader, AlbumInfo* album_info) |
96 : iapps::XmlDictReader(reader), album_info_(album_info) {} | 96 : iapps::XmlDictReader(reader), album_info_(album_info) {} |
97 | 97 |
98 virtual bool ShouldLoop() OVERRIDE { | 98 virtual bool ShouldLoop() override { |
99 return !(Found("AlbumId") && Found("AlbumName") && Found("KeyList")); | 99 return !(Found("AlbumId") && Found("AlbumName") && Found("KeyList")); |
100 } | 100 } |
101 | 101 |
102 virtual bool HandleKeyImpl(const std::string& key) OVERRIDE { | 102 virtual bool HandleKeyImpl(const std::string& key) override { |
103 if (key == "AlbumId") { | 103 if (key == "AlbumId") { |
104 if (!iapps::ReadInteger(reader_, &album_info_->id)) | 104 if (!iapps::ReadInteger(reader_, &album_info_->id)) |
105 return false; | 105 return false; |
106 } else if (key == "AlbumName") { | 106 } else if (key == "AlbumName") { |
107 if (!iapps::ReadString(reader_, &album_info_->name)) | 107 if (!iapps::ReadString(reader_, &album_info_->name)) |
108 return false; | 108 return false; |
109 } else if (key == "KeyList") { | 109 } else if (key == "KeyList") { |
110 if (!iapps::SeekToNodeAtCurrentDepth(reader_, "array")) | 110 if (!iapps::SeekToNodeAtCurrentDepth(reader_, "array")) |
111 return false; | 111 return false; |
112 if (!ReadStringArray(reader_, &album_info_->photo_ids)) | 112 if (!ReadStringArray(reader_, &album_info_->photo_ids)) |
113 return false; | 113 return false; |
114 } else if (!SkipToNext()) { | 114 } else if (!SkipToNext()) { |
115 return false; | 115 return false; |
116 } | 116 } |
117 return true; | 117 return true; |
118 } | 118 } |
119 | 119 |
120 virtual bool FinishedOk() OVERRIDE { | 120 virtual bool FinishedOk() override { |
121 return !ShouldLoop(); | 121 return !ShouldLoop(); |
122 } | 122 } |
123 | 123 |
124 private: | 124 private: |
125 AlbumInfo* album_info_; | 125 AlbumInfo* album_info_; |
126 }; | 126 }; |
127 | 127 |
128 // Inside the master image list, we expect photos to be arranged as | 128 // Inside the master image list, we expect photos to be arranged as |
129 // <dict> | 129 // <dict> |
130 // <key>$PHOTO_ID</key> | 130 // <key>$PHOTO_ID</key> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } // namespace | 191 } // namespace |
192 | 192 |
193 IPhotoLibraryParser::IPhotoLibraryParser() {} | 193 IPhotoLibraryParser::IPhotoLibraryParser() {} |
194 IPhotoLibraryParser::~IPhotoLibraryParser() {} | 194 IPhotoLibraryParser::~IPhotoLibraryParser() {} |
195 | 195 |
196 class IPhotoLibraryXmlDictReader : public iapps::XmlDictReader { | 196 class IPhotoLibraryXmlDictReader : public iapps::XmlDictReader { |
197 public: | 197 public: |
198 IPhotoLibraryXmlDictReader(XmlReader* reader, parser::Library* library) | 198 IPhotoLibraryXmlDictReader(XmlReader* reader, parser::Library* library) |
199 : iapps::XmlDictReader(reader), library_(library), ok_(true) {} | 199 : iapps::XmlDictReader(reader), library_(library), ok_(true) {} |
200 | 200 |
201 virtual bool ShouldLoop() OVERRIDE { | 201 virtual bool ShouldLoop() override { |
202 return !(Found("List of Albums") && Found("Master Image List")); | 202 return !(Found("List of Albums") && Found("Master Image List")); |
203 } | 203 } |
204 | 204 |
205 virtual bool HandleKeyImpl(const std::string& key) OVERRIDE { | 205 virtual bool HandleKeyImpl(const std::string& key) override { |
206 if (key == "List of Albums") { | 206 if (key == "List of Albums") { |
207 if (!iapps::SeekToNodeAtCurrentDepth(reader_, "array") || | 207 if (!iapps::SeekToNodeAtCurrentDepth(reader_, "array") || |
208 !reader_->Read()) { | 208 !reader_->Read()) { |
209 return true; | 209 return true; |
210 } | 210 } |
211 while (iapps::SeekToNodeAtCurrentDepth(reader_, "dict")) { | 211 while (iapps::SeekToNodeAtCurrentDepth(reader_, "dict")) { |
212 AlbumInfo album_info; | 212 AlbumInfo album_info; |
213 AlbumXmlDictReader dict_reader(reader_, &album_info); | 213 AlbumXmlDictReader dict_reader(reader_, &album_info); |
214 if (dict_reader.Read()) { | 214 if (dict_reader.Read()) { |
215 parser::Album album; | 215 parser::Album album; |
216 album = album_info.photo_ids; | 216 album = album_info.photo_ids; |
217 // Strip / from album name and dedupe any collisions. | 217 // Strip / from album name and dedupe any collisions. |
218 std::string name; | 218 std::string name; |
219 base::ReplaceChars(album_info.name, "//", " ", &name); | 219 base::ReplaceChars(album_info.name, "//", " ", &name); |
220 if (ContainsKey(library_->albums, name)) | 220 if (ContainsKey(library_->albums, name)) |
221 name = name + "("+base::Uint64ToString(album_info.id)+")"; | 221 name = name + "("+base::Uint64ToString(album_info.id)+")"; |
222 library_->albums[name] = album; | 222 library_->albums[name] = album; |
223 } | 223 } |
224 } | 224 } |
225 } else if (key == "Master Image List") { | 225 } else if (key == "Master Image List") { |
226 if (!ParseAllPhotos(reader_, &library_->all_photos)) { | 226 if (!ParseAllPhotos(reader_, &library_->all_photos)) { |
227 ok_ = false; | 227 ok_ = false; |
228 return false; | 228 return false; |
229 } | 229 } |
230 } | 230 } |
231 return true; | 231 return true; |
232 } | 232 } |
233 | 233 |
234 virtual bool FinishedOk() OVERRIDE { | 234 virtual bool FinishedOk() override { |
235 return ok_; | 235 return ok_; |
236 } | 236 } |
237 | 237 |
238 // The IPhotoLibrary allows duplicate "List of Albums" and | 238 // The IPhotoLibrary allows duplicate "List of Albums" and |
239 // "Master Image List" keys (although that seems odd.) | 239 // "Master Image List" keys (although that seems odd.) |
240 virtual bool AllowRepeats() OVERRIDE { | 240 virtual bool AllowRepeats() override { |
241 return true; | 241 return true; |
242 } | 242 } |
243 | 243 |
244 private: | 244 private: |
245 parser::Library* library_; | 245 parser::Library* library_; |
246 | 246 |
247 // The base class bails when we request, and then calls |FinishedOk()| | 247 // The base class bails when we request, and then calls |FinishedOk()| |
248 // to decide what to return. We need to remember that we bailed because | 248 // to decide what to return. We need to remember that we bailed because |
249 // of an error. That's what |ok_| does. | 249 // of an error. That's what |ok_| does. |
250 bool ok_; | 250 bool ok_; |
(...skipping 11 matching lines...) Expand all Loading... |
262 return false; | 262 return false; |
263 | 263 |
264 if (!iapps::SeekToNodeAtCurrentDepth(&reader, "dict")) | 264 if (!iapps::SeekToNodeAtCurrentDepth(&reader, "dict")) |
265 return false; | 265 return false; |
266 | 266 |
267 IPhotoLibraryXmlDictReader dict_reader(&reader, &library_); | 267 IPhotoLibraryXmlDictReader dict_reader(&reader, &library_); |
268 return dict_reader.Read(); | 268 return dict_reader.Read(); |
269 } | 269 } |
270 | 270 |
271 } // namespace iphoto | 271 } // namespace iphoto |
OLD | NEW |