Chromium Code Reviews| OLD | NEW | 
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 | 
| 11 #include "base/file_path.h" | 11 #include "base/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 "third_party/leveldatabase/src/include/leveldb/db.h" | 14 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 
| 15 | 15 | 
| 16 namespace tracked_objects { | 16 namespace tracked_objects { | 
| 17 class Location; | 17 class Location; | 
| 18 } | 18 } | 
| 19 | 19 | 
| 20 namespace leveldb { | 20 namespace leveldb { | 
| 21 class Status; | |
| 
 
jsbell
2012/03/10 00:54:50
This can be removed from the .h now.
 
tzik
2012/03/13 06:40:29
Done.
 
 | |
| 21 class WriteBatch; | 22 class WriteBatch; | 
| 22 } | 23 } | 
| 23 | 24 | 
| 24 namespace fileapi { | 25 namespace fileapi { | 
| 25 | 26 | 
| 26 // This class WILL NOT protect you against producing directory loops, giving an | 27 // This class WILL NOT protect you against producing directory loops, giving an | 
| 27 // empty directory a backing data file, giving two files the same backing file, | 28 // empty directory a backing data file, giving two files the same backing file, | 
| 28 // or pointing to a nonexistent backing file. It does no file IO other than | 29 // or pointing to a nonexistent backing file. It does no file IO other than | 
| 29 // that involved with talking to its underlying database. It does not create or | 30 // that involved with talking to its underlying database. It does not create or | 
| 30 // in any way touch real files; it only creates path entries in its database. | 31 // in any way touch real files; it only creates path entries in its database. | 
| 31 | 32 | 
| 32 // TODO(ericu): Safe mode, which does more checks such as the above on debug | 33 // TODO(ericu): Safe mode, which does more checks such as the above on debug | 
| 33 // builds. | 34 // builds. | 
| 34 // TODO(ericu): FSCK, for a full-database check [data file validation possibly | 35 // TODO(ericu): FSCK, for a full-database check [data file validation possibly | 
| 35 // done elsewhere]. | 36 // done elsewhere]. | 
| 36 // TODO(ericu): Add a method that will give a unique filename for a data file. | 37 // TODO(ericu): Add a method that will give a unique filename for a data file. | 
| 37 class FileSystemDirectoryDatabase { | 38 class FileSystemDirectoryDatabase { | 
| 38 public: | 39 public: | 
| 39 typedef int64 FileId; | 40 typedef int64 FileId; | 
| 41 enum RecoveringOption { | |
| 
 
ericu
2012/03/12 19:46:01
I'd prefer RecoveryOption to RecoveringOption, and
 
tzik
2012/03/13 06:40:29
Done.
 
 | |
| 42 REBUILD_ON_CORRUPTION, | |
| 43 LEAVE_ON_CORRUPTION, | |
| 44 }; | |
| 40 | 45 | 
| 41 struct FileInfo { | 46 struct FileInfo { | 
| 42 FileInfo(); | 47 FileInfo(); | 
| 43 ~FileInfo(); | 48 ~FileInfo(); | 
| 44 | 49 | 
| 45 bool is_directory() const { | 50 bool is_directory() const { | 
| 46 return data_path.empty(); | 51 return data_path.empty(); | 
| 47 } | 52 } | 
| 48 | 53 | 
| 49 FileId parent_id; | 54 FileId parent_id; | 
| (...skipping 30 matching lines...) Expand all Loading... | |
| 80 bool OverwritingMoveFile(FileId src_file_id, FileId dest_file_id); | 85 bool OverwritingMoveFile(FileId src_file_id, FileId dest_file_id); | 
| 81 | 86 | 
| 82 // This produces the series 0, 1, 2..., starting at 0 when the underlying | 87 // This produces the series 0, 1, 2..., starting at 0 when the underlying | 
| 83 // filesystem is first created, and maintaining state across | 88 // filesystem is first created, and maintaining state across | 
| 84 // creation/destruction of FileSystemDirectoryDatabase objects. | 89 // creation/destruction of FileSystemDirectoryDatabase objects. | 
| 85 bool GetNextInteger(int64* next); | 90 bool GetNextInteger(int64* next); | 
| 86 | 91 | 
| 87 static bool DestroyDatabase(const FilePath& path); | 92 static bool DestroyDatabase(const FilePath& path); | 
| 88 | 93 | 
| 89 private: | 94 private: | 
| 90 bool Init(); | 95 bool Init(RecoveringOption recovering_option); | 
| 91 bool StoreDefaultValues(); | 96 bool StoreDefaultValues(); | 
| 92 bool GetLastFileId(FileId* file_id); | 97 bool GetLastFileId(FileId* file_id); | 
| 93 bool VerifyIsDirectory(FileId file_id); | 98 bool VerifyIsDirectory(FileId file_id); | 
| 94 bool AddFileInfoHelper( | 99 bool AddFileInfoHelper( | 
| 95 const FileInfo& info, FileId file_id, leveldb::WriteBatch* batch); | 100 const FileInfo& info, FileId file_id, leveldb::WriteBatch* batch); | 
| 96 bool RemoveFileInfoHelper(FileId file_id, leveldb::WriteBatch* batch); | 101 bool RemoveFileInfoHelper(FileId file_id, leveldb::WriteBatch* batch); | 
| 97 void HandleError(const tracked_objects::Location& from_here, | 102 void HandleError(const tracked_objects::Location& from_here, | 
| 98 leveldb::Status status); | 103 leveldb::Status status); | 
| 99 | 104 | 
| 100 std::string path_; | 105 std::string path_; | 
| 101 scoped_ptr<leveldb::DB> db_; | 106 scoped_ptr<leveldb::DB> db_; | 
| 102 }; | 107 }; | 
| 103 | 108 | 
| 104 } // namespace fileapi | 109 } // namespace fileapi | 
| 105 | 110 | 
| 106 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_DIRECTORY_DATABASE_H_ | 111 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_DIRECTORY_DATABASE_H_ | 
| OLD | NEW |