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_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/callback.h" |
| 10 #include "base/file_path.h" |
| 11 #include "chrome/browser/extensions/extension_settings_storage.h" |
| 12 |
| 13 // Manages ExtensionSettingsStorage objects for extensions. |
| 14 class ExtensionSettings { |
| 15 public: |
| 16 // File path is the base of the extension settings directory. |
| 17 // The databases will be at base_path/extension_id. |
| 18 explicit ExtensionSettings(const FilePath& base_path); |
| 19 ~ExtensionSettings(); |
| 20 |
| 21 // Callback from the GetStorage() methods. |
| 22 typedef base::Callback<void(ExtensionSettingsStorage*)> Callback; |
| 23 |
| 24 // Gets the storage area for a given extension. |
| 25 // By default this will be of a cached LEVELDB storage, but on failure to |
| 26 // create a leveldb instance will fall back to cached NOOP storage. |
| 27 // Callbacks will happen asynchronously regardless of whether they need to go |
| 28 // to the FILE thread, but will always be called on the UI thread. |
| 29 void GetStorage(const std::string& extension_id, const Callback& callback); |
| 30 |
| 31 // Gets a storage area for a given extension with a specific type. |
| 32 // and whether it should be wrapped in a cache. |
| 33 // Use this for testing; if the given type fails to be created (e.g. if |
| 34 // leveldb creation fails) then a DCHECK will fail. |
| 35 // Callback objects will be deleted when used. |
| 36 void GetStorageForTesting( |
| 37 ExtensionSettingsStorage::Type type, |
| 38 bool cached, |
| 39 const std::string& extension_id, |
| 40 const Callback& callback); |
| 41 |
| 42 private: |
| 43 DISALLOW_COPY_AND_ASSIGN(ExtensionSettings); |
| 44 |
| 45 // Attempts to get and callback with an existing storage area. Returns |
| 46 // whether storage existed and the callback run. |
| 47 bool GetExistingStorage( |
| 48 const std::string& extension_id, const Callback& callback); |
| 49 |
| 50 const FilePath base_path_; |
| 51 std::map<std::string, ExtensionSettingsStorage*> storage_objs_; |
| 52 }; |
| 53 |
| 54 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_ |
OLD | NEW |