Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / browser / extension_prefs.h
blob924a0171fee39e437b5c78fe8cefb7710ed8252a
1 // Copyright 2014 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.
5 #ifndef EXTENSIONS_BROWSER_EXTENSION_PREFS_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_PREFS_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/basictypes.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h"
16 #include "base/prefs/scoped_user_pref_update.h"
17 #include "base/time/time.h"
18 #include "base/values.h"
19 #include "components/keyed_service/core/keyed_service.h"
20 #include "extensions/browser/blacklist_state.h"
21 #include "extensions/browser/extension_scoped_prefs.h"
22 #include "extensions/browser/install_flag.h"
23 #include "extensions/common/constants.h"
24 #include "extensions/common/extension.h"
25 #include "extensions/common/url_pattern_set.h"
26 #include "sync/api/string_ordinal.h"
28 class ExtensionPrefValueMap;
29 class PrefService;
31 namespace content {
32 class BrowserContext;
35 namespace user_prefs {
36 class PrefRegistrySyncable;
39 namespace extensions {
41 class AppSorting;
42 class ExtensionPrefsObserver;
43 class URLPatternSet;
45 // Class for managing global and per-extension preferences.
47 // This class distinguishes the following kinds of preferences:
48 // - global preferences:
49 // internal state for the extension system in general, not associated
50 // with an individual extension, such as lastUpdateTime.
51 // - per-extension preferences:
52 // meta-preferences describing properties of the extension like
53 // installation time, whether the extension is enabled, etc.
54 // - extension controlled preferences:
55 // browser preferences that an extension controls. For example, an
56 // extension could use the proxy API to specify the browser's proxy
57 // preference. Extension-controlled preferences are stored in
58 // PrefValueStore::extension_prefs(), which this class populates and
59 // maintains as the underlying extensions change.
60 class ExtensionPrefs : public ExtensionScopedPrefs, public KeyedService {
61 public:
62 typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo;
64 // Vector containing identifiers for preferences.
65 typedef std::set<std::string> PrefKeySet;
67 // This enum is used to store the reason an extension's install has been
68 // delayed. Do not remove items or re-order this enum as it is used in
69 // preferences.
70 enum DelayReason {
71 DELAY_REASON_NONE = 0,
72 DELAY_REASON_GC = 1,
73 DELAY_REASON_WAIT_FOR_IDLE = 2,
74 DELAY_REASON_WAIT_FOR_IMPORTS = 3,
77 // Creates base::Time classes. The default implementation is just to return
78 // the current time, but tests can inject alternative implementations.
79 class TimeProvider {
80 public:
81 TimeProvider();
83 virtual ~TimeProvider();
85 // By default, returns the current time (base::Time::Now()).
86 virtual base::Time GetCurrentTime() const;
88 private:
89 DISALLOW_COPY_AND_ASSIGN(TimeProvider);
92 // A wrapper around a ScopedUserPrefUpdate, which allows us to access the
93 // entry of a particular key for an extension. Use this if you need a mutable
94 // record of a dictionary or list in the current settings. Otherwise, prefer
95 // ReadPrefAsT() and UpdateExtensionPref() methods.
96 template <typename T, base::Value::Type type_enum_value>
97 class ScopedUpdate {
98 public:
99 ScopedUpdate(ExtensionPrefs* prefs,
100 const std::string& extension_id,
101 const std::string& key);
102 virtual ~ScopedUpdate();
104 // Returns a mutable value for the key (ownership remains with the prefs),
105 // if one exists. Otherwise, returns NULL.
106 virtual T* Get();
108 // Creates and returns a mutable value for the key (the prefs own the new
109 // value), if one does not already exist. Otherwise, returns the current
110 // value.
111 virtual T* Create();
113 private:
114 DictionaryPrefUpdate update_;
115 const std::string extension_id_;
116 const std::string key_;
118 DISALLOW_COPY_AND_ASSIGN(ScopedUpdate);
120 typedef ScopedUpdate<base::DictionaryValue, base::Value::TYPE_DICTIONARY>
121 ScopedDictionaryUpdate;
122 typedef ScopedUpdate<base::ListValue, base::Value::TYPE_LIST>
123 ScopedListUpdate;
125 // Creates an ExtensionPrefs object.
126 // Does not take ownership of |prefs| or |extension_pref_value_map|.
127 // If |extensions_disabled| is true, extension controlled preferences and
128 // content settings do not become effective. ExtensionPrefsObservers should be
129 // included in |early_observers| if they need to observe events which occur
130 // during initialization of the ExtensionPrefs object.
131 static ExtensionPrefs* Create(
132 content::BrowserContext* browser_context,
133 PrefService* prefs,
134 const base::FilePath& root_dir,
135 ExtensionPrefValueMap* extension_pref_value_map,
136 bool extensions_disabled,
137 const std::vector<ExtensionPrefsObserver*>& early_observers);
139 // A version of Create which allows injection of a custom base::Time provider.
140 // Use this as needed for testing.
141 static ExtensionPrefs* Create(
142 content::BrowserContext* browser_context,
143 PrefService* prefs,
144 const base::FilePath& root_dir,
145 ExtensionPrefValueMap* extension_pref_value_map,
146 bool extensions_disabled,
147 const std::vector<ExtensionPrefsObserver*>& early_observers,
148 scoped_ptr<TimeProvider> time_provider);
150 ~ExtensionPrefs() override;
152 // Convenience function to get the ExtensionPrefs for a BrowserContext.
153 static ExtensionPrefs* Get(content::BrowserContext* context);
155 // Returns all installed extensions from extension preferences provided by
156 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs
157 // access to the extension ID list before the ExtensionService is initialized.
158 static ExtensionIdList GetExtensionsFrom(const PrefService* pref_service);
160 // Add or remove an observer from the ExtensionPrefs.
161 void AddObserver(ExtensionPrefsObserver* observer);
162 void RemoveObserver(ExtensionPrefsObserver* observer);
164 // Returns true if the specified external extension was uninstalled by the
165 // user.
166 bool IsExternalExtensionUninstalled(const std::string& id) const;
168 // Checks whether |extension_id| is disabled. If there's no state pref for
169 // the extension, this will return false. Generally you should use
170 // ExtensionService::IsExtensionEnabled instead.
171 // Note that blacklisted extensions are NOT marked as disabled!
172 bool IsExtensionDisabled(const std::string& id) const;
174 // Get/Set the order that the browser actions appear in the toolbar.
175 ExtensionIdList GetToolbarOrder() const;
176 void SetToolbarOrder(const ExtensionIdList& extension_ids);
178 // Called when an extension is installed, so that prefs get created.
179 // If |page_ordinal| is invalid then a page will be found for the App.
180 // |install_flags| are a bitmask of extension::InstallFlags.
181 void OnExtensionInstalled(const Extension* extension,
182 Extension::State initial_state,
183 const syncer::StringOrdinal& page_ordinal,
184 int install_flags,
185 const std::string& install_parameter);
186 // OnExtensionInstalled with no install flags.
187 void OnExtensionInstalled(const Extension* extension,
188 Extension::State initial_state,
189 const syncer::StringOrdinal& page_ordinal,
190 const std::string& install_parameter) {
191 OnExtensionInstalled(extension,
192 initial_state,
193 page_ordinal,
194 kInstallFlagNone,
195 install_parameter);
198 // Called when an extension is uninstalled, so that prefs get cleaned up.
199 void OnExtensionUninstalled(const std::string& extension_id,
200 const Manifest::Location& location,
201 bool external_uninstall);
203 // Sets the extension's state to enabled and clears disable reasons.
204 void SetExtensionEnabled(const std::string& extension_id);
206 // Sets the extension's state to disabled and sets the disable reasons.
207 // However, if the current state is EXTERNAL_EXTENSION_UNINSTALLED then that
208 // is preserved (but the disable reasons are still set).
209 void SetExtensionDisabled(const std::string& extension_id,
210 int disable_reasons);
212 // Called to change the extension's BlacklistState. Currently only used for
213 // non-malicious extensions.
214 // TODO(oleg): replace SetExtensionBlacklisted by this function.
215 void SetExtensionBlacklistState(const std::string& extension_id,
216 BlacklistState state);
218 // Checks whether |extension_id| is marked as greylisted.
219 // TODO(oleg): Replace IsExtensionBlacklisted by this method.
220 BlacklistState GetExtensionBlacklistState(
221 const std::string& extension_id) const;
223 // Populates |out| with the ids of all installed extensions.
224 void GetExtensions(ExtensionIdList* out) const;
226 // ExtensionScopedPrefs methods:
227 void UpdateExtensionPref(const std::string& id,
228 const std::string& key,
229 base::Value* value) override;
231 void DeleteExtensionPrefs(const std::string& id) override;
233 bool ReadPrefAsBoolean(const std::string& extension_id,
234 const std::string& pref_key,
235 bool* out_value) const override;
237 bool ReadPrefAsInteger(const std::string& extension_id,
238 const std::string& pref_key,
239 int* out_value) const override;
241 bool ReadPrefAsString(const std::string& extension_id,
242 const std::string& pref_key,
243 std::string* out_value) const override;
245 bool ReadPrefAsList(const std::string& extension_id,
246 const std::string& pref_key,
247 const base::ListValue** out_value) const override;
249 bool ReadPrefAsDictionary(
250 const std::string& extension_id,
251 const std::string& pref_key,
252 const base::DictionaryValue** out_value) const override;
254 bool HasPrefForExtension(const std::string& extension_id) const override;
256 // Did the extension ask to escalate its permission during an upgrade?
257 bool DidExtensionEscalatePermissions(const std::string& id) const;
259 // Getters and setters for disabled reason.
260 // Note that you should rarely need to modify disable reasons directly -
261 // pass the proper value to SetExtensionState instead when you enable/disable
262 // an extension. In particular, AddDisableReason(s) is only legal when the
263 // extension is not enabled.
264 int GetDisableReasons(const std::string& extension_id) const;
265 bool HasDisableReason(const std::string& extension_id,
266 Extension::DisableReason disable_reason) const;
267 void AddDisableReason(const std::string& extension_id,
268 Extension::DisableReason disable_reason);
269 void AddDisableReasons(const std::string& extension_id, int disable_reasons);
270 void RemoveDisableReason(const std::string& extension_id,
271 Extension::DisableReason disable_reason);
272 void ClearDisableReasons(const std::string& extension_id);
274 // Gets the set of extensions that have been blacklisted in prefs. This will
275 // return only the blocked extensions, not the "greylist" extensions.
276 // TODO(oleg): Make method names consistent here, in extension service and in
277 // blacklist.
278 std::set<std::string> GetBlacklistedExtensions() const;
280 // Sets whether the extension with |id| is blacklisted.
281 void SetExtensionBlacklisted(const std::string& extension_id,
282 bool is_blacklisted);
284 // Returns the version string for the currently installed extension, or
285 // the empty string if not found.
286 std::string GetVersionString(const std::string& extension_id) const;
288 // Re-writes the extension manifest into the prefs.
289 // Called to change the extension's manifest when it's re-localized.
290 void UpdateManifest(const Extension* extension);
292 // Returns base extensions install directory.
293 const base::FilePath& install_directory() const { return install_directory_; }
295 // Returns whether the extension with |id| has its blacklist bit set.
297 // WARNING: this only checks the extension's entry in prefs, so by definition
298 // can only check extensions that prefs knows about. There may be other
299 // sources of blacklist information, such as safebrowsing. You probably want
300 // to use Blacklist::GetBlacklistedIDs rather than this method.
301 bool IsExtensionBlacklisted(const std::string& id) const;
303 // Increment the count of how many times we prompted the user to acknowledge
304 // the given extension, and return the new count.
305 int IncrementAcknowledgePromptCount(const std::string& extension_id);
307 // Whether the user has acknowledged an external extension.
308 bool IsExternalExtensionAcknowledged(const std::string& extension_id) const;
309 void AcknowledgeExternalExtension(const std::string& extension_id);
311 // Whether the user has acknowledged a blacklisted extension.
312 bool IsBlacklistedExtensionAcknowledged(
313 const std::string& extension_id) const;
314 void AcknowledgeBlacklistedExtension(const std::string& extension_id);
316 // Whether the external extension was installed during the first run
317 // of this profile.
318 bool IsExternalInstallFirstRun(const std::string& extension_id) const;
319 void SetExternalInstallFirstRun(const std::string& extension_id);
321 // Returns true if the extension notification code has already run for the
322 // first time for this profile. Currently we use this flag to mean that any
323 // extensions that would trigger notifications should get silently
324 // acknowledged. This is a fuse. Calling it the first time returns false.
325 // Subsequent calls return true. It's not possible through an API to ever
326 // reset it. Don't call it unless you mean it!
327 bool SetAlertSystemFirstRun();
329 // Returns the last value set via SetLastPingDay. If there isn't such a
330 // pref, the returned Time will return true for is_null().
331 base::Time LastPingDay(const std::string& extension_id) const;
333 // The time stored is based on the server's perspective of day start time, not
334 // the client's.
335 void SetLastPingDay(const std::string& extension_id, const base::Time& time);
337 // Similar to the 2 above, but for the extensions blacklist.
338 base::Time BlacklistLastPingDay() const;
339 void SetBlacklistLastPingDay(const base::Time& time);
341 // Similar to LastPingDay/SetLastPingDay, but for sending "days since active"
342 // ping.
343 base::Time LastActivePingDay(const std::string& extension_id) const;
344 void SetLastActivePingDay(const std::string& extension_id,
345 const base::Time& time);
347 // A bit we use for determining if we should send the "days since active"
348 // ping. A value of true means the item has been active (launched) since the
349 // last update check.
350 bool GetActiveBit(const std::string& extension_id) const;
351 void SetActiveBit(const std::string& extension_id, bool active);
353 // Returns the granted permission set for the extension with |extension_id|,
354 // and NULL if no preferences were found for |extension_id|.
355 // This passes ownership of the returned set to the caller.
356 scoped_refptr<const PermissionSet> GetGrantedPermissions(
357 const std::string& extension_id) const;
359 // Adds |permissions| to the granted permissions set for the extension with
360 // |extension_id|. The new granted permissions set will be the union of
361 // |permissions| and the already granted permissions.
362 void AddGrantedPermissions(const std::string& extension_id,
363 const PermissionSet* permissions);
365 // As above, but subtracts the given |permissions| from the granted set.
366 void RemoveGrantedPermissions(const std::string& extension_id,
367 const PermissionSet* permissions);
369 // Gets the active permission set for the specified extension. This may
370 // differ from the permissions in the manifest due to the optional
371 // permissions API. This passes ownership of the set to the caller.
372 scoped_refptr<const PermissionSet> GetActivePermissions(
373 const std::string& extension_id) const;
375 // Sets the active |permissions| for the extension with |extension_id|.
376 void SetActivePermissions(const std::string& extension_id,
377 const PermissionSet* permissions);
379 // Records whether or not this extension is currently running.
380 void SetExtensionRunning(const std::string& extension_id, bool is_running);
382 // Returns whether or not this extension is marked as running. This is used to
383 // restart apps across browser restarts.
384 bool IsExtensionRunning(const std::string& extension_id) const;
386 // Set/Get whether or not the app is active. Used to force a launch of apps
387 // that don't handle onRestarted() on a restart. We can only safely do that if
388 // the app was active when it was last running.
389 void SetIsActive(const std::string& extension_id, bool is_active);
390 bool IsActive(const std::string& extension_id) const;
392 // Returns true if the user enabled this extension to be loaded in incognito
393 // mode.
395 // IMPORTANT: you probably want to use extensions::util::IsIncognitoEnabled
396 // instead of this method.
397 bool IsIncognitoEnabled(const std::string& extension_id) const;
398 void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled);
400 // Returns true if the user has chosen to allow this extension to inject
401 // scripts into pages with file URLs.
403 // IMPORTANT: you probably want to use extensions::util::AllowFileAccess
404 // instead of this method.
405 bool AllowFileAccess(const std::string& extension_id) const;
406 void SetAllowFileAccess(const std::string& extension_id, bool allow);
407 bool HasAllowFileAccessSetting(const std::string& extension_id) const;
409 // Saves ExtensionInfo for each installed extension with the path to the
410 // version directory and the location. Blacklisted extensions won't be saved
411 // and neither will external extensions the user has explicitly uninstalled.
412 // Caller takes ownership of returned structure.
413 scoped_ptr<ExtensionsInfo> GetInstalledExtensionsInfo() const;
415 // Same as above, but only includes external extensions the user has
416 // explicitly uninstalled.
417 scoped_ptr<ExtensionsInfo> GetUninstalledExtensionsInfo() const;
419 // Returns the ExtensionInfo from the prefs for the given extension. If the
420 // extension is not present, NULL is returned.
421 scoped_ptr<ExtensionInfo> GetInstalledExtensionInfo(
422 const std::string& extension_id) const;
424 // We've downloaded an updated .crx file for the extension, but are waiting
425 // to install it.
427 // |install_flags| are a bitmask of extension::InstallFlags.
428 void SetDelayedInstallInfo(const Extension* extension,
429 Extension::State initial_state,
430 int install_flags,
431 DelayReason delay_reason,
432 const syncer::StringOrdinal& page_ordinal,
433 const std::string& install_parameter);
435 // Removes any delayed install information we have for the given
436 // |extension_id|. Returns true if there was info to remove; false otherwise.
437 bool RemoveDelayedInstallInfo(const std::string& extension_id);
439 // Update the prefs to finish the update for an extension.
440 bool FinishDelayedInstallInfo(const std::string& extension_id);
442 // Returns the ExtensionInfo from the prefs for delayed install information
443 // for |extension_id|, if we have any. Otherwise returns NULL.
444 scoped_ptr<ExtensionInfo> GetDelayedInstallInfo(
445 const std::string& extension_id) const;
447 DelayReason GetDelayedInstallReason(const std::string& extension_id) const;
449 // Returns information about all the extensions that have delayed install
450 // information.
451 scoped_ptr<ExtensionsInfo> GetAllDelayedInstallInfo() const;
453 // Returns true if the extension is an ephemeral app.
454 bool IsEphemeralApp(const std::string& extension_id) const;
456 // Promotes an ephemeral app to a regular installed app.
457 void OnEphemeralAppPromoted(const std::string& extension_id);
459 // Returns true if the user repositioned the app on the app launcher via drag
460 // and drop.
461 bool WasAppDraggedByUser(const std::string& extension_id) const;
463 // Sets a flag indicating that the user repositioned the app on the app
464 // launcher by drag and dropping it.
465 void SetAppDraggedByUser(const std::string& extension_id);
467 // Returns true if there is an extension which controls the preference value
468 // for |pref_key| *and* it is specific to incognito mode.
469 bool HasIncognitoPrefValue(const std::string& pref_key) const;
471 // Returns the creation flags mask for the extension.
472 int GetCreationFlags(const std::string& extension_id) const;
474 // Returns the creation flags mask for a delayed install extension.
475 int GetDelayedInstallCreationFlags(const std::string& extension_id) const;
477 // Returns true if the extension was installed from the Chrome Web Store.
478 bool IsFromWebStore(const std::string& extension_id) const;
480 // Returns true if the extension was installed from an App generated from a
481 // bookmark.
482 bool IsFromBookmark(const std::string& extension_id) const;
484 // Returns true if the extension was installed as a default app.
485 bool WasInstalledByDefault(const std::string& extension_id) const;
487 // Returns true if the extension was installed as an oem app.
488 bool WasInstalledByOem(const std::string& extension_id) const;
490 // Helper method to acquire the installation time of an extension.
491 // Returns base::Time() if the installation time could not be parsed or
492 // found.
493 base::Time GetInstallTime(const std::string& extension_id) const;
495 // Returns true if the extension should not be synced.
496 bool DoNotSync(const std::string& extension_id) const;
498 // Gets/sets the last launch time of an extension.
499 base::Time GetLastLaunchTime(const std::string& extension_id) const;
500 void SetLastLaunchTime(const std::string& extension_id,
501 const base::Time& time);
503 // Clear any launch times. This is called by the browsing data remover when
504 // history is cleared.
505 void ClearLastLaunchTimes();
507 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
509 bool extensions_disabled() const { return extensions_disabled_; }
511 // The underlying PrefService.
512 PrefService* pref_service() const { return prefs_; }
514 // The underlying AppSorting.
515 // TODO(treib,kalman): This should be private, and all callers should go
516 // through the ExtensionSystem instead.
517 AppSorting* app_sorting() const;
519 // Schedules garbage collection of an extension's on-disk data on the next
520 // start of this ExtensionService. Applies only to extensions with isolated
521 // storage.
522 void SetNeedsStorageGarbageCollection(bool value);
523 bool NeedsStorageGarbageCollection() const;
525 // Used by AppWindowGeometryCache to persist its cache. These methods
526 // should not be called directly.
527 const base::DictionaryValue* GetGeometryCache(
528 const std::string& extension_id) const;
529 void SetGeometryCache(const std::string& extension_id,
530 scoped_ptr<base::DictionaryValue> cache);
532 // Used for verification of installed extension ids. For the Set method, pass
533 // null to remove the preference.
534 const base::DictionaryValue* GetInstallSignature() const;
535 void SetInstallSignature(const base::DictionaryValue* signature);
537 // The installation parameter associated with the extension.
538 std::string GetInstallParam(const std::string& extension_id) const;
539 void SetInstallParam(const std::string& extension_id,
540 const std::string& install_parameter);
542 // The total number of times we've disabled an extension due to corrupted
543 // contents.
544 int GetCorruptedDisableCount() const;
545 void IncrementCorruptedDisableCount();
547 // Whether the extension with the given |id| needs to be synced. This is set
548 // when the state (such as enabled/disabled or allowed in incognito) is
549 // changed before Sync is ready.
550 bool NeedsSync(const std::string& extension_id) const;
551 void SetNeedsSync(const std::string& extension_id, bool needs_sync);
553 private:
554 friend class ExtensionPrefsBlacklistedExtensions; // Unit test.
555 friend class ExtensionPrefsComponentExtension; // Unit test.
556 friend class ExtensionPrefsUninstallExtension; // Unit test.
558 enum DisableReasonChange {
559 DISABLE_REASON_ADD,
560 DISABLE_REASON_REMOVE,
561 DISABLE_REASON_CLEAR
564 // See the Create methods.
565 ExtensionPrefs(content::BrowserContext* browser_context,
566 PrefService* prefs,
567 const base::FilePath& root_dir,
568 ExtensionPrefValueMap* extension_pref_value_map,
569 scoped_ptr<TimeProvider> time_provider,
570 bool extensions_disabled,
571 const std::vector<ExtensionPrefsObserver*>& early_observers);
573 // Converts absolute paths in the pref to paths relative to the
574 // install_directory_.
575 void MakePathsRelative();
577 // Converts internal relative paths to be absolute. Used for export to
578 // consumers who expect full paths.
579 void MakePathsAbsolute(base::DictionaryValue* dict);
581 // Helper function used by GetInstalledExtensionInfo() and
582 // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided
583 // |extension| dictionary.
584 scoped_ptr<ExtensionInfo> GetInstalledInfoHelper(
585 const std::string& extension_id,
586 const base::DictionaryValue* extension) const;
588 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a
589 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns.
590 bool ReadPrefAsURLPatternSet(const std::string& extension_id,
591 const std::string& pref_key,
592 URLPatternSet* result,
593 int valid_schemes) const;
595 // Converts |new_value| to a list of strings and sets the |pref_key| pref
596 // belonging to |extension_id|.
597 void SetExtensionPrefURLPatternSet(const std::string& extension_id,
598 const std::string& pref_key,
599 const URLPatternSet& new_value);
601 // Read the boolean preference entry and return true if the preference exists
602 // and the preference's value is true; false otherwise.
603 bool ReadPrefAsBooleanAndReturn(const std::string& extension_id,
604 const std::string& key) const;
606 // Interprets |pref_key| in |extension_id|'s preferences as an
607 // PermissionSet, and passes ownership of the set to the caller.
608 scoped_refptr<const PermissionSet> ReadPrefAsPermissionSet(
609 const std::string& extension_id,
610 const std::string& pref_key) const;
612 // Converts the |new_value| to its value and sets the |pref_key| pref
613 // belonging to |extension_id|.
614 void SetExtensionPrefPermissionSet(const std::string& extension_id,
615 const std::string& pref_key,
616 const PermissionSet* new_value);
618 // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it
619 // doesn't exist.
620 const base::DictionaryValue* GetExtensionPref(const std::string& id) const;
622 // Modifies the extensions disable reasons to add a new reason, remove an
623 // existing reason, or clear all reasons. Notifies observers if the set of
624 // DisableReasons has changed.
625 // If |change| is DISABLE_REASON_CLEAR, then |reason| is ignored.
626 void ModifyDisableReasons(const std::string& extension_id,
627 int reasons,
628 DisableReasonChange change);
630 // Fix missing preference entries in the extensions that are were introduced
631 // in a later Chrome version.
632 void FixMissingPrefs(const ExtensionIdList& extension_ids);
634 // Installs the persistent extension preferences into |prefs_|'s extension
635 // pref store. Does nothing if extensions_disabled_ is true.
636 void InitPrefStore();
638 // Migrates the permissions data in the pref store.
639 void MigratePermissions(const ExtensionIdList& extension_ids);
641 // Migrates the disable reasons from a single enum to a bit mask.
642 void MigrateDisableReasons(const ExtensionIdList& extension_ids);
644 // Checks whether there is a state pref for the extension and if so, whether
645 // it matches |check_state|.
646 bool DoesExtensionHaveState(const std::string& id,
647 Extension::State check_state) const;
649 // Reads the list of strings for |pref| from user prefs into
650 // |id_container_out|. Returns false if the pref wasn't found in the user
651 // pref store.
652 template <class ExtensionIdContainer>
653 bool GetUserExtensionPrefIntoContainer(
654 const char* pref,
655 ExtensionIdContainer* id_container_out) const;
657 // Writes the list of strings contained in |strings| to |pref| in prefs.
658 template <class ExtensionIdContainer>
659 void SetExtensionPrefFromContainer(const char* pref,
660 const ExtensionIdContainer& strings);
662 // Helper function to populate |extension_dict| with the values needed
663 // by a newly installed extension. Work is broken up between this
664 // function and FinishExtensionInfoPrefs() to accommodate delayed
665 // installations.
667 // |install_flags| are a bitmask of extension::InstallFlags.
668 void PopulateExtensionInfoPrefs(const Extension* extension,
669 const base::Time install_time,
670 Extension::State initial_state,
671 int install_flags,
672 const std::string& install_parameter,
673 base::DictionaryValue* extension_dict) const;
675 void InitExtensionControlledPrefs(ExtensionPrefValueMap* value_map);
677 // Helper function to complete initialization of the values in
678 // |extension_dict| for an extension install. Also see
679 // PopulateExtensionInfoPrefs().
680 void FinishExtensionInfoPrefs(
681 const std::string& extension_id,
682 const base::Time install_time,
683 bool needs_sort_ordinal,
684 const syncer::StringOrdinal& suggested_page_ordinal,
685 base::DictionaryValue* extension_dict);
687 content::BrowserContext* browser_context_;
689 // The pref service specific to this set of extension prefs. Owned by the
690 // BrowserContext.
691 PrefService* prefs_;
693 // Base extensions install directory.
694 base::FilePath install_directory_;
696 // Weak pointer, owned by BrowserContext.
697 ExtensionPrefValueMap* extension_pref_value_map_;
699 scoped_ptr<TimeProvider> time_provider_;
701 bool extensions_disabled_;
703 base::ObserverList<ExtensionPrefsObserver> observer_list_;
705 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
708 } // namespace extensions
710 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_