Remove unused parameter.
[chromium-blink-merge.git] / extensions / browser / extension_prefs.h
blob09b4fbab99dd60cdd9bacff24ea8c89a6cbb9f1e
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/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;
30 class PrefService;
32 namespace content {
33 class BrowserContext;
36 namespace user_prefs {
37 class PrefRegistrySyncable;
40 namespace extensions {
42 class AppSorting;
43 class ExtensionPrefsObserver;
44 class ExtensionPrefsUninstallExtension;
45 class URLPatternSet;
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 {
63 public:
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
71 // preferences.
72 enum DelayReason {
73 DELAY_REASON_NONE = 0,
74 DELAY_REASON_GC = 1,
75 DELAY_REASON_WAIT_FOR_IDLE = 2,
76 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.
81 class TimeProvider {
82 public:
83 TimeProvider();
85 virtual ~TimeProvider();
87 // By default, returns the current time (base::Time::Now()).
88 virtual base::Time GetCurrentTime() const;
90 private:
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>
99 class ScopedUpdate {
100 public:
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.
108 virtual T* Get();
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
112 // value.
113 virtual T* Create();
115 private:
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>
125 ScopedListUpdate;
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(
134 PrefService* prefs,
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(
144 PrefService* prefs,
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 ~ExtensionPrefs() override;
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
167 // user.
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 // Called when an extension is installed, so that prefs get created.
180 // If |page_ordinal| is invalid then a page will be found for the App.
181 // |install_flags| are a bitmask of extension::InstallFlags.
182 void OnExtensionInstalled(const Extension* extension,
183 Extension::State initial_state,
184 const syncer::StringOrdinal& page_ordinal,
185 int install_flags,
186 const std::string& install_parameter);
187 // OnExtensionInstalled with no install flags.
188 void OnExtensionInstalled(const Extension* extension,
189 Extension::State initial_state,
190 const syncer::StringOrdinal& page_ordinal,
191 const std::string& install_parameter) {
192 OnExtensionInstalled(extension,
193 initial_state,
194 page_ordinal,
195 kInstallFlagNone,
196 install_parameter);
199 // Called when an extension is uninstalled, so that prefs get cleaned up.
200 void OnExtensionUninstalled(const std::string& extension_id,
201 const Manifest::Location& location,
202 bool external_uninstall);
204 // Called to change the extension's state when it is enabled/disabled.
205 void SetExtensionState(const std::string& extension_id, Extension::State);
207 // Called to change the extension's BlacklistState. Currently only used for
208 // non-malicious extensions.
209 // TODO(oleg): replace SetExtensionBlacklisted by this function.
210 void SetExtensionBlacklistState(const std::string& extension_id,
211 BlacklistState state);
213 // Checks whether |extension_id| is marked as greylisted.
214 // TODO(oleg): Replace IsExtensionBlacklisted by this method.
215 BlacklistState GetExtensionBlacklistState(const std::string& extension_id);
217 // Populates |out| with the ids of all installed extensions.
218 void GetExtensions(ExtensionIdList* out);
220 // ExtensionScopedPrefs methods:
221 void UpdateExtensionPref(const std::string& id,
222 const std::string& key,
223 base::Value* value) override;
225 void DeleteExtensionPrefs(const std::string& id) override;
227 bool ReadPrefAsBoolean(const std::string& extension_id,
228 const std::string& pref_key,
229 bool* out_value) const override;
231 bool ReadPrefAsInteger(const std::string& extension_id,
232 const std::string& pref_key,
233 int* out_value) const override;
235 bool ReadPrefAsString(const std::string& extension_id,
236 const std::string& pref_key,
237 std::string* out_value) const override;
239 bool ReadPrefAsList(const std::string& extension_id,
240 const std::string& pref_key,
241 const base::ListValue** out_value) const override;
243 bool ReadPrefAsDictionary(
244 const std::string& extension_id,
245 const std::string& pref_key,
246 const base::DictionaryValue** out_value) const override;
248 bool HasPrefForExtension(const std::string& extension_id) const override;
250 // Did the extension ask to escalate its permission during an upgrade?
251 bool DidExtensionEscalatePermissions(const std::string& id);
253 // If |did_escalate| is true, the preferences for |extension| will be set to
254 // require the install warning when the user tries to enable.
255 void SetDidExtensionEscalatePermissions(
256 const Extension* extension,
257 bool did_escalate);
259 // Getters and setters for disabled reason.
260 int GetDisableReasons(const std::string& extension_id) const;
261 bool HasDisableReason(const std::string& extension_id,
262 Extension::DisableReason disable_reason) const;
263 void AddDisableReason(const std::string& extension_id,
264 Extension::DisableReason disable_reason);
265 void AddDisableReasons(const std::string& extension_id, int disable_reasons);
266 void RemoveDisableReason(const std::string& extension_id,
267 Extension::DisableReason disable_reason);
268 void ClearDisableReasons(const std::string& extension_id);
270 // Gets the set of extensions that have been blacklisted in prefs. This will
271 // return only the blocked extensions, not the "greylist" extensions.
272 // TODO(oleg): Make method names consistent here, in extension service and in
273 // blacklist.
274 std::set<std::string> GetBlacklistedExtensions();
276 // Sets whether the extension with |id| is blacklisted.
277 void SetExtensionBlacklisted(const std::string& extension_id,
278 bool is_blacklisted);
280 // Returns the version string for the currently installed extension, or
281 // the empty string if not found.
282 std::string GetVersionString(const std::string& extension_id);
284 // Re-writes the extension manifest into the prefs.
285 // Called to change the extension's manifest when it's re-localized.
286 void UpdateManifest(const Extension* extension);
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
312 // of this profile.
313 bool IsExternalInstallFirstRun(const std::string& extension_id);
314 void SetExternalInstallFirstRun(const std::string& extension_id);
316 // Returns true if the extension notification code has already run for the
317 // first time for this profile. Currently we use this flag to mean that any
318 // extensions that would trigger notifications should get silently
319 // acknowledged. This is a fuse. Calling it the first time returns false.
320 // Subsequent calls return true. It's not possible through an API to ever
321 // reset it. Don't call it unless you mean it!
322 bool SetAlertSystemFirstRun();
324 // Returns the last value set via SetLastPingDay. If there isn't such a
325 // pref, the returned Time will return true for is_null().
326 base::Time LastPingDay(const std::string& extension_id) const;
328 // The time stored is based on the server's perspective of day start time, not
329 // the client's.
330 void SetLastPingDay(const std::string& extension_id, const base::Time& time);
332 // Similar to the 2 above, but for the extensions blacklist.
333 base::Time BlacklistLastPingDay() const;
334 void SetBlacklistLastPingDay(const base::Time& time);
336 // Similar to LastPingDay/SetLastPingDay, but for sending "days since active"
337 // ping.
338 base::Time LastActivePingDay(const std::string& extension_id);
339 void SetLastActivePingDay(const std::string& extension_id,
340 const base::Time& time);
342 // A bit we use for determining if we should send the "days since active"
343 // ping. A value of true means the item has been active (launched) since the
344 // last update check.
345 bool GetActiveBit(const std::string& extension_id);
346 void SetActiveBit(const std::string& extension_id, bool active);
348 // Returns the granted permission set for the extension with |extension_id|,
349 // and NULL if no preferences were found for |extension_id|.
350 // This passes ownership of the returned set to the caller.
351 PermissionSet* GetGrantedPermissions(const std::string& extension_id);
353 // Adds |permissions| to the granted permissions set for the extension with
354 // |extension_id|. The new granted permissions set will be the union of
355 // |permissions| and the already granted permissions.
356 void AddGrantedPermissions(const std::string& extension_id,
357 const PermissionSet* permissions);
359 // As above, but subtracts the given |permissions| from the granted set.
360 void RemoveGrantedPermissions(const std::string& extension_id,
361 const PermissionSet* permissions);
363 // Gets the active permission set for the specified extension. This may
364 // differ from the permissions in the manifest due to the optional
365 // permissions API. This passes ownership of the set to the caller.
366 PermissionSet* GetActivePermissions(const std::string& extension_id);
368 // Sets the active |permissions| for the extension with |extension_id|.
369 void SetActivePermissions(const std::string& extension_id,
370 const PermissionSet* permissions);
372 // Records whether or not this extension is currently running.
373 void SetExtensionRunning(const std::string& extension_id, bool is_running);
375 // Returns whether or not this extension is marked as running. This is used to
376 // restart apps across browser restarts.
377 bool IsExtensionRunning(const std::string& extension_id);
379 // Set/Get whether or not the app is active. Used to force a launch of apps
380 // that don't handle onRestarted() on a restart. We can only safely do that if
381 // the app was active when it was last running.
382 void SetIsActive(const std::string& extension_id, bool is_active);
383 bool IsActive(const std::string& extension_id);
385 // Returns true if the user enabled this extension to be loaded in incognito
386 // mode.
388 // IMPORTANT: you probably want to use extensions::util::IsIncognitoEnabled
389 // instead of this method.
390 bool IsIncognitoEnabled(const std::string& extension_id) const;
391 void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled);
393 // Returns true if the user has chosen to allow this extension to inject
394 // scripts into pages with file URLs.
396 // IMPORTANT: you probably want to use extensions::util::AllowFileAccess
397 // instead of this method.
398 bool AllowFileAccess(const std::string& extension_id) const;
399 void SetAllowFileAccess(const std::string& extension_id, bool allow);
400 bool HasAllowFileAccessSetting(const std::string& extension_id) const;
402 // Saves ExtensionInfo for each installed extension with the path to the
403 // version directory and the location. Blacklisted extensions won't be saved
404 // and neither will external extensions the user has explicitly uninstalled.
405 // Caller takes ownership of returned structure.
406 scoped_ptr<ExtensionsInfo> GetInstalledExtensionsInfo() const;
408 // Same as above, but only includes external extensions the user has
409 // explicitly uninstalled.
410 scoped_ptr<ExtensionsInfo> GetUninstalledExtensionsInfo() const;
412 // Returns the ExtensionInfo from the prefs for the given extension. If the
413 // extension is not present, NULL is returned.
414 scoped_ptr<ExtensionInfo> GetInstalledExtensionInfo(
415 const std::string& extension_id) const;
417 // We've downloaded an updated .crx file for the extension, but are waiting
418 // to install it.
420 // |install_flags| are a bitmask of extension::InstallFlags.
421 void SetDelayedInstallInfo(const Extension* extension,
422 Extension::State initial_state,
423 int install_flags,
424 DelayReason delay_reason,
425 const syncer::StringOrdinal& page_ordinal,
426 const std::string& install_parameter);
428 // Removes any delayed install information we have for the given
429 // |extension_id|. Returns true if there was info to remove; false otherwise.
430 bool RemoveDelayedInstallInfo(const std::string& extension_id);
432 // Update the prefs to finish the update for an extension.
433 bool FinishDelayedInstallInfo(const std::string& extension_id);
435 // Returns the ExtensionInfo from the prefs for delayed install information
436 // for |extension_id|, if we have any. Otherwise returns NULL.
437 scoped_ptr<ExtensionInfo> GetDelayedInstallInfo(
438 const std::string& extension_id) const;
440 DelayReason GetDelayedInstallReason(const std::string& extension_id) const;
442 // Returns information about all the extensions that have delayed install
443 // information.
444 scoped_ptr<ExtensionsInfo> GetAllDelayedInstallInfo() const;
446 // Returns true if the extension is an ephemeral app.
447 bool IsEphemeralApp(const std::string& extension_id) const;
449 // Promotes an ephemeral app to a regular installed app.
450 void OnEphemeralAppPromoted(const std::string& extension_id);
452 // Returns true if the user repositioned the app on the app launcher via drag
453 // and drop.
454 bool WasAppDraggedByUser(const std::string& extension_id);
456 // Sets a flag indicating that the user repositioned the app on the app
457 // launcher by drag and dropping it.
458 void SetAppDraggedByUser(const std::string& extension_id);
460 // Returns true if there is an extension which controls the preference value
461 // for |pref_key| *and* it is specific to incognito mode.
462 bool HasIncognitoPrefValue(const std::string& pref_key);
464 // Returns the creation flags mask for the extension.
465 int GetCreationFlags(const std::string& extension_id) const;
467 // Returns the creation flags mask for a delayed install extension.
468 int GetDelayedInstallCreationFlags(const std::string& extension_id) const;
470 // Returns true if the extension was installed from the Chrome Web Store.
471 bool IsFromWebStore(const std::string& extension_id) const;
473 // Returns true if the extension was installed from an App generated from a
474 // bookmark.
475 bool IsFromBookmark(const std::string& extension_id) const;
477 // Returns true if the extension was installed as a default app.
478 bool WasInstalledByDefault(const std::string& extension_id) const;
480 // Returns true if the extension was installed as an oem app.
481 bool WasInstalledByOem(const std::string& extension_id) const;
483 // Helper method to acquire the installation time of an extension.
484 // Returns base::Time() if the installation time could not be parsed or
485 // found.
486 base::Time GetInstallTime(const std::string& extension_id) const;
488 // Returns true if the extension should not be synced.
489 bool DoNotSync(const std::string& extension_id) const;
491 // Gets/sets the last launch time of an extension.
492 base::Time GetLastLaunchTime(const std::string& extension_id) const;
493 void SetLastLaunchTime(const std::string& extension_id,
494 const base::Time& time);
496 // Clear any launch times. This is called by the browsing data remover when
497 // history is cleared.
498 void ClearLastLaunchTimes();
500 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
502 bool extensions_disabled() const { return extensions_disabled_; }
504 // The underlying PrefService.
505 PrefService* pref_service() const { return prefs_; }
507 // The underlying AppSorting.
508 AppSorting* app_sorting() const { return app_sorting_.get(); }
510 // Schedules garbage collection of an extension's on-disk data on the next
511 // start of this ExtensionService. Applies only to extensions with isolated
512 // storage.
513 void SetNeedsStorageGarbageCollection(bool value);
514 bool NeedsStorageGarbageCollection();
516 // Used by AppWindowGeometryCache to persist its cache. These methods
517 // should not be called directly.
518 const base::DictionaryValue* GetGeometryCache(
519 const std::string& extension_id) const;
520 void SetGeometryCache(const std::string& extension_id,
521 scoped_ptr<base::DictionaryValue> cache);
523 // Used for verification of installed extension ids. For the Set method, pass
524 // null to remove the preference.
525 const base::DictionaryValue* GetInstallSignature();
526 void SetInstallSignature(const base::DictionaryValue* signature);
528 // The installation parameter associated with the extension.
529 std::string GetInstallParam(const std::string& extension_id) const;
530 void SetInstallParam(const std::string& extension_id,
531 const std::string& install_parameter);
533 // The total number of times we've disabled an extension due to corrupted
534 // contents.
535 int GetCorruptedDisableCount();
536 void IncrementCorruptedDisableCount();
538 private:
539 friend class ExtensionPrefsBlacklistedExtensions; // Unit test.
540 friend class ExtensionPrefsUninstallExtension; // Unit test.
542 enum DisableReasonChange {
543 DISABLE_REASON_ADD,
544 DISABLE_REASON_REMOVE,
545 DISABLE_REASON_CLEAR
548 // See the Create methods.
549 ExtensionPrefs(PrefService* prefs,
550 const base::FilePath& root_dir,
551 ExtensionPrefValueMap* extension_pref_value_map,
552 scoped_ptr<AppSorting> app_sorting,
553 scoped_ptr<TimeProvider> time_provider,
554 bool extensions_disabled,
555 const std::vector<ExtensionPrefsObserver*>& early_observers);
557 // Converts absolute paths in the pref to paths relative to the
558 // install_directory_.
559 void MakePathsRelative();
561 // Converts internal relative paths to be absolute. Used for export to
562 // consumers who expect full paths.
563 void MakePathsAbsolute(base::DictionaryValue* dict);
565 // Helper function used by GetInstalledExtensionInfo() and
566 // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided
567 // |extension| dictionary.
568 scoped_ptr<ExtensionInfo> GetInstalledInfoHelper(
569 const std::string& extension_id,
570 const base::DictionaryValue* extension) const;
572 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a
573 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns.
574 bool ReadPrefAsURLPatternSet(const std::string& extension_id,
575 const std::string& pref_key,
576 URLPatternSet* result,
577 int valid_schemes);
579 // Converts |new_value| to a list of strings and sets the |pref_key| pref
580 // belonging to |extension_id|.
581 void SetExtensionPrefURLPatternSet(const std::string& extension_id,
582 const std::string& pref_key,
583 const URLPatternSet& new_value);
585 // Read the boolean preference entry and return true if the preference exists
586 // and the preference's value is true; false otherwise.
587 bool ReadPrefAsBooleanAndReturn(const std::string& extension_id,
588 const std::string& key) const;
590 // Interprets |pref_key| in |extension_id|'s preferences as an
591 // PermissionSet, and passes ownership of the set to the caller.
592 PermissionSet* ReadPrefAsPermissionSet(const std::string& extension_id,
593 const std::string& pref_key);
595 // Converts the |new_value| to its value and sets the |pref_key| pref
596 // belonging to |extension_id|.
597 void SetExtensionPrefPermissionSet(const std::string& extension_id,
598 const std::string& pref_key,
599 const PermissionSet* new_value);
601 // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it
602 // doesn't exist.
603 const base::DictionaryValue* GetExtensionPref(const std::string& id) const;
605 // Modifies the extensions disable reasons to add a new reason, remove an
606 // existing reason, or clear all reasons. Notifies observers if the set of
607 // DisableReasons has changed.
608 // If |change| is DISABLE_REASON_CLEAR, then |reason| is ignored.
609 void ModifyDisableReasons(const std::string& extension_id,
610 int reasons,
611 DisableReasonChange change);
613 // Fix missing preference entries in the extensions that are were introduced
614 // in a later Chrome version.
615 void FixMissingPrefs(const ExtensionIdList& extension_ids);
617 // Installs the persistent extension preferences into |prefs_|'s extension
618 // pref store. Does nothing if extensions_disabled_ is true.
619 void InitPrefStore();
621 // Migrates the permissions data in the pref store.
622 void MigratePermissions(const ExtensionIdList& extension_ids);
624 // Migrates the disable reasons from a single enum to a bit mask.
625 void MigrateDisableReasons(const ExtensionIdList& extension_ids);
627 // Checks whether there is a state pref for the extension and if so, whether
628 // it matches |check_state|.
629 bool DoesExtensionHaveState(const std::string& id,
630 Extension::State check_state) const;
632 // Reads the list of strings for |pref| from user prefs into
633 // |id_container_out|. Returns false if the pref wasn't found in the user
634 // pref store.
635 template <class ExtensionIdContainer>
636 bool GetUserExtensionPrefIntoContainer(
637 const char* pref,
638 ExtensionIdContainer* id_container_out);
640 // Writes the list of strings contained in |strings| to |pref| in prefs.
641 template <class ExtensionIdContainer>
642 void SetExtensionPrefFromContainer(const char* pref,
643 const ExtensionIdContainer& strings);
645 // Helper function to populate |extension_dict| with the values needed
646 // by a newly installed extension. Work is broken up between this
647 // function and FinishExtensionInfoPrefs() to accomodate delayed
648 // installations.
650 // |install_flags| are a bitmask of extension::InstallFlags.
651 void PopulateExtensionInfoPrefs(const Extension* extension,
652 const base::Time install_time,
653 Extension::State initial_state,
654 int install_flags,
655 const std::string& install_parameter,
656 base::DictionaryValue* extension_dict);
658 void InitExtensionControlledPrefs(ExtensionPrefValueMap* value_map);
660 // Helper function to complete initialization of the values in
661 // |extension_dict| for an extension install. Also see
662 // PopulateExtensionInfoPrefs().
663 void FinishExtensionInfoPrefs(
664 const std::string& extension_id,
665 const base::Time install_time,
666 bool needs_sort_ordinal,
667 const syncer::StringOrdinal& suggested_page_ordinal,
668 base::DictionaryValue* extension_dict);
670 // The pref service specific to this set of extension prefs. Owned by the
671 // BrowserContext.
672 PrefService* prefs_;
674 // Base extensions install directory.
675 base::FilePath install_directory_;
677 // Weak pointer, owned by BrowserContext.
678 ExtensionPrefValueMap* extension_pref_value_map_;
680 // Contains all the logic for handling the order for various extension
681 // properties.
682 scoped_ptr<AppSorting> app_sorting_;
684 scoped_ptr<TimeProvider> time_provider_;
686 bool extensions_disabled_;
688 ObserverList<ExtensionPrefsObserver> observer_list_;
690 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
693 } // namespace extensions
695 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_