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 "storage/common/storage_export.h" |
16 | 16 |
17 namespace content { | 17 namespace content { |
18 class SandboxDirectoryDatabaseTest; | 18 class SandboxDirectoryDatabaseTest; |
19 } | 19 } |
20 | 20 |
21 namespace tracked_objects { | 21 namespace tracked_objects { |
22 class Location; | 22 class Location; |
23 } | 23 } |
24 | 24 |
25 namespace leveldb { | 25 namespace leveldb { |
26 class DB; | 26 class DB; |
27 class Env; | 27 class Env; |
28 class Status; | 28 class Status; |
29 class WriteBatch; | 29 class WriteBatch; |
30 } | 30 } |
31 | 31 |
32 namespace fileapi { | 32 namespace storage { |
33 | 33 |
34 // This class WILL NOT protect you against producing directory loops, giving an | 34 // This class WILL NOT protect you against producing directory loops, giving an |
35 // empty directory a backing data file, giving two files the same backing file, | 35 // empty directory a backing data file, giving two files the same backing file, |
36 // or pointing to a nonexistent backing file. It does no file IO other than | 36 // or pointing to a nonexistent backing file. It does no file IO other than |
37 // that involved with talking to its underlying database. It does not create or | 37 // that involved with talking to its underlying database. It does not create or |
38 // in any way touch real files; it only creates path entries in its database. | 38 // in any way touch real files; it only creates path entries in its database. |
39 | 39 |
40 // TODO(ericu): Safe mode, which does more checks such as the above on debug | 40 // TODO(ericu): Safe mode, which does more checks such as the above on debug |
41 // builds. | 41 // builds. |
42 // TODO(ericu): Add a method that will give a unique filename for a data file. | 42 // TODO(ericu): Add a method that will give a unique filename for a data file. |
43 class WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE SandboxDirectoryDatabase { | 43 class STORAGE_EXPORT_PRIVATE SandboxDirectoryDatabase { |
44 public: | 44 public: |
45 typedef int64 FileId; | 45 typedef int64 FileId; |
46 | 46 |
47 struct WEBKIT_STORAGE_BROWSER_EXPORT_PRIVATE FileInfo { | 47 struct STORAGE_EXPORT_PRIVATE FileInfo { |
48 FileInfo(); | 48 FileInfo(); |
49 ~FileInfo(); | 49 ~FileInfo(); |
50 | 50 |
51 bool is_directory() const { | 51 bool is_directory() const { return data_path.empty(); } |
52 return data_path.empty(); | |
53 } | |
54 | 52 |
55 FileId parent_id; | 53 FileId parent_id; |
56 base::FilePath data_path; | 54 base::FilePath data_path; |
57 base::FilePath::StringType name; | 55 base::FilePath::StringType name; |
58 // This modification time is valid only for directories, not files, as | 56 // This modification time is valid only for directories, not files, as |
59 // FileWriter will get the files out of sync. | 57 // FileWriter will get the files out of sync. |
60 // For files, look at the modification time of the underlying data_path. | 58 // For files, look at the modification time of the underlying data_path. |
61 base::Time modification_time; | 59 base::Time modification_time; |
62 }; | 60 }; |
63 | 61 |
64 SandboxDirectoryDatabase( | 62 SandboxDirectoryDatabase(const base::FilePath& filesystem_data_directory, |
65 const base::FilePath& filesystem_data_directory, | 63 leveldb::Env* env_override); |
66 leveldb::Env* env_override); | |
67 ~SandboxDirectoryDatabase(); | 64 ~SandboxDirectoryDatabase(); |
68 | 65 |
69 bool GetChildWithName( | 66 bool GetChildWithName(FileId parent_id, |
70 FileId parent_id, | 67 const base::FilePath::StringType& name, |
71 const base::FilePath::StringType& name, | 68 FileId* child_id); |
72 FileId* child_id); | |
73 bool GetFileWithPath(const base::FilePath& path, FileId* file_id); | 69 bool GetFileWithPath(const base::FilePath& path, FileId* file_id); |
74 // ListChildren will succeed, returning 0 children, if parent_id doesn't | 70 // ListChildren will succeed, returning 0 children, if parent_id doesn't |
75 // exist. | 71 // exist. |
76 bool ListChildren(FileId parent_id, std::vector<FileId>* children); | 72 bool ListChildren(FileId parent_id, std::vector<FileId>* children); |
77 bool GetFileInfo(FileId file_id, FileInfo* info); | 73 bool GetFileInfo(FileId file_id, FileInfo* info); |
78 base::File::Error AddFileInfo(const FileInfo& info, FileId* file_id); | 74 base::File::Error AddFileInfo(const FileInfo& info, FileId* file_id); |
79 bool RemoveFileInfo(FileId file_id); | 75 bool RemoveFileInfo(FileId file_id); |
80 // This does a full update of the FileInfo, and is what you'd use for moves | 76 // This does a full update of the FileInfo, and is what you'd use for moves |
81 // and renames. If you just want to update the modification_time, use | 77 // and renames. If you just want to update the modification_time, use |
82 // UpdateModificationTime. | 78 // UpdateModificationTime. |
83 bool UpdateFileInfo(FileId file_id, const FileInfo& info); | 79 bool UpdateFileInfo(FileId file_id, const FileInfo& info); |
84 bool UpdateModificationTime( | 80 bool UpdateModificationTime(FileId file_id, |
85 FileId file_id, const base::Time& modification_time); | 81 const base::Time& modification_time); |
86 // This is used for an overwriting move of a file [not a directory] on top of | 82 // This is used for an overwriting move of a file [not a directory] on top of |
87 // another file [also not a directory]; we need to alter two files' info in a | 83 // another file [also not a directory]; we need to alter two files' info in a |
88 // single transaction to avoid weird backing file references in the event of a | 84 // single transaction to avoid weird backing file references in the event of a |
89 // partial failure. | 85 // partial failure. |
90 bool OverwritingMoveFile(FileId src_file_id, FileId dest_file_id); | 86 bool OverwritingMoveFile(FileId src_file_id, FileId dest_file_id); |
91 | 87 |
92 // 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 |
93 // filesystem is first created, and maintaining state across | 89 // filesystem is first created, and maintaining state across |
94 // creation/destruction of SandboxDirectoryDatabase objects. | 90 // creation/destruction of SandboxDirectoryDatabase objects. |
95 bool GetNextInteger(int64* next); | 91 bool GetNextInteger(int64* next); |
(...skipping 14 matching lines...) Expand all Loading... |
110 }; | 106 }; |
111 | 107 |
112 friend class content::SandboxDirectoryDatabaseTest; | 108 friend class content::SandboxDirectoryDatabaseTest; |
113 friend class ObfuscatedFileUtil; | 109 friend class ObfuscatedFileUtil; |
114 | 110 |
115 bool Init(RecoveryOption recovery_option); | 111 bool Init(RecoveryOption recovery_option); |
116 bool RepairDatabase(const std::string& db_path); | 112 bool RepairDatabase(const std::string& db_path); |
117 void ReportInitStatus(const leveldb::Status& status); | 113 void ReportInitStatus(const leveldb::Status& status); |
118 bool StoreDefaultValues(); | 114 bool StoreDefaultValues(); |
119 bool GetLastFileId(FileId* file_id); | 115 bool GetLastFileId(FileId* file_id); |
120 bool AddFileInfoHelper( | 116 bool AddFileInfoHelper(const FileInfo& info, |
121 const FileInfo& info, FileId file_id, leveldb::WriteBatch* batch); | 117 FileId file_id, |
| 118 leveldb::WriteBatch* batch); |
122 bool RemoveFileInfoHelper(FileId file_id, leveldb::WriteBatch* batch); | 119 bool RemoveFileInfoHelper(FileId file_id, leveldb::WriteBatch* batch); |
123 void HandleError(const tracked_objects::Location& from_here, | 120 void HandleError(const tracked_objects::Location& from_here, |
124 const leveldb::Status& status); | 121 const leveldb::Status& status); |
125 | 122 |
126 const base::FilePath filesystem_data_directory_; | 123 const base::FilePath filesystem_data_directory_; |
127 leveldb::Env* env_override_; | 124 leveldb::Env* env_override_; |
128 scoped_ptr<leveldb::DB> db_; | 125 scoped_ptr<leveldb::DB> db_; |
129 base::Time last_reported_time_; | 126 base::Time last_reported_time_; |
130 DISALLOW_COPY_AND_ASSIGN(SandboxDirectoryDatabase); | 127 DISALLOW_COPY_AND_ASSIGN(SandboxDirectoryDatabase); |
131 }; | 128 }; |
132 | 129 |
133 } // namespace fileapi | 130 } // namespace storage |
134 | 131 |
135 #endif // WEBKIT_BROWSER_FILEAPI_SANDBOX_DIRECTORY_DATABASE_H_ | 132 #endif // WEBKIT_BROWSER_FILEAPI_SANDBOX_DIRECTORY_DATABASE_H_ |
OLD | NEW |