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