Move ownership of AppSorting from ExtensionPrefs to ExtensionSystem
[chromium-blink-merge.git] / extensions / browser / extension_prefs.h
blobb5a322420fb36466194e11354a0431ce04ebf539
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 ExtensionPrefsUninstallExtension;
44 class URLPatternSet;
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 {
62 public:
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
70 // preferences.
71 enum DelayReason {
72 DELAY_REASON_NONE = 0,
73 DELAY_REASON_GC = 1,
74 DELAY_REASON_WAIT_FOR_IDLE = 2,
75 DELAY_REASON_WAIT_FOR_IMPORTS = 3,
78 // Creates base::Time classes. The default implementation is just to return
79 // the current time, but tests can inject alternative implementations.
80 class TimeProvider {
81 public:
82 TimeProvider();
84 virtual ~TimeProvider();
86 // By default, returns the current time (base::Time::Now()).
87 virtual base::Time GetCurrentTime() const;
89 private:
90 DISALLOW_COPY_AND_ASSIGN(TimeProvider);
93 // A wrapper around a ScopedUserPrefUpdate, which allows us to access the
94 // entry of a particular key for an extension. Use this if you need a mutable
95 // record of a dictionary or list in the current settings. Otherwise, prefer
96 // ReadPrefAsT() and UpdateExtensionPref() methods.
97 template <typename T, base::Value::Type type_enum_value>
98 class ScopedUpdate {
99 public:
100 ScopedUpdate(ExtensionPrefs* prefs,
101 const std::string& extension_id,
102 const std::string& key);
103 virtual ~ScopedUpdate();
105 // Returns a mutable value for the key (ownership remains with the prefs),
106 // if one exists. Otherwise, returns NULL.
107 virtual T* Get();
109 // Creates and returns a mutable value for the key (the prefs own the new
110 // value), if one does not already exist. Otherwise, returns the current
111 // value.
112 virtual T* Create();
114 private:
115 DictionaryPrefUpdate update_;
116 const std::string extension_id_;
117 const std::string key_;
119 DISALLOW_COPY_AND_ASSIGN(ScopedUpdate);
121 typedef ScopedUpdate<base::DictionaryValue, base::Value::TYPE_DICTIONARY>
122 ScopedDictionaryUpdate;
123 typedef ScopedUpdate<base::ListValue, base::Value::TYPE_LIST>
124 ScopedListUpdate;
126 // Creates an ExtensionPrefs object.
127 // Does not take ownership of |prefs| or |extension_pref_value_map|.
128 // If |extensions_disabled| is true, extension controlled preferences and
129 // content settings do not become effective. ExtensionPrefsObservers should be
130 // included in |early_observers| if they need to observe events which occur
131 // during initialization of the ExtensionPrefs object.
132 static ExtensionPrefs* Create(
133 content::BrowserContext* browser_context,
134 PrefService* prefs,
135 const base::FilePath& root_dir,
136 ExtensionPrefValueMap* extension_pref_value_map,
137 bool extensions_disabled,
138 const std::vector<ExtensionPrefsObserver*>& early_observers);
140 // A version of Create which allows injection of a custom base::Time provider.
141 // Use this as needed for testing.
142 static ExtensionPrefs* Create(
143 content::BrowserContext* browser_context,
144 PrefService* prefs,
145 const base::FilePath& root_dir,
146 ExtensionPrefValueMap* extension_pref_value_map,
147 bool extensions_disabled,
148 const std::vector<ExtensionPrefsObserver*>& early_observers,
149 scoped_ptr<TimeProvider> time_provider);
151 ~ExtensionPrefs() override;
153 // Convenience function to get the ExtensionPrefs for a BrowserContext.
154 static ExtensionPrefs* Get(content::BrowserContext* context);
156 // Returns all installed extensions from extension preferences provided by
157 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs
158 // access to the extension ID list before the ExtensionService is initialized.
159 static ExtensionIdList GetExtensionsFrom(const PrefService* pref_service);
161 // Add or remove an observer from the ExtensionPrefs.
162 void AddObserver(ExtensionPrefsObserver* observer);
163 void RemoveObserver(ExtensionPrefsObserver* observer);
165 // Returns true if the specified external extension was uninstalled by the
166 // user.
167 bool IsExternalExtensionUninstalled(const std::string& id) const;
169 // Checks whether |extension_id| is disabled. If there's no state pref for
170 // the extension, this will return false. Generally you should use
171 // ExtensionService::IsExtensionEnabled instead.
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 // Called to change the extension's state when it is enabled/disabled.
204 void SetExtensionState(const std::string& extension_id, Extension::State);
206 // Called to change the extension's BlacklistState. Currently only used for
207 // non-malicious extensions.
208 // TODO(oleg): replace SetExtensionBlacklisted by this function.
209 void SetExtensionBlacklistState(const std::string& extension_id,
210 BlacklistState state);
212 // Checks whether |extension_id| is marked as greylisted.
213 // TODO(oleg): Replace IsExtensionBlacklisted by this method.
214 BlacklistState GetExtensionBlacklistState(
215 const std::string& extension_id) const;
217 // Populates |out| with the ids of all installed extensions.
218 void GetExtensions(ExtensionIdList* out) const;
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) const;
253 // Getters and setters for disabled reason.
254 int GetDisableReasons(const std::string& extension_id) const;
255 bool HasDisableReason(const std::string& extension_id,
256 Extension::DisableReason disable_reason) const;
257 void AddDisableReason(const std::string& extension_id,
258 Extension::DisableReason disable_reason);
259 void AddDisableReasons(const std::string& extension_id, int disable_reasons);
260 void RemoveDisableReason(const std::string& extension_id,
261 Extension::DisableReason disable_reason);
262 void ClearDisableReasons(const std::string& extension_id);
264 // Gets the set of extensions that have been blacklisted in prefs. This will
265 // return only the blocked extensions, not the "greylist" extensions.
266 // TODO(oleg): Make method names consistent here, in extension service and in
267 // blacklist.
268 std::set<std::string> GetBlacklistedExtensions() const;
270 // Sets whether the extension with |id| is blacklisted.
271 void SetExtensionBlacklisted(const std::string& extension_id,
272 bool is_blacklisted);
274 // Returns the version string for the currently installed extension, or
275 // the empty string if not found.
276 std::string GetVersionString(const std::string& extension_id) const;
278 // Re-writes the extension manifest into the prefs.
279 // Called to change the extension's manifest when it's re-localized.
280 void UpdateManifest(const Extension* extension);
282 // Returns base extensions install directory.
283 const base::FilePath& install_directory() const { return install_directory_; }
285 // Returns whether the extension with |id| has its blacklist bit set.
287 // WARNING: this only checks the extension's entry in prefs, so by definition
288 // can only check extensions that prefs knows about. There may be other
289 // sources of blacklist information, such as safebrowsing. You probably want
290 // to use Blacklist::GetBlacklistedIDs rather than this method.
291 bool IsExtensionBlacklisted(const std::string& id) const;
293 // Increment the count of how many times we prompted the user to acknowledge
294 // the given extension, and return the new count.
295 int IncrementAcknowledgePromptCount(const std::string& extension_id);
297 // Whether the user has acknowledged an external extension.
298 bool IsExternalExtensionAcknowledged(const std::string& extension_id) const;
299 void AcknowledgeExternalExtension(const std::string& extension_id);
301 // Whether the user has acknowledged a blacklisted extension.
302 bool IsBlacklistedExtensionAcknowledged(
303 const std::string& extension_id) const;
304 void AcknowledgeBlacklistedExtension(const std::string& extension_id);
306 // Whether the external extension was installed during the first run
307 // of this profile.
308 bool IsExternalInstallFirstRun(const std::string& extension_id) const;
309 void SetExternalInstallFirstRun(const std::string& extension_id);
311 // Returns true if the extension notification code has already run for the
312 // first time for this profile. Currently we use this flag to mean that any
313 // extensions that would trigger notifications should get silently
314 // acknowledged. This is a fuse. Calling it the first time returns false.
315 // Subsequent calls return true. It's not possible through an API to ever
316 // reset it. Don't call it unless you mean it!
317 bool SetAlertSystemFirstRun();
319 // Returns the last value set via SetLastPingDay. If there isn't such a
320 // pref, the returned Time will return true for is_null().
321 base::Time LastPingDay(const std::string& extension_id) const;
323 // The time stored is based on the server's perspective of day start time, not
324 // the client's.
325 void SetLastPingDay(const std::string& extension_id, const base::Time& time);
327 // Similar to the 2 above, but for the extensions blacklist.
328 base::Time BlacklistLastPingDay() const;
329 void SetBlacklistLastPingDay(const base::Time& time);
331 // Similar to LastPingDay/SetLastPingDay, but for sending "days since active"
332 // ping.
333 base::Time LastActivePingDay(const std::string& extension_id) const;
334 void SetLastActivePingDay(const std::string& extension_id,
335 const base::Time& time);
337 // A bit we use for determining if we should send the "days since active"
338 // ping. A value of true means the item has been active (launched) since the
339 // last update check.
340 bool GetActiveBit(const std::string& extension_id) const;
341 void SetActiveBit(const std::string& extension_id, bool active);
343 // Returns the granted permission set for the extension with |extension_id|,
344 // and NULL if no preferences were found for |extension_id|.
345 // This passes ownership of the returned set to the caller.
346 PermissionSet* GetGrantedPermissions(const std::string& extension_id) const;
348 // Adds |permissions| to the granted permissions set for the extension with
349 // |extension_id|. The new granted permissions set will be the union of
350 // |permissions| and the already granted permissions.
351 void AddGrantedPermissions(const std::string& extension_id,
352 const PermissionSet* permissions);
354 // As above, but subtracts the given |permissions| from the granted set.
355 void RemoveGrantedPermissions(const std::string& extension_id,
356 const PermissionSet* permissions);
358 // Gets the active permission set for the specified extension. This may
359 // differ from the permissions in the manifest due to the optional
360 // permissions API. This passes ownership of the set to the caller.
361 PermissionSet* GetActivePermissions(const std::string& extension_id) const;
363 // Sets the active |permissions| for the extension with |extension_id|.
364 void SetActivePermissions(const std::string& extension_id,
365 const PermissionSet* permissions);
367 // Records whether or not this extension is currently running.
368 void SetExtensionRunning(const std::string& extension_id, bool is_running);
370 // Returns whether or not this extension is marked as running. This is used to
371 // restart apps across browser restarts.
372 bool IsExtensionRunning(const std::string& extension_id) const;
374 // Set/Get whether or not the app is active. Used to force a launch of apps
375 // that don't handle onRestarted() on a restart. We can only safely do that if
376 // the app was active when it was last running.
377 void SetIsActive(const std::string& extension_id, bool is_active);
378 bool IsActive(const std::string& extension_id) const;
380 // Returns true if the user enabled this extension to be loaded in incognito
381 // mode.
383 // IMPORTANT: you probably want to use extensions::util::IsIncognitoEnabled
384 // instead of this method.
385 bool IsIncognitoEnabled(const std::string& extension_id) const;
386 void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled);
388 // Returns true if the user has chosen to allow this extension to inject
389 // scripts into pages with file URLs.
391 // IMPORTANT: you probably want to use extensions::util::AllowFileAccess
392 // instead of this method.
393 bool AllowFileAccess(const std::string& extension_id) const;
394 void SetAllowFileAccess(const std::string& extension_id, bool allow);
395 bool HasAllowFileAccessSetting(const std::string& extension_id) const;
397 // Saves ExtensionInfo for each installed extension with the path to the
398 // version directory and the location. Blacklisted extensions won't be saved
399 // and neither will external extensions the user has explicitly uninstalled.
400 // Caller takes ownership of returned structure.
401 scoped_ptr<ExtensionsInfo> GetInstalledExtensionsInfo() const;
403 // Same as above, but only includes external extensions the user has
404 // explicitly uninstalled.
405 scoped_ptr<ExtensionsInfo> GetUninstalledExtensionsInfo() const;
407 // Returns the ExtensionInfo from the prefs for the given extension. If the
408 // extension is not present, NULL is returned.
409 scoped_ptr<ExtensionInfo> GetInstalledExtensionInfo(
410 const std::string& extension_id) const;
412 // We've downloaded an updated .crx file for the extension, but are waiting
413 // to install it.
415 // |install_flags| are a bitmask of extension::InstallFlags.
416 void SetDelayedInstallInfo(const Extension* extension,
417 Extension::State initial_state,
418 int install_flags,
419 DelayReason delay_reason,
420 const syncer::StringOrdinal& page_ordinal,
421 const std::string& install_parameter);
423 // Removes any delayed install information we have for the given
424 // |extension_id|. Returns true if there was info to remove; false otherwise.
425 bool RemoveDelayedInstallInfo(const std::string& extension_id);
427 // Update the prefs to finish the update for an extension.
428 bool FinishDelayedInstallInfo(const std::string& extension_id);
430 // Returns the ExtensionInfo from the prefs for delayed install information
431 // for |extension_id|, if we have any. Otherwise returns NULL.
432 scoped_ptr<ExtensionInfo> GetDelayedInstallInfo(
433 const std::string& extension_id) const;
435 DelayReason GetDelayedInstallReason(const std::string& extension_id) const;
437 // Returns information about all the extensions that have delayed install
438 // information.
439 scoped_ptr<ExtensionsInfo> GetAllDelayedInstallInfo() const;
441 // Returns true if the extension is an ephemeral app.
442 bool IsEphemeralApp(const std::string& extension_id) const;
444 // Promotes an ephemeral app to a regular installed app.
445 void OnEphemeralAppPromoted(const std::string& extension_id);
447 // Returns true if the user repositioned the app on the app launcher via drag
448 // and drop.
449 bool WasAppDraggedByUser(const std::string& extension_id) const;
451 // Sets a flag indicating that the user repositioned the app on the app
452 // launcher by drag and dropping it.
453 void SetAppDraggedByUser(const std::string& extension_id);
455 // Returns true if there is an extension which controls the preference value
456 // for |pref_key| *and* it is specific to incognito mode.
457 bool HasIncognitoPrefValue(const std::string& pref_key) const;
459 // Returns the creation flags mask for the extension.
460 int GetCreationFlags(const std::string& extension_id) const;
462 // Returns the creation flags mask for a delayed install extension.
463 int GetDelayedInstallCreationFlags(const std::string& extension_id) const;
465 // Returns true if the extension was installed from the Chrome Web Store.
466 bool IsFromWebStore(const std::string& extension_id) const;
468 // Returns true if the extension was installed from an App generated from a
469 // bookmark.
470 bool IsFromBookmark(const std::string& extension_id) const;
472 // Returns true if the extension was installed as a default app.
473 bool WasInstalledByDefault(const std::string& extension_id) const;
475 // Returns true if the extension was installed as an oem app.
476 bool WasInstalledByOem(const std::string& extension_id) const;
478 // Helper method to acquire the installation time of an extension.
479 // Returns base::Time() if the installation time could not be parsed or
480 // found.
481 base::Time GetInstallTime(const std::string& extension_id) const;
483 // Returns true if the extension should not be synced.
484 bool DoNotSync(const std::string& extension_id) const;
486 // Gets/sets the last launch time of an extension.
487 base::Time GetLastLaunchTime(const std::string& extension_id) const;
488 void SetLastLaunchTime(const std::string& extension_id,
489 const base::Time& time);
491 // Clear any launch times. This is called by the browsing data remover when
492 // history is cleared.
493 void ClearLastLaunchTimes();
495 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
497 bool extensions_disabled() const { return extensions_disabled_; }
499 // The underlying PrefService.
500 PrefService* pref_service() const { return prefs_; }
502 // The underlying AppSorting.
503 // TODO(treib,kalman): This should be private, and all callers should go
504 // through the ExtensionSystem instead.
505 AppSorting* app_sorting() const;
507 // Schedules garbage collection of an extension's on-disk data on the next
508 // start of this ExtensionService. Applies only to extensions with isolated
509 // storage.
510 void SetNeedsStorageGarbageCollection(bool value);
511 bool NeedsStorageGarbageCollection() const;
513 // Used by AppWindowGeometryCache to persist its cache. These methods
514 // should not be called directly.
515 const base::DictionaryValue* GetGeometryCache(
516 const std::string& extension_id) const;
517 void SetGeometryCache(const std::string& extension_id,
518 scoped_ptr<base::DictionaryValue> cache);
520 // Used for verification of installed extension ids. For the Set method, pass
521 // null to remove the preference.
522 const base::DictionaryValue* GetInstallSignature() const;
523 void SetInstallSignature(const base::DictionaryValue* signature);
525 // The installation parameter associated with the extension.
526 std::string GetInstallParam(const std::string& extension_id) const;
527 void SetInstallParam(const std::string& extension_id,
528 const std::string& install_parameter);
530 // The total number of times we've disabled an extension due to corrupted
531 // contents.
532 int GetCorruptedDisableCount() const;
533 void IncrementCorruptedDisableCount();
535 // Whether the extension with the given |id| needs to be synced. This is set
536 // when the state (such as enabled/disabled or allowed in incognito) is
537 // changed before Sync is ready.
538 bool NeedsSync(const std::string& extension_id) const;
539 void SetNeedsSync(const std::string& extension_id, bool needs_sync);
541 private:
542 friend class ExtensionPrefsBlacklistedExtensions; // Unit test.
543 friend class ExtensionPrefsComponentExtension; // Unit test.
544 friend class ExtensionPrefsUninstallExtension; // Unit test.
546 enum DisableReasonChange {
547 DISABLE_REASON_ADD,
548 DISABLE_REASON_REMOVE,
549 DISABLE_REASON_CLEAR
552 // See the Create methods.
553 ExtensionPrefs(content::BrowserContext* browser_context,
554 PrefService* prefs,
555 const base::FilePath& root_dir,
556 ExtensionPrefValueMap* extension_pref_value_map,
557 scoped_ptr<TimeProvider> time_provider,
558 bool extensions_disabled,
559 const std::vector<ExtensionPrefsObserver*>& early_observers);
561 // Converts absolute paths in the pref to paths relative to the
562 // install_directory_.
563 void MakePathsRelative();
565 // Converts internal relative paths to be absolute. Used for export to
566 // consumers who expect full paths.
567 void MakePathsAbsolute(base::DictionaryValue* dict);
569 // Helper function used by GetInstalledExtensionInfo() and
570 // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided
571 // |extension| dictionary.
572 scoped_ptr<ExtensionInfo> GetInstalledInfoHelper(
573 const std::string& extension_id,
574 const base::DictionaryValue* extension) const;
576 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a
577 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns.
578 bool ReadPrefAsURLPatternSet(const std::string& extension_id,
579 const std::string& pref_key,
580 URLPatternSet* result,
581 int valid_schemes) const;
583 // Converts |new_value| to a list of strings and sets the |pref_key| pref
584 // belonging to |extension_id|.
585 void SetExtensionPrefURLPatternSet(const std::string& extension_id,
586 const std::string& pref_key,
587 const URLPatternSet& new_value);
589 // Read the boolean preference entry and return true if the preference exists
590 // and the preference's value is true; false otherwise.
591 bool ReadPrefAsBooleanAndReturn(const std::string& extension_id,
592 const std::string& key) const;
594 // Interprets |pref_key| in |extension_id|'s preferences as an
595 // PermissionSet, and passes ownership of the set to the caller.
596 PermissionSet* ReadPrefAsPermissionSet(const std::string& extension_id,
597 const std::string& pref_key) const;
599 // Converts the |new_value| to its value and sets the |pref_key| pref
600 // belonging to |extension_id|.
601 void SetExtensionPrefPermissionSet(const std::string& extension_id,
602 const std::string& pref_key,
603 const PermissionSet* new_value);
605 // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it
606 // doesn't exist.
607 const base::DictionaryValue* GetExtensionPref(const std::string& id) const;
609 // Modifies the extensions disable reasons to add a new reason, remove an
610 // existing reason, or clear all reasons. Notifies observers if the set of
611 // DisableReasons has changed.
612 // If |change| is DISABLE_REASON_CLEAR, then |reason| is ignored.
613 void ModifyDisableReasons(const std::string& extension_id,
614 int reasons,
615 DisableReasonChange change);
617 // Fix missing preference entries in the extensions that are were introduced
618 // in a later Chrome version.
619 void FixMissingPrefs(const ExtensionIdList& extension_ids);
621 // Installs the persistent extension preferences into |prefs_|'s extension
622 // pref store. Does nothing if extensions_disabled_ is true.
623 void InitPrefStore();
625 // Migrates the permissions data in the pref store.
626 void MigratePermissions(const ExtensionIdList& extension_ids);
628 // Migrates the disable reasons from a single enum to a bit mask.
629 void MigrateDisableReasons(const ExtensionIdList& extension_ids);
631 // Checks whether there is a state pref for the extension and if so, whether
632 // it matches |check_state|.
633 bool DoesExtensionHaveState(const std::string& id,
634 Extension::State check_state) const;
636 // Reads the list of strings for |pref| from user prefs into
637 // |id_container_out|. Returns false if the pref wasn't found in the user
638 // pref store.
639 template <class ExtensionIdContainer>
640 bool GetUserExtensionPrefIntoContainer(
641 const char* pref,
642 ExtensionIdContainer* id_container_out) const;
644 // Writes the list of strings contained in |strings| to |pref| in prefs.
645 template <class ExtensionIdContainer>
646 void SetExtensionPrefFromContainer(const char* pref,
647 const ExtensionIdContainer& strings);
649 // Helper function to populate |extension_dict| with the values needed
650 // by a newly installed extension. Work is broken up between this
651 // function and FinishExtensionInfoPrefs() to accommodate delayed
652 // installations.
654 // |install_flags| are a bitmask of extension::InstallFlags.
655 void PopulateExtensionInfoPrefs(const Extension* extension,
656 const base::Time install_time,
657 Extension::State initial_state,
658 int install_flags,
659 const std::string& install_parameter,
660 base::DictionaryValue* extension_dict) const;
662 void InitExtensionControlledPrefs(ExtensionPrefValueMap* value_map);
664 // Helper function to complete initialization of the values in
665 // |extension_dict| for an extension install. Also see
666 // PopulateExtensionInfoPrefs().
667 void FinishExtensionInfoPrefs(
668 const std::string& extension_id,
669 const base::Time install_time,
670 bool needs_sort_ordinal,
671 const syncer::StringOrdinal& suggested_page_ordinal,
672 base::DictionaryValue* extension_dict);
674 content::BrowserContext* browser_context_;
676 // The pref service specific to this set of extension prefs. Owned by the
677 // BrowserContext.
678 PrefService* prefs_;
680 // Base extensions install directory.
681 base::FilePath install_directory_;
683 // Weak pointer, owned by BrowserContext.
684 ExtensionPrefValueMap* extension_pref_value_map_;
686 scoped_ptr<TimeProvider> time_provider_;
688 bool extensions_disabled_;
690 base::ObserverList<ExtensionPrefsObserver> observer_list_;
692 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
695 } // namespace extensions
697 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_