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. 4 5 #include "chrome/common/media_galleries/picasa_types.h" 6 7 #include "base/logging.h" 8 #include "chrome/common/media_galleries/pmp_constants.h" 9 10 namespace picasa { 11 12 namespace { 13 14 base::PlatformFile OpenPlatformFile(const base::FilePath& directory_path, 15 const std::string& suffix) { 16 base::FilePath path = directory_path.Append(base::FilePath::FromUTF8Unsafe( 17 std::string(kPicasaAlbumTableName) + "_" + suffix)); 18 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; 19 return base::CreatePlatformFile(path, flags, NULL, NULL); 20 } 21 22 base::PlatformFile OpenColumnPlatformFile(const base::FilePath& directory_path, 23 const std::string& column_name) { 24 return OpenPlatformFile(directory_path, column_name + "." + kPmpExtension); 25 } 26 27 void ClosePlatformFile(base::PlatformFile* platform_file) { 28 DCHECK(platform_file); 29 if (base::ClosePlatformFile(*platform_file)) 30 *platform_file = base::kInvalidPlatformFileValue; 31 } 32 33 } // namespace 34 35 const char kPicasaDatabaseDirName[] = "db3"; 36 const char kPicasaTempDirName[] = "tmp"; 37 38 const char kPicasaAlbumTableName[] = "albumdata"; 39 const char kAlbumTokenPrefix[] = "]album:"; 40 const char kPicasaINIFilename[] = ".picasa.ini"; 41 42 const uint32 kAlbumCategoryAlbum = 0; 43 const uint32 kAlbumCategoryFolder = 2; 44 const uint32 kAlbumCategoryInvalid = 0xffff; // Sentinel value. 45 46 AlbumInfo::AlbumInfo() {} 47 48 AlbumInfo::AlbumInfo(const std::string& name, const base::Time& timestamp, 49 const std::string& uid, const base::FilePath& path) 50 : name(name), 51 timestamp(timestamp), 52 uid(uid), 53 path(path) { 54 } 55 56 AlbumInfo::~AlbumInfo() {} 57 58 AlbumTableFiles::AlbumTableFiles() 59 : indicator_file(base::kInvalidPlatformFileValue), 60 category_file(base::kInvalidPlatformFileValue), 61 date_file(base::kInvalidPlatformFileValue), 62 filename_file(base::kInvalidPlatformFileValue), 63 name_file(base::kInvalidPlatformFileValue), 64 token_file(base::kInvalidPlatformFileValue), 65 uid_file(base::kInvalidPlatformFileValue) { 66 } 67 68 AlbumTableFiles::AlbumTableFiles(const base::FilePath& directory_path) 69 : indicator_file(OpenPlatformFile(directory_path, "0")), 70 category_file(OpenColumnPlatformFile(directory_path, "category")), 71 date_file(OpenColumnPlatformFile(directory_path, "date")), 72 filename_file(OpenColumnPlatformFile(directory_path, "filename")), 73 name_file(OpenColumnPlatformFile(directory_path, "name")), 74 token_file(OpenColumnPlatformFile(directory_path, "token")), 75 uid_file(OpenColumnPlatformFile(directory_path, "uid")) { 76 } 77 78 AlbumTableFilesForTransit::AlbumTableFilesForTransit() 79 : indicator_file(IPC::InvalidPlatformFileForTransit()), 80 category_file(IPC::InvalidPlatformFileForTransit()), 81 date_file(IPC::InvalidPlatformFileForTransit()), 82 filename_file(IPC::InvalidPlatformFileForTransit()), 83 name_file(IPC::InvalidPlatformFileForTransit()), 84 token_file(IPC::InvalidPlatformFileForTransit()), 85 uid_file(IPC::InvalidPlatformFileForTransit()) { 86 } 87 88 void CloseAlbumTableFiles(AlbumTableFiles* table_files) { 89 ClosePlatformFile(&(table_files->indicator_file)); 90 ClosePlatformFile(&(table_files->category_file)); 91 ClosePlatformFile(&(table_files->date_file)); 92 ClosePlatformFile(&(table_files->filename_file)); 93 ClosePlatformFile(&(table_files->name_file)); 94 ClosePlatformFile(&(table_files->token_file)); 95 ClosePlatformFile(&(table_files->uid_file)); 96 } 97 98 } // namespace picasa 99