| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 EXTENSIONS_BROWSER_VALUE_STORE_LEVELDB_VALUE_STORE_H_ | 5 #ifndef EXTENSIONS_BROWSER_VALUE_STORE_LEVELDB_VALUE_STORE_H_ |
| 6 #define EXTENSIONS_BROWSER_VALUE_STORE_LEVELDB_VALUE_STORE_H_ | 6 #define EXTENSIONS_BROWSER_VALUE_STORE_LEVELDB_VALUE_STORE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "extensions/browser/value_store/value_store.h" | 14 #include "extensions/browser/value_store/value_store.h" |
| 15 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 15 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
| 16 | 16 |
| 17 // Value store area, backed by a leveldb database. | 17 // Value store area, backed by a leveldb database. |
| 18 // All methods must be run on the FILE thread. | 18 // All methods must be run on the FILE thread. |
| 19 class LeveldbValueStore : public ValueStore { | 19 class LeveldbValueStore : public ValueStore { |
| 20 public: | 20 public: |
| 21 // Creates a database bound to |path|. The underlying database won't be | 21 // Creates a database bound to |path|. The underlying database won't be |
| 22 // opened (i.e. may not be created) until one of the get/set/etc methods are | 22 // opened (i.e. may not be created) until one of the get/set/etc methods are |
| 23 // called - this is because opening the database may fail, and extensions | 23 // called - this is because opening the database may fail, and extensions |
| 24 // need to be notified of that, but we don't want to permanently give up. | 24 // need to be notified of that, but we don't want to permanently give up. |
| 25 // | 25 // |
| 26 // Must be created on the FILE thread. | 26 // Must be created on the FILE thread. |
| 27 explicit LeveldbValueStore(const base::FilePath& path); | 27 explicit LeveldbValueStore(const base::FilePath& path); |
| 28 | 28 |
| 29 // Must be deleted on the FILE thread. | 29 // Must be deleted on the FILE thread. |
| 30 virtual ~LeveldbValueStore(); | 30 ~LeveldbValueStore() override; |
| 31 | 31 |
| 32 // ValueStore implementation. | 32 // ValueStore implementation. |
| 33 virtual size_t GetBytesInUse(const std::string& key) override; | 33 size_t GetBytesInUse(const std::string& key) override; |
| 34 virtual size_t GetBytesInUse(const std::vector<std::string>& keys) override; | 34 size_t GetBytesInUse(const std::vector<std::string>& keys) override; |
| 35 virtual size_t GetBytesInUse() override; | 35 size_t GetBytesInUse() override; |
| 36 virtual ReadResult Get(const std::string& key) override; | 36 ReadResult Get(const std::string& key) override; |
| 37 virtual ReadResult Get(const std::vector<std::string>& keys) override; | 37 ReadResult Get(const std::vector<std::string>& keys) override; |
| 38 virtual ReadResult Get() override; | 38 ReadResult Get() override; |
| 39 virtual WriteResult Set( | 39 WriteResult Set(WriteOptions options, |
| 40 WriteOptions options, | 40 const std::string& key, |
| 41 const std::string& key, | 41 const base::Value& value) override; |
| 42 const base::Value& value) override; | 42 WriteResult Set(WriteOptions options, |
| 43 virtual WriteResult Set( | 43 const base::DictionaryValue& values) override; |
| 44 WriteOptions options, const base::DictionaryValue& values) override; | 44 WriteResult Remove(const std::string& key) override; |
| 45 virtual WriteResult Remove(const std::string& key) override; | 45 WriteResult Remove(const std::vector<std::string>& keys) override; |
| 46 virtual WriteResult Remove(const std::vector<std::string>& keys) override; | 46 WriteResult Clear() override; |
| 47 virtual WriteResult Clear() override; | 47 bool Restore() override; |
| 48 virtual bool Restore() override; | 48 bool RestoreKey(const std::string& key) override; |
| 49 virtual bool RestoreKey(const std::string& key) override; | |
| 50 | 49 |
| 51 // Write directly to the backing levelDB. Only used for testing to cause | 50 // Write directly to the backing levelDB. Only used for testing to cause |
| 52 // corruption in the database. | 51 // corruption in the database. |
| 53 bool WriteToDbForTest(leveldb::WriteBatch* batch); | 52 bool WriteToDbForTest(leveldb::WriteBatch* batch); |
| 54 | 53 |
| 55 private: | 54 private: |
| 56 // Tries to open the database if it hasn't been opened already. | 55 // Tries to open the database if it hasn't been opened already. |
| 57 scoped_ptr<ValueStore::Error> EnsureDbIsOpen(); | 56 scoped_ptr<ValueStore::Error> EnsureDbIsOpen(); |
| 58 | 57 |
| 59 // Reads a setting from the database. | 58 // Reads a setting from the database. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 90 // The location of the leveldb backend. | 89 // The location of the leveldb backend. |
| 91 const base::FilePath db_path_; | 90 const base::FilePath db_path_; |
| 92 | 91 |
| 93 // leveldb backend. | 92 // leveldb backend. |
| 94 scoped_ptr<leveldb::DB> db_; | 93 scoped_ptr<leveldb::DB> db_; |
| 95 | 94 |
| 96 DISALLOW_COPY_AND_ASSIGN(LeveldbValueStore); | 95 DISALLOW_COPY_AND_ASSIGN(LeveldbValueStore); |
| 97 }; | 96 }; |
| 98 | 97 |
| 99 #endif // EXTENSIONS_BROWSER_VALUE_STORE_LEVELDB_VALUE_STORE_H_ | 98 #endif // EXTENSIONS_BROWSER_VALUE_STORE_LEVELDB_VALUE_STORE_H_ |
| OLD | NEW |