| 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_SANDBOX_DIRECTORY_DATABASE_H_ |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_DIRECTORY_DATABASE_H_ | 6 #define WEBKIT_FILEAPI_SANDBOX_DIRECTORY_DATABASE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/time.h" | 13 #include "base/time.h" |
| 14 #include "webkit/storage/webkit_storage_export.h" | 14 #include "webkit/storage/webkit_storage_export.h" |
| 15 | 15 |
| 16 namespace tracked_objects { | 16 namespace tracked_objects { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 // This class WILL NOT protect you against producing directory loops, giving an | 28 // This class WILL NOT protect you against producing directory loops, giving an |
| 29 // empty directory a backing data file, giving two files the same backing file, | 29 // empty directory a backing data file, giving two files the same backing file, |
| 30 // or pointing to a nonexistent backing file. It does no file IO other than | 30 // or pointing to a nonexistent backing file. It does no file IO other than |
| 31 // that involved with talking to its underlying database. It does not create or | 31 // that involved with talking to its underlying database. It does not create or |
| 32 // in any way touch real files; it only creates path entries in its database. | 32 // in any way touch real files; it only creates path entries in its database. |
| 33 | 33 |
| 34 // TODO(ericu): Safe mode, which does more checks such as the above on debug | 34 // TODO(ericu): Safe mode, which does more checks such as the above on debug |
| 35 // builds. | 35 // builds. |
| 36 // TODO(ericu): Add a method that will give a unique filename for a data file. | 36 // TODO(ericu): Add a method that will give a unique filename for a data file. |
| 37 class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemDirectoryDatabase { | 37 class WEBKIT_STORAGE_EXPORT_PRIVATE SandboxDirectoryDatabase { |
| 38 public: | 38 public: |
| 39 typedef int64 FileId; | 39 typedef int64 FileId; |
| 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 base::FilePath data_path; | 50 base::FilePath data_path; |
| 51 base::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 SandboxDirectoryDatabase( |
| 59 const base::FilePath& filesystem_data_directory); | 59 const base::FilePath& filesystem_data_directory); |
| 60 ~FileSystemDirectoryDatabase(); | 60 ~SandboxDirectoryDatabase(); |
| 61 | 61 |
| 62 bool GetChildWithName( | 62 bool GetChildWithName( |
| 63 FileId parent_id, const base::FilePath::StringType& name, FileId* child_id
); | 63 FileId parent_id, |
| 64 const base::FilePath::StringType& name, |
| 65 FileId* child_id); |
| 64 bool GetFileWithPath(const base::FilePath& path, FileId* file_id); | 66 bool GetFileWithPath(const base::FilePath& path, FileId* file_id); |
| 65 // ListChildren will succeed, returning 0 children, if parent_id doesn't | 67 // ListChildren will succeed, returning 0 children, if parent_id doesn't |
| 66 // exist. | 68 // exist. |
| 67 bool ListChildren(FileId parent_id, std::vector<FileId>* children); | 69 bool ListChildren(FileId parent_id, std::vector<FileId>* children); |
| 68 bool GetFileInfo(FileId file_id, FileInfo* info); | 70 bool GetFileInfo(FileId file_id, FileInfo* info); |
| 69 bool AddFileInfo(const FileInfo& info, FileId* file_id); | 71 bool AddFileInfo(const FileInfo& info, FileId* file_id); |
| 70 bool RemoveFileInfo(FileId file_id); | 72 bool RemoveFileInfo(FileId file_id); |
| 71 // This does a full update of the FileInfo, and is what you'd use for moves | 73 // 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 | 74 // and renames. If you just want to update the modification_time, use |
| 73 // UpdateModificationTime. | 75 // UpdateModificationTime. |
| 74 bool UpdateFileInfo(FileId file_id, const FileInfo& info); | 76 bool UpdateFileInfo(FileId file_id, const FileInfo& info); |
| 75 bool UpdateModificationTime( | 77 bool UpdateModificationTime( |
| 76 FileId file_id, const base::Time& modification_time); | 78 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 | 79 // 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 | 80 // 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 | 81 // single transaction to avoid weird backing file references in the event of a |
| 80 // partial failure. | 82 // partial failure. |
| 81 bool OverwritingMoveFile(FileId src_file_id, FileId dest_file_id); | 83 bool OverwritingMoveFile(FileId src_file_id, FileId dest_file_id); |
| 82 | 84 |
| 83 // This produces the series 0, 1, 2..., starting at 0 when the underlying | 85 // This produces the series 0, 1, 2..., starting at 0 when the underlying |
| 84 // filesystem is first created, and maintaining state across | 86 // filesystem is first created, and maintaining state across |
| 85 // creation/destruction of FileSystemDirectoryDatabase objects. | 87 // creation/destruction of SandboxDirectoryDatabase objects. |
| 86 bool GetNextInteger(int64* next); | 88 bool GetNextInteger(int64* next); |
| 87 | 89 |
| 88 // Returns true if the database looks consistent with local filesystem. | 90 // Returns true if the database looks consistent with local filesystem. |
| 89 bool IsFileSystemConsistent(); | 91 bool IsFileSystemConsistent(); |
| 90 | 92 |
| 91 static bool DestroyDatabase(const base::FilePath& path); | 93 static bool DestroyDatabase(const base::FilePath& path); |
| 92 | 94 |
| 93 private: | 95 private: |
| 94 enum RecoveryOption { | 96 enum RecoveryOption { |
| 95 DELETE_ON_CORRUPTION, | 97 DELETE_ON_CORRUPTION, |
| 96 REPAIR_ON_CORRUPTION, | 98 REPAIR_ON_CORRUPTION, |
| 97 FAIL_ON_CORRUPTION, | 99 FAIL_ON_CORRUPTION, |
| 98 }; | 100 }; |
| 99 | 101 |
| 100 friend class FileSystemDirectoryDatabaseTest; | 102 friend class SandboxDirectoryDatabaseTest; |
| 101 | 103 |
| 102 bool Init(RecoveryOption recovery_option); | 104 bool Init(RecoveryOption recovery_option); |
| 103 bool RepairDatabase(const std::string& db_path); | 105 bool RepairDatabase(const std::string& db_path); |
| 104 void ReportInitStatus(const leveldb::Status& status); | 106 void ReportInitStatus(const leveldb::Status& status); |
| 105 bool StoreDefaultValues(); | 107 bool StoreDefaultValues(); |
| 106 bool GetLastFileId(FileId* file_id); | 108 bool GetLastFileId(FileId* file_id); |
| 107 bool VerifyIsDirectory(FileId file_id); | 109 bool VerifyIsDirectory(FileId file_id); |
| 108 bool AddFileInfoHelper( | 110 bool AddFileInfoHelper( |
| 109 const FileInfo& info, FileId file_id, leveldb::WriteBatch* batch); | 111 const FileInfo& info, FileId file_id, leveldb::WriteBatch* batch); |
| 110 bool RemoveFileInfoHelper(FileId file_id, leveldb::WriteBatch* batch); | 112 bool RemoveFileInfoHelper(FileId file_id, leveldb::WriteBatch* batch); |
| 111 void HandleError(const tracked_objects::Location& from_here, | 113 void HandleError(const tracked_objects::Location& from_here, |
| 112 const leveldb::Status& status); | 114 const leveldb::Status& status); |
| 113 | 115 |
| 114 const base::FilePath filesystem_data_directory_; | 116 const base::FilePath filesystem_data_directory_; |
| 115 scoped_ptr<leveldb::DB> db_; | 117 scoped_ptr<leveldb::DB> db_; |
| 116 base::Time last_reported_time_; | 118 base::Time last_reported_time_; |
| 117 DISALLOW_COPY_AND_ASSIGN(FileSystemDirectoryDatabase); | 119 DISALLOW_COPY_AND_ASSIGN(SandboxDirectoryDatabase); |
| 118 }; | 120 }; |
| 119 | 121 |
| 120 } // namespace fileapi | 122 } // namespace fileapi |
| 121 | 123 |
| 122 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_DIRECTORY_DATABASE_H_ | 124 #endif // WEBKIT_FILEAPI_SANDBOX_DIRECTORY_DATABASE_H_ |
| OLD | NEW |