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 AlbumInfo::AlbumInfo() {} 36 37 AlbumInfo::AlbumInfo(const std::string& name, const base::Time& timestamp, 38 const std::string& uid, const base::FilePath& path) 39 : name(name), 40 timestamp(timestamp), 41 uid(uid), 42 path(path) { 43 } 44 45 AlbumInfo::~AlbumInfo() {} 46 47 AlbumTableFiles::AlbumTableFiles() 48 : indicator_file(base::kInvalidPlatformFileValue), 49 category_file(base::kInvalidPlatformFileValue), 50 date_file(base::kInvalidPlatformFileValue), 51 filename_file(base::kInvalidPlatformFileValue), 52 name_file(base::kInvalidPlatformFileValue), 53 token_file(base::kInvalidPlatformFileValue), 54 uid_file(base::kInvalidPlatformFileValue) { 55 } 56 57 AlbumTableFiles::AlbumTableFiles(const base::FilePath& directory_path) 58 : indicator_file(OpenPlatformFile(directory_path, "0")), 59 category_file(OpenColumnPlatformFile(directory_path, "category")), 60 date_file(OpenColumnPlatformFile(directory_path, "date")), 61 filename_file(OpenColumnPlatformFile(directory_path, "filename")), 62 name_file(OpenColumnPlatformFile(directory_path, "name")), 63 token_file(OpenColumnPlatformFile(directory_path, "token")), 64 uid_file(OpenColumnPlatformFile(directory_path, "uid")) { 65 } 66 67 AlbumTableFilesForTransit::AlbumTableFilesForTransit() 68 : indicator_file(IPC::InvalidPlatformFileForTransit()), 69 category_file(IPC::InvalidPlatformFileForTransit()), 70 date_file(IPC::InvalidPlatformFileForTransit()), 71 filename_file(IPC::InvalidPlatformFileForTransit()), 72 name_file(IPC::InvalidPlatformFileForTransit()), 73 token_file(IPC::InvalidPlatformFileForTransit()), 74 uid_file(IPC::InvalidPlatformFileForTransit()) { 75 } 76 77 void CloseAlbumTableFiles(AlbumTableFiles* table_files) { 78 ClosePlatformFile(&(table_files->indicator_file)); 79 ClosePlatformFile(&(table_files->category_file)); 80 ClosePlatformFile(&(table_files->date_file)); 81 ClosePlatformFile(&(table_files->filename_file)); 82 ClosePlatformFile(&(table_files->name_file)); 83 ClosePlatformFile(&(table_files->token_file)); 84 ClosePlatformFile(&(table_files->uid_file)); 85 } 86 87 } // namespace picasa 88