OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_LEVELDB_STORAGE_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_LEVELDB_STORAGE_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_LEVELDB_STORAGE_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_LEVELDB_STORAGE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/task.h" | 15 #include "base/task.h" |
16 #include "chrome/browser/extensions/settings/settings_storage.h" | 16 #include "chrome/browser/extensions/settings/settings_storage.h" |
| 17 #include "chrome/browser/extensions/settings/settings_storage_factory.h" |
17 #include "third_party/leveldatabase/src/include/leveldb/db.h" | 18 #include "third_party/leveldatabase/src/include/leveldb/db.h" |
18 | 19 |
| 20 namespace extensions { |
| 21 |
19 // Extension settings storage object, backed by a leveldb database. | 22 // Extension settings storage object, backed by a leveldb database. |
20 // | 23 // |
21 namespace extensions { | |
22 | |
23 // No caching is done; that should be handled by wrapping with an | 24 // No caching is done; that should be handled by wrapping with an |
24 // SettingsStorageCache. | 25 // SettingsStorageCache. |
25 // All methods must be run on the FILE thread. | 26 // All methods must be run on the FILE thread. |
26 class SettingsLeveldbStorage : public SettingsStorage { | 27 class SettingsLeveldbStorage : public SettingsStorage { |
27 public: | 28 public: |
28 // Tries to create a leveldb storage area for an extension at a base path. | 29 // Factory for creating SettingsLeveldbStorage instances. |
29 // Returns NULL if creation fails. | 30 class Factory : public SettingsStorageFactory { |
30 static SettingsLeveldbStorage* Create( | 31 public: |
31 const FilePath& base_path, const std::string& extension_id); | 32 Factory() {} |
| 33 virtual ~Factory() {} |
| 34 |
| 35 // SettingsStorageFactory implementation. |
| 36 virtual SettingsStorage* Create( |
| 37 const FilePath& base_path, const std::string& extension_id) OVERRIDE; |
| 38 |
| 39 private: |
| 40 DISALLOW_COPY_AND_ASSIGN(Factory); |
| 41 }; |
32 | 42 |
33 // Must be deleted on the FILE thread. | 43 // Must be deleted on the FILE thread. |
34 virtual ~SettingsLeveldbStorage(); | 44 virtual ~SettingsLeveldbStorage(); |
35 | 45 |
36 // SettingsStorage implementation. | 46 // SettingsStorage implementation. |
37 virtual ReadResult Get(const std::string& key) OVERRIDE; | 47 virtual ReadResult Get(const std::string& key) OVERRIDE; |
38 virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE; | 48 virtual ReadResult Get(const std::vector<std::string>& keys) OVERRIDE; |
39 virtual ReadResult Get() OVERRIDE; | 49 virtual ReadResult Get() OVERRIDE; |
40 virtual WriteResult Set(const std::string& key, const Value& value) OVERRIDE; | 50 virtual WriteResult Set(const std::string& key, const Value& value) OVERRIDE; |
41 virtual WriteResult Set(const DictionaryValue& settings) OVERRIDE; | 51 virtual WriteResult Set(const DictionaryValue& settings) OVERRIDE; |
(...skipping 23 matching lines...) Expand all Loading... |
65 | 75 |
66 // leveldb backend. | 76 // leveldb backend. |
67 scoped_ptr<leveldb::DB> db_; | 77 scoped_ptr<leveldb::DB> db_; |
68 | 78 |
69 DISALLOW_COPY_AND_ASSIGN(SettingsLeveldbStorage); | 79 DISALLOW_COPY_AND_ASSIGN(SettingsLeveldbStorage); |
70 }; | 80 }; |
71 | 81 |
72 } // namespace extensions | 82 } // namespace extensions |
73 | 83 |
74 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_LEVELDB_STORAGE_H_ | 84 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_LEVELDB_STORAGE_H_ |
OLD | NEW |