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

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

Issue 9764006: Make ExtensionPrefValueMap a ProfileKeyedService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: -- Created 8 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_pref_value_map.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_VALUE_MAP_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_VALUE_MAP_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_VALUE_MAP_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_VALUE_MAP_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 12
13 #include "base/observer_list.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "chrome/browser/prefs/value_map_pref_store.h" 15 #include "base/values.h"
16 #include "chrome/browser/prefs/pref_value_map.h"
17 #include "chrome/browser/profiles/profile_keyed_service.h"
15 #include "chrome/browser/extensions/extension_prefs_scope.h" 18 #include "chrome/browser/extensions/extension_prefs_scope.h"
16 19
17 // Non-persistent data container that is shared by ExtensionPrefStores. All 20 // Non-persistent data container that is shared by ExtensionPrefStores. All
18 // extension pref values (incognito and regular) are stored herein and 21 // extension pref values (incognito and regular) are stored herein and
19 // provided to ExtensionPrefStores. 22 // provided to ExtensionPrefStores.
20 // 23 //
21 // The semantics of the ExtensionPrefValueMap are: 24 // The semantics of the ExtensionPrefValueMap are:
22 // - The precedence of extensions is determined by their installation time. 25 // - The precedence of extensions is determined by their installation time.
23 // The extension that has been installed later takes higher precedence. 26 // The extension that has been installed later takes higher precedence.
24 // - If two extensions set a value for the same preference, the following 27 // - If two extensions set a value for the same preference, the following
(...skipping 11 matching lines...) Expand all
36 // 1 | 2 | - | - | 1 | 2 39 // 1 | 2 | - | - | 1 | 2
37 // 1 | - | 3 | - | 3 | 3 40 // 1 | - | 3 | - | 3 | 3
38 // 1 | - | - | 4 | 1 | 4 41 // 1 | - | - | 4 | 1 | 4
39 // 1 | 2 | 3 | - | 3 | 3(!) 42 // 1 | 2 | 3 | - | 3 | 3(!)
40 // 1 | 2 | - | 4 | 1 | 4 43 // 1 | 2 | - | 4 | 1 | 4
41 // 1 | 2 | 3 | 4 | 3 | 4 44 // 1 | 2 | 3 | 4 | 3 | 4
42 // A = extension A, B = extension B, E = effective value 45 // A = extension A, B = extension B, E = effective value
43 // .reg = regular value 46 // .reg = regular value
44 // .inc = incognito value 47 // .inc = incognito value
45 // Extension B has higher precedence than A. 48 // Extension B has higher precedence than A.
46 class ExtensionPrefValueMap { 49 class ExtensionPrefValueMap : public ProfileKeyedService {
47 public: 50 public:
48 // Observer interface for monitoring ExtensionPrefValueMap. 51 // Observer interface for monitoring ExtensionPrefValueMap.
49 class Observer { 52 class Observer {
50 public: 53 public:
51 virtual ~Observer() {} 54 virtual ~Observer() {}
52 55
53 // Called when the value for the given |key| set by one of the extensions 56 // Called when the value for the given |key| set by one of the extensions
54 // changes. This does not necessarily mean that the effective value has 57 // changes. This does not necessarily mean that the effective value has
55 // changed. 58 // changed.
56 virtual void OnPrefValueChanged(const std::string& key) = 0; 59 virtual void OnPrefValueChanged(const std::string& key) = 0;
57 // Notification about the ExtensionPrefValueMap being fully initialized. 60 // Notification about the ExtensionPrefValueMap being fully initialized.
58 virtual void OnInitializationCompleted() = 0; 61 virtual void OnInitializationCompleted() = 0;
59 // Called when the ExtensionPrefValueMap is being destroyed. When called, 62 // Called when the ExtensionPrefValueMap is being destroyed. When called,
60 // observers must unsubscribe. 63 // observers must unsubscribe.
61 virtual void OnExtensionPrefValueMapDestruction() = 0; 64 virtual void OnExtensionPrefValueMapDestruction() = 0;
62 }; 65 };
63 66
64 ExtensionPrefValueMap(); 67 ExtensionPrefValueMap();
65 virtual ~ExtensionPrefValueMap(); 68 virtual ~ExtensionPrefValueMap();
66 69
70 // ProfileKeyedService implementation.
71 virtual void Shutdown() OVERRIDE;
72
67 // Set an extension preference |value| for |key| of extension |ext_id|. 73 // Set an extension preference |value| for |key| of extension |ext_id|.
68 // Takes ownership of |value|. 74 // Takes ownership of |value|.
69 // Note that regular extension pref values need to be reported to 75 // Note that regular extension pref values need to be reported to
70 // incognito and to regular ExtensionPrefStores. 76 // incognito and to regular ExtensionPrefStores.
71 // Precondition: the extension must be registered. 77 // Precondition: the extension must be registered.
72 void SetExtensionPref(const std::string& ext_id, 78 void SetExtensionPref(const std::string& ext_id,
73 const std::string& key, 79 const std::string& key,
74 ExtensionPrefsScope scope, 80 ExtensionPrefsScope scope,
75 base::Value* value); 81 base::Value* value);
76 82
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 162
157 void NotifyOfDestruction(); 163 void NotifyOfDestruction();
158 void NotifyPrefValueChanged(const std::string& key); 164 void NotifyPrefValueChanged(const std::string& key);
159 void NotifyPrefValueChanged(const std::set<std::string>& keys); 165 void NotifyPrefValueChanged(const std::set<std::string>& keys);
160 166
161 // Mapping of which extension set which preference value. The effective 167 // Mapping of which extension set which preference value. The effective
162 // preferences values (i.e. the ones with the highest precedence) 168 // preferences values (i.e. the ones with the highest precedence)
163 // are stored in ExtensionPrefStores. 169 // are stored in ExtensionPrefStores.
164 ExtensionEntryMap entries_; 170 ExtensionEntryMap entries_;
165 171
172 // In normal Profile shutdown, Shutdown() notifies observers that we are
173 // being destroyed. In tests, it isn't called, so the notification must
174 // be done in the destructor. This bit tracks whether it has been done yet.
175 bool destroyed_;
176
166 ObserverList<Observer, true> observers_; 177 ObserverList<Observer, true> observers_;
167 178
168 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefValueMap); 179 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefValueMap);
169 }; 180 };
170 181
171 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_VALUE_MAP_H_ 182 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREF_VALUE_MAP_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_pref_value_map.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698