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_ORIGIN_DATABASE_H_ | 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_ |
6 #define WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_ | 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
(...skipping 21 matching lines...) Expand all Loading... |
32 std::string origin; | 32 std::string origin; |
33 FilePath path; | 33 FilePath path; |
34 | 34 |
35 OriginRecord(); | 35 OriginRecord(); |
36 OriginRecord(const std::string& origin, const FilePath& path); | 36 OriginRecord(const std::string& origin, const FilePath& path); |
37 ~OriginRecord(); | 37 ~OriginRecord(); |
38 }; | 38 }; |
39 | 39 |
40 // Only one instance of FileSystemOriginDatabase should exist for a given path | 40 // Only one instance of FileSystemOriginDatabase should exist for a given path |
41 // at a given time. | 41 // at a given time. |
42 explicit FileSystemOriginDatabase(const FilePath& path); | 42 explicit FileSystemOriginDatabase(const FilePath& file_system_directory); |
43 ~FileSystemOriginDatabase(); | 43 ~FileSystemOriginDatabase(); |
44 | 44 |
45 bool HasOriginPath(const std::string& origin); | 45 bool HasOriginPath(const std::string& origin); |
46 | 46 |
47 // This will produce a unique path and add it to its database, if it's not | 47 // This will produce a unique path and add it to its database, if it's not |
48 // already present. | 48 // already present. |
49 bool GetPathForOrigin(const std::string& origin, FilePath* directory); | 49 bool GetPathForOrigin(const std::string& origin, FilePath* directory); |
50 | 50 |
51 // Also returns success if the origin is not found. | 51 // Also returns success if the origin is not found. |
52 bool RemovePathForOrigin(const std::string& origin); | 52 bool RemovePathForOrigin(const std::string& origin); |
53 | 53 |
54 bool ListAllOrigins(std::vector<OriginRecord>* origins); | 54 bool ListAllOrigins(std::vector<OriginRecord>* origins); |
55 | 55 |
56 // This will release all database resources in use; call it to save memory. | 56 // This will release all database resources in use; call it to save memory. |
57 void DropDatabase(); | 57 void DropDatabase(); |
58 | 58 |
59 private: | 59 private: |
60 bool Init(); | 60 enum RecoveryOption { |
| 61 REPAIR_ON_CORRUPTION, |
| 62 DELETE_ON_CORRUPTION, |
| 63 FAIL_ON_CORRUPTION, |
| 64 }; |
| 65 |
| 66 bool Init(RecoveryOption recovery_option); |
| 67 bool RepairDatabase(const std::string& db_path); |
61 void HandleError(const tracked_objects::Location& from_here, | 68 void HandleError(const tracked_objects::Location& from_here, |
62 const leveldb::Status& status); | 69 const leveldb::Status& status); |
63 void ReportInitStatus(const leveldb::Status& status); | 70 void ReportInitStatus(const leveldb::Status& status); |
64 bool GetLastPathNumber(int* number); | 71 bool GetLastPathNumber(int* number); |
65 | 72 |
66 std::string path_; | 73 FilePath file_system_directory_; |
67 scoped_ptr<leveldb::DB> db_; | 74 scoped_ptr<leveldb::DB> db_; |
68 base::Time last_reported_time_; | 75 base::Time last_reported_time_; |
69 DISALLOW_COPY_AND_ASSIGN(FileSystemOriginDatabase); | 76 DISALLOW_COPY_AND_ASSIGN(FileSystemOriginDatabase); |
70 }; | 77 }; |
71 | 78 |
72 } // namespace fileapi | 79 } // namespace fileapi |
73 | 80 |
74 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_ | 81 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_ |
OLD | NEW |