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

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

Issue 5213002: Fix for Bug 50726 "Save extension list and "winning" prefs from extensions" (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Temporary hack to fix regression in unit tests Created 10 years, 1 month 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
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 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_PREFS_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_
7 #pragma once 7 #pragma once
8 8
9 #include <set> 9 #include <set>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/linked_ptr.h" 13 #include "base/linked_ptr.h"
14 #include "base/time.h" 14 #include "base/time.h"
15 #include "chrome/browser/prefs/pref_service.h" 15 #include "chrome/browser/prefs/pref_service.h"
16 #include "chrome/common/extensions/extension.h" 16 #include "chrome/common/extensions/extension.h"
17 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
18 18
19 // Class for managing global and per-extension preferences. 19 // Class for managing global and per-extension preferences.
20 // This class is instantiated by ExtensionsService, so it should be accessed 20 // This class is instantiated by ExtensionsService, so it should be accessed
21 // from there. 21 // from there.
22 //
23 // This class distinguishes the following kinds of preferences:
24 // - global preferences:
25 // not associated with extensions
Aaron Boodman 2010/11/23 20:35:13 comment nit: maybe: internal state for the extensi
battre (please use the other) 2010/11/30 17:46:53 Done.
26 // - per-extension preferences:
27 // meta-preferences describing properties of the extension like
Aaron Boodman 2010/11/23 20:35:13 internal state of an individual extension, such as
battre (please use the other) 2010/11/30 17:46:53 I think "internal state" does not really fit stuff
28 // installation time, whether the extension is enabled, etc.
29 // - extension controlled preferences:
30 // global preferences that an individual extension wants to set;
31 // these are arbitrary preferences that are controlled by other
32 // sub-systems.
Aaron Boodman 2010/11/23 20:35:13 TODO(aa): Is this information relevant to readers
battre (please use the other) 2010/11/30 17:46:53 Do you refer to the nomenclature of the three diff
22 class ExtensionPrefs { 33 class ExtensionPrefs {
23 public: 34 public:
24 // Key name for a preference that keeps track of per-extension settings. This 35 // Key name for a preference that keeps track of per-extension settings. This
25 // is a dictionary object read from the Preferences file, keyed off of 36 // is a dictionary object read from the Preferences file, keyed off of
26 // extension ids. 37 // extension ids.
27 static const char kExtensionsPref[]; 38 static const char kExtensionsPref[];
28 39
29 typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo; 40 typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo;
30 41
42 // Vector containing identifiers for preferences.
43 typedef std::vector<std::string> PrefKeySet;
44
45 // Vector containing identifiers for extensions.
46 typedef std::vector<std::string> ExtensionIdSet;
47
31 // This enum is used for the launch type the user wants to use for an 48 // This enum is used for the launch type the user wants to use for an
32 // application. 49 // application.
33 // Do not remove items or re-order this enum as it is used in preferences 50 // Do not remove items or re-order this enum as it is used in preferences
34 // and histograms. 51 // and histograms.
35 enum LaunchType { 52 enum LaunchType {
36 LAUNCH_PINNED, 53 LAUNCH_PINNED,
37 LAUNCH_REGULAR, 54 LAUNCH_REGULAR,
38 LAUNCH_FULLSCREEN 55 LAUNCH_FULLSCREEN
39 }; 56 };
40 57
(...skipping 25 matching lines...) Expand all
66 void OnExtensionInstalled(const Extension* extension, 83 void OnExtensionInstalled(const Extension* extension,
67 Extension::State initial_state, 84 Extension::State initial_state,
68 bool initial_incognito_enabled); 85 bool initial_incognito_enabled);
69 86
70 // Called when an extension is uninstalled, so that prefs get cleaned up. 87 // Called when an extension is uninstalled, so that prefs get cleaned up.
71 void OnExtensionUninstalled(const std::string& extension_id, 88 void OnExtensionUninstalled(const std::string& extension_id,
72 const Extension::Location& location, 89 const Extension::Location& location,
73 bool external_uninstall); 90 bool external_uninstall);
74 91
75 // Returns the state (enabled/disabled) of the given extension. 92 // Returns the state (enabled/disabled) of the given extension.
76 Extension::State GetExtensionState(const std::string& extension_id); 93 Extension::State GetExtensionState(const std::string& extension_id) const;
77 94
78 // Called to change the extension's state when it is enabled/disabled. 95 // Called to change the extension's state when it is enabled/disabled.
79 void SetExtensionState(const Extension* extension, Extension::State); 96 void SetExtensionState(const Extension* extension, Extension::State);
80 97
81 // Getter and setter for browser action visibility. 98 // Getter and setter for browser action visibility.
82 bool GetBrowserActionVisibility(const Extension* extension); 99 bool GetBrowserActionVisibility(const Extension* extension);
83 void SetBrowserActionVisibility(const Extension* extension, bool visible); 100 void SetBrowserActionVisibility(const Extension* extension, bool visible);
84 101
85 // Did the extension ask to escalate its permission during an upgrade? 102 // Did the extension ask to escalate its permission during an upgrade?
86 bool DidExtensionEscalatePermissions(const std::string& id); 103 bool DidExtensionEscalatePermissions(const std::string& id);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // highest current application launch index found. 208 // highest current application launch index found.
192 int GetNextAppLaunchIndex(); 209 int GetNextAppLaunchIndex();
193 210
194 // The extension's update URL data. If not empty, the ExtensionUpdater 211 // The extension's update URL data. If not empty, the ExtensionUpdater
195 // will append a ap= parameter to the URL when checking if a new version 212 // will append a ap= parameter to the URL when checking if a new version
196 // of the extension is available. 213 // of the extension is available.
197 void SetUpdateUrlData(const std::string& extension_id, 214 void SetUpdateUrlData(const std::string& extension_id,
198 const std::string& data); 215 const std::string& data);
199 std::string GetUpdateUrlData(const std::string& extension_id); 216 std::string GetUpdateUrlData(const std::string& extension_id);
200 217
218 // Sets a preference value that is controlled by the extension. In other
219 // words, this is not a pref value *about* the extension but something
220 // global the extension wants to override.
221 void SetExtensionControlledPref(const std::string& extension_id,
222 const std::string& pref_key,
223 Value* value);
224
201 static void RegisterUserPrefs(PrefService* prefs); 225 static void RegisterUserPrefs(PrefService* prefs);
202 226
203 // The underlying PrefService. 227 // The underlying PrefService.
204 PrefService* pref_service() const { return prefs_; } 228 PrefService* pref_service() const { return prefs_; }
205 229
230 protected:
231 // For unit testing. Enables injecting an artificial clock that is used
232 // to query the current time, when an extension is installed.
233 virtual base::Time GetCurrentTime() const;
234
206 private: 235 private:
207 // Converts absolute paths in the pref to paths relative to the 236 // Converts absolute paths in the pref to paths relative to the
208 // install_directory_. 237 // install_directory_.
209 void MakePathsRelative(); 238 void MakePathsRelative();
210 239
211 // Converts internal relative paths to be absolute. Used for export to 240 // Converts internal relative paths to be absolute. Used for export to
212 // consumers who expect full paths. 241 // consumers who expect full paths.
213 void MakePathsAbsolute(DictionaryValue* dict); 242 void MakePathsAbsolute(DictionaryValue* dict);
214 243
215 // Sets the pref |key| for extension |id| to |value|. 244 // Sets the pref |key| for extension |id| to |value|.
(...skipping 21 matching lines...) Expand all
237 bool ReadExtensionPrefInteger(const std::string& extension_id, 266 bool ReadExtensionPrefInteger(const std::string& extension_id,
238 const std::string& pref_key, 267 const std::string& pref_key,
239 int* out_value); 268 int* out_value);
240 269
241 // Ensures and returns a mutable dictionary for extension |id|'s prefs. 270 // Ensures and returns a mutable dictionary for extension |id|'s prefs.
242 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); 271 DictionaryValue* GetOrCreateExtensionPref(const std::string& id);
243 272
244 // Same as above, but returns NULL if it doesn't exist. 273 // Same as above, but returns NULL if it doesn't exist.
245 DictionaryValue* GetExtensionPref(const std::string& id) const; 274 DictionaryValue* GetExtensionPref(const std::string& id) const;
246 275
276 // Returns the dictionary of preferences controlled by the specified extension
277 // or NULL if unknown. All entries in the dictionary contain non-expanded
278 // paths.
279 DictionaryValue* GetExtensionControlledPrefs(const std::string& id) const;
280
281 // Returns all installed and enabled extensions
282 void GetEnabledExtensions(ExtensionIdSet* out) const;
Aaron Boodman 2010/11/23 20:35:13 This method seems generally useful. Make public?
battre (please use the other) 2010/11/30 17:46:53 Done.
283
247 // Serializes the data and schedules a persistent save via the |PrefService|. 284 // Serializes the data and schedules a persistent save via the |PrefService|.
248 // Additionally fires a PREF_CHANGED notification with the top-level 285 // Additionally fires a PREF_CHANGED notification with the top-level
249 // |kExtensionsPref| path set. 286 // |kExtensionsPref| path set.
250 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. 287 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular.
251 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to 288 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to
252 // the mutable extension dictionary. 289 // the mutable extension dictionary.
253 void SavePrefsAndNotify(); 290 void SavePrefsAndNotify();
254 291
255 // Checks if kPrefBlacklist is set to true in the DictionaryValue. 292 // Checks if kPrefBlacklist is set to true in the DictionaryValue.
256 // Return false if the value is false or kPrefBlacklist does not exist. 293 // Return false if the value is false or kPrefBlacklist does not exist.
257 // This is used to decide if an extension is blacklisted. 294 // This is used to decide if an extension is blacklisted.
258 bool IsBlacklistBitSet(DictionaryValue* ext); 295 bool IsBlacklistBitSet(DictionaryValue* ext);
259 296
260 // Helper methods for the public last ping day functions. 297 // Helper methods for the public last ping day functions.
261 base::Time LastPingDayImpl(const DictionaryValue* dictionary) const; 298 base::Time LastPingDayImpl(const DictionaryValue* dictionary) const;
262 void SetLastPingDayImpl(const base::Time& time, DictionaryValue* dictionary); 299 void SetLastPingDayImpl(const base::Time& time, DictionaryValue* dictionary);
263 300
301 // Helper method to acquire the installation time of an extension
302 base::Time GetInstallTime(const std::string& extension_id) const;
303
304 // Grant access to GetInstallTime.
305 friend struct InstallTimeComparator;
306
307 // Fix missing preference entries in the extensions that are were introduced
308 // in a later Chrome version.
309 void FixMissingPrefs(const ExtensionIdSet& extension_ids);
310
311 // Installs the persistent extension preferences into |prefs_|'s extension
312 // pref store.
313 void InstallPersistedExtensionControlledPrefs();
314
315 // Returns the extension controlled preference value of the extension that was
316 // installed most recently.
317 const Value* WinningExtensionControlledPrefValue(const std::string& key)
318 const;
319
320 // Find the most recently installed extension that defines a preference
321 // for |pref_key|, then store its value in the PrefValueStore's extension pref
322 // store and send notifications to observers in case the value changed.
323 void UpdateWinningPref(const std::string& pref_key);
324
325 // Retrieves a list of preference keys that the specified extension
326 // intents to manage.
327 void GetExtensionControlledPrefKeys(const std::string& extension_id,
328 PrefKeySet *out) const;
329
264 // The pref service specific to this set of extension prefs. 330 // The pref service specific to this set of extension prefs.
265 PrefService* prefs_; 331 PrefService* prefs_;
266 332
267 // Base extensions install directory. 333 // Base extensions install directory.
268 FilePath install_directory_; 334 FilePath install_directory_;
269 335
270 // The URLs of all of the toolstrips. 336 // The URLs of all of the toolstrips.
271 URLList shelf_order_; 337 URLList shelf_order_;
272 338
273 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); 339 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
274 }; 340 };
275 341
276 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ 342 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698