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

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: Remove core file Created 9 years, 5 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::RefCounted<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::RefCounted<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 // Starts the process of creation of a storage area.
53 // Must be run on the UI thread.
54 void StartCreationOfStorage(
55 const std::string& extension_id,
56 ExtensionSettingsStorage::Type type,
57 ExtensionSettingsStorage::Type fallback_type,
58 bool cached,
59 const Callback& callback);
60
61 // Creates a new storage area of a given type, with a fallback type if
62 // creation fails, and optionally wrapped in a cache.
63 // Must be run on the FILE thread.
64 void CreateStorageOnFileThread(
65 const std::string& extension_id,
66 ExtensionSettingsStorage::Type type,
67 ExtensionSettingsStorage::Type fallback_type,
68 bool cached,
69 const Callback& callback);
70
71 // Creates a storage area of a given type, optionally wrapped in a cache.
72 // Returns NULL if creation fails.
73 ExtensionSettingsStorage* CreateStorage(
74 const std::string& extension_id,
75 ExtensionSettingsStorage::Type type,
76 bool cached);
77
78 // End the creation of a storage area.
79 // Must be run on the UI thread.
80 void EndCreationOfStorage(
81 const std::string& extension_id,
82 ExtensionSettingsStorage* storage,
83 const Callback& callback);
84
85 // The base file path to create any leveldb databases at.
86 const FilePath base_path_;
87
88 // A cache of ExtensionSettingsStorage objects that have already been created.
89 // Ensure that there is only ever one created per extension.
90 std::map<std::string, ExtensionSettingsStorage*> storage_objs_;
91
92 DISALLOW_COPY_AND_ASSIGN(ExtensionSettings);
93 };
94
95 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698