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_
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/app_sorting.h"
21 #include "extensions/browser/blacklist_state.h"
22 #include "extensions/browser/extension_scoped_prefs.h"
23 #include "extensions/browser/install_flag.h"
24 #include "extensions/common/constants.h"
25 #include "extensions/common/extension.h"
26 #include "extensions/common/url_pattern_set.h"
27 #include "sync/api/string_ordinal.h"
29 class ExtensionPrefValueMap
;
36 namespace user_prefs
{
37 class PrefRegistrySyncable
;
40 namespace extensions
{
43 class ExtensionPrefsObserver
;
44 class ExtensionPrefsUninstallExtension
;
47 // Class for managing global and per-extension preferences.
49 // This class distinguishes the following kinds of preferences:
50 // - global preferences:
51 // internal state for the extension system in general, not associated
52 // with an individual extension, such as lastUpdateTime.
53 // - per-extension preferences:
54 // meta-preferences describing properties of the extension like
55 // installation time, whether the extension is enabled, etc.
56 // - extension controlled preferences:
57 // browser preferences that an extension controls. For example, an
58 // extension could use the proxy API to specify the browser's proxy
59 // preference. Extension-controlled preferences are stored in
60 // PrefValueStore::extension_prefs(), which this class populates and
61 // maintains as the underlying extensions change.
62 class ExtensionPrefs
: public ExtensionScopedPrefs
, public KeyedService
{
64 typedef std::vector
<linked_ptr
<ExtensionInfo
> > ExtensionsInfo
;
66 // Vector containing identifiers for preferences.
67 typedef std::set
<std::string
> PrefKeySet
;
69 // This enum is used to store the reason an extension's install has been
70 // delayed. Do not remove items or re-order this enum as it is used in
73 DELAY_REASON_NONE
= 0,
75 DELAY_REASON_WAIT_FOR_IDLE
= 2,
76 DELAY_REASON_WAIT_FOR_IMPORTS
= 3,
80 // Creates base::Time classes. The default implementation is just to return
81 // the current time, but tests can inject alternative implementations.
86 virtual ~TimeProvider();
88 // By default, returns the current time (base::Time::Now()).
89 virtual base::Time
GetCurrentTime() const;
92 DISALLOW_COPY_AND_ASSIGN(TimeProvider
);
95 // A wrapper around a ScopedUserPrefUpdate, which allows us to access the
96 // entry of a particular key for an extension. Use this if you need a mutable
97 // record of a dictionary or list in the current settings. Otherwise, prefer
98 // ReadPrefAsT() and UpdateExtensionPref() methods.
99 template <typename T
, base::Value::Type type_enum_value
>
102 ScopedUpdate(ExtensionPrefs
* prefs
,
103 const std::string
& extension_id
,
104 const std::string
& key
);
105 virtual ~ScopedUpdate();
107 // Returns a mutable value for the key (ownership remains with the prefs),
108 // if one exists. Otherwise, returns NULL.
111 // Creates and returns a mutable value for the key (the prefs own the new
112 // value), if one does not already exist. Otherwise, returns the current
117 DictionaryPrefUpdate update_
;
118 const std::string extension_id_
;
119 const std::string key_
;
121 DISALLOW_COPY_AND_ASSIGN(ScopedUpdate
);
123 typedef ScopedUpdate
<base::DictionaryValue
, base::Value::TYPE_DICTIONARY
>
124 ScopedDictionaryUpdate
;
125 typedef ScopedUpdate
<base::ListValue
, base::Value::TYPE_LIST
>
128 // Creates an ExtensionPrefs object.
129 // Does not take ownership of |prefs| or |extension_pref_value_map|.
130 // If |extensions_disabled| is true, extension controlled preferences and
131 // content settings do not become effective. ExtensionPrefsObservers should be
132 // included in |early_observers| if they need to observe events which occur
133 // during initialization of the ExtensionPrefs object.
134 static ExtensionPrefs
* Create(
136 const base::FilePath
& root_dir
,
137 ExtensionPrefValueMap
* extension_pref_value_map
,
138 scoped_ptr
<AppSorting
> app_sorting
,
139 bool extensions_disabled
,
140 const std::vector
<ExtensionPrefsObserver
*>& early_observers
);
142 // A version of Create which allows injection of a custom base::Time provider.
143 // Use this as needed for testing.
144 static ExtensionPrefs
* Create(
146 const base::FilePath
& root_dir
,
147 ExtensionPrefValueMap
* extension_pref_value_map
,
148 scoped_ptr
<AppSorting
> app_sorting
,
149 bool extensions_disabled
,
150 const std::vector
<ExtensionPrefsObserver
*>& early_observers
,
151 scoped_ptr
<TimeProvider
> time_provider
);
153 virtual ~ExtensionPrefs();
155 // Convenience function to get the ExtensionPrefs for a BrowserContext.
156 static ExtensionPrefs
* Get(content::BrowserContext
* context
);
158 // Returns all installed extensions from extension preferences provided by
159 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs
160 // access to the extension ID list before the ExtensionService is initialized.
161 static ExtensionIdList
GetExtensionsFrom(const PrefService
* pref_service
);
163 // Add or remove an observer from the ExtensionPrefs.
164 void AddObserver(ExtensionPrefsObserver
* observer
);
165 void RemoveObserver(ExtensionPrefsObserver
* observer
);
167 // Returns true if the specified external extension was uninstalled by the
169 bool IsExternalExtensionUninstalled(const std::string
& id
) const;
171 // Checks whether |extension_id| is disabled. If there's no state pref for
172 // the extension, this will return false. Generally you should use
173 // ExtensionService::IsExtensionEnabled instead.
174 bool IsExtensionDisabled(const std::string
& id
) const;
176 // Get/Set the order that the browser actions appear in the toolbar.
177 ExtensionIdList
GetToolbarOrder();
178 void SetToolbarOrder(const ExtensionIdList
& extension_ids
);
180 // Called when an extension is installed, so that prefs get created.
181 // If |page_ordinal| is invalid then a page will be found for the App.
182 // |install_flags| are a bitmask of extension::InstallFlags.
183 void OnExtensionInstalled(const Extension
* extension
,
184 Extension::State initial_state
,
185 const syncer::StringOrdinal
& page_ordinal
,
187 const std::string
& install_parameter
);
188 // OnExtensionInstalled with no install flags.
189 void OnExtensionInstalled(const Extension
* extension
,
190 Extension::State initial_state
,
191 const syncer::StringOrdinal
& page_ordinal
,
192 const std::string
& install_parameter
) {
193 OnExtensionInstalled(extension
,
200 // Called when an extension is uninstalled, so that prefs get cleaned up.
201 void OnExtensionUninstalled(const std::string
& extension_id
,
202 const Manifest::Location
& location
,
203 bool external_uninstall
);
205 // Called to change the extension's state when it is enabled/disabled.
206 void SetExtensionState(const std::string
& extension_id
, Extension::State
);
208 // Called to change the extension's BlacklistState. Currently only used for
209 // non-malicious extensions.
210 // TODO(oleg): replace SetExtensionBlacklisted by this function.
211 void SetExtensionBlacklistState(const std::string
& extension_id
,
212 BlacklistState state
);
214 // Checks whether |extension_id| is marked as greylisted.
215 // TODO(oleg): Replace IsExtensionBlacklisted by this method.
216 BlacklistState
GetExtensionBlacklistState(const std::string
& extension_id
);
218 // Populates |out| with the ids of all installed extensions.
219 void GetExtensions(ExtensionIdList
* out
);
221 // ExtensionScopedPrefs methods:
222 virtual void UpdateExtensionPref(const std::string
& id
,
223 const std::string
& key
,
224 base::Value
* value
) OVERRIDE
;
226 virtual void DeleteExtensionPrefs(const std::string
& id
) OVERRIDE
;
228 virtual bool ReadPrefAsBoolean(const std::string
& extension_id
,
229 const std::string
& pref_key
,
230 bool* out_value
) const OVERRIDE
;
232 virtual bool ReadPrefAsInteger(const std::string
& extension_id
,
233 const std::string
& pref_key
,
234 int* out_value
) const OVERRIDE
;
236 virtual bool ReadPrefAsString(const std::string
& extension_id
,
237 const std::string
& pref_key
,
238 std::string
* out_value
) const OVERRIDE
;
240 virtual bool ReadPrefAsList(const std::string
& extension_id
,
241 const std::string
& pref_key
,
242 const base::ListValue
** out_value
) const OVERRIDE
;
244 virtual bool ReadPrefAsDictionary(
245 const std::string
& extension_id
,
246 const std::string
& pref_key
,
247 const base::DictionaryValue
** out_value
) const OVERRIDE
;
249 virtual bool HasPrefForExtension(const std::string
& extension_id
) const
252 // Did the extension ask to escalate its permission during an upgrade?
253 bool DidExtensionEscalatePermissions(const std::string
& id
);
255 // If |did_escalate| is true, the preferences for |extension| will be set to
256 // require the install warning when the user tries to enable.
257 void SetDidExtensionEscalatePermissions(
258 const Extension
* extension
,
261 // Getters and setters for disabled reason.
262 int GetDisableReasons(const std::string
& extension_id
) const;
263 bool HasDisableReason(const std::string
& extension_id
,
264 Extension::DisableReason disable_reason
) const;
265 void AddDisableReason(const std::string
& extension_id
,
266 Extension::DisableReason disable_reason
);
267 void RemoveDisableReason(const std::string
& extension_id
,
268 Extension::DisableReason disable_reason
);
269 void ClearDisableReasons(const std::string
& extension_id
);
271 // Gets the set of extensions that have been blacklisted in prefs. This will
272 // return only the blocked extensions, not the "greylist" extensions.
273 // TODO(oleg): Make method names consistent here, in extension service and in
275 std::set
<std::string
> GetBlacklistedExtensions();
277 // Sets whether the extension with |id| is blacklisted.
278 void SetExtensionBlacklisted(const std::string
& extension_id
,
279 bool is_blacklisted
);
281 // Returns the version string for the currently installed extension, or
282 // the empty string if not found.
283 std::string
GetVersionString(const std::string
& extension_id
);
285 // Re-writes the extension manifest into the prefs.
286 // Called to change the extension's manifest when it's re-localized.
287 void UpdateManifest(const Extension
* extension
);
289 // Returns base extensions install directory.
290 const base::FilePath
& install_directory() const { return install_directory_
; }
292 // Returns whether the extension with |id| has its blacklist bit set.
294 // WARNING: this only checks the extension's entry in prefs, so by definition
295 // can only check extensions that prefs knows about. There may be other
296 // sources of blacklist information, such as safebrowsing. You probably want
297 // to use Blacklist::GetBlacklistedIDs rather than this method.
298 bool IsExtensionBlacklisted(const std::string
& id
) const;
300 // Increment the count of how many times we prompted the user to acknowledge
301 // the given extension, and return the new count.
302 int IncrementAcknowledgePromptCount(const std::string
& extension_id
);
304 // Whether the user has acknowledged an external extension.
305 bool IsExternalExtensionAcknowledged(const std::string
& extension_id
);
306 void AcknowledgeExternalExtension(const std::string
& extension_id
);
308 // Whether the user has acknowledged a blacklisted extension.
309 bool IsBlacklistedExtensionAcknowledged(const std::string
& extension_id
);
310 void AcknowledgeBlacklistedExtension(const std::string
& extension_id
);
312 // Whether the external extension was installed during the first run
314 bool IsExternalInstallFirstRun(const std::string
& extension_id
);
315 void SetExternalInstallFirstRun(const std::string
& extension_id
);
317 // Whether the user has been notified about extension with |extension_id|
319 bool HasWipeoutBeenAcknowledged(const std::string
& extension_id
);
320 void SetWipeoutAcknowledged(const std::string
& extension_id
, bool value
);
322 // Whether the user has been notified about extension with |extension_id|
323 // taking over some aspect of the user's settings (homepage, startup pages,
324 // or search engine).
325 bool HasSettingsApiBubbleBeenAcknowledged(const std::string
& extension_id
);
326 void SetSettingsApiBubbleBeenAcknowledged(const std::string
& extension_id
,
329 // Whether the user has been notified about extension with |extension_id|
330 // overriding the new tab page.
331 bool HasNtpOverriddenBubbleBeenAcknowledged(const std::string
& extension_id
);
332 void SetNtpOverriddenBubbleBeenAcknowledged(const std::string
& extension_id
,
335 // Whether the user has been notified about extension with |extension_id|
336 // overriding the proxy.
337 bool HasProxyOverriddenBubbleBeenAcknowledged(
338 const std::string
& extension_id
);
339 void SetProxyOverriddenBubbleBeenAcknowledged(const std::string
& extension_id
,
342 // Returns true if the extension notification code has already run for the
343 // first time for this profile. Currently we use this flag to mean that any
344 // extensions that would trigger notifications should get silently
345 // acknowledged. This is a fuse. Calling it the first time returns false.
346 // Subsequent calls return true. It's not possible through an API to ever
347 // reset it. Don't call it unless you mean it!
348 bool SetAlertSystemFirstRun();
350 // Checks if extensions are blacklisted by default, by policy.
351 // The ManagementPolicy::Provider methods also take this into account, and
352 // should be used instead when the extension ID is known.
353 bool ExtensionsBlacklistedByDefault() const;
355 // Returns the last value set via SetLastPingDay. If there isn't such a
356 // pref, the returned Time will return true for is_null().
357 base::Time
LastPingDay(const std::string
& extension_id
) const;
359 // The time stored is based on the server's perspective of day start time, not
361 void SetLastPingDay(const std::string
& extension_id
, const base::Time
& time
);
363 // Similar to the 2 above, but for the extensions blacklist.
364 base::Time
BlacklistLastPingDay() const;
365 void SetBlacklistLastPingDay(const base::Time
& time
);
367 // Similar to LastPingDay/SetLastPingDay, but for sending "days since active"
369 base::Time
LastActivePingDay(const std::string
& extension_id
);
370 void SetLastActivePingDay(const std::string
& extension_id
,
371 const base::Time
& time
);
373 // A bit we use for determining if we should send the "days since active"
374 // ping. A value of true means the item has been active (launched) since the
375 // last update check.
376 bool GetActiveBit(const std::string
& extension_id
);
377 void SetActiveBit(const std::string
& extension_id
, bool active
);
379 // Returns the granted permission set for the extension with |extension_id|,
380 // and NULL if no preferences were found for |extension_id|.
381 // This passes ownership of the returned set to the caller.
382 PermissionSet
* GetGrantedPermissions(const std::string
& extension_id
);
384 // Adds |permissions| to the granted permissions set for the extension with
385 // |extension_id|. The new granted permissions set will be the union of
386 // |permissions| and the already granted permissions.
387 void AddGrantedPermissions(const std::string
& extension_id
,
388 const PermissionSet
* permissions
);
390 // As above, but subtracts the given |permissions| from the granted set.
391 void RemoveGrantedPermissions(const std::string
& extension_id
,
392 const PermissionSet
* permissions
);
394 // Gets the active permission set for the specified extension. This may
395 // differ from the permissions in the manifest due to the optional
396 // permissions API. This passes ownership of the set to the caller.
397 PermissionSet
* GetActivePermissions(const std::string
& extension_id
);
399 // Sets the active |permissions| for the extension with |extension_id|.
400 void SetActivePermissions(const std::string
& extension_id
,
401 const PermissionSet
* permissions
);
403 // Records whether or not this extension is currently running.
404 void SetExtensionRunning(const std::string
& extension_id
, bool is_running
);
406 // Returns whether or not this extension is marked as running. This is used to
407 // restart apps across browser restarts.
408 bool IsExtensionRunning(const std::string
& extension_id
);
410 // Set/Get whether or not the app is active. Used to force a launch of apps
411 // that don't handle onRestarted() on a restart. We can only safely do that if
412 // the app was active when it was last running.
413 void SetIsActive(const std::string
& extension_id
, bool is_active
);
414 bool IsActive(const std::string
& extension_id
);
416 // Returns true if the user enabled this extension to be loaded in incognito
419 // IMPORTANT: you probably want to use extensions::util::IsIncognitoEnabled
420 // instead of this method.
421 bool IsIncognitoEnabled(const std::string
& extension_id
) const;
422 void SetIsIncognitoEnabled(const std::string
& extension_id
, bool enabled
);
424 // Returns true if the user has chosen to allow this extension to inject
425 // scripts into pages with file URLs.
427 // IMPORTANT: you probably want to use extensions::util::AllowFileAccess
428 // instead of this method.
429 bool AllowFileAccess(const std::string
& extension_id
) const;
430 void SetAllowFileAccess(const std::string
& extension_id
, bool allow
);
431 bool HasAllowFileAccessSetting(const std::string
& extension_id
) const;
433 // Saves ExtensionInfo for each installed extension with the path to the
434 // version directory and the location. Blacklisted extensions won't be saved
435 // and neither will external extensions the user has explicitly uninstalled.
436 // Caller takes ownership of returned structure.
437 scoped_ptr
<ExtensionsInfo
> GetInstalledExtensionsInfo() const;
439 // Same as above, but only includes external extensions the user has
440 // explicitly uninstalled.
441 scoped_ptr
<ExtensionsInfo
> GetUninstalledExtensionsInfo() const;
443 // Returns the ExtensionInfo from the prefs for the given extension. If the
444 // extension is not present, NULL is returned.
445 scoped_ptr
<ExtensionInfo
> GetInstalledExtensionInfo(
446 const std::string
& extension_id
) const;
448 // We've downloaded an updated .crx file for the extension, but are waiting
451 // |install_flags| are a bitmask of extension::InstallFlags.
452 void SetDelayedInstallInfo(const Extension
* extension
,
453 Extension::State initial_state
,
455 DelayReason delay_reason
,
456 const syncer::StringOrdinal
& page_ordinal
,
457 const std::string
& install_parameter
);
459 // Removes any delayed install information we have for the given
460 // |extension_id|. Returns true if there was info to remove; false otherwise.
461 bool RemoveDelayedInstallInfo(const std::string
& extension_id
);
463 // Update the prefs to finish the update for an extension.
464 bool FinishDelayedInstallInfo(const std::string
& extension_id
);
466 // Returns the ExtensionInfo from the prefs for delayed install information
467 // for |extension_id|, if we have any. Otherwise returns NULL.
468 scoped_ptr
<ExtensionInfo
> GetDelayedInstallInfo(
469 const std::string
& extension_id
) const;
471 DelayReason
GetDelayedInstallReason(const std::string
& extension_id
) const;
473 // Returns information about all the extensions that have delayed install
475 scoped_ptr
<ExtensionsInfo
> GetAllDelayedInstallInfo() const;
477 // Returns true if the extension is an ephemeral app.
478 bool IsEphemeralApp(const std::string
& extension_id
) const;
480 // Promotes an ephemeral app to a regular installed app.
481 void OnEphemeralAppPromoted(const std::string
& extension_id
);
483 // Returns true if the user repositioned the app on the app launcher via drag
485 bool WasAppDraggedByUser(const std::string
& extension_id
);
487 // Sets a flag indicating that the user repositioned the app on the app
488 // launcher by drag and dropping it.
489 void SetAppDraggedByUser(const std::string
& extension_id
);
491 // Returns true if there is an extension which controls the preference value
492 // for |pref_key| *and* it is specific to incognito mode.
493 bool HasIncognitoPrefValue(const std::string
& pref_key
);
495 // Returns the creation flags mask for the extension.
496 int GetCreationFlags(const std::string
& extension_id
) const;
498 // Returns the creation flags mask for a delayed install extension.
499 int GetDelayedInstallCreationFlags(const std::string
& extension_id
) const;
501 // Returns true if the extension was installed from the Chrome Web Store.
502 bool IsFromWebStore(const std::string
& extension_id
) const;
504 // Returns true if the extension was installed from an App generated from a
506 bool IsFromBookmark(const std::string
& extension_id
) const;
508 // Returns true if the extension was installed as a default app.
509 bool WasInstalledByDefault(const std::string
& extension_id
) const;
511 // Returns true if the extension was installed as an oem app.
512 bool WasInstalledByOem(const std::string
& extension_id
) const;
514 // Helper method to acquire the installation time of an extension.
515 // Returns base::Time() if the installation time could not be parsed or
517 base::Time
GetInstallTime(const std::string
& extension_id
) const;
519 // Returns true if the extension should not be synced.
520 bool DoNotSync(const std::string
& extension_id
) const;
522 // Gets/sets the last launch time of an extension.
523 base::Time
GetLastLaunchTime(const std::string
& extension_id
) const;
524 void SetLastLaunchTime(const std::string
& extension_id
,
525 const base::Time
& time
);
527 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
529 bool extensions_disabled() const { return extensions_disabled_
; }
531 // The underlying PrefService.
532 PrefService
* pref_service() const { return prefs_
; }
534 // The underlying AppSorting.
535 AppSorting
* app_sorting() const { return app_sorting_
.get(); }
537 // Describes the URLs that are able to install extensions. See
538 // pref_names::kAllowedInstallSites for more information.
539 URLPatternSet
GetAllowedInstallSites();
541 // Schedules garbage collection of an extension's on-disk data on the next
542 // start of this ExtensionService. Applies only to extensions with isolated
544 void SetNeedsStorageGarbageCollection(bool value
);
545 bool NeedsStorageGarbageCollection();
547 // Used by AppWindowGeometryCache to persist its cache. These methods
548 // should not be called directly.
549 const base::DictionaryValue
* GetGeometryCache(
550 const std::string
& extension_id
) const;
551 void SetGeometryCache(const std::string
& extension_id
,
552 scoped_ptr
<base::DictionaryValue
> cache
);
554 // Used for verification of installed extension ids. For the Set method, pass
555 // null to remove the preference.
556 const base::DictionaryValue
* GetInstallSignature();
557 void SetInstallSignature(const base::DictionaryValue
* signature
);
559 // The installation parameter associated with the extension.
560 std::string
GetInstallParam(const std::string
& extension_id
) const;
561 void SetInstallParam(const std::string
& extension_id
,
562 const std::string
& install_parameter
);
564 // The total number of times we've disabled an extension due to corrupted
566 int GetCorruptedDisableCount();
567 void IncrementCorruptedDisableCount();
570 friend class ExtensionPrefsBlacklistedExtensions
; // Unit test.
571 friend class ExtensionPrefsUninstallExtension
; // Unit test.
573 enum DisableReasonChange
{
575 DISABLE_REASON_REMOVE
,
579 // See the Create methods.
580 ExtensionPrefs(PrefService
* prefs
,
581 const base::FilePath
& root_dir
,
582 ExtensionPrefValueMap
* extension_pref_value_map
,
583 scoped_ptr
<AppSorting
> app_sorting
,
584 scoped_ptr
<TimeProvider
> time_provider
,
585 bool extensions_disabled
,
586 const std::vector
<ExtensionPrefsObserver
*>& early_observers
);
588 // Converts absolute paths in the pref to paths relative to the
589 // install_directory_.
590 void MakePathsRelative();
592 // Converts internal relative paths to be absolute. Used for export to
593 // consumers who expect full paths.
594 void MakePathsAbsolute(base::DictionaryValue
* dict
);
596 // Helper function used by GetInstalledExtensionInfo() and
597 // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided
598 // |extension| dictionary.
599 scoped_ptr
<ExtensionInfo
> GetInstalledInfoHelper(
600 const std::string
& extension_id
,
601 const base::DictionaryValue
* extension
) const;
603 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a
604 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns.
605 bool ReadPrefAsURLPatternSet(const std::string
& extension_id
,
606 const std::string
& pref_key
,
607 URLPatternSet
* result
,
610 // Converts |new_value| to a list of strings and sets the |pref_key| pref
611 // belonging to |extension_id|.
612 void SetExtensionPrefURLPatternSet(const std::string
& extension_id
,
613 const std::string
& pref_key
,
614 const URLPatternSet
& new_value
);
616 // Read the boolean preference entry and return true if the preference exists
617 // and the preference's value is true; false otherwise.
618 bool ReadPrefAsBooleanAndReturn(const std::string
& extension_id
,
619 const std::string
& key
) const;
621 // Interprets |pref_key| in |extension_id|'s preferences as an
622 // PermissionSet, and passes ownership of the set to the caller.
623 PermissionSet
* ReadPrefAsPermissionSet(const std::string
& extension_id
,
624 const std::string
& pref_key
);
626 // Converts the |new_value| to its value and sets the |pref_key| pref
627 // belonging to |extension_id|.
628 void SetExtensionPrefPermissionSet(const std::string
& extension_id
,
629 const std::string
& pref_key
,
630 const PermissionSet
* new_value
);
632 // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it
634 const base::DictionaryValue
* GetExtensionPref(const std::string
& id
) const;
636 // Modifies the extensions disable reasons to add a new reason, remove an
637 // existing reason, or clear all reasons. Notifies observers if the set of
638 // DisableReasons has changed.
639 // If |change| is DISABLE_REASON_CLEAR, then |reason| is ignored.
640 void ModifyDisableReason(const std::string
& extension_id
,
641 Extension::DisableReason reason
,
642 DisableReasonChange change
);
644 // Fix missing preference entries in the extensions that are were introduced
645 // in a later Chrome version.
646 void FixMissingPrefs(const ExtensionIdList
& extension_ids
);
648 // Installs the persistent extension preferences into |prefs_|'s extension
649 // pref store. Does nothing if extensions_disabled_ is true.
650 void InitPrefStore();
652 // Migrates the permissions data in the pref store.
653 void MigratePermissions(const ExtensionIdList
& extension_ids
);
655 // Migrates the disable reasons from a single enum to a bit mask.
656 void MigrateDisableReasons(const ExtensionIdList
& extension_ids
);
658 // Checks whether there is a state pref for the extension and if so, whether
659 // it matches |check_state|.
660 bool DoesExtensionHaveState(const std::string
& id
,
661 Extension::State check_state
) const;
663 // Reads the list of strings for |pref| from user prefs into
664 // |id_container_out|. Returns false if the pref wasn't found in the user
666 template <class ExtensionIdContainer
>
667 bool GetUserExtensionPrefIntoContainer(
669 ExtensionIdContainer
* id_container_out
);
671 // Writes the list of strings contained in |strings| to |pref| in prefs.
672 template <class ExtensionIdContainer
>
673 void SetExtensionPrefFromContainer(const char* pref
,
674 const ExtensionIdContainer
& strings
);
676 // Helper function to populate |extension_dict| with the values needed
677 // by a newly installed extension. Work is broken up between this
678 // function and FinishExtensionInfoPrefs() to accomodate delayed
681 // |install_flags| are a bitmask of extension::InstallFlags.
682 void PopulateExtensionInfoPrefs(const Extension
* extension
,
683 const base::Time install_time
,
684 Extension::State initial_state
,
686 const std::string
& install_parameter
,
687 base::DictionaryValue
* extension_dict
);
689 void InitExtensionControlledPrefs(ExtensionPrefValueMap
* value_map
);
691 // Helper function to complete initialization of the values in
692 // |extension_dict| for an extension install. Also see
693 // PopulateExtensionInfoPrefs().
694 void FinishExtensionInfoPrefs(
695 const std::string
& extension_id
,
696 const base::Time install_time
,
697 bool needs_sort_ordinal
,
698 const syncer::StringOrdinal
& suggested_page_ordinal
,
699 base::DictionaryValue
* extension_dict
);
701 // The pref service specific to this set of extension prefs. Owned by the
705 // Base extensions install directory.
706 base::FilePath install_directory_
;
708 // Weak pointer, owned by BrowserContext.
709 ExtensionPrefValueMap
* extension_pref_value_map_
;
711 // Contains all the logic for handling the order for various extension
713 scoped_ptr
<AppSorting
> app_sorting_
;
715 scoped_ptr
<TimeProvider
> time_provider_
;
717 bool extensions_disabled_
;
719 ObserverList
<ExtensionPrefsObserver
> observer_list_
;
721 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs
);
724 } // namespace extensions
726 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_