OLD | NEW |
| (Empty) |
1 // Copyright (c) 2013 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 CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_ | |
6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_ | |
7 | |
8 #include <vector> | |
9 | |
10 #include "base/files/file_path.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/string16.h" | |
13 #include "content/common/content_export.h" | |
14 | |
15 namespace leveldb { | |
16 class Comparator; | |
17 class DB; | |
18 class Env; | |
19 class Snapshot; | |
20 } | |
21 | |
22 namespace content { | |
23 | |
24 class LevelDBComparator; | |
25 class LevelDBDatabase; | |
26 class LevelDBIterator; | |
27 class LevelDBSlice; | |
28 class LevelDBWriteBatch; | |
29 | |
30 class LevelDBSnapshot { | |
31 private: | |
32 friend class LevelDBDatabase; | |
33 friend class LevelDBTransaction; | |
34 | |
35 explicit LevelDBSnapshot(LevelDBDatabase* db); | |
36 ~LevelDBSnapshot(); | |
37 | |
38 leveldb::DB* db_; | |
39 const leveldb::Snapshot* snapshot_; | |
40 }; | |
41 | |
42 class CONTENT_EXPORT LevelDBDatabase { | |
43 public: | |
44 static scoped_ptr<LevelDBDatabase> Open(const base::FilePath& file_name, | |
45 const LevelDBComparator* comparator); | |
46 static scoped_ptr<LevelDBDatabase> OpenInMemory( | |
47 const LevelDBComparator* comparator); | |
48 static bool Destroy(const base::FilePath& file_name); | |
49 virtual ~LevelDBDatabase(); | |
50 | |
51 bool Put(const LevelDBSlice& key, const std::vector<char>& value); | |
52 bool Remove(const LevelDBSlice& key); | |
53 virtual bool Get(const LevelDBSlice& key, | |
54 std::vector<char>& value, | |
55 bool& found, | |
56 const LevelDBSnapshot* = 0); | |
57 bool Write(LevelDBWriteBatch& batch); | |
58 scoped_ptr<LevelDBIterator> CreateIterator(const LevelDBSnapshot* = 0); | |
59 const LevelDBComparator* Comparator() const; | |
60 | |
61 protected: | |
62 LevelDBDatabase(); | |
63 | |
64 private: | |
65 friend class LevelDBSnapshot; | |
66 | |
67 scoped_ptr<leveldb::Env> env_; | |
68 scoped_ptr<leveldb::Comparator> comparator_adapter_; | |
69 scoped_ptr<leveldb::DB> db_; | |
70 const LevelDBComparator* comparator_; | |
71 }; | |
72 | |
73 } // namespace content | |
74 | |
75 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_ | |
OLD | NEW |