Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / browser / extension_prefs.h
blob026a4c65464dd0418ce6e05c118bc0c680c1940b
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() const;
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(
216 const std::string& extension_id) const;
218 // Populates |out| with the ids of all installed extensions.
219 void GetExtensions(ExtensionIdList* out) const;
221 // ExtensionScopedPrefs methods:
222 void UpdateExtensionPref(const std::string& id,
223 const std::string& key,
224 base::Value* value) override;
226 void DeleteExtensionPrefs(const std::string& id) override;
228 bool ReadPrefAsBoolean(const std::string& extension_id,
229 const std::string& pref_key,
230 bool* out_value) const override;
232 bool ReadPrefAsInteger(const std::string& extension_id,
233 const std::string& pref_key,
234 int* out_value) const override;
236 bool ReadPrefAsString(const std::string& extension_id,
237 const std::string& pref_key,
238 std::string* out_value) const override;
240 bool ReadPrefAsList(const std::string& extension_id,
241 const std::string& pref_key,
242 const base::ListValue** out_value) const override;
244 bool ReadPrefAsDictionary(
245 const std::string& extension_id,
246 const std::string& pref_key,
247 const base::DictionaryValue** out_value) const override;
249 bool HasPrefForExtension(const std::string& extension_id) const override;
251 // Did the extension ask to escalate its permission during an upgrade?
252 bool DidExtensionEscalatePermissions(const std::string& id) const;
254 // Getters and setters for disabled reason.
255 int GetDisableReasons(const std::string& extension_id) const;
256 bool HasDisableReason(const std::string& extension_id,
257 Extension::DisableReason disable_reason) const;
258 void AddDisableReason(const std::string& extension_id,
259 Extension::DisableReason disable_reason);
260 void AddDisableReasons(const std::string& extension_id, int disable_reasons);
261 void RemoveDisableReason(const std::string& extension_id,
262 Extension::DisableReason disable_reason);
263 void ClearDisableReasons(const std::string& extension_id);
265 // Gets the set of extensions that have been blacklisted in prefs. This will
266 // return only the blocked extensions, not the "greylist" extensions.
267 // TODO(oleg): Make method names consistent here, in extension service and in
268 // blacklist.
269 std::set<std::string> GetBlacklistedExtensions() const;
271 // Sets whether the extension with |id| is blacklisted.
272 void SetExtensionBlacklisted(const std::string& extension_id,
273 bool is_blacklisted);
275 // Returns the version string for the currently installed extension, or
276 // the empty string if not found.
277 std::string GetVersionString(const std::string& extension_id) const;
279 // Re-writes the extension manifest into the prefs.
280 // Called to change the extension's manifest when it's re-localized.
281 void UpdateManifest(const Extension* extension);
283 // Returns base extensions install directory.
284 const base::FilePath& install_directory() const { return install_directory_; }
286 // Returns whether the extension with |id| has its blacklist bit set.
288 // WARNING: this only checks the extension's entry in prefs, so by definition
289 // can only check extensions that prefs knows about. There may be other
290 // sources of blacklist information, such as safebrowsing. You probably want
291 // to use Blacklist::GetBlacklistedIDs rather than this method.
292 bool IsExtensionBlacklisted(const std::string& id) const;
294 // Increment the count of how many times we prompted the user to acknowledge
295 // the given extension, and return the new count.
296 int IncrementAcknowledgePromptCount(const std::string& extension_id);
298 // Whether the user has acknowledged an external extension.
299 bool IsExternalExtensionAcknowledged(const std::string& extension_id) const;
300 void AcknowledgeExternalExtension(const std::string& extension_id);
302 // Whether the user has acknowledged a blacklisted extension.
303 bool IsBlacklistedExtensionAcknowledged(
304 const std::string& extension_id) const;
305 void AcknowledgeBlacklistedExtension(const std::string& extension_id);
307 // Whether the external extension was installed during the first run
308 // of this profile.
309 bool IsExternalInstallFirstRun(const std::string& extension_id) const;
310 void SetExternalInstallFirstRun(const std::string& extension_id);
312 // Returns true if the extension notification code has already run for the
313 // first time for this profile. Currently we use this flag to mean that any
314 // extensions that would trigger notifications should get silently
315 // acknowledged. This is a fuse. Calling it the first time returns false.
316 // Subsequent calls return true. It's not possible through an API to ever
317 // reset it. Don't call it unless you mean it!
318 bool SetAlertSystemFirstRun();
320 // Returns the last value set via SetLastPingDay. If there isn't such a
321 // pref, the returned Time will return true for is_null().
322 base::Time LastPingDay(const std::string& extension_id) const;
324 // The time stored is based on the server's perspective of day start time, not
325 // the client's.
326 void SetLastPingDay(const std::string& extension_id, const base::Time& time);
328 // Similar to the 2 above, but for the extensions blacklist.
329 base::Time BlacklistLastPingDay() const;
330 void SetBlacklistLastPingDay(const base::Time& time);
332 // Similar to LastPingDay/SetLastPingDay, but for sending "days since active"
333 // ping.
334 base::Time LastActivePingDay(const std::string& extension_id) const;
335 void SetLastActivePingDay(const std::string& extension_id,
336 const base::Time& time);
338 // A bit we use for determining if we should send the "days since active"
339 // ping. A value of true means the item has been active (launched) since the
340 // last update check.
341 bool GetActiveBit(const std::string& extension_id) const;
342 void SetActiveBit(const std::string& extension_id, bool active);
344 // Returns the granted permission set for the extension with |extension_id|,
345 // and NULL if no preferences were found for |extension_id|.
346 // This passes ownership of the returned set to the caller.
347 PermissionSet* GetGrantedPermissions(const std::string& extension_id) const;
349 // Adds |permissions| to the granted permissions set for the extension with
350 // |extension_id|. The new granted permissions set will be the union of
351 // |permissions| and the already granted permissions.
352 void AddGrantedPermissions(const std::string& extension_id,
353 const PermissionSet* permissions);
355 // As above, but subtracts the given |permissions| from the granted set.
356 void RemoveGrantedPermissions(const std::string& extension_id,
357 const PermissionSet* permissions);
359 // Gets the active permission set for the specified extension. This may
360 // differ from the permissions in the manifest due to the optional
361 // permissions API. This passes ownership of the set to the caller.
362 PermissionSet* GetActivePermissions(const std::string& extension_id) const;
364 // Sets the active |permissions| for the extension with |extension_id|.
365 void SetActivePermissions(const std::string& extension_id,
366 const PermissionSet* permissions);
368 // Records whether or not this extension is currently running.
369 void SetExtensionRunning(const std::string& extension_id, bool is_running);
371 // Returns whether or not this extension is marked as running. This is used to
372 // restart apps across browser restarts.
373 bool IsExtensionRunning(const std::string& extension_id) const;
375 // Set/Get whether or not the app is active. Used to force a launch of apps
376 // that don't handle onRestarted() on a restart. We can only safely do that if
377 // the app was active when it was last running.
378 void SetIsActive(const std::string& extension_id, bool is_active);
379 bool IsActive(const std::string& extension_id) const;
381 // Returns true if the user enabled this extension to be loaded in incognito
382 // mode.
384 // IMPORTANT: you probably want to use extensions::util::IsIncognitoEnabled
385 // instead of this method.
386 bool IsIncognitoEnabled(const std::string& extension_id) const;
387 void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled);
389 // Returns true if the user has chosen to allow this extension to inject
390 // scripts into pages with file URLs.
392 // IMPORTANT: you probably want to use extensions::util::AllowFileAccess
393 // instead of this method.
394 bool AllowFileAccess(const std::string& extension_id) const;
395 void SetAllowFileAccess(const std::string& extension_id, bool allow);
396 bool HasAllowFileAccessSetting(const std::string& extension_id) const;
398 // Saves ExtensionInfo for each installed extension with the path to the
399 // version directory and the location. Blacklisted extensions won't be saved
400 // and neither will external extensions the user has explicitly uninstalled.
401 // Caller takes ownership of returned structure.
402 scoped_ptr<ExtensionsInfo> GetInstalledExtensionsInfo() const;
404 // Same as above, but only includes external extensions the user has
405 // explicitly uninstalled.
406 scoped_ptr<ExtensionsInfo> GetUninstalledExtensionsInfo() const;
408 // Returns the ExtensionInfo from the prefs for the given extension. If the
409 // extension is not present, NULL is returned.
410 scoped_ptr<ExtensionInfo> GetInstalledExtensionInfo(
411 const std::string& extension_id) const;
413 // We've downloaded an updated .crx file for the extension, but are waiting
414 // to install it.
416 // |install_flags| are a bitmask of extension::InstallFlags.
417 void SetDelayedInstallInfo(const Extension* extension,
418 Extension::State initial_state,
419 int install_flags,
420 DelayReason delay_reason,
421 const syncer::StringOrdinal& page_ordinal,
422 const std::string& install_parameter);
424 // Removes any delayed install information we have for the given
425 // |extension_id|. Returns true if there was info to remove; false otherwise.
426 bool RemoveDelayedInstallInfo(const std::string& extension_id);
428 // Update the prefs to finish the update for an extension.
429 bool FinishDelayedInstallInfo(const std::string& extension_id);
431 // Returns the ExtensionInfo from the prefs for delayed install information
432 // for |extension_id|, if we have any. Otherwise returns NULL.
433 scoped_ptr<ExtensionInfo> GetDelayedInstallInfo(
434 const std::string& extension_id) const;
436 DelayReason GetDelayedInstallReason(const std::string& extension_id) const;
438 // Returns information about all the extensions that have delayed install
439 // information.
440 scoped_ptr<ExtensionsInfo> GetAllDelayedInstallInfo() const;
442 // Returns true if the extension is an ephemeral app.
443 bool IsEphemeralApp(const std::string& extension_id) const;
445 // Promotes an ephemeral app to a regular installed app.
446 void OnEphemeralAppPromoted(const std::string& extension_id);
448 // Returns true if the user repositioned the app on the app launcher via drag
449 // and drop.
450 bool WasAppDraggedByUser(const std::string& extension_id) const;
452 // Sets a flag indicating that the user repositioned the app on the app
453 // launcher by drag and dropping it.
454 void SetAppDraggedByUser(const std::string& extension_id);
456 // Returns true if there is an extension which controls the preference value
457 // for |pref_key| *and* it is specific to incognito mode.
458 bool HasIncognitoPrefValue(const std::string& pref_key) const;
460 // Returns the creation flags mask for the extension.
461 int GetCreationFlags(const std::string& extension_id) const;
463 // Returns the creation flags mask for a delayed install extension.
464 int GetDelayedInstallCreationFlags(const std::string& extension_id) const;
466 // Returns true if the extension was installed from the Chrome Web Store.
467 bool IsFromWebStore(const std::string& extension_id) const;
469 // Returns true if the extension was installed from an App generated from a
470 // bookmark.
471 bool IsFromBookmark(const std::string& extension_id) const;
473 // Returns true if the extension was installed as a default app.
474 bool WasInstalledByDefault(const std::string& extension_id) const;
476 // Returns true if the extension was installed as an oem app.
477 bool WasInstalledByOem(const std::string& extension_id) const;
479 // Helper method to acquire the installation time of an extension.
480 // Returns base::Time() if the installation time could not be parsed or
481 // found.
482 base::Time GetInstallTime(const std::string& extension_id) const;
484 // Returns true if the extension should not be synced.
485 bool DoNotSync(const std::string& extension_id) const;
487 // Gets/sets the last launch time of an extension.
488 base::Time GetLastLaunchTime(const std::string& extension_id) const;
489 void SetLastLaunchTime(const std::string& extension_id,
490 const base::Time& time);
492 // Clear any launch times. This is called by the browsing data remover when
493 // history is cleared.
494 void ClearLastLaunchTimes();
496 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
498 bool extensions_disabled() const { return extensions_disabled_; }
500 // The underlying PrefService.
501 PrefService* pref_service() const { return prefs_; }
503 // The underlying AppSorting.
504 AppSorting* app_sorting() const { return app_sorting_.get(); }
506 // Schedules garbage collection of an extension's on-disk data on the next
507 // start of this ExtensionService. Applies only to extensions with isolated
508 // storage.
509 void SetNeedsStorageGarbageCollection(bool value);
510 bool NeedsStorageGarbageCollection() const;
512 // Used by AppWindowGeometryCache to persist its cache. These methods
513 // should not be called directly.
514 const base::DictionaryValue* GetGeometryCache(
515 const std::string& extension_id) const;
516 void SetGeometryCache(const std::string& extension_id,
517 scoped_ptr<base::DictionaryValue> cache);
519 // Used for verification of installed extension ids. For the Set method, pass
520 // null to remove the preference.
521 const base::DictionaryValue* GetInstallSignature() const;
522 void SetInstallSignature(const base::DictionaryValue* signature);
524 // The installation parameter associated with the extension.
525 std::string GetInstallParam(const std::string& extension_id) const;
526 void SetInstallParam(const std::string& extension_id,
527 const std::string& install_parameter);
529 // The total number of times we've disabled an extension due to corrupted
530 // contents.
531 int GetCorruptedDisableCount() const;
532 void IncrementCorruptedDisableCount();
534 // Whether the extension with the given |id| needs to be synced. This is set
535 // when the state (such as enabled/disabled or allowed in incognito) is
536 // changed before Sync is ready.
537 bool NeedsSync(const std::string& extension_id) const;
538 void SetNeedsSync(const std::string& extension_id, bool needs_sync);
540 private:
541 friend class ExtensionPrefsBlacklistedExtensions; // Unit test.
542 friend class ExtensionPrefsComponentExtension; // Unit test.
543 friend class ExtensionPrefsUninstallExtension; // Unit test.
545 enum DisableReasonChange {
546 DISABLE_REASON_ADD,
547 DISABLE_REASON_REMOVE,
548 DISABLE_REASON_CLEAR
551 // See the Create methods.
552 ExtensionPrefs(PrefService* prefs,
553 const base::FilePath& root_dir,
554 ExtensionPrefValueMap* extension_pref_value_map,
555 scoped_ptr<AppSorting> app_sorting,
556 scoped_ptr<TimeProvider> time_provider,
557 bool extensions_disabled,
558 const std::vector<ExtensionPrefsObserver*>& early_observers);
560 // Converts absolute paths in the pref to paths relative to the
561 // install_directory_.
562 void MakePathsRelative();
564 // Converts internal relative paths to be absolute. Used for export to
565 // consumers who expect full paths.
566 void MakePathsAbsolute(base::DictionaryValue* dict);
568 // Helper function used by GetInstalledExtensionInfo() and
569 // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided
570 // |extension| dictionary.
571 scoped_ptr<ExtensionInfo> GetInstalledInfoHelper(
572 const std::string& extension_id,
573 const base::DictionaryValue* extension) const;
575 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a
576 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns.
577 bool ReadPrefAsURLPatternSet(const std::string& extension_id,
578 const std::string& pref_key,
579 URLPatternSet* result,
580 int valid_schemes) const;
582 // Converts |new_value| to a list of strings and sets the |pref_key| pref
583 // belonging to |extension_id|.
584 void SetExtensionPrefURLPatternSet(const std::string& extension_id,
585 const std::string& pref_key,
586 const URLPatternSet& new_value);
588 // Read the boolean preference entry and return true if the preference exists
589 // and the preference's value is true; false otherwise.
590 bool ReadPrefAsBooleanAndReturn(const std::string& extension_id,
591 const std::string& key) const;
593 // Interprets |pref_key| in |extension_id|'s preferences as an
594 // PermissionSet, and passes ownership of the set to the caller.
595 PermissionSet* ReadPrefAsPermissionSet(const std::string& extension_id,
596 const std::string& pref_key) const;
598 // Converts the |new_value| to its value and sets the |pref_key| pref
599 // belonging to |extension_id|.
600 void SetExtensionPrefPermissionSet(const std::string& extension_id,
601 const std::string& pref_key,
602 const PermissionSet* new_value);
604 // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it
605 // doesn't exist.
606 const base::DictionaryValue* GetExtensionPref(const std::string& id) const;
608 // Modifies the extensions disable reasons to add a new reason, remove an
609 // existing reason, or clear all reasons. Notifies observers if the set of
610 // DisableReasons has changed.
611 // If |change| is DISABLE_REASON_CLEAR, then |reason| is ignored.
612 void ModifyDisableReasons(const std::string& extension_id,
613 int reasons,
614 DisableReasonChange change);
616 // Fix missing preference entries in the extensions that are were introduced
617 // in a later Chrome version.
618 void FixMissingPrefs(const ExtensionIdList& extension_ids);
620 // Installs the persistent extension preferences into |prefs_|'s extension
621 // pref store. Does nothing if extensions_disabled_ is true.
622 void InitPrefStore();
624 // Migrates the permissions data in the pref store.
625 void MigratePermissions(const ExtensionIdList& extension_ids);
627 // Migrates the disable reasons from a single enum to a bit mask.
628 void MigrateDisableReasons(const ExtensionIdList& extension_ids);
630 // Checks whether there is a state pref for the extension and if so, whether
631 // it matches |check_state|.
632 bool DoesExtensionHaveState(const std::string& id,
633 Extension::State check_state) const;
635 // Reads the list of strings for |pref| from user prefs into
636 // |id_container_out|. Returns false if the pref wasn't found in the user
637 // pref store.
638 template <class ExtensionIdContainer>
639 bool GetUserExtensionPrefIntoContainer(
640 const char* pref,
641 ExtensionIdContainer* id_container_out) const;
643 // Writes the list of strings contained in |strings| to |pref| in prefs.
644 template <class ExtensionIdContainer>
645 void SetExtensionPrefFromContainer(const char* pref,
646 const ExtensionIdContainer& strings);
648 // Helper function to populate |extension_dict| with the values needed
649 // by a newly installed extension. Work is broken up between this
650 // function and FinishExtensionInfoPrefs() to accommodate delayed
651 // installations.
653 // |install_flags| are a bitmask of extension::InstallFlags.
654 void PopulateExtensionInfoPrefs(const Extension* extension,
655 const base::Time install_time,
656 Extension::State initial_state,
657 int install_flags,
658 const std::string& install_parameter,
659 base::DictionaryValue* extension_dict) const;
661 void InitExtensionControlledPrefs(ExtensionPrefValueMap* value_map);
663 // Helper function to complete initialization of the values in
664 // |extension_dict| for an extension install. Also see
665 // PopulateExtensionInfoPrefs().
666 void FinishExtensionInfoPrefs(
667 const std::string& extension_id,
668 const base::Time install_time,
669 bool needs_sort_ordinal,
670 const syncer::StringOrdinal& suggested_page_ordinal,
671 base::DictionaryValue* extension_dict);
673 // The pref service specific to this set of extension prefs. Owned by the
674 // BrowserContext.
675 PrefService* prefs_;
677 // Base extensions install directory.
678 base::FilePath install_directory_;
680 // Weak pointer, owned by BrowserContext.
681 ExtensionPrefValueMap* extension_pref_value_map_;
683 // Contains all the logic for handling the order for various extension
684 // properties.
685 scoped_ptr<AppSorting> app_sorting_;
687 scoped_ptr<TimeProvider> time_provider_;
689 bool extensions_disabled_;
691 base::ObserverList<ExtensionPrefsObserver> observer_list_;
693 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
696 } // namespace extensions
698 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_