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_PREF_VALUE_MAP_H_ | |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_VALUE_MAP_H_ | |
7 #pragma once | |
8 | |
9 #include <map> | |
10 #include <set> | |
11 | |
12 #include "base/time.h" | |
13 #include "chrome/browser/prefs/value_map_pref_store.h" | |
14 | |
15 // Non-persistent data container that is shared by ExtensionPrefStores. All | |
16 // extension pref values (incognito and regular) are stored herein and | |
17 // provided to ExtensionPrefStores. | |
18 class ExtensionPrefValueMap { | |
battre
2011/01/05 09:59:40
If you find a better name for this class, I'd be h
| |
19 public: | |
20 ExtensionPrefValueMap(); | |
21 virtual ~ExtensionPrefValueMap(); | |
22 | |
23 // Set an extension preference |value| for |key| of extension |ext_id|. | |
24 // Takes ownership of |value|. | |
25 // Note that regular extension pref values need to be reported to | |
26 // incognito and to regular ExtensionPrefStores. | |
27 // Precondition: the extension must be registered. | |
28 void SetExtensionPref(const std::string& ext_id, | |
29 const std::string& key, | |
30 bool incognito, | |
31 Value* value); | |
32 | |
33 // Remove the extension preference value for |key| of extension |ext_id|. | |
34 // Precondition: the extension must be registered. | |
35 void RemoveExtensionPref(const std::string& ext_id, | |
36 const std::string& key, | |
37 bool incognito); | |
38 | |
39 // Tell the store it's now fully initialized. | |
40 void OnInitializationCompleted(); | |
41 | |
42 // Registers the time when an extension |ext_id| is installed. | |
43 void RegisterExtension(const std::string& ext_id, | |
44 const base::Time& install_time, | |
45 bool is_enabled); | |
46 | |
47 // Deletes all entries related to extension |ext_id|. | |
48 void UnregisterExtension(const std::string& ext_id); | |
49 | |
50 // Hides or makes the extension preference values of the specified extension | |
51 // visible. | |
52 void UpdateExtensionsState(const std::string& ext_id, | |
53 bool is_enabled); | |
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
Would SetExtensionState be a more precise name for
battre
2011/01/05 20:23:08
The SetExtensionState name collides with SetExtens
| |
54 | |
55 // Adds an observer that is always notified if a regular or incognito | |
56 // extension pref value changes - regardless whether this change is | |
57 // visible or hidden due to another extension with a higher precedence. | |
58 // Observers can query GetEffectivePrefValue to see the effective value. | |
59 void AddObserver(PrefStore::Observer* observer); | |
60 | |
61 void RemoveObserver(PrefStore::Observer* observer); | |
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
I can see that it's convenient to reuse the PrefSt
battre
2011/01/05 20:23:08
Done.
| |
62 | |
63 const Value* GetEffectivePrefValue(const std::string& key, | |
64 bool incognito) const; | |
65 private: | |
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
newline before private: declaration.
battre
2011/01/05 20:23:08
Done.
| |
66 struct ExtensionEntry { | |
67 // Installation time of the extension. | |
68 base::Time install_time; | |
69 // Whether extension is enabled in the profile. | |
70 bool enabled; | |
71 // Regular preferences. | |
72 PrefValueMap reg_preferences; | |
73 // Incognito preferences, empty for regular ExtensionPerfStore. | |
Mattias Nissler (ping if slow)
2011/01/05 12:08:07
s/Perf/Pref/
battre
2011/01/05 20:23:08
Done.
| |
74 PrefValueMap inc_preferences; | |
75 }; | |
76 | |
77 typedef std::map<std::string, ExtensionEntry*> ExtensionEntryMap; | |
78 | |
79 const PrefValueMap* GetExtensionPrefValueMap(const std::string& ext_id, | |
80 bool incognito) const; | |
81 | |
82 PrefValueMap* GetExtensionPrefValueMap(const std::string& ext_id, | |
83 bool incognito); | |
84 | |
85 // Returns all keys of pref values that are set by |ext_id|, regardless | |
86 // whether they are set for incognito or regular pref values. | |
87 void GetExtensionControlledKeys(const std::string& ext_id, | |
88 std::set<std::string>* out) const; | |
89 | |
90 void NotifyInitializationCompleted(); | |
91 void NotifyPrefValueChanged(const std::string& key); | |
92 void NotifyPrefValueChanged(const std::set<std::string>& keys); | |
93 | |
94 bool initialization_complete_; | |
95 | |
96 // Mapping of which extension set which preference value. The effective | |
97 // preferences values (i.e. the ones with the highest precedence) | |
98 // are stored in the datastructures of the base class. | |
99 ExtensionEntryMap entries_; | |
100 | |
101 ObserverList<PrefStore::Observer, true> observers_; | |
102 | |
103 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefValueMap); | |
104 }; | |
105 | |
106 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_STORE_H_ | |
OLD | NEW |