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.
5 #ifndef CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_
6 #define CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_
10 #include "base/files/file_path.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h"
13 #include "base/strings/string_piece.h"
14 #include "content/common/content_export.h"
15 #include "third_party/leveldatabase/src/include/leveldb/status.h"
26 class LevelDBComparator
;
27 class LevelDBDatabase
;
28 class LevelDBIterator
;
29 class LevelDBWriteBatch
;
31 class LevelDBSnapshot
{
33 friend class LevelDBDatabase
;
34 friend class LevelDBTransaction
;
36 explicit LevelDBSnapshot(LevelDBDatabase
* db
);
40 const leveldb::Snapshot
* snapshot_
;
43 class CONTENT_EXPORT LevelDBLock
{
45 virtual ~LevelDBLock() {}
48 class CONTENT_EXPORT LevelDBDatabase
{
50 static leveldb::Status
Open(const base::FilePath
& file_name
,
51 const LevelDBComparator
* comparator
,
52 scoped_ptr
<LevelDBDatabase
>* db
,
53 bool* is_disk_full
= 0);
54 static scoped_ptr
<LevelDBDatabase
> OpenInMemory(
55 const LevelDBComparator
* comparator
);
56 static leveldb::Status
Destroy(const base::FilePath
& file_name
);
57 static scoped_ptr
<LevelDBLock
> LockForTesting(
58 const base::FilePath
& file_name
);
59 virtual ~LevelDBDatabase();
61 leveldb::Status
Put(const base::StringPiece
& key
, std::string
* value
);
62 leveldb::Status
Remove(const base::StringPiece
& key
);
63 virtual leveldb::Status
Get(const base::StringPiece
& key
,
66 const LevelDBSnapshot
* = 0);
67 leveldb::Status
Write(const LevelDBWriteBatch
& write_batch
);
68 scoped_ptr
<LevelDBIterator
> CreateIterator(const LevelDBSnapshot
* = 0);
69 const LevelDBComparator
* Comparator() const;
70 void Compact(const base::StringPiece
& start
, const base::StringPiece
& stop
);
76 friend class LevelDBSnapshot
;
78 scoped_ptr
<leveldb::Env
> env_
;
79 scoped_ptr
<leveldb::Comparator
> comparator_adapter_
;
80 scoped_ptr
<leveldb::DB
> db_
;
81 const LevelDBComparator
* comparator_
;
84 } // namespace content
86 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_