leveldb_database.h revision a1401311d1ab56c4ed0a474bd38c108f75cb0cd9
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 <string> 9 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" 16 17namespace leveldb { 18class Comparator; 19class DB; 20class Env; 21class Snapshot; 22} 23 24namespace content { 25 26class LevelDBComparator; 27class LevelDBDatabase; 28class LevelDBIterator; 29class LevelDBWriteBatch; 30 31class LevelDBSnapshot { 32 private: 33 friend class LevelDBDatabase; 34 friend class LevelDBTransaction; 35 36 explicit LevelDBSnapshot(LevelDBDatabase* db); 37 ~LevelDBSnapshot(); 38 39 leveldb::DB* db_; 40 const leveldb::Snapshot* snapshot_; 41}; 42 43class CONTENT_EXPORT LevelDBLock { 44public: 45 virtual ~LevelDBLock() {} 46}; 47 48class CONTENT_EXPORT LevelDBDatabase { 49 public: 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(); 60 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, 64 std::string* value, 65 bool* found, 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); 71 72 protected: 73 LevelDBDatabase(); 74 75 private: 76 friend class LevelDBSnapshot; 77 78 scoped_ptr<leveldb::Env> env_; 79 scoped_ptr<leveldb::Comparator> comparator_adapter_; 80 scoped_ptr<leveldb::DB> db_; 81 const LevelDBComparator* comparator_; 82}; 83 84} // namespace content 85 86#endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_ 87