Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / content / browser / indexed_db / leveldb / leveldb_database.h
blob60a38ec3682be1a7a42dfd9bffea9c0fa517b656
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_
8 #include <string>
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/comparator.h"
16 #include "third_party/leveldatabase/src/include/leveldb/status.h"
18 namespace leveldb {
19 class Comparator;
20 class DB;
21 class FilterPolicy;
22 class Env;
23 class Snapshot;
26 namespace content {
28 class LevelDBComparator;
29 class LevelDBDatabase;
30 class LevelDBIterator;
31 class LevelDBWriteBatch;
33 class LevelDBSnapshot {
34 private:
35 friend class LevelDBDatabase;
36 friend class LevelDBTransaction;
38 explicit LevelDBSnapshot(LevelDBDatabase* db);
39 ~LevelDBSnapshot();
41 leveldb::DB* db_;
42 const leveldb::Snapshot* snapshot_;
44 DISALLOW_COPY_AND_ASSIGN(LevelDBSnapshot);
47 class CONTENT_EXPORT LevelDBLock {
48 public:
49 LevelDBLock() {}
50 virtual ~LevelDBLock() {}
52 private:
53 DISALLOW_COPY_AND_ASSIGN(LevelDBLock);
56 class CONTENT_EXPORT LevelDBDatabase {
57 public:
58 class ComparatorAdapter : public leveldb::Comparator {
59 public:
60 explicit ComparatorAdapter(const LevelDBComparator* comparator);
62 int Compare(const leveldb::Slice& a,
63 const leveldb::Slice& b) const override;
65 const char* Name() const override;
67 void FindShortestSeparator(std::string* start,
68 const leveldb::Slice& limit) const override;
69 void FindShortSuccessor(std::string* key) const override;
71 private:
72 const LevelDBComparator* comparator_;
75 static leveldb::Status Open(const base::FilePath& file_name,
76 const LevelDBComparator* comparator,
77 scoped_ptr<LevelDBDatabase>* db,
78 bool* is_disk_full = 0);
79 static scoped_ptr<LevelDBDatabase> OpenInMemory(
80 const LevelDBComparator* comparator);
81 static leveldb::Status Destroy(const base::FilePath& file_name);
82 static scoped_ptr<LevelDBLock> LockForTesting(
83 const base::FilePath& file_name);
84 virtual ~LevelDBDatabase();
86 leveldb::Status Put(const base::StringPiece& key, std::string* value);
87 leveldb::Status Remove(const base::StringPiece& key);
88 virtual leveldb::Status Get(const base::StringPiece& key,
89 std::string* value,
90 bool* found,
91 const LevelDBSnapshot* = 0);
92 leveldb::Status Write(const LevelDBWriteBatch& write_batch);
93 scoped_ptr<LevelDBIterator> CreateIterator(const LevelDBSnapshot* = 0);
94 const LevelDBComparator* Comparator() const;
95 void Compact(const base::StringPiece& start, const base::StringPiece& stop);
96 void CompactAll();
98 protected:
99 LevelDBDatabase();
101 private:
102 friend class LevelDBSnapshot;
104 void CloseDatabase();
106 scoped_ptr<leveldb::Env> env_;
107 scoped_ptr<leveldb::Comparator> comparator_adapter_;
108 scoped_ptr<leveldb::DB> db_;
109 scoped_ptr<const leveldb::FilterPolicy> filter_policy_;
110 const LevelDBComparator* comparator_;
113 } // namespace content
115 #endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_