leveldb_database.h revision 7dbb3d5cf0c15f500944d211057644d6a2f37371
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#include <vector> 10 11#include "base/files/file_path.h" 12#include "base/memory/scoped_ptr.h" 13#include "base/strings/string16.h" 14#include "base/strings/string_piece.h" 15#include "content/common/content_export.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 LevelDBDatabase { 44 public: 45 static scoped_ptr<LevelDBDatabase> Open(const base::FilePath& file_name, 46 const LevelDBComparator* comparator, 47 bool* is_disk_full = 0); 48 static scoped_ptr<LevelDBDatabase> OpenInMemory( 49 const LevelDBComparator* comparator); 50 static bool Destroy(const base::FilePath& file_name); 51 virtual ~LevelDBDatabase(); 52 53 bool Put(const base::StringPiece& key, std::string* value); 54 bool Remove(const base::StringPiece& key); 55 virtual bool Get(const base::StringPiece& key, 56 std::string* value, 57 bool* found, 58 const LevelDBSnapshot* = 0); 59 bool Write(const LevelDBWriteBatch& write_batch); 60 scoped_ptr<LevelDBIterator> CreateIterator(const LevelDBSnapshot* = 0); 61 const LevelDBComparator* Comparator() const; 62 63 protected: 64 LevelDBDatabase(); 65 66 private: 67 friend class LevelDBSnapshot; 68 69 scoped_ptr<leveldb::Env> env_; 70 scoped_ptr<leveldb::Comparator> comparator_adapter_; 71 scoped_ptr<leveldb::DB> db_; 72 const LevelDBComparator* comparator_; 73}; 74 75} // namespace content 76 77#endif // CONTENT_BROWSER_INDEXED_DB_LEVELDB_LEVELDB_DATABASE_H_ 78