| 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_BROWSER_FILEAPI_SANDBOX_DIRECTORY_DATABASE_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_SANDBOX_DIRECTORY_DATABASE_H_ |
| 6 #define WEBKIT_BROWSER_FILEAPI_SANDBOX_DIRECTORY_DATABASE_H_ | 6 #define WEBKIT_BROWSER_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.h" | 11 #include "base/files/file.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "webkit/browser/webkit_storage_browser_export.h" | 15 #include "webkit/browser/webkit_storage_browser_export.h" |
| 16 | 16 |
| 17 namespace tracked_objects { | 17 namespace tracked_objects { |
| 18 class Location; | 18 class Location; |
| 19 } | 19 } |
| 20 | 20 |
| 21 namespace leveldb { | 21 namespace leveldb { |
| 22 class DB; | 22 class DB; |
| 23 class Env; |
| 23 class Status; | 24 class Status; |
| 24 class WriteBatch; | 25 class WriteBatch; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace fileapi { | 28 namespace fileapi { |
| 28 | 29 |
| 29 // This class WILL NOT protect you against producing directory loops, giving an | 30 // This class WILL NOT protect you against producing directory loops, giving an |
| 30 // empty directory a backing data file, giving two files the same backing file, | 31 // empty directory a backing data file, giving two files the same backing file, |
| 31 // or pointing to a nonexistent backing file. It does no file IO other than | 32 // or pointing to a nonexistent backing file. It does no file IO other than |
| 32 // that involved with talking to its underlying database. It does not create or | 33 // that involved with talking to its underlying database. It does not create or |
| (...skipping 16 matching lines...) Expand all Loading... |
| 49 | 50 |
| 50 FileId parent_id; | 51 FileId parent_id; |
| 51 base::FilePath data_path; | 52 base::FilePath data_path; |
| 52 base::FilePath::StringType name; | 53 base::FilePath::StringType name; |
| 53 // This modification time is valid only for directories, not files, as | 54 // This modification time is valid only for directories, not files, as |
| 54 // FileWriter will get the files out of sync. | 55 // FileWriter will get the files out of sync. |
| 55 // For files, look at the modification time of the underlying data_path. | 56 // For files, look at the modification time of the underlying data_path. |
| 56 base::Time modification_time; | 57 base::Time modification_time; |
| 57 }; | 58 }; |
| 58 | 59 |
| 59 explicit SandboxDirectoryDatabase( | 60 SandboxDirectoryDatabase( |
| 60 const base::FilePath& filesystem_data_directory); | 61 const base::FilePath& filesystem_data_directory, |
| 62 leveldb::Env* env_override); |
| 61 ~SandboxDirectoryDatabase(); | 63 ~SandboxDirectoryDatabase(); |
| 62 | 64 |
| 63 bool GetChildWithName( | 65 bool GetChildWithName( |
| 64 FileId parent_id, | 66 FileId parent_id, |
| 65 const base::FilePath::StringType& name, | 67 const base::FilePath::StringType& name, |
| 66 FileId* child_id); | 68 FileId* child_id); |
| 67 bool GetFileWithPath(const base::FilePath& path, FileId* file_id); | 69 bool GetFileWithPath(const base::FilePath& path, FileId* file_id); |
| 68 // ListChildren will succeed, returning 0 children, if parent_id doesn't | 70 // ListChildren will succeed, returning 0 children, if parent_id doesn't |
| 69 // exist. | 71 // exist. |
| 70 bool ListChildren(FileId parent_id, std::vector<FileId>* children); | 72 bool ListChildren(FileId parent_id, std::vector<FileId>* children); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 86 // This produces the series 0, 1, 2..., starting at 0 when the underlying | 88 // This produces the series 0, 1, 2..., starting at 0 when the underlying |
| 87 // filesystem is first created, and maintaining state across | 89 // filesystem is first created, and maintaining state across |
| 88 // creation/destruction of SandboxDirectoryDatabase objects. | 90 // creation/destruction of SandboxDirectoryDatabase objects. |
| 89 bool GetNextInteger(int64* next); | 91 bool GetNextInteger(int64* next); |
| 90 | 92 |
| 91 bool IsDirectory(FileId file_id); | 93 bool IsDirectory(FileId file_id); |
| 92 | 94 |
| 93 // Returns true if the database looks consistent with local filesystem. | 95 // Returns true if the database looks consistent with local filesystem. |
| 94 bool IsFileSystemConsistent(); | 96 bool IsFileSystemConsistent(); |
| 95 | 97 |
| 96 static bool DestroyDatabase(const base::FilePath& path); | 98 static bool DestroyDatabase(const base::FilePath& path, |
| 99 leveldb::Env* env_override); |
| 97 | 100 |
| 98 private: | 101 private: |
| 99 enum RecoveryOption { | 102 enum RecoveryOption { |
| 100 DELETE_ON_CORRUPTION, | 103 DELETE_ON_CORRUPTION, |
| 101 REPAIR_ON_CORRUPTION, | 104 REPAIR_ON_CORRUPTION, |
| 102 FAIL_ON_CORRUPTION, | 105 FAIL_ON_CORRUPTION, |
| 103 }; | 106 }; |
| 104 | 107 |
| 105 friend class ObfuscatedFileUtil; | 108 friend class ObfuscatedFileUtil; |
| 106 friend class SandboxDirectoryDatabaseTest; | 109 friend class SandboxDirectoryDatabaseTest; |
| 107 | 110 |
| 108 bool Init(RecoveryOption recovery_option); | 111 bool Init(RecoveryOption recovery_option); |
| 109 bool RepairDatabase(const std::string& db_path); | 112 bool RepairDatabase(const std::string& db_path); |
| 110 void ReportInitStatus(const leveldb::Status& status); | 113 void ReportInitStatus(const leveldb::Status& status); |
| 111 bool StoreDefaultValues(); | 114 bool StoreDefaultValues(); |
| 112 bool GetLastFileId(FileId* file_id); | 115 bool GetLastFileId(FileId* file_id); |
| 113 bool AddFileInfoHelper( | 116 bool AddFileInfoHelper( |
| 114 const FileInfo& info, FileId file_id, leveldb::WriteBatch* batch); | 117 const FileInfo& info, FileId file_id, leveldb::WriteBatch* batch); |
| 115 bool RemoveFileInfoHelper(FileId file_id, leveldb::WriteBatch* batch); | 118 bool RemoveFileInfoHelper(FileId file_id, leveldb::WriteBatch* batch); |
| 116 void HandleError(const tracked_objects::Location& from_here, | 119 void HandleError(const tracked_objects::Location& from_here, |
| 117 const leveldb::Status& status); | 120 const leveldb::Status& status); |
| 118 | 121 |
| 119 const base::FilePath filesystem_data_directory_; | 122 const base::FilePath filesystem_data_directory_; |
| 123 leveldb::Env* env_override_; |
| 120 scoped_ptr<leveldb::DB> db_; | 124 scoped_ptr<leveldb::DB> db_; |
| 121 base::Time last_reported_time_; | 125 base::Time last_reported_time_; |
| 122 DISALLOW_COPY_AND_ASSIGN(SandboxDirectoryDatabase); | 126 DISALLOW_COPY_AND_ASSIGN(SandboxDirectoryDatabase); |
| 123 }; | 127 }; |
| 124 | 128 |
| 125 } // namespace fileapi | 129 } // namespace fileapi |
| 126 | 130 |
| 127 #endif // WEBKIT_BROWSER_FILEAPI_SANDBOX_DIRECTORY_DATABASE_H_ | 131 #endif // WEBKIT_BROWSER_FILEAPI_SANDBOX_DIRECTORY_DATABASE_H_ |
| OLD | NEW |