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

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

Issue 2823037: Add an ExtensionPrefStore, layered between the user prefs nad the managed pre... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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_PREF_STORE_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_
7
8 #include <list>
9 #include <map>
10 #include <string>
11 #include <vector>
12
13 #include "base/scoped_ptr.h"
14 #include "chrome/common/pref_store.h"
15
16 class DictionaryValue;
17 class PrefService;
18 class Value;
19
20 // This PrefStore keeps track of preferences set by extensions: for example,
21 // proxy settings. A stack of relevant extension IDs is stored in order of
22 // their addition to this PrefStore. For each preference, the last-added
23 // enabled extension that tries to set it overrules any others.
24 class ExtensionPrefStore : public PrefStore {
25 public:
26 explicit ExtensionPrefStore(PrefService* pref_service);
27 virtual ~ExtensionPrefStore() {}
28
29 // The PrefService creates the ExtensionPrefStore, so we need to be able to
30 // defer setting the PrefService here until after construction.
31 void SetPrefService(PrefService* pref_service) {
32 pref_service_ = pref_service;
33 }
34
35 // Begins tracking the preference and value an extension wishes to set. This
36 // must be called each time an extension API tries to set a preference.
37 virtual void InstallExtensionPref(std::string extension_id,
38 const wchar_t* pref_path,
39 Value* pref_value);
40
41 // Removes an extension and all its preference settings from this PrefStore.
42 // This must be called when an extension is uninstalled or disabled.
43 virtual void UninstallExtension(std::string extension_id);
44
45 // PrefStore methods:
46 virtual DictionaryValue* prefs() { return prefs_.get(); }
47
48 virtual PrefReadError ReadPrefs() { return PREF_READ_ERROR_NONE; }
49
50 protected:
51 // Returns a vector of the extension IDs in the extension_stack_.
52 // This should only be accessed by subclasses for unit-testing.
53 void GetExtensionIDs(std::vector<std::string>* result);
54
55 private:
56 // The pref service referring to this pref store. Weak reference.
57 PrefService* pref_service_;
58
59 // Maps preference paths to their values.
60 typedef std::map<const wchar_t*, Value*> PrefValueMap;
61
62 // Applies the highest-priority extension's setting for the given preference
63 // path, or clears the setting in this PrefStore if no extensions wish to
64 // control it.
65 void UpdateOnePref(const wchar_t* path);
66
67 // Updates each preference in the |pref_values| list.
68 void UpdatePrefs(const PrefValueMap* pref_values);
69
70 // A cache of the highest-priority values for each preference that any
71 // extension is controlling, for quick read access. Owns the stored values.
72 scoped_ptr<DictionaryValue> prefs_;
73
74 // Associates an extension ID with the prefs it sets.
75 struct ExtensionPrefs {
76 std::string extension_id;
77 PrefValueMap* pref_values;
78 };
79
80 // A pseudo-stack of extensions and their preferences. Extensions are always
81 // added to the head, but may be removed from the middle. This stack owns
82 // the values in the extensions' PrefValueMaps.
83 typedef std::list<ExtensionPrefs*> ExtensionStack;
84 ExtensionStack extension_stack_;
85 };
86
87 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/shown_sections_handler_unittest.cc ('k') | chrome/browser/extensions/extension_pref_store.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698