OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_LEVELDB_STORAGE_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_LEVELDB_STORAGE_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/scoped_ptr.h" |
| 13 #include "base/task.h" |
| 14 #include "chrome/browser/extensions/extension_settings_storage.h" |
| 15 #include "third_party/leveldb/include/leveldb/db.h" |
| 16 |
| 17 // Extension settings storage object, backed by a leveldb database. |
| 18 // No caching is done; that should be handled by wrapping with an |
| 19 // ExtensionSettingsStorageCache. |
| 20 class ExtensionSettingsLeveldbStorage : public ExtensionSettingsStorage { |
| 21 public: |
| 22 // Tries to create a leveldb storage area for an extension at a base path. |
| 23 // Returns NULL if creation fails. |
| 24 // Must be run on the FILE thread. |
| 25 static ExtensionSettingsLeveldbStorage* Create( |
| 26 const FilePath& base_path, const std::string& extension_id); |
| 27 |
| 28 // Can be run on any thread. |
| 29 virtual void DeleteSoon() OVERRIDE; |
| 30 |
| 31 virtual void Get(const std::string& key, Callback* callback) OVERRIDE; |
| 32 virtual void Get(const ListValue& keys, Callback* callback) OVERRIDE; |
| 33 virtual void Get(Callback* callback) OVERRIDE; |
| 34 virtual void Set( |
| 35 const std::string& key, const Value& value, Callback* callback) OVERRIDE; |
| 36 virtual void Set(const DictionaryValue& values, Callback* callback) OVERRIDE; |
| 37 virtual void Remove(const std::string& key, Callback* callback) OVERRIDE; |
| 38 virtual void Remove(const ListValue& keys, Callback* callback) OVERRIDE; |
| 39 virtual void Clear(Callback *callback) OVERRIDE; |
| 40 |
| 41 private: |
| 42 // Ownership of db is taken. |
| 43 explicit ExtensionSettingsLeveldbStorage(leveldb::DB* db); |
| 44 |
| 45 // This must only be deleted on the FILE thread. |
| 46 friend class DeleteTask<ExtensionSettingsLeveldbStorage>; |
| 47 virtual ~ExtensionSettingsLeveldbStorage(); |
| 48 |
| 49 // leveldb backend. |
| 50 scoped_ptr<leveldb::DB> db_; |
| 51 |
| 52 // Whether this has or is about to be deleted on the FILE thread. |
| 53 // Used to prevent any use of this after DeleteSoon() is called. |
| 54 bool marked_for_deletion_; |
| 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsLeveldbStorage); |
| 57 }; |
| 58 |
| 59 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_LEVELDB_STORAGE_H_ |
OLD | NEW |