Update path of checkdeps to buildtools checkout
[chromium-blink-merge.git] / extensions / browser / extension_prefs.h
blobfc65d7393bc37aacd5a2bf54da4da10e0c06fbe6
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/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,
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 virtual ~ExtensionPrefs();
154 // Convenience function to get the ExtensionPrefs for a BrowserContext.
155 static ExtensionPrefs* Get(content::BrowserContext* context);
157 // Returns all installed extensions from extension preferences provided by
158 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs
159 // access to the extension ID list before the ExtensionService is initialized.
160 static ExtensionIdList GetExtensionsFrom(const PrefService* pref_service);
162 // Add or remove an observer from the ExtensionPrefs.
163 void AddObserver(ExtensionPrefsObserver* observer);
164 void RemoveObserver(ExtensionPrefsObserver* observer);
166 // Returns true if the specified external extension was uninstalled by the
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 // Gets the set of known disabled extension IDs into |id_set_out|. Returns
180 // false iff the set of known disabled extension IDs hasn't been set yet.
181 bool GetKnownDisabled(ExtensionIdSet* id_set_out);
183 // Sets the set of known disabled extension IDs.
184 void SetKnownDisabled(const ExtensionIdSet& extension_ids);
186 // Called when an extension is installed, so that prefs get created.
187 // |blacklisted_for_malware| should be set if the extension was included in a
188 // blacklist due to being malware. If |page_ordinal| is an invalid ordinal,
189 // then a page will be found for the App.
190 void OnExtensionInstalled(const Extension* extension,
191 Extension::State initial_state,
192 bool blacklisted_for_malware,
193 bool is_ephemeral,
194 const syncer::StringOrdinal& page_ordinal,
195 const std::string& install_parameter);
197 // Called when an extension is uninstalled, so that prefs get cleaned up.
198 void OnExtensionUninstalled(const std::string& extension_id,
199 const Manifest::Location& location,
200 bool external_uninstall);
202 // Called to change the extension's state when it is enabled/disabled.
203 void SetExtensionState(const std::string& extension_id, Extension::State);
205 // Called to change the extension's BlacklistState. Currently only used for
206 // non-malicious extensions.
207 // TODO(oleg): replace SetExtensionBlacklisted by this function.
208 void SetExtensionBlacklistState(const std::string& extension_id,
209 BlacklistState state);
211 // Checks whether |extension_id| is marked as greylisted.
212 // TODO(oleg): Replace IsExtensionBlacklisted by this method.
213 BlacklistState GetExtensionBlacklistState(const std::string& extension_id);
215 // Populates |out| with the ids of all installed extensions.
216 void GetExtensions(ExtensionIdList* out);
218 // ExtensionScopedPrefs methods:
219 virtual void UpdateExtensionPref(const std::string& id,
220 const std::string& key,
221 base::Value* value) OVERRIDE;
223 virtual void DeleteExtensionPrefs(const std::string& id) OVERRIDE;
225 virtual bool ReadPrefAsBoolean(const std::string& extension_id,
226 const std::string& pref_key,
227 bool* out_value) const OVERRIDE;
229 virtual bool ReadPrefAsInteger(const std::string& extension_id,
230 const std::string& pref_key,
231 int* out_value) const OVERRIDE;
233 virtual bool ReadPrefAsString(const std::string& extension_id,
234 const std::string& pref_key,
235 std::string* out_value) const OVERRIDE;
237 virtual bool ReadPrefAsList(const std::string& extension_id,
238 const std::string& pref_key,
239 const base::ListValue** out_value) const OVERRIDE;
241 virtual bool ReadPrefAsDictionary(
242 const std::string& extension_id,
243 const std::string& pref_key,
244 const base::DictionaryValue** out_value) const OVERRIDE;
246 virtual bool HasPrefForExtension(const std::string& extension_id) const
247 OVERRIDE;
249 // Did the extension ask to escalate its permission during an upgrade?
250 bool DidExtensionEscalatePermissions(const std::string& id);
252 // If |did_escalate| is true, the preferences for |extension| will be set to
253 // require the install warning when the user tries to enable.
254 void SetDidExtensionEscalatePermissions(
255 const Extension* extension,
256 bool did_escalate);
258 // Getters and setters for disabled reason.
259 int GetDisableReasons(const std::string& extension_id) const;
260 bool HasDisableReason(const std::string& extension_id,
261 Extension::DisableReason disable_reason) const;
262 void AddDisableReason(const std::string& extension_id,
263 Extension::DisableReason disable_reason);
264 void RemoveDisableReason(const std::string& extension_id,
265 Extension::DisableReason disable_reason);
266 void ClearDisableReasons(const std::string& extension_id);
268 // Gets the set of extensions that have been blacklisted in prefs. This will
269 // return only the blocked extensions, not the "greylist" extensions.
270 // TODO(oleg): Make method names consistent here, in extension service and in
271 // blacklist.
272 std::set<std::string> GetBlacklistedExtensions();
274 // Sets whether the extension with |id| is blacklisted.
275 void SetExtensionBlacklisted(const std::string& extension_id,
276 bool is_blacklisted);
278 // Returns the version string for the currently installed extension, or
279 // the empty string if not found.
280 std::string GetVersionString(const std::string& extension_id);
282 // Re-writes the extension manifest into the prefs.
283 // Called to change the extension's manifest when it's re-localized.
284 void UpdateManifest(const Extension* extension);
286 // Returns extension path based on extension ID, or empty FilePath on error.
287 base::FilePath GetExtensionPath(const std::string& extension_id);
289 // Returns base extensions install directory.
290 const base::FilePath& install_directory() const { return install_directory_; }
292 // Returns whether the extension with |id| has its blacklist bit set.
294 // WARNING: this only checks the extension's entry in prefs, so by definition
295 // can only check extensions that prefs knows about. There may be other
296 // sources of blacklist information, such as safebrowsing. You probably want
297 // to use Blacklist::GetBlacklistedIDs rather than this method.
298 bool IsExtensionBlacklisted(const std::string& id) const;
300 // Increment the count of how many times we prompted the user to acknowledge
301 // the given extension, and return the new count.
302 int IncrementAcknowledgePromptCount(const std::string& extension_id);
304 // Whether the user has acknowledged an external extension.
305 bool IsExternalExtensionAcknowledged(const std::string& extension_id);
306 void AcknowledgeExternalExtension(const std::string& extension_id);
308 // Whether the user has acknowledged a blacklisted extension.
309 bool IsBlacklistedExtensionAcknowledged(const std::string& extension_id);
310 void AcknowledgeBlacklistedExtension(const std::string& extension_id);
312 // Whether the external extension was installed during the first run
313 // of this profile.
314 bool IsExternalInstallFirstRun(const std::string& extension_id);
315 void SetExternalInstallFirstRun(const std::string& extension_id);
317 // Whether the user has been notified about extension with |extension_id|
318 // being wiped out.
319 bool HasWipeoutBeenAcknowledged(const std::string& extension_id);
320 void SetWipeoutAcknowledged(const std::string& extension_id, bool value);
322 // Whether the user has been notified about extension with |extension_id|
323 // taking over some aspect of the user's settings (homepage, startup pages,
324 // or search engine).
325 bool HasSettingsApiBubbleBeenAcknowledged(const std::string& extension_id);
326 void SetSettingsApiBubbleBeenAcknowledged(const std::string& extension_id,
327 bool value);
329 // Whether the user has been notified about extension with |extension_id|
330 // overriding the new tab page.
331 bool HasNtpOverriddenBubbleBeenAcknowledged(const std::string& extension_id);
332 void SetNtpOverriddenBubbleBeenAcknowledged(const std::string& extension_id,
333 bool value);
335 // Returns true if the extension notification code has already run for the
336 // first time for this profile. Currently we use this flag to mean that any
337 // extensions that would trigger notifications should get silently
338 // acknowledged. This is a fuse. Calling it the first time returns false.
339 // Subsequent calls return true. It's not possible through an API to ever
340 // reset it. Don't call it unless you mean it!
341 bool SetAlertSystemFirstRun();
343 // Checks if extensions are blacklisted by default, by policy.
344 // The ManagementPolicy::Provider methods also take this into account, and
345 // should be used instead when the extension ID is known.
346 bool ExtensionsBlacklistedByDefault() const;
348 // Returns the last value set via SetLastPingDay. If there isn't such a
349 // pref, the returned Time will return true for is_null().
350 base::Time LastPingDay(const std::string& extension_id) const;
352 // The time stored is based on the server's perspective of day start time, not
353 // the client's.
354 void SetLastPingDay(const std::string& extension_id, const base::Time& time);
356 // Similar to the 2 above, but for the extensions blacklist.
357 base::Time BlacklistLastPingDay() const;
358 void SetBlacklistLastPingDay(const base::Time& time);
360 // Similar to LastPingDay/SetLastPingDay, but for sending "days since active"
361 // ping.
362 base::Time LastActivePingDay(const std::string& extension_id);
363 void SetLastActivePingDay(const std::string& extension_id,
364 const base::Time& time);
366 // A bit we use for determining if we should send the "days since active"
367 // ping. A value of true means the item has been active (launched) since the
368 // last update check.
369 bool GetActiveBit(const std::string& extension_id);
370 void SetActiveBit(const std::string& extension_id, bool active);
372 // Returns the granted permission set for the extension with |extension_id|,
373 // and NULL if no preferences were found for |extension_id|.
374 // This passes ownership of the returned set to the caller.
375 PermissionSet* GetGrantedPermissions(const std::string& extension_id);
377 // Adds |permissions| to the granted permissions set for the extension with
378 // |extension_id|. The new granted permissions set will be the union of
379 // |permissions| and the already granted permissions.
380 void AddGrantedPermissions(const std::string& extension_id,
381 const PermissionSet* permissions);
383 // As above, but subtracts the given |permissions| from the granted set.
384 void RemoveGrantedPermissions(const std::string& extension_id,
385 const PermissionSet* permissions);
387 // Gets the active permission set for the specified extension. This may
388 // differ from the permissions in the manifest due to the optional
389 // permissions API. This passes ownership of the set to the caller.
390 PermissionSet* GetActivePermissions(const std::string& extension_id);
392 // Sets the active |permissions| for the extension with |extension_id|.
393 void SetActivePermissions(const std::string& extension_id,
394 const PermissionSet* permissions);
396 // Records whether or not this extension is currently running.
397 void SetExtensionRunning(const std::string& extension_id, bool is_running);
399 // Returns whether or not this extension is marked as running. This is used to
400 // restart apps across browser restarts.
401 bool IsExtensionRunning(const std::string& extension_id);
403 // Set/Get whether or not the app is active. Used to force a launch of apps
404 // that don't handle onRestarted() on a restart. We can only safely do that if
405 // the app was active when it was last running.
406 void SetIsActive(const std::string& extension_id, bool is_active);
407 bool IsActive(const std::string& extension_id);
409 // Returns true if the user enabled this extension to be loaded in incognito
410 // mode.
412 // IMPORTANT: you probably want to use extensions::util::IsIncognitoEnabled
413 // instead of this method.
414 bool IsIncognitoEnabled(const std::string& extension_id) const;
415 void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled);
417 // Returns true if the user has chosen to allow this extension to inject
418 // scripts into pages with file URLs.
420 // IMPORTANT: you probably want to use extensions::util::AllowFileAccess
421 // instead of this method.
422 bool AllowFileAccess(const std::string& extension_id) const;
423 void SetAllowFileAccess(const std::string& extension_id, bool allow);
424 bool HasAllowFileAccessSetting(const std::string& extension_id) const;
426 // Saves ExtensionInfo for each installed extension with the path to the
427 // version directory and the location. Blacklisted extensions won't be saved
428 // and neither will external extensions the user has explicitly uninstalled.
429 // Caller takes ownership of returned structure.
430 scoped_ptr<ExtensionsInfo> GetInstalledExtensionsInfo() const;
432 // Same as above, but only includes external extensions the user has
433 // explicitly uninstalled.
434 scoped_ptr<ExtensionsInfo> GetUninstalledExtensionsInfo() const;
436 // Returns the ExtensionInfo from the prefs for the given extension. If the
437 // extension is not present, NULL is returned.
438 scoped_ptr<ExtensionInfo> GetInstalledExtensionInfo(
439 const std::string& extension_id) const;
441 // We've downloaded an updated .crx file for the extension, but are waiting
442 // to install it.
443 void SetDelayedInstallInfo(const Extension* extension,
444 Extension::State initial_state,
445 bool blacklisted_for_malware,
446 bool is_ephemeral,
447 DelayReason delay_reason,
448 const syncer::StringOrdinal& page_ordinal,
449 const std::string& install_parameter);
451 // Removes any delayed install information we have for the given
452 // |extension_id|. Returns true if there was info to remove; false otherwise.
453 bool RemoveDelayedInstallInfo(const std::string& extension_id);
455 // Update the prefs to finish the update for an extension.
456 bool FinishDelayedInstallInfo(const std::string& extension_id);
458 // Returns the ExtensionInfo from the prefs for delayed install information
459 // for |extension_id|, if we have any. Otherwise returns NULL.
460 scoped_ptr<ExtensionInfo> GetDelayedInstallInfo(
461 const std::string& extension_id) const;
463 DelayReason GetDelayedInstallReason(const std::string& extension_id) const;
465 // Returns information about all the extensions that have delayed install
466 // information.
467 scoped_ptr<ExtensionsInfo> GetAllDelayedInstallInfo() const;
469 // Returns information about evicted ephemeral apps.
470 scoped_ptr<ExtensionsInfo> GetEvictedEphemeralAppsInfo() const;
472 // Return information about a specific evicted ephemeral app. Can return NULL
473 // if no such evicted app exists or is currently installed.
474 scoped_ptr<ExtensionInfo> GetEvictedEphemeralAppInfo(
475 const std::string& extension_id) const;
477 // Permanently remove the preferences for an evicted ephemeral app.
478 void RemoveEvictedEphemeralApp(const std::string& extension_id);
480 // Returns true if the extension is an ephemeral app.
481 bool IsEphemeralApp(const std::string& extension_id) const;
483 // Promotes an ephemeral app to a regular installed app.
484 void OnEphemeralAppPromoted(const std::string& extension_id);
486 // Returns true if the user repositioned the app on the app launcher via drag
487 // and drop.
488 bool WasAppDraggedByUser(const std::string& extension_id);
490 // Sets a flag indicating that the user repositioned the app on the app
491 // launcher by drag and dropping it.
492 void SetAppDraggedByUser(const std::string& extension_id);
494 // Returns true if there is an extension which controls the preference value
495 // for |pref_key| *and* it is specific to incognito mode.
496 bool HasIncognitoPrefValue(const std::string& pref_key);
498 // Returns the creation flags mask for the extension.
499 int GetCreationFlags(const std::string& extension_id) const;
501 // Returns the creation flags mask for a delayed install extension.
502 int GetDelayedInstallCreationFlags(const std::string& extension_id) const;
504 // Returns true if the extension was installed from the Chrome Web Store.
505 bool IsFromWebStore(const std::string& extension_id) const;
507 // Returns true if the extension was installed from an App generated from a
508 // bookmark.
509 bool IsFromBookmark(const std::string& extension_id) const;
511 // Returns true if the extension was installed as a default app.
512 bool WasInstalledByDefault(const std::string& extension_id) const;
514 // Returns true if the extension was installed as an oem app.
515 bool WasInstalledByOem(const std::string& extension_id) const;
517 // Helper method to acquire the installation time of an extension.
518 // Returns base::Time() if the installation time could not be parsed or
519 // found.
520 base::Time GetInstallTime(const std::string& extension_id) const;
522 // Gets/sets the last launch time of an extension.
523 base::Time GetLastLaunchTime(const std::string& extension_id) const;
524 void SetLastLaunchTime(const std::string& extension_id,
525 const base::Time& time);
527 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
529 bool extensions_disabled() const { return extensions_disabled_; }
531 // The underlying PrefService.
532 PrefService* pref_service() const { return prefs_; }
534 // The underlying AppSorting.
535 AppSorting* app_sorting() const { return app_sorting_.get(); }
537 // Describes the URLs that are able to install extensions. See
538 // pref_names::kAllowedInstallSites for more information.
539 URLPatternSet GetAllowedInstallSites();
541 // Schedules garbage collection of an extension's on-disk data on the next
542 // start of this ExtensionService. Applies only to extensions with isolated
543 // storage.
544 void SetNeedsStorageGarbageCollection(bool value);
545 bool NeedsStorageGarbageCollection();
547 // Used by AppWindowGeometryCache to persist its cache. These methods
548 // should not be called directly.
549 const base::DictionaryValue* GetGeometryCache(
550 const std::string& extension_id) const;
551 void SetGeometryCache(const std::string& extension_id,
552 scoped_ptr<base::DictionaryValue> cache);
554 // Used for verification of installed extension ids. For the Set method, pass
555 // null to remove the preference.
556 const base::DictionaryValue* GetInstallSignature();
557 void SetInstallSignature(const base::DictionaryValue* signature);
559 // The installation parameter associated with the extension.
560 std::string GetInstallParam(const std::string& extension_id) const;
561 void SetInstallParam(const std::string& extension_id,
562 const std::string& install_parameter);
564 // Gets/sets the next threshold for displaying a notification if an extension
565 // or app consumes excessive disk space. Returns 0 if the initial threshold
566 // has not yet been reached.
567 int64 GetNextStorageThreshold(const std::string& extension_id) const;
568 void SetNextStorageThreshold(const std::string& extension_id,
569 int64 next_threshold);
571 // Gets/sets whether notifications should be shown if an extension or app
572 // consumes too much disk space.
573 bool IsStorageNotificationEnabled(const std::string& extension_id) const;
574 void SetStorageNotificationEnabled(const std::string& extension_id,
575 bool enable_notifications);
577 private:
578 friend class ExtensionPrefsBlacklistedExtensions; // Unit test.
579 friend class ExtensionPrefsUninstallExtension; // Unit test.
581 enum DisableReasonChange {
582 DISABLE_REASON_ADD,
583 DISABLE_REASON_REMOVE,
584 DISABLE_REASON_CLEAR
587 // See the Create methods.
588 ExtensionPrefs(PrefService* prefs,
589 const base::FilePath& root_dir,
590 ExtensionPrefValueMap* extension_pref_value_map,
591 scoped_ptr<AppSorting> app_sorting,
592 scoped_ptr<TimeProvider> time_provider,
593 bool extensions_disabled,
594 const std::vector<ExtensionPrefsObserver*>& early_observers);
596 // Converts absolute paths in the pref to paths relative to the
597 // install_directory_.
598 void MakePathsRelative();
600 // Converts internal relative paths to be absolute. Used for export to
601 // consumers who expect full paths.
602 void MakePathsAbsolute(base::DictionaryValue* dict);
604 // Helper function used by GetInstalledExtensionInfo() and
605 // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided
606 // |extension| dictionary.
607 scoped_ptr<ExtensionInfo> GetInstalledInfoHelper(
608 const std::string& extension_id,
609 const base::DictionaryValue* extension) const;
611 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a
612 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns.
613 bool ReadPrefAsURLPatternSet(const std::string& extension_id,
614 const std::string& pref_key,
615 URLPatternSet* result,
616 int valid_schemes);
618 // Converts |new_value| to a list of strings and sets the |pref_key| pref
619 // belonging to |extension_id|.
620 void SetExtensionPrefURLPatternSet(const std::string& extension_id,
621 const std::string& pref_key,
622 const URLPatternSet& new_value);
624 // Read the boolean preference entry and return true if the preference exists
625 // and the preference's value is true; false otherwise.
626 bool ReadPrefAsBooleanAndReturn(const std::string& extension_id,
627 const std::string& key) const;
629 // Interprets |pref_key| in |extension_id|'s preferences as an
630 // PermissionSet, and passes ownership of the set to the caller.
631 PermissionSet* ReadPrefAsPermissionSet(const std::string& extension_id,
632 const std::string& pref_key);
634 // Converts the |new_value| to its value and sets the |pref_key| pref
635 // belonging to |extension_id|.
636 void SetExtensionPrefPermissionSet(const std::string& extension_id,
637 const std::string& pref_key,
638 const PermissionSet* new_value);
640 // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it
641 // doesn't exist.
642 const base::DictionaryValue* GetExtensionPref(const std::string& id) const;
644 // Modifies the extensions disable reasons to add a new reason, remove an
645 // existing reason, or clear all reasons. Notifies observers if the set of
646 // DisableReasons has changed.
647 // If |change| is DISABLE_REASON_CLEAR, then |reason| is ignored.
648 void ModifyDisableReason(const std::string& extension_id,
649 Extension::DisableReason reason,
650 DisableReasonChange change);
652 // Fix missing preference entries in the extensions that are were introduced
653 // in a later Chrome version.
654 void FixMissingPrefs(const ExtensionIdList& extension_ids);
656 // Installs the persistent extension preferences into |prefs_|'s extension
657 // pref store. Does nothing if extensions_disabled_ is true.
658 void InitPrefStore();
660 // Migrates the permissions data in the pref store.
661 void MigratePermissions(const ExtensionIdList& extension_ids);
663 // Migrates the disable reasons from a single enum to a bit mask.
664 void MigrateDisableReasons(const ExtensionIdList& extension_ids);
666 // Checks whether there is a state pref for the extension and if so, whether
667 // it matches |check_state|.
668 bool DoesExtensionHaveState(const std::string& id,
669 Extension::State check_state) const;
671 // Reads the list of strings for |pref| from user prefs into
672 // |id_container_out|. Returns false if the pref wasn't found in the user
673 // pref store.
674 template <class ExtensionIdContainer>
675 bool GetUserExtensionPrefIntoContainer(
676 const char* pref,
677 ExtensionIdContainer* id_container_out);
679 // Writes the list of strings contained in |strings| to |pref| in prefs.
680 template <class ExtensionIdContainer>
681 void SetExtensionPrefFromContainer(const char* pref,
682 const ExtensionIdContainer& strings);
684 // Helper function to populate |extension_dict| with the values needed
685 // by a newly installed extension. Work is broken up between this
686 // function and FinishExtensionInfoPrefs() to accomodate delayed
687 // installations.
688 void PopulateExtensionInfoPrefs(const Extension* extension,
689 const base::Time install_time,
690 Extension::State initial_state,
691 bool blacklisted_for_malware,
692 bool is_ephemeral,
693 const std::string& install_parameter,
694 base::DictionaryValue* extension_dict);
696 void InitExtensionControlledPrefs(ExtensionPrefValueMap* value_map);
698 // Helper function to complete initialization of the values in
699 // |extension_dict| for an extension install. Also see
700 // PopulateExtensionInfoPrefs().
701 void FinishExtensionInfoPrefs(
702 const std::string& extension_id,
703 const base::Time install_time,
704 bool needs_sort_ordinal,
705 const syncer::StringOrdinal& suggested_page_ordinal,
706 base::DictionaryValue* extension_dict);
708 // The pref service specific to this set of extension prefs. Owned by the
709 // BrowserContext.
710 PrefService* prefs_;
712 // Base extensions install directory.
713 base::FilePath install_directory_;
715 // Weak pointer, owned by BrowserContext.
716 ExtensionPrefValueMap* extension_pref_value_map_;
718 // Contains all the logic for handling the order for various extension
719 // properties.
720 scoped_ptr<AppSorting> app_sorting_;
722 scoped_ptr<TimeProvider> time_provider_;
724 bool extensions_disabled_;
726 ObserverList<ExtensionPrefsObserver> observer_list_;
728 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
731 } // namespace extensions
733 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_