OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> |
11 | 11 |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "third_party/leveldb/include/leveldb/db.h" | 14 #include "third_party/leveldb/include/leveldb/db.h" |
15 | 15 |
16 namespace fileapi { | 16 namespace fileapi { |
17 | 17 |
18 // All methods of this class other than the constructor may be used only from | 18 // All methods of this class other than the constructor may be used only from |
19 // the browser's FILE thread. The constructor may be used on any thread. | 19 // the browser's FILE thread. The constructor may be used on any thread. |
20 class FileSystemOriginDatabase { | 20 class FileSystemOriginDatabase { |
21 public: | 21 public: |
22 struct OriginRecord { | 22 struct OriginRecord { |
23 std::string origin; | 23 std::string origin; |
24 FilePath path; | 24 FilePath path; |
25 | 25 |
26 OriginRecord(); | 26 OriginRecord(); |
27 OriginRecord(const std::string& origin, const FilePath& path); | 27 OriginRecord(const std::string& origin, const FilePath& path); |
28 ~OriginRecord(); | 28 ~OriginRecord(); |
29 }; | 29 }; |
30 | 30 |
31 // Only one instance of FileSystemOriginDatabase should exist for a given path | 31 // Only one instance of FileSystemOriginDatabase should exist for a given path |
32 // at a given time. | 32 // at a given time. |
33 FileSystemOriginDatabase(const FilePath& path); | 33 explicit FileSystemOriginDatabase(const FilePath& path); |
34 ~FileSystemOriginDatabase(); | 34 ~FileSystemOriginDatabase(); |
35 | 35 |
36 bool HasOriginPath(const std::string& origin); | 36 bool HasOriginPath(const std::string& origin); |
37 | 37 |
38 // This will produce a unique path and add it to its database, if it's not | 38 // This will produce a unique path and add it to its database, if it's not |
39 // already present. | 39 // already present. |
40 bool GetPathForOrigin(const std::string& origin, FilePath* directory); | 40 bool GetPathForOrigin(const std::string& origin, FilePath* directory); |
41 | 41 |
42 // Also returns success if the origin is not found. | 42 // Also returns success if the origin is not found. |
43 bool RemovePathForOrigin(const std::string& origin); | 43 bool RemovePathForOrigin(const std::string& origin); |
44 | 44 |
45 bool ListAllOrigins(std::vector<OriginRecord>* origins); | 45 bool ListAllOrigins(std::vector<OriginRecord>* origins); |
46 | 46 |
47 // This will release all database resources in use; call it to save memory. | 47 // This will release all database resources in use; call it to save memory. |
48 void DropDatabase(); | 48 void DropDatabase(); |
49 | 49 |
50 private: | 50 private: |
51 bool Init(); | 51 bool Init(); |
52 void HandleError(leveldb::Status status); | 52 void HandleError(leveldb::Status status); |
53 bool GetLastPathNumber(int* number); | 53 bool GetLastPathNumber(int* number); |
54 | 54 |
55 std::string path_; | 55 std::string path_; |
56 scoped_ptr<leveldb::DB> db_; | 56 scoped_ptr<leveldb::DB> db_; |
57 DISALLOW_COPY_AND_ASSIGN(FileSystemOriginDatabase); | 57 DISALLOW_COPY_AND_ASSIGN(FileSystemOriginDatabase); |
58 }; | 58 }; |
59 | 59 |
60 } // namespace fileapi | 60 } // namespace fileapi |
61 | 61 |
62 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_ | 62 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_ORIGIN_DATABASE_H_ |
OLD | NEW |