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
,
194 const syncer::StringOrdinal
& page_ordinal
,
195 const std::string
& install_parameter
);
197 // Called when an extension is uninstalled, so that prefs get cleaned up.
198 void OnExtensionUninstalled(const std::string
& extension_id
,
199 const Manifest::Location
& location
,
200 bool external_uninstall
);
202 // Called to change the extension's state when it is enabled/disabled.
203 void SetExtensionState(const std::string
& extension_id
, Extension::State
);
205 // Called to change the extension's BlacklistState. Currently only used for
206 // non-malicious extensions.
207 // TODO(oleg): replace SetExtensionBlacklisted by this function.
208 void SetExtensionBlacklistState(const std::string
& extension_id
,
209 BlacklistState state
);
211 // Checks whether |extension_id| is marked as greylisted.
212 // TODO(oleg): Replace IsExtensionBlacklisted by this method.
213 BlacklistState
GetExtensionBlacklistState(const std::string
& extension_id
);
215 // Populates |out| with the ids of all installed extensions.
216 void GetExtensions(ExtensionIdList
* out
);
218 // ExtensionScopedPrefs methods:
219 virtual void UpdateExtensionPref(const std::string
& id
,
220 const std::string
& key
,
221 base::Value
* value
) OVERRIDE
;
223 virtual void DeleteExtensionPrefs(const std::string
& id
) OVERRIDE
;
225 virtual bool ReadPrefAsBoolean(const std::string
& extension_id
,
226 const std::string
& pref_key
,
227 bool* out_value
) const OVERRIDE
;
229 virtual bool ReadPrefAsInteger(const std::string
& extension_id
,
230 const std::string
& pref_key
,
231 int* out_value
) const OVERRIDE
;
233 virtual bool ReadPrefAsString(const std::string
& extension_id
,
234 const std::string
& pref_key
,
235 std::string
* out_value
) const OVERRIDE
;
237 virtual bool ReadPrefAsList(const std::string
& extension_id
,
238 const std::string
& pref_key
,
239 const base::ListValue
** out_value
) const OVERRIDE
;
241 virtual bool ReadPrefAsDictionary(
242 const std::string
& extension_id
,
243 const std::string
& pref_key
,
244 const base::DictionaryValue
** out_value
) const OVERRIDE
;
246 virtual bool HasPrefForExtension(const std::string
& extension_id
) const
249 // Did the extension ask to escalate its permission during an upgrade?
250 bool DidExtensionEscalatePermissions(const std::string
& id
);
252 // If |did_escalate| is true, the preferences for |extension| will be set to
253 // require the install warning when the user tries to enable.
254 void SetDidExtensionEscalatePermissions(
255 const Extension
* extension
,
258 // Getters and setters for disabled reason.
259 int GetDisableReasons(const std::string
& extension_id
) const;
260 bool HasDisableReason(const std::string
& extension_id
,
261 Extension::DisableReason disable_reason
) const;
262 void AddDisableReason(const std::string
& extension_id
,
263 Extension::DisableReason disable_reason
);
264 void RemoveDisableReason(const std::string
& extension_id
,
265 Extension::DisableReason disable_reason
);
266 void ClearDisableReasons(const std::string
& extension_id
);
268 // Gets the set of extensions that have been blacklisted in prefs. This will
269 // return only the blocked extensions, not the "greylist" extensions.
270 // TODO(oleg): Make method names consistent here, in extension service and in
272 std::set
<std::string
> GetBlacklistedExtensions();
274 // Sets whether the extension with |id| is blacklisted.
275 void SetExtensionBlacklisted(const std::string
& extension_id
,
276 bool is_blacklisted
);
278 // Returns the version string for the currently installed extension, or
279 // the empty string if not found.
280 std::string
GetVersionString(const std::string
& extension_id
);
282 // Re-writes the extension manifest into the prefs.
283 // Called to change the extension's manifest when it's re-localized.
284 void UpdateManifest(const Extension
* extension
);
286 // Returns base extensions install directory.
287 const base::FilePath
& install_directory() const { return install_directory_
; }
289 // Returns whether the extension with |id| has its blacklist bit set.
291 // WARNING: this only checks the extension's entry in prefs, so by definition
292 // can only check extensions that prefs knows about. There may be other
293 // sources of blacklist information, such as safebrowsing. You probably want
294 // to use Blacklist::GetBlacklistedIDs rather than this method.
295 bool IsExtensionBlacklisted(const std::string
& id
) const;
297 // Increment the count of how many times we prompted the user to acknowledge
298 // the given extension, and return the new count.
299 int IncrementAcknowledgePromptCount(const std::string
& extension_id
);
301 // Whether the user has acknowledged an external extension.
302 bool IsExternalExtensionAcknowledged(const std::string
& extension_id
);
303 void AcknowledgeExternalExtension(const std::string
& extension_id
);
305 // Whether the user has acknowledged a blacklisted extension.
306 bool IsBlacklistedExtensionAcknowledged(const std::string
& extension_id
);
307 void AcknowledgeBlacklistedExtension(const std::string
& extension_id
);
309 // Whether the external extension was installed during the first run
311 bool IsExternalInstallFirstRun(const std::string
& extension_id
);
312 void SetExternalInstallFirstRun(const std::string
& extension_id
);
314 // Whether the user has been notified about extension with |extension_id|
316 bool HasWipeoutBeenAcknowledged(const std::string
& extension_id
);
317 void SetWipeoutAcknowledged(const std::string
& extension_id
, bool value
);
319 // Whether the user has been notified about extension with |extension_id|
320 // taking over some aspect of the user's settings (homepage, startup pages,
321 // or search engine).
322 bool HasSettingsApiBubbleBeenAcknowledged(const std::string
& extension_id
);
323 void SetSettingsApiBubbleBeenAcknowledged(const std::string
& extension_id
,
326 // Whether the user has been notified about extension with |extension_id|
327 // overriding the new tab page.
328 bool HasNtpOverriddenBubbleBeenAcknowledged(const std::string
& extension_id
);
329 void SetNtpOverriddenBubbleBeenAcknowledged(const std::string
& extension_id
,
332 // Whether the user has been notified about extension with |extension_id|
333 // overriding the proxy.
334 bool HasProxyOverriddenBubbleBeenAcknowledged(
335 const std::string
& extension_id
);
336 void SetProxyOverriddenBubbleBeenAcknowledged(const std::string
& extension_id
,
339 // Returns true if the extension notification code has already run for the
340 // first time for this profile. Currently we use this flag to mean that any
341 // extensions that would trigger notifications should get silently
342 // acknowledged. This is a fuse. Calling it the first time returns false.
343 // Subsequent calls return true. It's not possible through an API to ever
344 // reset it. Don't call it unless you mean it!
345 bool SetAlertSystemFirstRun();
347 // Checks if extensions are blacklisted by default, by policy.
348 // The ManagementPolicy::Provider methods also take this into account, and
349 // should be used instead when the extension ID is known.
350 bool ExtensionsBlacklistedByDefault() const;
352 // Returns the last value set via SetLastPingDay. If there isn't such a
353 // pref, the returned Time will return true for is_null().
354 base::Time
LastPingDay(const std::string
& extension_id
) const;
356 // The time stored is based on the server's perspective of day start time, not
358 void SetLastPingDay(const std::string
& extension_id
, const base::Time
& time
);
360 // Similar to the 2 above, but for the extensions blacklist.
361 base::Time
BlacklistLastPingDay() const;
362 void SetBlacklistLastPingDay(const base::Time
& time
);
364 // Similar to LastPingDay/SetLastPingDay, but for sending "days since active"
366 base::Time
LastActivePingDay(const std::string
& extension_id
);
367 void SetLastActivePingDay(const std::string
& extension_id
,
368 const base::Time
& time
);
370 // A bit we use for determining if we should send the "days since active"
371 // ping. A value of true means the item has been active (launched) since the
372 // last update check.
373 bool GetActiveBit(const std::string
& extension_id
);
374 void SetActiveBit(const std::string
& extension_id
, bool active
);
376 // Returns the granted permission set for the extension with |extension_id|,
377 // and NULL if no preferences were found for |extension_id|.
378 // This passes ownership of the returned set to the caller.
379 PermissionSet
* GetGrantedPermissions(const std::string
& extension_id
);
381 // Adds |permissions| to the granted permissions set for the extension with
382 // |extension_id|. The new granted permissions set will be the union of
383 // |permissions| and the already granted permissions.
384 void AddGrantedPermissions(const std::string
& extension_id
,
385 const PermissionSet
* permissions
);
387 // As above, but subtracts the given |permissions| from the granted set.
388 void RemoveGrantedPermissions(const std::string
& extension_id
,
389 const PermissionSet
* permissions
);
391 // Gets the active permission set for the specified extension. This may
392 // differ from the permissions in the manifest due to the optional
393 // permissions API. This passes ownership of the set to the caller.
394 PermissionSet
* GetActivePermissions(const std::string
& extension_id
);
396 // Sets the active |permissions| for the extension with |extension_id|.
397 void SetActivePermissions(const std::string
& extension_id
,
398 const PermissionSet
* permissions
);
400 // Records whether or not this extension is currently running.
401 void SetExtensionRunning(const std::string
& extension_id
, bool is_running
);
403 // Returns whether or not this extension is marked as running. This is used to
404 // restart apps across browser restarts.
405 bool IsExtensionRunning(const std::string
& extension_id
);
407 // Set/Get whether or not the app is active. Used to force a launch of apps
408 // that don't handle onRestarted() on a restart. We can only safely do that if
409 // the app was active when it was last running.
410 void SetIsActive(const std::string
& extension_id
, bool is_active
);
411 bool IsActive(const std::string
& extension_id
);
413 // Returns true if the user enabled this extension to be loaded in incognito
416 // IMPORTANT: you probably want to use extensions::util::IsIncognitoEnabled
417 // instead of this method.
418 bool IsIncognitoEnabled(const std::string
& extension_id
) const;
419 void SetIsIncognitoEnabled(const std::string
& extension_id
, bool enabled
);
421 // Returns true if the user has chosen to allow this extension to inject
422 // scripts into pages with file URLs.
424 // IMPORTANT: you probably want to use extensions::util::AllowFileAccess
425 // instead of this method.
426 bool AllowFileAccess(const std::string
& extension_id
) const;
427 void SetAllowFileAccess(const std::string
& extension_id
, bool allow
);
428 bool HasAllowFileAccessSetting(const std::string
& extension_id
) const;
430 // Saves ExtensionInfo for each installed extension with the path to the
431 // version directory and the location. Blacklisted extensions won't be saved
432 // and neither will external extensions the user has explicitly uninstalled.
433 // Caller takes ownership of returned structure.
434 scoped_ptr
<ExtensionsInfo
> GetInstalledExtensionsInfo() const;
436 // Same as above, but only includes external extensions the user has
437 // explicitly uninstalled.
438 scoped_ptr
<ExtensionsInfo
> GetUninstalledExtensionsInfo() const;
440 // Returns the ExtensionInfo from the prefs for the given extension. If the
441 // extension is not present, NULL is returned.
442 scoped_ptr
<ExtensionInfo
> GetInstalledExtensionInfo(
443 const std::string
& extension_id
) const;
445 // We've downloaded an updated .crx file for the extension, but are waiting
447 void SetDelayedInstallInfo(const Extension
* extension
,
448 Extension::State initial_state
,
449 bool blacklisted_for_malware
,
451 DelayReason delay_reason
,
452 const syncer::StringOrdinal
& page_ordinal
,
453 const std::string
& install_parameter
);
455 // Removes any delayed install information we have for the given
456 // |extension_id|. Returns true if there was info to remove; false otherwise.
457 bool RemoveDelayedInstallInfo(const std::string
& extension_id
);
459 // Update the prefs to finish the update for an extension.
460 bool FinishDelayedInstallInfo(const std::string
& extension_id
);
462 // Returns the ExtensionInfo from the prefs for delayed install information
463 // for |extension_id|, if we have any. Otherwise returns NULL.
464 scoped_ptr
<ExtensionInfo
> GetDelayedInstallInfo(
465 const std::string
& extension_id
) const;
467 DelayReason
GetDelayedInstallReason(const std::string
& extension_id
) const;
469 // Returns information about all the extensions that have delayed install
471 scoped_ptr
<ExtensionsInfo
> GetAllDelayedInstallInfo() const;
473 // Returns information about evicted ephemeral apps.
474 scoped_ptr
<ExtensionsInfo
> GetEvictedEphemeralAppsInfo() const;
476 // Return information about a specific evicted ephemeral app. Can return NULL
477 // if no such evicted app exists or is currently installed.
478 scoped_ptr
<ExtensionInfo
> GetEvictedEphemeralAppInfo(
479 const std::string
& extension_id
) const;
481 // Permanently remove the preferences for an evicted ephemeral app.
482 void RemoveEvictedEphemeralApp(const std::string
& extension_id
);
484 // Returns true if the extension is an ephemeral app.
485 bool IsEphemeralApp(const std::string
& extension_id
) const;
487 // Promotes an ephemeral app to a regular installed app.
488 void OnEphemeralAppPromoted(const std::string
& extension_id
);
490 // Returns true if the user repositioned the app on the app launcher via drag
492 bool WasAppDraggedByUser(const std::string
& extension_id
);
494 // Sets a flag indicating that the user repositioned the app on the app
495 // launcher by drag and dropping it.
496 void SetAppDraggedByUser(const std::string
& extension_id
);
498 // Returns true if there is an extension which controls the preference value
499 // for |pref_key| *and* it is specific to incognito mode.
500 bool HasIncognitoPrefValue(const std::string
& pref_key
);
502 // Returns the creation flags mask for the extension.
503 int GetCreationFlags(const std::string
& extension_id
) const;
505 // Returns the creation flags mask for a delayed install extension.
506 int GetDelayedInstallCreationFlags(const std::string
& extension_id
) const;
508 // Returns true if the extension was installed from the Chrome Web Store.
509 bool IsFromWebStore(const std::string
& extension_id
) const;
511 // Returns true if the extension was installed from an App generated from a
513 bool IsFromBookmark(const std::string
& extension_id
) const;
515 // Returns true if the extension was installed as a default app.
516 bool WasInstalledByDefault(const std::string
& extension_id
) const;
518 // Returns true if the extension was installed as an oem app.
519 bool WasInstalledByOem(const std::string
& extension_id
) const;
521 // Helper method to acquire the installation time of an extension.
522 // Returns base::Time() if the installation time could not be parsed or
524 base::Time
GetInstallTime(const std::string
& extension_id
) const;
526 // Gets/sets the last launch time of an extension.
527 base::Time
GetLastLaunchTime(const std::string
& extension_id
) const;
528 void SetLastLaunchTime(const std::string
& extension_id
,
529 const base::Time
& time
);
531 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable
* registry
);
533 bool extensions_disabled() const { return extensions_disabled_
; }
535 // The underlying PrefService.
536 PrefService
* pref_service() const { return prefs_
; }
538 // The underlying AppSorting.
539 AppSorting
* app_sorting() const { return app_sorting_
.get(); }
541 // Describes the URLs that are able to install extensions. See
542 // pref_names::kAllowedInstallSites for more information.
543 URLPatternSet
GetAllowedInstallSites();
545 // Schedules garbage collection of an extension's on-disk data on the next
546 // start of this ExtensionService. Applies only to extensions with isolated
548 void SetNeedsStorageGarbageCollection(bool value
);
549 bool NeedsStorageGarbageCollection();
551 // Used by AppWindowGeometryCache to persist its cache. These methods
552 // should not be called directly.
553 const base::DictionaryValue
* GetGeometryCache(
554 const std::string
& extension_id
) const;
555 void SetGeometryCache(const std::string
& extension_id
,
556 scoped_ptr
<base::DictionaryValue
> cache
);
558 // Used for verification of installed extension ids. For the Set method, pass
559 // null to remove the preference.
560 const base::DictionaryValue
* GetInstallSignature();
561 void SetInstallSignature(const base::DictionaryValue
* signature
);
563 // The installation parameter associated with the extension.
564 std::string
GetInstallParam(const std::string
& extension_id
) const;
565 void SetInstallParam(const std::string
& extension_id
,
566 const std::string
& install_parameter
);
569 friend class ExtensionPrefsBlacklistedExtensions
; // Unit test.
570 friend class ExtensionPrefsUninstallExtension
; // Unit test.
572 enum DisableReasonChange
{
574 DISABLE_REASON_REMOVE
,
578 // See the Create methods.
579 ExtensionPrefs(PrefService
* prefs
,
580 const base::FilePath
& root_dir
,
581 ExtensionPrefValueMap
* extension_pref_value_map
,
582 scoped_ptr
<AppSorting
> app_sorting
,
583 scoped_ptr
<TimeProvider
> time_provider
,
584 bool extensions_disabled
,
585 const std::vector
<ExtensionPrefsObserver
*>& early_observers
);
587 // Converts absolute paths in the pref to paths relative to the
588 // install_directory_.
589 void MakePathsRelative();
591 // Converts internal relative paths to be absolute. Used for export to
592 // consumers who expect full paths.
593 void MakePathsAbsolute(base::DictionaryValue
* dict
);
595 // Helper function used by GetInstalledExtensionInfo() and
596 // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided
597 // |extension| dictionary.
598 scoped_ptr
<ExtensionInfo
> GetInstalledInfoHelper(
599 const std::string
& extension_id
,
600 const base::DictionaryValue
* extension
) const;
602 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a
603 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns.
604 bool ReadPrefAsURLPatternSet(const std::string
& extension_id
,
605 const std::string
& pref_key
,
606 URLPatternSet
* result
,
609 // Converts |new_value| to a list of strings and sets the |pref_key| pref
610 // belonging to |extension_id|.
611 void SetExtensionPrefURLPatternSet(const std::string
& extension_id
,
612 const std::string
& pref_key
,
613 const URLPatternSet
& new_value
);
615 // Read the boolean preference entry and return true if the preference exists
616 // and the preference's value is true; false otherwise.
617 bool ReadPrefAsBooleanAndReturn(const std::string
& extension_id
,
618 const std::string
& key
) const;
620 // Interprets |pref_key| in |extension_id|'s preferences as an
621 // PermissionSet, and passes ownership of the set to the caller.
622 PermissionSet
* ReadPrefAsPermissionSet(const std::string
& extension_id
,
623 const std::string
& pref_key
);
625 // Converts the |new_value| to its value and sets the |pref_key| pref
626 // belonging to |extension_id|.
627 void SetExtensionPrefPermissionSet(const std::string
& extension_id
,
628 const std::string
& pref_key
,
629 const PermissionSet
* new_value
);
631 // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it
633 const base::DictionaryValue
* GetExtensionPref(const std::string
& id
) const;
635 // Modifies the extensions disable reasons to add a new reason, remove an
636 // existing reason, or clear all reasons. Notifies observers if the set of
637 // DisableReasons has changed.
638 // If |change| is DISABLE_REASON_CLEAR, then |reason| is ignored.
639 void ModifyDisableReason(const std::string
& extension_id
,
640 Extension::DisableReason reason
,
641 DisableReasonChange change
);
643 // Fix missing preference entries in the extensions that are were introduced
644 // in a later Chrome version.
645 void FixMissingPrefs(const ExtensionIdList
& extension_ids
);
647 // Installs the persistent extension preferences into |prefs_|'s extension
648 // pref store. Does nothing if extensions_disabled_ is true.
649 void InitPrefStore();
651 // Migrates the permissions data in the pref store.
652 void MigratePermissions(const ExtensionIdList
& extension_ids
);
654 // Migrates the disable reasons from a single enum to a bit mask.
655 void MigrateDisableReasons(const ExtensionIdList
& extension_ids
);
657 // Checks whether there is a state pref for the extension and if so, whether
658 // it matches |check_state|.
659 bool DoesExtensionHaveState(const std::string
& id
,
660 Extension::State check_state
) const;
662 // Reads the list of strings for |pref| from user prefs into
663 // |id_container_out|. Returns false if the pref wasn't found in the user
665 template <class ExtensionIdContainer
>
666 bool GetUserExtensionPrefIntoContainer(
668 ExtensionIdContainer
* id_container_out
);
670 // Writes the list of strings contained in |strings| to |pref| in prefs.
671 template <class ExtensionIdContainer
>
672 void SetExtensionPrefFromContainer(const char* pref
,
673 const ExtensionIdContainer
& strings
);
675 // Helper function to populate |extension_dict| with the values needed
676 // by a newly installed extension. Work is broken up between this
677 // function and FinishExtensionInfoPrefs() to accomodate delayed
679 void PopulateExtensionInfoPrefs(const Extension
* extension
,
680 const base::Time install_time
,
681 Extension::State initial_state
,
682 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_