| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_DIRECTORY_DATABASE_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_DIRECTORY_DATABASE_H_ |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_DIRECTORY_DATABASE_H_ | 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_DIRECTORY_DATABASE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 | 40 |
| 41 struct WEBKIT_STORAGE_EXPORT_PRIVATE FileInfo { | 41 struct WEBKIT_STORAGE_EXPORT_PRIVATE FileInfo { |
| 42 FileInfo(); | 42 FileInfo(); |
| 43 ~FileInfo(); | 43 ~FileInfo(); |
| 44 | 44 |
| 45 bool is_directory() const { | 45 bool is_directory() const { |
| 46 return data_path.empty(); | 46 return data_path.empty(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 FileId parent_id; | 49 FileId parent_id; |
| 50 FilePath data_path; | 50 base::FilePath data_path; |
| 51 FilePath::StringType name; | 51 base::FilePath::StringType name; |
| 52 // This modification time is valid only for directories, not files, as | 52 // This modification time is valid only for directories, not files, as |
| 53 // FileWriter will get the files out of sync. | 53 // FileWriter will get the files out of sync. |
| 54 // For files, look at the modification time of the underlying data_path. | 54 // For files, look at the modification time of the underlying data_path. |
| 55 base::Time modification_time; | 55 base::Time modification_time; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 explicit FileSystemDirectoryDatabase( | 58 explicit FileSystemDirectoryDatabase( |
| 59 const FilePath& filesystem_data_directory); | 59 const base::FilePath& filesystem_data_directory); |
| 60 ~FileSystemDirectoryDatabase(); | 60 ~FileSystemDirectoryDatabase(); |
| 61 | 61 |
| 62 bool GetChildWithName( | 62 bool GetChildWithName( |
| 63 FileId parent_id, const FilePath::StringType& name, FileId* child_id); | 63 FileId parent_id, const base::FilePath::StringType& name, FileId* child_id
); |
| 64 bool GetFileWithPath(const FilePath& path, FileId* file_id); | 64 bool GetFileWithPath(const base::FilePath& path, FileId* file_id); |
| 65 // ListChildren will succeed, returning 0 children, if parent_id doesn't | 65 // ListChildren will succeed, returning 0 children, if parent_id doesn't |
| 66 // exist. | 66 // exist. |
| 67 bool ListChildren(FileId parent_id, std::vector<FileId>* children); | 67 bool ListChildren(FileId parent_id, std::vector<FileId>* children); |
| 68 bool GetFileInfo(FileId file_id, FileInfo* info); | 68 bool GetFileInfo(FileId file_id, FileInfo* info); |
| 69 bool AddFileInfo(const FileInfo& info, FileId* file_id); | 69 bool AddFileInfo(const FileInfo& info, FileId* file_id); |
| 70 bool RemoveFileInfo(FileId file_id); | 70 bool RemoveFileInfo(FileId file_id); |
| 71 // This does a full update of the FileInfo, and is what you'd use for moves | 71 // This does a full update of the FileInfo, and is what you'd use for moves |
| 72 // and renames. If you just want to update the modification_time, use | 72 // and renames. If you just want to update the modification_time, use |
| 73 // UpdateModificationTime. | 73 // UpdateModificationTime. |
| 74 bool UpdateFileInfo(FileId file_id, const FileInfo& info); | 74 bool UpdateFileInfo(FileId file_id, const FileInfo& info); |
| 75 bool UpdateModificationTime( | 75 bool UpdateModificationTime( |
| 76 FileId file_id, const base::Time& modification_time); | 76 FileId file_id, const base::Time& modification_time); |
| 77 // This is used for an overwriting move of a file [not a directory] on top of | 77 // This is used for an overwriting move of a file [not a directory] on top of |
| 78 // another file [also not a directory]; we need to alter two files' info in a | 78 // another file [also not a directory]; we need to alter two files' info in a |
| 79 // single transaction to avoid weird backing file references in the event of a | 79 // single transaction to avoid weird backing file references in the event of a |
| 80 // partial failure. | 80 // partial failure. |
| 81 bool OverwritingMoveFile(FileId src_file_id, FileId dest_file_id); | 81 bool OverwritingMoveFile(FileId src_file_id, FileId dest_file_id); |
| 82 | 82 |
| 83 // This produces the series 0, 1, 2..., starting at 0 when the underlying | 83 // This produces the series 0, 1, 2..., starting at 0 when the underlying |
| 84 // filesystem is first created, and maintaining state across | 84 // filesystem is first created, and maintaining state across |
| 85 // creation/destruction of FileSystemDirectoryDatabase objects. | 85 // creation/destruction of FileSystemDirectoryDatabase objects. |
| 86 bool GetNextInteger(int64* next); | 86 bool GetNextInteger(int64* next); |
| 87 | 87 |
| 88 // Returns true if the database looks consistent with local filesystem. | 88 // Returns true if the database looks consistent with local filesystem. |
| 89 bool IsFileSystemConsistent(); | 89 bool IsFileSystemConsistent(); |
| 90 | 90 |
| 91 static bool DestroyDatabase(const FilePath& path); | 91 static bool DestroyDatabase(const base::FilePath& path); |
| 92 | 92 |
| 93 private: | 93 private: |
| 94 enum RecoveryOption { | 94 enum RecoveryOption { |
| 95 DELETE_ON_CORRUPTION, | 95 DELETE_ON_CORRUPTION, |
| 96 REPAIR_ON_CORRUPTION, | 96 REPAIR_ON_CORRUPTION, |
| 97 FAIL_ON_CORRUPTION, | 97 FAIL_ON_CORRUPTION, |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 friend class FileSystemDirectoryDatabaseTest; | 100 friend class FileSystemDirectoryDatabaseTest; |
| 101 | 101 |
| 102 bool Init(RecoveryOption recovery_option); | 102 bool Init(RecoveryOption recovery_option); |
| 103 bool RepairDatabase(const std::string& db_path); | 103 bool RepairDatabase(const std::string& db_path); |
| 104 void ReportInitStatus(const leveldb::Status& status); | 104 void ReportInitStatus(const leveldb::Status& status); |
| 105 bool StoreDefaultValues(); | 105 bool StoreDefaultValues(); |
| 106 bool GetLastFileId(FileId* file_id); | 106 bool GetLastFileId(FileId* file_id); |
| 107 bool VerifyIsDirectory(FileId file_id); | 107 bool VerifyIsDirectory(FileId file_id); |
| 108 bool AddFileInfoHelper( | 108 bool AddFileInfoHelper( |
| 109 const FileInfo& info, FileId file_id, leveldb::WriteBatch* batch); | 109 const FileInfo& info, FileId file_id, leveldb::WriteBatch* batch); |
| 110 bool RemoveFileInfoHelper(FileId file_id, leveldb::WriteBatch* batch); | 110 bool RemoveFileInfoHelper(FileId file_id, leveldb::WriteBatch* batch); |
| 111 void HandleError(const tracked_objects::Location& from_here, | 111 void HandleError(const tracked_objects::Location& from_here, |
| 112 const leveldb::Status& status); | 112 const leveldb::Status& status); |
| 113 | 113 |
| 114 const FilePath filesystem_data_directory_; | 114 const base::FilePath filesystem_data_directory_; |
| 115 scoped_ptr<leveldb::DB> db_; | 115 scoped_ptr<leveldb::DB> db_; |
| 116 base::Time last_reported_time_; | 116 base::Time last_reported_time_; |
| 117 DISALLOW_COPY_AND_ASSIGN(FileSystemDirectoryDatabase); | 117 DISALLOW_COPY_AND_ASSIGN(FileSystemDirectoryDatabase); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 } // namespace fileapi | 120 } // namespace fileapi |
| 121 | 121 |
| 122 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_DIRECTORY_DATABASE_H_ | 122 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_DIRECTORY_DATABASE_H_ |
| OLD | NEW |