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

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: Addressed Mattias' comments Created 10 years 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 should be accessed via ExtensionsService.
Aaron Boodman 2010/12/03 08:58:10 This last sentence no longer seems useful. It can
battre (please use the other) 2010/12/03 19:32:58 Done.
21 // from there. 21 //
22 // This class distinguishes the following kinds of preferences:
23 // - global preferences:
24 // internal state for the extension system in general, not associated
25 // with an individual extension, such as lastUpdateTime.
26 // - per-extension preferences:
27 // meta-preferences describing properties of the extension like
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/12/03 08:58:10 A quick example might clarify things here. Also,
battre (please use the other) 2010/12/03 19:32:58 Done.
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 LAUNCH_WINDOW 56 LAUNCH_WINDOW
40 }; 57 };
41 58
42 explicit ExtensionPrefs(PrefService* prefs, const FilePath& root_dir_); 59 explicit ExtensionPrefs(Profile* profile,
60 const FilePath& root_dir);
43 ~ExtensionPrefs(); 61 ~ExtensionPrefs();
44 62
45 // Returns a copy of the Extensions prefs. 63 // Returns a copy of the Extensions prefs.
46 // TODO(erikkay) Remove this so that external consumers don't need to be 64 // TODO(erikkay) Remove this so that external consumers don't need to be
47 // aware of the internal structure of the preferences. 65 // aware of the internal structure of the preferences.
48 DictionaryValue* CopyCurrentExtensions(); 66 DictionaryValue* CopyCurrentExtensions();
49 67
50 // Populate |killed_ids| with extension ids that have been killed. 68 // Populate |killed_ids| with extension ids that have been killed.
51 void GetKilledExtensionIds(std::set<std::string>* killed_ids); 69 void GetKilledExtensionIds(std::set<std::string>* killed_ids);
52 70
(...skipping 14 matching lines...) Expand all
67 void OnExtensionInstalled(const Extension* extension, 85 void OnExtensionInstalled(const Extension* extension,
68 Extension::State initial_state, 86 Extension::State initial_state,
69 bool initial_incognito_enabled); 87 bool initial_incognito_enabled);
70 88
71 // Called when an extension is uninstalled, so that prefs get cleaned up. 89 // Called when an extension is uninstalled, so that prefs get cleaned up.
72 void OnExtensionUninstalled(const std::string& extension_id, 90 void OnExtensionUninstalled(const std::string& extension_id,
73 const Extension::Location& location, 91 const Extension::Location& location,
74 bool external_uninstall); 92 bool external_uninstall);
75 93
76 // Returns the state (enabled/disabled) of the given extension. 94 // Returns the state (enabled/disabled) of the given extension.
77 Extension::State GetExtensionState(const std::string& extension_id); 95 Extension::State GetExtensionState(const std::string& extension_id) const;
78 96
79 // Called to change the extension's state when it is enabled/disabled. 97 // Called to change the extension's state when it is enabled/disabled.
80 void SetExtensionState(const Extension* extension, Extension::State); 98 void SetExtensionState(const Extension* extension, Extension::State);
81 99
100 // Returns all installed and enabled extensions
101 void GetEnabledExtensions(ExtensionIdSet* out) const;
102
82 // Getter and setter for browser action visibility. 103 // Getter and setter for browser action visibility.
83 bool GetBrowserActionVisibility(const Extension* extension); 104 bool GetBrowserActionVisibility(const Extension* extension);
84 void SetBrowserActionVisibility(const Extension* extension, bool visible); 105 void SetBrowserActionVisibility(const Extension* extension, bool visible);
85 106
86 // Did the extension ask to escalate its permission during an upgrade? 107 // Did the extension ask to escalate its permission during an upgrade?
87 bool DidExtensionEscalatePermissions(const std::string& id); 108 bool DidExtensionEscalatePermissions(const std::string& id);
88 109
89 // If |did_escalate| is true, the preferences for |extension| will be set to 110 // If |did_escalate| is true, the preferences for |extension| will be set to
90 // require the install warning when the user tries to enable. 111 // require the install warning when the user tries to enable.
91 void SetDidExtensionEscalatePermissions(const Extension* extension, 112 void SetDidExtensionEscalatePermissions(const Extension* extension,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // highest current application launch index found. 246 // highest current application launch index found.
226 int GetNextAppLaunchIndex(); 247 int GetNextAppLaunchIndex();
227 248
228 // The extension's update URL data. If not empty, the ExtensionUpdater 249 // The extension's update URL data. If not empty, the ExtensionUpdater
229 // will append a ap= parameter to the URL when checking if a new version 250 // will append a ap= parameter to the URL when checking if a new version
230 // of the extension is available. 251 // of the extension is available.
231 void SetUpdateUrlData(const std::string& extension_id, 252 void SetUpdateUrlData(const std::string& extension_id,
232 const std::string& data); 253 const std::string& data);
233 std::string GetUpdateUrlData(const std::string& extension_id); 254 std::string GetUpdateUrlData(const std::string& extension_id);
234 255
256 // Sets a preference value that is controlled by the extension. In other
257 // words, this is not a pref value *about* the extension but something
258 // global the extension wants to override.
259 void SetExtensionControlledPref(const std::string& extension_id,
260 const std::string& pref_key,
261 Value* value);
262
235 static void RegisterUserPrefs(PrefService* prefs); 263 static void RegisterUserPrefs(PrefService* prefs);
236 264
237 // The underlying PrefService. 265 // The underlying PrefService.
238 PrefService* pref_service() const { return prefs_; } 266 PrefService* pref_service() const { return prefs_; }
239 267
268 protected:
269 // For unit testing. Enables injecting an artificial clock that is used
270 // to query the current time, when an extension is installed.
271 virtual base::Time GetCurrentTime() const;
272
240 private: 273 private:
241 // Converts absolute paths in the pref to paths relative to the 274 // Converts absolute paths in the pref to paths relative to the
242 // install_directory_. 275 // install_directory_.
243 void MakePathsRelative(); 276 void MakePathsRelative();
244 277
245 // Converts internal relative paths to be absolute. Used for export to 278 // Converts internal relative paths to be absolute. Used for export to
246 // consumers who expect full paths. 279 // consumers who expect full paths.
247 void MakePathsAbsolute(DictionaryValue* dict); 280 void MakePathsAbsolute(DictionaryValue* dict);
248 281
249 // Sets the pref |key| for extension |id| to |value|. 282 // Sets the pref |key| for extension |id| to |value|.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 void AddToExtensionPrefStringSet(const std::string& extension_id, 322 void AddToExtensionPrefStringSet(const std::string& extension_id,
290 const std::string& pref_key, 323 const std::string& pref_key,
291 const std::set<std::string>& added_values); 324 const std::set<std::string>& added_values);
292 325
293 // Ensures and returns a mutable dictionary for extension |id|'s prefs. 326 // Ensures and returns a mutable dictionary for extension |id|'s prefs.
294 DictionaryValue* GetOrCreateExtensionPref(const std::string& id); 327 DictionaryValue* GetOrCreateExtensionPref(const std::string& id);
295 328
296 // Same as above, but returns NULL if it doesn't exist. 329 // Same as above, but returns NULL if it doesn't exist.
297 DictionaryValue* GetExtensionPref(const std::string& id) const; 330 DictionaryValue* GetExtensionPref(const std::string& id) const;
298 331
332 // Returns the dictionary of preferences controlled by the specified extension
333 // or NULL if unknown. All entries in the dictionary contain non-expanded
334 // paths.
335 DictionaryValue* GetExtensionControlledPrefs(const std::string& id) const;
336
299 // Serializes the data and schedules a persistent save via the |PrefService|. 337 // Serializes the data and schedules a persistent save via the |PrefService|.
300 // Additionally fires a PREF_CHANGED notification with the top-level 338 // Additionally fires a PREF_CHANGED notification with the top-level
301 // |kExtensionsPref| path set. 339 // |kExtensionsPref| path set.
302 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular. 340 // TODO(andybons): Switch this to EXTENSION_PREF_CHANGED to be more granular.
303 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to 341 // TODO(andybons): Use a ScopedPrefUpdate to update observers on changes to
304 // the mutable extension dictionary. 342 // the mutable extension dictionary.
305 void SavePrefsAndNotify(); 343 void SavePrefsAndNotify();
306 344
307 // Checks if kPrefBlacklist is set to true in the DictionaryValue. 345 // Checks if kPrefBlacklist is set to true in the DictionaryValue.
308 // Return false if the value is false or kPrefBlacklist does not exist. 346 // Return false if the value is false or kPrefBlacklist does not exist.
309 // This is used to decide if an extension is blacklisted. 347 // This is used to decide if an extension is blacklisted.
310 bool IsBlacklistBitSet(DictionaryValue* ext); 348 bool IsBlacklistBitSet(DictionaryValue* ext);
311 349
312 // Helper methods for the public last ping day functions. 350 // Helper methods for the public last ping day functions.
313 base::Time LastPingDayImpl(const DictionaryValue* dictionary) const; 351 base::Time LastPingDayImpl(const DictionaryValue* dictionary) const;
314 void SetLastPingDayImpl(const base::Time& time, DictionaryValue* dictionary); 352 void SetLastPingDayImpl(const base::Time& time, DictionaryValue* dictionary);
315 353
354 // Helper method to acquire the installation time of an extension.
355 base::Time GetInstallTime(const std::string& extension_id) const;
356
357 // Fix missing preference entries in the extensions that are were introduced
358 // in a later Chrome version.
359 void FixMissingPrefs(const ExtensionIdSet& extension_ids);
360
361 // Installs the persistent extension preferences into |prefs_|'s extension
Aaron Boodman 2010/12/03 08:58:10 It seems like what this thing really does is intia
battre (please use the other) 2010/12/03 19:32:58 Done.
362 // pref store.
363 void InstallPersistedExtensionControlledPrefs();
364
365 // Returns the extension controlled preference value of the extension that was
366 // installed most recently.
367 const Value* WinningExtensionControlledPrefValue(
Aaron Boodman 2010/12/03 08:58:10 Method names should be verbs, so "GetWinning...",
battre (please use the other) 2010/12/03 19:32:58 I have changed it to GetWinning. GetMostRecent doe
368 const std::string& key) const;
369
370 // Executes UpdateWinningPref for all |pref_keys|.
371 void UpdateWinningPrefs(const PrefKeySet& pref_keys);
Aaron Boodman 2010/12/03 08:58:10 UpdatePrefStore?
battre (please use the other) 2010/12/03 19:32:58 Done.
372
373 // Finds the most recently installed extension that defines a preference
374 // for |pref_key|, then store its value in the PrefValueStore's extension pref
375 // store and send notifications to observers in case the value changed.
376 void UpdateWinningPref(const std::string& pref_key);
Aaron Boodman 2010/12/03 08:58:10 Also UpdatePrefStore? (method overload)
battre (please use the other) 2010/12/03 19:32:58 Done.
377
378 // Retrieves a list of preference keys that the specified extension
379 // intents to manage. Keys are always appended, |out| is not cleared.
Aaron Boodman 2010/12/03 08:58:10 s/intents/intends
battre (please use the other) 2010/12/03 19:32:58 Done.
380 void GetExtensionControlledPrefKeys(const std::string& extension_id,
381 PrefKeySet *out) const;
382
383 Profile* profile_;
384
316 // The pref service specific to this set of extension prefs. 385 // The pref service specific to this set of extension prefs.
317 PrefService* prefs_; 386 PrefService* prefs_;
318 387
319 // Base extensions install directory. 388 // Base extensions install directory.
320 FilePath install_directory_; 389 FilePath install_directory_;
321 390
322 // The URLs of all of the toolstrips. 391 // The URLs of all of the toolstrips.
323 URLList shelf_order_; 392 URLList shelf_order_;
324 393
325 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); 394 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
326 }; 395 };
327 396
328 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ 397 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698