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/browser/media_galleries/fileapi/iphoto_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/iphoto_file_util.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 239 |
240 base::File::Error IPhotoFileUtil::ReadDirectorySync( | 240 base::File::Error IPhotoFileUtil::ReadDirectorySync( |
241 storage::FileSystemOperationContext* context, | 241 storage::FileSystemOperationContext* context, |
242 const storage::FileSystemURL& url, | 242 const storage::FileSystemURL& url, |
243 EntryList* file_list) { | 243 EntryList* file_list) { |
244 DCHECK(file_list->empty()); | 244 DCHECK(file_list->empty()); |
245 std::vector<std::string> components = GetVirtualPathComponents(url); | 245 std::vector<std::string> components = GetVirtualPathComponents(url); |
246 | 246 |
247 // Root directory. Child is the /Albums dir. | 247 // Root directory. Child is the /Albums dir. |
248 if (components.size() == 0) { | 248 if (components.size() == 0) { |
249 file_list->push_back(DirectoryEntry(kIPhotoAlbumsDir, | 249 file_list->push_back( |
250 DirectoryEntry::DIRECTORY, | 250 DirectoryEntry(kIPhotoAlbumsDir, DirectoryEntry::DIRECTORY)); |
251 0, base::Time())); | |
252 return base::File::FILE_OK; | 251 return base::File::FILE_OK; |
253 } | 252 } |
254 | 253 |
255 if (components[0] == kIPhotoAlbumsDir) { | 254 if (components[0] == kIPhotoAlbumsDir) { |
256 if (components.size() == 1) { | 255 if (components.size() == 1) { |
257 // Albums dir contains all album names. | 256 // Albums dir contains all album names. |
258 std::vector<std::string> albums = | 257 std::vector<std::string> albums = |
259 GetDataProvider()->GetAlbumNames(); | 258 GetDataProvider()->GetAlbumNames(); |
260 for (std::vector<std::string>::const_iterator it = albums.begin(); | 259 for (std::vector<std::string>::const_iterator it = albums.begin(); |
261 it != albums.end(); it++) { | 260 it != albums.end(); it++) { |
262 file_list->push_back(DirectoryEntry(*it, DirectoryEntry::DIRECTORY, | 261 file_list->push_back(DirectoryEntry(*it, DirectoryEntry::DIRECTORY)); |
263 0, base::Time())); | |
264 } | 262 } |
265 return base::File::FILE_OK; | 263 return base::File::FILE_OK; |
266 } else if (components.size() == 2) { | 264 } else if (components.size() == 2) { |
267 std::vector<std::string> albums = | 265 std::vector<std::string> albums = |
268 GetDataProvider()->GetAlbumNames(); | 266 GetDataProvider()->GetAlbumNames(); |
269 if (!ContainsElement(albums, components[1])) | 267 if (!ContainsElement(albums, components[1])) |
270 return base::File::FILE_ERROR_NOT_FOUND; | 268 return base::File::FILE_ERROR_NOT_FOUND; |
271 | 269 |
272 // Album dirs contain all photos in them. | 270 // Album dirs contain all photos in them. |
273 if (GetDataProvider()->HasOriginals(components[1])) { | 271 if (GetDataProvider()->HasOriginals(components[1])) { |
274 file_list->push_back(DirectoryEntry(kIPhotoOriginalsDir, | 272 file_list->push_back( |
275 DirectoryEntry::DIRECTORY, | 273 DirectoryEntry(kIPhotoOriginalsDir, DirectoryEntry::DIRECTORY)); |
276 0, base::Time())); | |
277 } | 274 } |
278 std::map<std::string, base::FilePath> locations = | 275 std::map<std::string, base::FilePath> locations = |
279 GetDataProvider()->GetAlbumContents(components[1]); | 276 GetDataProvider()->GetAlbumContents(components[1]); |
280 for (std::map<std::string, base::FilePath>::const_iterator it = | 277 for (std::map<std::string, base::FilePath>::const_iterator it = |
281 locations.begin(); | 278 locations.begin(); |
282 it != locations.end(); it++) { | 279 it != locations.end(); it++) { |
283 base::File::Info info; | 280 base::File::Info info; |
284 if (!base::GetFileInfo(it->second, &info)) | 281 if (!base::GetFileInfo(it->second, &info)) |
285 return base::File::FILE_ERROR_IO; | 282 return base::File::FILE_ERROR_IO; |
286 file_list->push_back(DirectoryEntry(it->first, DirectoryEntry::FILE, | 283 file_list->push_back(DirectoryEntry(it->first, DirectoryEntry::FILE)); |
287 info.size, info.last_modified)); | |
288 } | 284 } |
289 return base::File::FILE_OK; | 285 return base::File::FILE_OK; |
290 } else if (components.size() == 3 && | 286 } else if (components.size() == 3 && |
291 components[2] == kIPhotoOriginalsDir && | 287 components[2] == kIPhotoOriginalsDir && |
292 GetDataProvider()->HasOriginals(components[1])) { | 288 GetDataProvider()->HasOriginals(components[1])) { |
293 std::map<std::string, base::FilePath> originals = | 289 std::map<std::string, base::FilePath> originals = |
294 GetDataProvider()->GetOriginals(components[1]); | 290 GetDataProvider()->GetOriginals(components[1]); |
295 for (std::map<std::string, base::FilePath>::const_iterator it = | 291 for (std::map<std::string, base::FilePath>::const_iterator it = |
296 originals.begin(); | 292 originals.begin(); |
297 it != originals.end(); it++) { | 293 it != originals.end(); it++) { |
298 base::File::Info info; | 294 base::File::Info info; |
299 if (!base::GetFileInfo(it->second, &info)) | 295 if (!base::GetFileInfo(it->second, &info)) |
300 return base::File::FILE_ERROR_IO; | 296 return base::File::FILE_ERROR_IO; |
301 file_list->push_back(DirectoryEntry(it->first, DirectoryEntry::FILE, | 297 file_list->push_back(DirectoryEntry(it->first, DirectoryEntry::FILE)); |
302 info.size, info.last_modified)); | |
303 } | 298 } |
304 return base::File::FILE_OK; | 299 return base::File::FILE_OK; |
305 } | 300 } |
306 } | 301 } |
307 | 302 |
308 return base::File::FILE_ERROR_NOT_FOUND; | 303 return base::File::FILE_ERROR_NOT_FOUND; |
309 } | 304 } |
310 | 305 |
311 base::File::Error IPhotoFileUtil::DeleteDirectorySync( | 306 base::File::Error IPhotoFileUtil::DeleteDirectorySync( |
312 storage::FileSystemOperationContext* context, | 307 storage::FileSystemOperationContext* context, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 return base::File::FILE_ERROR_NOT_FOUND; | 344 return base::File::FILE_ERROR_NOT_FOUND; |
350 } | 345 } |
351 | 346 |
352 IPhotoDataProvider* IPhotoFileUtil::GetDataProvider() { | 347 IPhotoDataProvider* IPhotoFileUtil::GetDataProvider() { |
353 if (!imported_registry_) | 348 if (!imported_registry_) |
354 imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); | 349 imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); |
355 return imported_registry_->IPhotoDataProvider(); | 350 return imported_registry_->IPhotoDataProvider(); |
356 } | 351 } |
357 | 352 |
358 } // namespace iphoto | 353 } // namespace iphoto |
OLD | NEW |