| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_ | |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <utility> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/time.h" | |
| 15 #include "webkit/storage/webkit_storage_export.h" | |
| 16 | |
| 17 namespace leveldb { | |
| 18 class DB; | |
| 19 class Status; | |
| 20 } | |
| 21 | |
| 22 namespace tracked_objects { | |
| 23 class Location; | |
| 24 } | |
| 25 | |
| 26 namespace fileapi { | |
| 27 | |
| 28 // All methods of this class other than the constructor may be used only from | |
| 29 // the browser's FILE thread. The constructor may be used on any thread. | |
| 30 class WEBKIT_STORAGE_EXPORT_PRIVATE FileSystemOriginDatabase { | |
| 31 public: | |
| 32 struct WEBKIT_STORAGE_EXPORT_PRIVATE OriginRecord { | |
| 33 std::string origin; | |
| 34 base::FilePath path; | |
| 35 | |
| 36 OriginRecord(); | |
| 37 OriginRecord(const std::string& origin, const base::FilePath& path); | |
| 38 ~OriginRecord(); | |
| 39 }; | |
| 40 | |
| 41 // Only one instance of FileSystemOriginDatabase should exist for a given path | |
| 42 // at a given time. | |
| 43 explicit FileSystemOriginDatabase(const base::FilePath& file_system_directory)
; | |
| 44 ~FileSystemOriginDatabase(); | |
| 45 | |
| 46 bool HasOriginPath(const std::string& origin); | |
| 47 | |
| 48 // This will produce a unique path and add it to its database, if it's not | |
| 49 // already present. | |
| 50 bool GetPathForOrigin(const std::string& origin, base::FilePath* directory); | |
| 51 | |
| 52 // Also returns success if the origin is not found. | |
| 53 bool RemovePathForOrigin(const std::string& origin); | |
| 54 | |
| 55 bool ListAllOrigins(std::vector<OriginRecord>* origins); | |
| 56 | |
| 57 // This will release all database resources in use; call it to save memory. | |
| 58 void DropDatabase(); | |
| 59 | |
| 60 private: | |
| 61 enum RecoveryOption { | |
| 62 REPAIR_ON_CORRUPTION, | |
| 63 DELETE_ON_CORRUPTION, | |
| 64 FAIL_ON_CORRUPTION, | |
| 65 }; | |
| 66 | |
| 67 bool Init(RecoveryOption recovery_option); | |
| 68 bool RepairDatabase(const std::string& db_path); | |
| 69 void HandleError(const tracked_objects::Location& from_here, | |
| 70 const leveldb::Status& status); | |
| 71 void ReportInitStatus(const leveldb::Status& status); | |
| 72 bool GetLastPathNumber(int* number); | |
| 73 | |
| 74 base::FilePath file_system_directory_; | |
| 75 scoped_ptr<leveldb::DB> db_; | |
| 76 base::Time last_reported_time_; | |
| 77 DISALLOW_COPY_AND_ASSIGN(FileSystemOriginDatabase); | |
| 78 }; | |
| 79 | |
| 80 } // namespace fileapi | |
| 81 | |
| 82 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_ | |
| OLD | NEW |