Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: webkit/fileapi/file_system_directory_database.h

Issue 9910005: Add database recovery for FileSystemDirectoryDatabase. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 14 matching lines...) Expand all
25 namespace fileapi { 25 namespace fileapi {
26 26
27 // 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
28 // 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,
29 // 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
30 // 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
31 // 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.
32 32
33 // 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
34 // builds. 34 // builds.
35 // TODO(ericu): FSCK, for a full-database check [data file validation possibly
36 // done elsewhere].
37 // TODO(ericu): Add a method that will give a unique filename for a data file. 35 // TODO(ericu): Add a method that will give a unique filename for a data file.
38 class FileSystemDirectoryDatabase { 36 class FileSystemDirectoryDatabase {
39 public: 37 public:
40 typedef int64 FileId; 38 typedef int64 FileId;
41 39
42 struct FileInfo { 40 struct FileInfo {
43 FileInfo(); 41 FileInfo();
44 ~FileInfo(); 42 ~FileInfo();
45 43
46 bool is_directory() const { 44 bool is_directory() const {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // another file [also not a directory]; we need to alter two files' info in a 77 // another file [also not a directory]; we need to alter two files' info in a
80 // single transaction to avoid weird backing file references in the event of a 78 // single transaction to avoid weird backing file references in the event of a
81 // partial failure. 79 // partial failure.
82 bool OverwritingMoveFile(FileId src_file_id, FileId dest_file_id); 80 bool OverwritingMoveFile(FileId src_file_id, FileId dest_file_id);
83 81
84 // This produces the series 0, 1, 2..., starting at 0 when the underlying 82 // This produces the series 0, 1, 2..., starting at 0 when the underlying
85 // filesystem is first created, and maintaining state across 83 // filesystem is first created, and maintaining state across
86 // creation/destruction of FileSystemDirectoryDatabase objects. 84 // creation/destruction of FileSystemDirectoryDatabase objects.
87 bool GetNextInteger(int64* next); 85 bool GetNextInteger(int64* next);
88 86
87 // Returns true if the database looks consistent with local filesystem.
88 bool IsFileSystemConsistent();
89
89 static bool DestroyDatabase(const FilePath& path); 90 static bool DestroyDatabase(const FilePath& path);
90 91
91 private: 92 private:
92 enum RecoveryOption { 93 enum RecoveryOption {
93 DELETE_ON_CORRUPTION, 94 DELETE_ON_CORRUPTION,
95 REPAIR_ON_CORRUPTION,
94 FAIL_ON_CORRUPTION, 96 FAIL_ON_CORRUPTION,
95 }; 97 };
96 98
99 friend class FileSystemDirectoryDatabaseTest;
100
97 bool Init(RecoveryOption recovery_option); 101 bool Init(RecoveryOption recovery_option);
102 bool RepairDatabase(const std::string& db_path);
98 void ReportInitStatus(const leveldb::Status& status); 103 void ReportInitStatus(const leveldb::Status& status);
99 bool StoreDefaultValues(); 104 bool StoreDefaultValues();
100 bool GetLastFileId(FileId* file_id); 105 bool GetLastFileId(FileId* file_id);
101 bool VerifyIsDirectory(FileId file_id); 106 bool VerifyIsDirectory(FileId file_id);
102 bool AddFileInfoHelper( 107 bool AddFileInfoHelper(
103 const FileInfo& info, FileId file_id, leveldb::WriteBatch* batch); 108 const FileInfo& info, FileId file_id, leveldb::WriteBatch* batch);
104 bool RemoveFileInfoHelper(FileId file_id, leveldb::WriteBatch* batch); 109 bool RemoveFileInfoHelper(FileId file_id, leveldb::WriteBatch* batch);
105 void HandleError(const tracked_objects::Location& from_here, 110 void HandleError(const tracked_objects::Location& from_here,
106 const leveldb::Status& status); 111 const leveldb::Status& status);
107 112
108 FilePath filesystem_data_directory_; 113 FilePath filesystem_data_directory_;
109 scoped_ptr<leveldb::DB> db_; 114 scoped_ptr<leveldb::DB> db_;
110 base::Time last_reported_time_; 115 base::Time last_reported_time_;
111 DISALLOW_COPY_AND_ASSIGN(FileSystemDirectoryDatabase); 116 DISALLOW_COPY_AND_ASSIGN(FileSystemDirectoryDatabase);
112 }; 117 };
113 118
114 } // namespace fileapi 119 } // namespace fileapi
115 120
116 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_DIRECTORY_DATABASE_H_ 121 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_DIRECTORY_DATABASE_H_
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_database_test_helper.cc ('k') | webkit/fileapi/file_system_directory_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698