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/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
;
35 namespace user_prefs
{
36 class PrefRegistrySyncable
;
39 namespace extensions
{
42 class ExtensionPrefsObserver
;
43 class ExtensionPrefsUninstallExtension
;
46 // Class for managing global and per-extension preferences.
48 // This class distinguishes the following kinds of preferences:
49 // - global preferences:
50 // internal state for the extension system in general, not associated
51 // with an individual extension, such as lastUpdateTime.
52 // - per-extension preferences:
53 // meta-preferences describing properties of the extension like
54 // installation time, whether the extension is enabled, etc.
55 // - extension controlled preferences:
56 // browser preferences that an extension controls. For example, an
57 // extension could use the proxy API to specify the browser's proxy
58 // preference. Extension-controlled preferences are stored in
59 // PrefValueStore::extension_prefs(), which this class populates and
60 // maintains as the underlying extensions change.
61 class ExtensionPrefs
: public ExtensionScopedPrefs
, public KeyedService
{
63 typedef std::vector
<linked_ptr
<ExtensionInfo
> > ExtensionsInfo
;
65 // Vector containing identifiers for preferences.
66 typedef std::set
<std::string
> PrefKeySet
;
68 // This enum is used to store the reason an extension's install has been
69 // delayed. Do not remove items or re-order this enum as it is used in
72 DELAY_REASON_NONE
= 0,
74 DELAY_REASON_WAIT_FOR_IDLE
= 2,
75 DELAY_REASON_WAIT_FOR_IMPORTS
= 3,
79 // Creates base::Time classes. The default implementation is just to return
80 // the current time, but tests can inject alternative implementations.
85 virtual ~TimeProvider();
87 // By default, returns the current time (base::Time::Now()).
88 virtual base::Time
GetCurrentTime() const;
91 DISALLOW_COPY_AND_ASSIGN(TimeProvider
);
94 // A wrapper around a ScopedUserPrefUpdate, which allows us to access the
95 // entry of a particular key for an extension. Use this if you need a mutable
96 // record of a dictionary or list in the current settings. Otherwise, prefer
97 // ReadPrefAsT() and UpdateExtensionPref() methods.
98 template <typename T
, base::Value::Type type_enum_value
>
101 ScopedUpdate(ExtensionPrefs
* prefs
,
102 const std::string
& extension_id
,
103 const std::string
& key
);
104 virtual ~ScopedUpdate();
106 // Returns a mutable value for the key (ownership remains with the prefs),
107 // if one exists. Otherwise, returns NULL.
110 // Creates and returns a mutable value for the key (the prefs own the new
111 // value), if one does not already exist. Otherwise, returns the current
116 DictionaryPrefUpdate update_
;
117 const std::string extension_id_
;
118 const std::string key_
;
120 DISALLOW_COPY_AND_ASSIGN(ScopedUpdate
);
122 typedef ScopedUpdate
<base::DictionaryValue
, base::Value::TYPE_DICTIONARY
>
123 ScopedDictionaryUpdate
;
124 typedef ScopedUpdate
<base::ListValue
, base::Value::TYPE_LIST
>
127 // Creates an ExtensionPrefs object.
128 // Does not take ownership of |prefs| or |extension_pref_value_map|.
129 // If |extensions_disabled| is true, extension controlled preferences and
130 // content settings do not become effective. ExtensionPrefsObservers should be
131 // included in |early_observers| if they need to observe events which occur
132 // during initialization of the ExtensionPrefs object.
133 static ExtensionPrefs
* Create(
135 const base::FilePath
& root_dir
,
136 ExtensionPrefValueMap
* extension_pref_value_map
,
137 scoped_ptr
<AppSorting
> app_sorting
,
138 bool extensions_disabled
,
139 const std::vector
<ExtensionPrefsObserver
*>& early_observers
);
141 // A version of Create which allows injection of a custom base::Time provider.
142 // Use this as needed for testing.
143 static ExtensionPrefs
* Create(
145 const base::FilePath
& root_dir
,
146 ExtensionPrefValueMap
* extension_pref_value_map
,
147 scoped_ptr
<AppSorting
> app_sorting
,
148 bool extensions_disabled
,
149 const std::vector
<ExtensionPrefsObserver
*>& early_observers
,
150 scoped_ptr
<TimeProvider
> time_provider
);
152 virtual ~ExtensionPrefs();
154 // Convenience function to get the ExtensionPrefs for a BrowserContext.
155 static ExtensionPrefs
* Get(content::BrowserContext
* context
);
157 // Returns all installed extensions from extension preferences provided by
158 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs
159 // access to the extension ID list before the ExtensionService is initialized.
160 static ExtensionIdList
GetExtensionsFrom(const PrefService
* pref_service
);
162 // Add or remove an observer from the ExtensionPrefs.
163 void AddObserver(ExtensionPrefsObserver
* observer
);
164 void RemoveObserver(ExtensionPrefsObserver
* observer
);
166 // Returns true if the specified external extension was uninstalled by the
168 bool IsExternalExtensionUninstalled(const std::string
& id
) const;
170 // Checks whether |extension_id| is disabled. If there's no state pref for
171 // the extension, this will return false. Generally you should use
172 // ExtensionService::IsExtensionEnabled instead.
173 bool IsExtensionDisabled(const std::string
& id
) const;
175 // Get/Set the order that the browser actions appear in the toolbar.
176 ExtensionIdList
GetToolbarOrder();
177 void SetToolbarOrder(const ExtensionIdList
& extension_ids
);
179 // Gets the set of known disabled extension IDs into |id_set_out|. Returns
180 // false iff the set of known disabled extension IDs hasn't been set yet.
181 bool GetKnownDisabled(ExtensionIdSet
* id_set_out
);
183 // Sets the set of known disabled extension IDs.
184 void SetKnownDisabled(const ExtensionIdSet
& extension_ids
);
186 // Called when an extension is installed, so that prefs get created.
187 // |blacklisted_for_malware| should be set if the extension was included in a
188 // blacklist due to being malware. If |page_ordinal| is an invalid ordinal,
189 // then a page will be found for the App.
190 void OnExtensionInstalled(const Extension
* extension
,
191 Extension::State initial_state
,
192 bool blacklisted_for_malware
,
193 const syncer::StringOrdinal
& page_ordinal
,
194 const std::string
& install_parameter
);
196 // Called when an extension is uninstalled, so that prefs get cleaned up.
197 void OnExtensionUninstalled(const std::string
& extension_id
,
198 const Manifest::Location
& location
,
199 bool external_uninstall
);
201 // Called to change the extension's state when it is enabled/disabled.
202 void SetExtensionState(const std::string
& extension_id
, Extension::State
);
204 // Called to change the extension's BlacklistState. Currently only used for
205 // non-malicious extensions.
206 // TODO(oleg): replace SetExtensionBlacklisted by this function.
207 void SetExtensionBlacklistState(const std::string
& extension_id
,
208 BlacklistState state
);
210 // Checks whether |extension_id| is marked as greylisted.
211 // TODO(oleg): Replace IsExtensionBlacklisted by this method.
212 BlacklistState
GetExtensionBlacklistState(const std::string
& extension_id
);
214 // Populates |out| with the ids of all installed extensions.
215 void GetExtensions(ExtensionIdList
* out
);
217 // ExtensionScopedPrefs methods:
218 virtual void UpdateExtensionPref(const std::string
& id
,
219 const std::string
& key
,
220 base::Value
* value
) OVERRIDE
;
222 virtual void DeleteExtensionPrefs(const std::string
& id
) OVERRIDE
;
224 virtual bool ReadPrefAsBoolean(const std::string
& extension_id
,
225 const std::string
& pref_key
,
226 bool* out_value
) const OVERRIDE
;
228 virtual bool ReadPrefAsInteger(const std::string
& extension_id
,
229 const std::string
& pref_key
,
230 int* out_value
) const OVERRIDE
;
232 virtual bool ReadPrefAsString(const std::string
& extension_id
,
233 const std::string
& pref_key
,
234 std::string
* out_value
) const OVERRIDE
;
236 virtual bool ReadPrefAsList(const std::string
& extension_id
,
237 const std::string
& pref_key
,
238 const base::ListValue
** out_value
) const OVERRIDE
;
240 virtual bool ReadPrefAsDictionary(
241 const std::string
& extension_id
,
242 const std::string
& pref_key
,
243 const base::DictionaryValue
** out_value
) const OVERRIDE
;
245 virtual bool HasPrefForExtension(const std::string
& extension_id
) const
248 // Did the extension ask to escalate its permission during an upgrade?
249 bool DidExtensionEscalatePermissions(const std::string
& id
);
251 // If |did_escalate| is true, the preferences for |extension| will be set to
252 // require the install warning when the user tries to enable.
253 void SetDidExtensionEscalatePermissions(
254 const Extension
* extension
,
257 // Getters and setters for disabled reason.
258 int GetDisableReasons(const std::string
& extension_id
) const;
259 bool HasDisableReason(const std::string
& extension_id
,
260 Extension::DisableReason disable_reason
) const;
261 void AddDisableReason(const std::string
& extension_id
,
262 Extension::DisableReason disable_reason
);
263 void RemoveDisableReason(const std::string
& extension_id
,
264 Extension::DisableReason disable_reason
);
265 void ClearDisableReasons(const std::string
& extension_id
);
267 // Gets the set of extensions that have been blacklisted in prefs. This will
268 // return only the blocked extensions, not the "greylist" extensions.
269 // TODO(oleg): Make method names consistent here, in extension service and in
271 std::set
<std::string
> GetBlacklistedExtensions();
273 // Sets whether the extension with |id| is blacklisted.
274 void SetExtensionBlacklisted(const std::string
& extension_id
,
275 bool is_blacklisted
);
277 // Returns the version string for the currently installed extension, or
278 // the empty string if not found.
279 std::string
GetVersionString(const std::string
& extension_id
);
281 // Re-writes the extension manifest into the prefs.
282 // Called to change the extension's manifest when it's re-localized.
283 void UpdateManifest(const Extension
* extension
);
285 // Returns extension path based on extension ID, or empty FilePath on error.
286 base::FilePath
GetExtensionPath(const std::string
& extension_id
);
288 // Returns base extensions install directory.
289 const base::FilePath
& install_directory() const { return install_directory_
; }
291 // Returns whether the extension with |id| has its blacklist bit set.
293 // WARNING: this only checks the extension's entry in prefs, so by definition
294 // can only check extensions that prefs knows about. There may be other
295 // sources of blacklist information, such as safebrowsing. You probably want
296 // to use Blacklist::GetBlacklistedIDs rather than this method.
297 bool IsExtensionBlacklisted(const std::string
& id
) const;
299 // Increment the count of how many times we prompted the user to acknowledge
300 // the given extension, and return the new count.
301 int IncrementAcknowledgePromptCount(const std::string
& extension_id
);
303 // Whether the user has acknowledged an external extension.
304 bool IsExternalExtensionAcknowledged(const std::string
& extension_id
);
305 void AcknowledgeExternalExtension(const std::string
& extension_id
);
307 // Whether the user has acknowledged a blacklisted extension.
308 bool IsBlacklistedExtensionAcknowledged(const std::string
& extension_id
);
309 void AcknowledgeBlacklistedExtension(const std::string
& extension_id
);
311 // Whether the external extension was installed during the first run
313 bool IsExternalInstallFirstRun(const std::string
& extension_id
);
314 void SetExternalInstallFirstRun(const std::string
& extension_id
);
316 // Whether the user has been notified about extension with |extension_id|
318 bool HasWipeoutBeenAcknowledged(const std::string
& extension_id
);
319 void SetWipeoutAcknowledged(const std::string
& extension_id
, bool value
);
321 // Whether the user has been notified about extension with |extension_id|
322 // taking over some aspect of the user's settings (homepage, startup pages,
323 // or search engine).
324 bool HasSettingsApiBubbleBeenAcknowledged(const std::string
& extension_id
);
325 void SetSettingsApiBubbleBeenAcknowledged(const std::string
& extension_id
,
328 // Whether the user has been notified about extension with |extension_id|
329 // overriding the new tab page.
330 bool HasNtpOverriddenBubbleBeenAcknowledged(const std::string
& extension_id
);
331 void SetNtpOverriddenBubbleBeenAcknowledged(const std::string
& extension_id
,
334 // Returns true if the extension notification code has already run for the
335 // first time for this profile. Currently we use this flag to mean that any
336 // extensions that would trigger notifications should get silently
337 // acknowledged. This is a fuse. Calling it the first time returns false.
338 // Subsequent calls return true. It's not possible through an API to ever
339 // reset it. Don't call it unless you mean it!
340 bool SetAlertSystemFirstRun();
342 // Checks if extensions are blacklisted by default, by policy.
343 // The ManagementPolicy::Provider methods also take this into account, and
344 // should be used instead when the extension ID is known.
345 bool ExtensionsBlacklistedByDefault() const;
347 // Returns the last value set via SetLastPingDay. If there isn't such a
348 // pref, the returned Time will return true for is_null().
349 base::Time
LastPingDay(const std::string
& extension_id
) const;
351 // The time stored is based on the server's perspective of day start time, not
353 void SetLastPingDay(const std::string
& extension_id
, const base::Time
& time
);
355 // Similar to the 2 above, but for the extensions blacklist.
356 base::Time
BlacklistLastPingDay() const;
357 void SetBlacklistLastPingDay(const base::Time
& time
);
359 // Similar to LastPingDay/SetLastPingDay, but for sending "days since active"
361 base::Time
LastActivePingDay(const std::string
& extension_id
);
362 void SetLastActivePingDay(const std::string
& extension_id
,
363 const base::Time
& time
);
365 // A bit we use for determining if we should send the "days since active"
366 // ping. A value of true means the item has been active (launched) since the
367 // last update check.
368 bool GetActiveBit(const std::string
& extension_id
);
369 void SetActiveBit(const std::string
& extension_id
, bool active
);
371 // Returns the granted permission set for the extension with |extension_id|,
372 // and NULL if no preferences were found for |extension_id|.
373 // This passes ownership of the returned set to the caller.
374 PermissionSet
* GetGrantedPermissions(const std::string
& extension_id
);
376 // Adds |permissions| to the granted permissions set for the extension with
377 // |extension_id|. The new granted permissions set will be the union of
378 // |permissions| and the already granted permissions.
379 void AddGrantedPermissions(const std::string
& extension_id
,
380 const PermissionSet
* permissions
);
382 // As above, but subtracts the given |permissions| from the granted set.
383 void RemoveGrantedPermissions(const std::string
& extension_id
,
384 const PermissionSet
* permissions
);
386 // Gets the active permission set for the specified extension. This may
387 // differ from the permissions in the manifest due to the optional
388 // permissions API. This passes ownership of the set to the caller.
389 PermissionSet
* GetActivePermissions(const std::string
& extension_id
);
391 // Sets the active |permissions| for the extension with |extension_id|.
392 void SetActivePermissions(const std::string
& extension_id
,
393 const PermissionSet
* permissions
);
395 // Records whether or not this extension is currently running.
396 void SetExtensionRunning(const std::string
& extension_id
, bool is_running
);
398 // Returns whether or not this extension is marked as running. This is used to
399 // restart apps across browser restarts.
400 bool IsExtensionRunning(const std::string
& extension_id
);
402 // Set/Get whether or not the app is active. Used to force a launch of apps
403 // that don't handle onRestarted() on a restart. We can only safely do that if
404 // the app was active when it was last running.
405 void SetIsActive(const std::string
& extension_id
, bool is_active
);
406 bool IsActive(const std::string
& extension_id
);
408 // Returns true if the user enabled this extension to be loaded in incognito
411 // IMPORTANT: you probably want to use extensions::util::IsIncognitoEnabled
412 // instead of this method.
413 bool IsIncognitoEnabled(const std::string
& extension_id
) const;
414 void SetIsIncognitoEnabled(const std::string
& extension_id
, bool enabled
);
416 // Returns true if the user has chosen to allow this extension to inject
417 // scripts into pages with file URLs.
419 // IMPORTANT: you probably want to use extensions::util::AllowFileAccess
420 // instead of this method.
421 bool AllowFileAccess(const std::string
& extension_id
) const;
422 void SetAllowFileAccess(const std::string
& extension_id
, bool allow
);
423 bool HasAllowFileAccessSetting(const std::string
& extension_id
) const;
425 // Saves ExtensionInfo for each installed extension with the path to the
426 // version directory and the location. Blacklisted extensions won't be saved
427 // and neither will external extensions the user has explicitly uninstalled.
428 // Caller takes ownership of returned structure.
429 scoped_ptr
<ExtensionsInfo
> GetInstalledExtensionsInfo() const;
431 // Same as above, but only includes external extensions the user has
432 // explicitly uninstalled.
433 scoped_ptr
<ExtensionsInfo
> GetUninstalledExtensionsInfo() const;
435 // Returns the ExtensionInfo from the prefs for the given extension. If the
436 // extension is not present, NULL is returned.
437 scoped_ptr
<ExtensionInfo
> GetInstalledExtensionInfo(
438 const std::string
& extension_id
) const;
440 // We've downloaded an updated .crx file for the extension, but are waiting
442 void SetDelayedInstallInfo(const Extension
* extension
,
443 Extension::State initial_state
,
444 bool blacklisted_for_malware
,
445 DelayReason delay_reason
,
446 const syncer::StringOrdinal
& page_ordinal
,
447 const std::string
& install_parameter
);
449 // Removes any delayed install information we have for the given
450 // |extension_id|. Returns true if there was info to remove; false otherwise.
451 bool RemoveDelayedInstallInfo(const std::string
& extension_id
);
453 // Update the prefs to finish the update for an extension.
454 bool FinishDelayedInstallInfo(const std::string
& extension_id
);
456 // Returns the ExtensionInfo from the prefs for delayed install information
457 // for |extension_id|, if we have any. Otherwise returns NULL.
458 scoped_ptr
<ExtensionInfo
> GetDelayedInstallInfo(
459 const std::string
& extension_id
) const;
461 DelayReason
GetDelayedInstallReason(const std::string
& extension_id
) const;
463 // Returns information about all the extensions that have delayed install
465 scoped_ptr
<ExtensionsInfo
> GetAllDelayedInstallInfo() const;
467 // Returns information about evicted ephemeral apps.
468 scoped_ptr
<ExtensionsInfo
> GetEvictedEphemeralAppsInfo() const;
470 // Return information about a specific evicted ephemeral app. Can return NULL
471 // if no such evicted app exists or is currently installed.
472 scoped_ptr
<ExtensionInfo
> GetEvictedEphemeralAppInfo(
473 const std::string
& extension_id
) const;
475 // Permanently remove the preferences for an evicted ephemeral app.
476 void RemoveEvictedEphemeralApp(const std::string
& extension_id
);
478 // Returns true if the user repositioned the app on the app launcher via drag
480 bool WasAppDraggedByUser(const std::string
& extension_id
);
482 // Sets a flag indicating that the user repositioned the app on the app
483 // launcher by drag and dropping it.
484 void SetAppDraggedByUser(const std::string
& extension_id
);
486 // Returns true if there is an extension which controls the preference value
487 // for |pref_key| *and* it is specific to incognito mode.
488 bool HasIncognitoPrefValue(const std::string
& pref_key
);
490 // Returns the creation flags mask for the extension.
491 int GetCreationFlags(const std::string
& extension_id
) const;
493 // Returns the creation flags mask for a delayed install extension.
494 int GetDelayedInstallCreationFlags(const std::string
& extension_id
) const;
496 // Returns true if the extension was installed from the Chrome Web Store.
497 bool IsFromWebStore(const std::string
& extension_id
) const;
499 // Returns true if the extension was installed from an App generated from a
501 bool IsFromBookmark(const std::string
& extension_id
) const;
503 // Returns true if the extension was installed as a default app.
504 bool WasInstalledByDefault(const std::string
& extension_id
) const;
506 // Returns true if the extension was installed as an oem app.
507 bool WasInstalledByOem(const std::string
& extension_id
) const;
509 // Helper method to acquire the installation time of an extension.
510 // Returns base::Time() if the installation time could not be parsed or
512 base::Time
GetInstallTime(const std::string
& extension_id
) const;
514 // Gets/sets the last launch time of an extension.
515 base::Time
GetLastLaunchTime(const std::string
& extension_id
) const;
516 void SetLastLaunchTime(const std::string
& extension_id
,
517 const base::Time
& time
);
519 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
521 bool extensions_disabled() const { return extensions_disabled_
; }
523 // The underlying PrefService.
524 PrefService
* pref_service() const { return prefs_
; }
526 // The underlying AppSorting.
527 AppSorting
* app_sorting() const { return app_sorting_
.get(); }
529 // Describes the URLs that are able to install extensions. See
530 // pref_names::kAllowedInstallSites for more information.
531 URLPatternSet
GetAllowedInstallSites();
533 // Schedules garbage collection of an extension's on-disk data on the next
534 // start of this ExtensionService. Applies only to extensions with isolated
536 void SetNeedsStorageGarbageCollection(bool value
);
537 bool NeedsStorageGarbageCollection();
539 // Used by AppWindowGeometryCache to persist its cache. These methods
540 // should not be called directly.
541 const base::DictionaryValue
* GetGeometryCache(
542 const std::string
& extension_id
) const;
543 void SetGeometryCache(const std::string
& extension_id
,
544 scoped_ptr
<base::DictionaryValue
> cache
);
546 // Used for verification of installed extension ids. For the Set method, pass
547 // null to remove the preference.
548 const base::DictionaryValue
* GetInstallSignature();
549 void SetInstallSignature(const base::DictionaryValue
* signature
);
551 // The installation parameter associated with the extension.
552 std::string
GetInstallParam(const std::string
& extension_id
) const;
553 void SetInstallParam(const std::string
& extension_id
,
554 const std::string
& install_parameter
);
556 // Gets/sets the next threshold for displaying a notification if an extension
557 // or app consumes excessive disk space. Returns 0 if the initial threshold
558 // has not yet been reached.
559 int64
GetNextStorageThreshold(const std::string
& extension_id
) const;
560 void SetNextStorageThreshold(const std::string
& extension_id
,
561 int64 next_threshold
);
563 // Gets/sets whether notifications should be shown if an extension or app
564 // consumes too much disk space.
565 bool IsStorageNotificationEnabled(const std::string
& extension_id
) const;
566 void SetStorageNotificationEnabled(const std::string
& extension_id
,
567 bool enable_notifications
);
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
680 void PopulateExtensionInfoPrefs(const Extension
* extension
,
681 const base::Time install_time
,
682 Extension::State initial_state
,
683 bool blacklisted_for_malware
,
684 const std::string
& install_parameter
,
685 base::DictionaryValue
* extension_dict
);
687 void InitExtensionControlledPrefs(ExtensionPrefValueMap
* value_map
);
689 // Helper function to complete initialization of the values in
690 // |extension_dict| for an extension install. Also see
691 // PopulateExtensionInfoPrefs().
692 void FinishExtensionInfoPrefs(
693 const std::string
& extension_id
,
694 const base::Time install_time
,
695 bool needs_sort_ordinal
,
696 const syncer::StringOrdinal
& suggested_page_ordinal
,
697 base::DictionaryValue
* extension_dict
);
699 // The pref service specific to this set of extension prefs. Owned by the
703 // Base extensions install directory.
704 base::FilePath install_directory_
;
706 // Weak pointer, owned by BrowserContext.
707 ExtensionPrefValueMap
* extension_pref_value_map_
;
709 // Contains all the logic for handling the order for various extension
711 scoped_ptr
<AppSorting
> app_sorting_
;
713 scoped_ptr
<TimeProvider
> time_provider_
;
715 bool extensions_disabled_
;
717 ObserverList
<ExtensionPrefsObserver
> observer_list_
;
719 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs
);
722 } // namespace extensions
724 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_