Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: chrome/browser/extensions/extension_settings.h

Issue 7189029: Implement an initial extension settings API. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Make clang happy Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "base/memory/ref_counted.h"
12 #include "chrome/browser/extensions/extension_settings_storage.h"
13
14 // Manages ExtensionSettingsStorage objects for extensions.
15 class ExtensionSettings : public base::RefCountedThreadSafe<ExtensionSettings> {
16 public:
17 // File path is the base of the extension settings directory.
18 // The databases will be at base_path/extension_id.
19 explicit ExtensionSettings(const FilePath& base_path);
20
21 // Callback from the GetStorage() methods.
22 typedef base::Callback<void(ExtensionSettingsStorage*)> Callback;
23
24 // Gets the storage area for a given extension. Only valid for the duration
25 // of the callback.
26 // By default this will be of a cached LEVELDB storage, but on failure to
27 // create a leveldb instance will fall back to cached NOOP storage.
28 // Callbacks will happen asynchronously regardless of whether they need to go
29 // to the FILE thread, but will always be called on the UI thread.
30 void GetStorage(const std::string& extension_id, const Callback& callback);
31
32 // Gets a storage area for a given extension with a specific type.
33 // and whether it should be wrapped in a cache.
34 // Use this for testing; if the given type fails to be created (e.g. if
35 // leveldb creation fails) then a DCHECK will fail.
36 // Callback objects will be deleted when used.
37 void GetStorageForTesting(
38 ExtensionSettingsStorage::Type type,
39 bool cached,
40 const std::string& extension_id,
41 const Callback& callback);
42
43 private:
44 friend class base::RefCountedThreadSafe<ExtensionSettings>;
45 ~ExtensionSettings();
46
47 // Attempts to get and callback with an existing storage area. Returns
48 // whether storage existed and the callback run.
49 bool GetExistingStorage(
50 const std::string& extension_id, const Callback& callback);
51
52 // Runs a Callback with a storage argument, then deletes the callback.
53 void RunWithStorage(Callback* callback, ExtensionSettingsStorage* storage);
54
55 // Starts the process of creation of a storage area.
56 // Must be run on the UI thread.
57 void StartCreationOfStorage(
58 const std::string& extension_id,
59 ExtensionSettingsStorage::Type type,
60 ExtensionSettingsStorage::Type fallback_type,
61 bool cached,
62 const Callback& callback);
63
64 // Creates a new storage area of a given type, with a fallback type if
65 // creation fails, and optionally wrapped in a cache.
66 // Must be run on the FILE thread.
67 void CreateStorageOnFileThread(
68 const std::string& extension_id,
69 ExtensionSettingsStorage::Type type,
70 ExtensionSettingsStorage::Type fallback_type,
71 bool cached,
72 const Callback& callback);
73
74 // Creates a storage area of a given type, optionally wrapped in a cache.
75 // Returns NULL if creation fails.
76 ExtensionSettingsStorage* CreateStorage(
77 const std::string& extension_id,
78 ExtensionSettingsStorage::Type type,
79 bool cached);
80
81 // End the creation of a storage area.
82 // Must be run on the UI thread.
83 void EndCreationOfStorage(
84 const std::string& extension_id,
85 ExtensionSettingsStorage* storage,
86 const Callback& callback);
87
88 // The base file path to create any leveldb databases at.
89 const FilePath base_path_;
90
91 // A cache of ExtensionSettingsStorage objects that have already been created.
92 // Ensure that there is only ever one created per extension.
93 std::map<std::string, ExtensionSettingsStorage*> storage_objs_;
94
95 DISALLOW_COPY_AND_ASSIGN(ExtensionSettings);
96 };
97
98 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/extension_settings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698