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/file_path.h" | |
10 #include "chrome/browser/extensions/extension_settings_storage.h" | |
11 | |
12 // Manages ExtensionSettingsStorage objects for extensions. | |
13 class ExtensionSettings { | |
14 public: | |
15 // File path is the base of the extension settings directory. | |
16 // The databases will be at base_path/extension_id. | |
17 explicit ExtensionSettings(const FilePath& base_path); | |
18 ~ExtensionSettings(); | |
19 | |
20 // Callback for the GetStorage() methods. The callback will always be Run() | |
21 // from a PostMessage to the UI thread, even if the storage area is cached. | |
22 class Callback { | |
23 public: | |
24 virtual ~Callback() {} | |
25 | |
26 // Called when the storage area is available. Ownership of the object | |
27 // remains with the ExtensionSettings object. | |
28 virtual void Run(ExtensionSettingsStorage* storage) = 0; | |
29 }; | |
30 | |
31 // Gets the storage area for a given extension. | |
32 // By default this will be of a cached LEVELDB storage, but on failure to | |
33 // create a leveldb instance will fall back to cached NOOP storage. | |
34 // Callback objects will be deleted when used. | |
35 void GetStorage(const std::string& extension_id, Callback* callback); | |
36 | |
37 // Gets a storage area for a given extension with a specific type. | |
38 // and whether it should be wrapped in a cache. | |
39 // Use this for testing; if the given type fails to be created (e.g. if | |
40 // leveldb creation fails) then a DCHECK will fail. | |
41 // Callback objects will be deleted when used. | |
42 void GetStorageForTesting( | |
43 ExtensionSettingsStorage::Type type, | |
44 bool cached, | |
45 const std::string& extension_id, | |
46 Callback* callback); | |
47 | |
48 private: | |
49 DISALLOW_COPY_AND_ASSIGN(ExtensionSettings); | |
Matt Perry
2011/06/23 18:11:45
this should be the very last thing in the class
not at google - send to devlin
2011/06/27 08:51:02
Done.
| |
50 | |
51 // Attempts to get and callback with an existing storage area. Returns | |
52 // whether storage existed and the callback run. | |
53 bool GetExistingStorage(const std::string& extension_id, Callback* callback); | |
54 | |
55 const FilePath base_path_; | |
56 std::map<std::string, ExtensionSettingsStorage*> storage_objs_; | |
Matt Perry
2011/06/23 18:11:45
please document these member vars
not at google - send to devlin
2011/06/27 08:51:02
Done.
| |
57 }; | |
58 | |
59 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_ | |
OLD | NEW |