Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / extensions / browser / extension_prefs.h
blobca8c62e4ef57747ab08a4f34519194e020b08a25
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 PermissionSet* GetGrantedPermissions(const std::string& extension_id) const;
358 // Adds |permissions| to the granted permissions set for the extension with
359 // |extension_id|. The new granted permissions set will be the union of
360 // |permissions| and the already granted permissions.
361 void AddGrantedPermissions(const std::string& extension_id,
362 const PermissionSet* permissions);
364 // As above, but subtracts the given |permissions| from the granted set.
365 void RemoveGrantedPermissions(const std::string& extension_id,
366 const PermissionSet* permissions);
368 // Gets the active permission set for the specified extension. This may
369 // differ from the permissions in the manifest due to the optional
370 // permissions API. This passes ownership of the set to the caller.
371 PermissionSet* GetActivePermissions(const std::string& extension_id) const;
373 // Sets the active |permissions| for the extension with |extension_id|.
374 void SetActivePermissions(const std::string& extension_id,
375 const PermissionSet* permissions);
377 // Records whether or not this extension is currently running.
378 void SetExtensionRunning(const std::string& extension_id, bool is_running);
380 // Returns whether or not this extension is marked as running. This is used to
381 // restart apps across browser restarts.
382 bool IsExtensionRunning(const std::string& extension_id) const;
384 // Set/Get whether or not the app is active. Used to force a launch of apps
385 // that don't handle onRestarted() on a restart. We can only safely do that if
386 // the app was active when it was last running.
387 void SetIsActive(const std::string& extension_id, bool is_active);
388 bool IsActive(const std::string& extension_id) const;
390 // Returns true if the user enabled this extension to be loaded in incognito
391 // mode.
393 // IMPORTANT: you probably want to use extensions::util::IsIncognitoEnabled
394 // instead of this method.
395 bool IsIncognitoEnabled(const std::string& extension_id) const;
396 void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled);
398 // Returns true if the user has chosen to allow this extension to inject
399 // scripts into pages with file URLs.
401 // IMPORTANT: you probably want to use extensions::util::AllowFileAccess
402 // instead of this method.
403 bool AllowFileAccess(const std::string& extension_id) const;
404 void SetAllowFileAccess(const std::string& extension_id, bool allow);
405 bool HasAllowFileAccessSetting(const std::string& extension_id) const;
407 // Saves ExtensionInfo for each installed extension with the path to the
408 // version directory and the location. Blacklisted extensions won't be saved
409 // and neither will external extensions the user has explicitly uninstalled.
410 // Caller takes ownership of returned structure.
411 scoped_ptr<ExtensionsInfo> GetInstalledExtensionsInfo() const;
413 // Same as above, but only includes external extensions the user has
414 // explicitly uninstalled.
415 scoped_ptr<ExtensionsInfo> GetUninstalledExtensionsInfo() const;
417 // Returns the ExtensionInfo from the prefs for the given extension. If the
418 // extension is not present, NULL is returned.
419 scoped_ptr<ExtensionInfo> GetInstalledExtensionInfo(
420 const std::string& extension_id) const;
422 // We've downloaded an updated .crx file for the extension, but are waiting
423 // to install it.
425 // |install_flags| are a bitmask of extension::InstallFlags.
426 void SetDelayedInstallInfo(const Extension* extension,
427 Extension::State initial_state,
428 int install_flags,
429 DelayReason delay_reason,
430 const syncer::StringOrdinal& page_ordinal,
431 const std::string& install_parameter);
433 // Removes any delayed install information we have for the given
434 // |extension_id|. Returns true if there was info to remove; false otherwise.
435 bool RemoveDelayedInstallInfo(const std::string& extension_id);
437 // Update the prefs to finish the update for an extension.
438 bool FinishDelayedInstallInfo(const std::string& extension_id);
440 // Returns the ExtensionInfo from the prefs for delayed install information
441 // for |extension_id|, if we have any. Otherwise returns NULL.
442 scoped_ptr<ExtensionInfo> GetDelayedInstallInfo(
443 const std::string& extension_id) const;
445 DelayReason GetDelayedInstallReason(const std::string& extension_id) const;
447 // Returns information about all the extensions that have delayed install
448 // information.
449 scoped_ptr<ExtensionsInfo> GetAllDelayedInstallInfo() const;
451 // Returns true if the extension is an ephemeral app.
452 bool IsEphemeralApp(const std::string& extension_id) const;
454 // Promotes an ephemeral app to a regular installed app.
455 void OnEphemeralAppPromoted(const std::string& extension_id);
457 // Returns true if the user repositioned the app on the app launcher via drag
458 // and drop.
459 bool WasAppDraggedByUser(const std::string& extension_id) const;
461 // Sets a flag indicating that the user repositioned the app on the app
462 // launcher by drag and dropping it.
463 void SetAppDraggedByUser(const std::string& extension_id);
465 // Returns true if there is an extension which controls the preference value
466 // for |pref_key| *and* it is specific to incognito mode.
467 bool HasIncognitoPrefValue(const std::string& pref_key) const;
469 // Returns the creation flags mask for the extension.
470 int GetCreationFlags(const std::string& extension_id) const;
472 // Returns the creation flags mask for a delayed install extension.
473 int GetDelayedInstallCreationFlags(const std::string& extension_id) const;
475 // Returns true if the extension was installed from the Chrome Web Store.
476 bool IsFromWebStore(const std::string& extension_id) const;
478 // Returns true if the extension was installed from an App generated from a
479 // bookmark.
480 bool IsFromBookmark(const std::string& extension_id) const;
482 // Returns true if the extension was installed as a default app.
483 bool WasInstalledByDefault(const std::string& extension_id) const;
485 // Returns true if the extension was installed as an oem app.
486 bool WasInstalledByOem(const std::string& extension_id) const;
488 // Helper method to acquire the installation time of an extension.
489 // Returns base::Time() if the installation time could not be parsed or
490 // found.
491 base::Time GetInstallTime(const std::string& extension_id) const;
493 // Returns true if the extension should not be synced.
494 bool DoNotSync(const std::string& extension_id) const;
496 // Gets/sets the last launch time of an extension.
497 base::Time GetLastLaunchTime(const std::string& extension_id) const;
498 void SetLastLaunchTime(const std::string& extension_id,
499 const base::Time& time);
501 // Clear any launch times. This is called by the browsing data remover when
502 // history is cleared.
503 void ClearLastLaunchTimes();
505 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
507 bool extensions_disabled() const { return extensions_disabled_; }
509 // The underlying PrefService.
510 PrefService* pref_service() const { return prefs_; }
512 // The underlying AppSorting.
513 // TODO(treib,kalman): This should be private, and all callers should go
514 // through the ExtensionSystem instead.
515 AppSorting* app_sorting() const;
517 // Schedules garbage collection of an extension's on-disk data on the next
518 // start of this ExtensionService. Applies only to extensions with isolated
519 // storage.
520 void SetNeedsStorageGarbageCollection(bool value);
521 bool NeedsStorageGarbageCollection() const;
523 // Used by AppWindowGeometryCache to persist its cache. These methods
524 // should not be called directly.
525 const base::DictionaryValue* GetGeometryCache(
526 const std::string& extension_id) const;
527 void SetGeometryCache(const std::string& extension_id,
528 scoped_ptr<base::DictionaryValue> cache);
530 // Used for verification of installed extension ids. For the Set method, pass
531 // null to remove the preference.
532 const base::DictionaryValue* GetInstallSignature() const;
533 void SetInstallSignature(const base::DictionaryValue* signature);
535 // The installation parameter associated with the extension.
536 std::string GetInstallParam(const std::string& extension_id) const;
537 void SetInstallParam(const std::string& extension_id,
538 const std::string& install_parameter);
540 // The total number of times we've disabled an extension due to corrupted
541 // contents.
542 int GetCorruptedDisableCount() const;
543 void IncrementCorruptedDisableCount();
545 // Whether the extension with the given |id| needs to be synced. This is set
546 // when the state (such as enabled/disabled or allowed in incognito) is
547 // changed before Sync is ready.
548 bool NeedsSync(const std::string& extension_id) const;
549 void SetNeedsSync(const std::string& extension_id, bool needs_sync);
551 private:
552 friend class ExtensionPrefsBlacklistedExtensions; // Unit test.
553 friend class ExtensionPrefsComponentExtension; // Unit test.
554 friend class ExtensionPrefsUninstallExtension; // Unit test.
556 enum DisableReasonChange {
557 DISABLE_REASON_ADD,
558 DISABLE_REASON_REMOVE,
559 DISABLE_REASON_CLEAR
562 // See the Create methods.
563 ExtensionPrefs(content::BrowserContext* browser_context,
564 PrefService* prefs,
565 const base::FilePath& root_dir,
566 ExtensionPrefValueMap* extension_pref_value_map,
567 scoped_ptr<TimeProvider> time_provider,
568 bool extensions_disabled,
569 const std::vector<ExtensionPrefsObserver*>& early_observers);
571 // Converts absolute paths in the pref to paths relative to the
572 // install_directory_.
573 void MakePathsRelative();
575 // Converts internal relative paths to be absolute. Used for export to
576 // consumers who expect full paths.
577 void MakePathsAbsolute(base::DictionaryValue* dict);
579 // Helper function used by GetInstalledExtensionInfo() and
580 // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided
581 // |extension| dictionary.
582 scoped_ptr<ExtensionInfo> GetInstalledInfoHelper(
583 const std::string& extension_id,
584 const base::DictionaryValue* extension) const;
586 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a
587 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns.
588 bool ReadPrefAsURLPatternSet(const std::string& extension_id,
589 const std::string& pref_key,
590 URLPatternSet* result,
591 int valid_schemes) const;
593 // Converts |new_value| to a list of strings and sets the |pref_key| pref
594 // belonging to |extension_id|.
595 void SetExtensionPrefURLPatternSet(const std::string& extension_id,
596 const std::string& pref_key,
597 const URLPatternSet& new_value);
599 // Read the boolean preference entry and return true if the preference exists
600 // and the preference's value is true; false otherwise.
601 bool ReadPrefAsBooleanAndReturn(const std::string& extension_id,
602 const std::string& key) const;
604 // Interprets |pref_key| in |extension_id|'s preferences as an
605 // PermissionSet, and passes ownership of the set to the caller.
606 PermissionSet* ReadPrefAsPermissionSet(const std::string& extension_id,
607 const std::string& pref_key) const;
609 // Converts the |new_value| to its value and sets the |pref_key| pref
610 // belonging to |extension_id|.
611 void SetExtensionPrefPermissionSet(const std::string& extension_id,
612 const std::string& pref_key,
613 const PermissionSet* new_value);
615 // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it
616 // doesn't exist.
617 const base::DictionaryValue* GetExtensionPref(const std::string& id) const;
619 // Modifies the extensions disable reasons to add a new reason, remove an
620 // existing reason, or clear all reasons. Notifies observers if the set of
621 // DisableReasons has changed.
622 // If |change| is DISABLE_REASON_CLEAR, then |reason| is ignored.
623 void ModifyDisableReasons(const std::string& extension_id,
624 int reasons,
625 DisableReasonChange change);
627 // Fix missing preference entries in the extensions that are were introduced
628 // in a later Chrome version.
629 void FixMissingPrefs(const ExtensionIdList& extension_ids);
631 // Installs the persistent extension preferences into |prefs_|'s extension
632 // pref store. Does nothing if extensions_disabled_ is true.
633 void InitPrefStore();
635 // Migrates the permissions data in the pref store.
636 void MigratePermissions(const ExtensionIdList& extension_ids);
638 // Migrates the disable reasons from a single enum to a bit mask.
639 void MigrateDisableReasons(const ExtensionIdList& extension_ids);
641 // Checks whether there is a state pref for the extension and if so, whether
642 // it matches |check_state|.
643 bool DoesExtensionHaveState(const std::string& id,
644 Extension::State check_state) const;
646 // Reads the list of strings for |pref| from user prefs into
647 // |id_container_out|. Returns false if the pref wasn't found in the user
648 // pref store.
649 template <class ExtensionIdContainer>
650 bool GetUserExtensionPrefIntoContainer(
651 const char* pref,
652 ExtensionIdContainer* id_container_out) const;
654 // Writes the list of strings contained in |strings| to |pref| in prefs.
655 template <class ExtensionIdContainer>
656 void SetExtensionPrefFromContainer(const char* pref,
657 const ExtensionIdContainer& strings);
659 // Helper function to populate |extension_dict| with the values needed
660 // by a newly installed extension. Work is broken up between this
661 // function and FinishExtensionInfoPrefs() to accommodate delayed
662 // installations.
664 // |install_flags| are a bitmask of extension::InstallFlags.
665 void PopulateExtensionInfoPrefs(const Extension* extension,
666 const base::Time install_time,
667 Extension::State initial_state,
668 int install_flags,
669 const std::string& install_parameter,
670 base::DictionaryValue* extension_dict) const;
672 void InitExtensionControlledPrefs(ExtensionPrefValueMap* value_map);
674 // Helper function to complete initialization of the values in
675 // |extension_dict| for an extension install. Also see
676 // PopulateExtensionInfoPrefs().
677 void FinishExtensionInfoPrefs(
678 const std::string& extension_id,
679 const base::Time install_time,
680 bool needs_sort_ordinal,
681 const syncer::StringOrdinal& suggested_page_ordinal,
682 base::DictionaryValue* extension_dict);
684 content::BrowserContext* browser_context_;
686 // The pref service specific to this set of extension prefs. Owned by the
687 // BrowserContext.
688 PrefService* prefs_;
690 // Base extensions install directory.
691 base::FilePath install_directory_;
693 // Weak pointer, owned by BrowserContext.
694 ExtensionPrefValueMap* extension_pref_value_map_;
696 scoped_ptr<TimeProvider> time_provider_;
698 bool extensions_disabled_;
700 base::ObserverList<ExtensionPrefsObserver> observer_list_;
702 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
705 } // namespace extensions
707 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_