extension_prefs.h revision b2df76ea8fec9e32f6f3718986dba0d95315b29c
1// Copyright (c) 2012 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.
4
5#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_
7
8#include <set>
9#include <string>
10#include <vector>
11
12#include "base/memory/linked_ptr.h"
13#include "base/memory/scoped_ptr.h"
14#include "base/time.h"
15#include "base/values.h"
16#include "chrome/browser/extensions/api/content_settings/content_settings_store.h"
17#include "chrome/browser/extensions/extension_prefs_scope.h"
18#include "chrome/browser/extensions/extension_scoped_prefs.h"
19#include "chrome/browser/prefs/scoped_user_pref_update.h"
20#include "chrome/common/extensions/extension.h"
21#include "extensions/common/url_pattern_set.h"
22#include "sync/api/string_ordinal.h"
23
24class ExtensionPrefValueMap;
25class ExtensionSorting;
26class PrefService;
27
28namespace user_prefs {
29class PrefRegistrySyncable;
30}
31
32namespace extensions {
33class ExtensionPrefsUninstallExtension;
34class URLPatternSet;
35
36// Class for managing global and per-extension preferences.
37//
38// This class distinguishes the following kinds of preferences:
39// - global preferences:
40//       internal state for the extension system in general, not associated
41//       with an individual extension, such as lastUpdateTime.
42// - per-extension preferences:
43//       meta-preferences describing properties of the extension like
44//       installation time, whether the extension is enabled, etc.
45// - extension controlled preferences:
46//       browser preferences that an extension controls. For example, an
47//       extension could use the proxy API to specify the browser's proxy
48//       preference. Extension-controlled preferences are stored in
49//       PrefValueStore::extension_prefs(), which this class populates and
50//       maintains as the underlying extensions change.
51class ExtensionPrefs : public ContentSettingsStore::Observer,
52                       public ExtensionScopedPrefs {
53 public:
54  // Key name for a preference that keeps track of per-extension settings. This
55  // is a dictionary object read from the Preferences file, keyed off of
56  // extension ids.
57  static const char kExtensionsPref[];
58
59  typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo;
60
61  // Vector containing identifiers for preferences.
62  typedef std::set<std::string> PrefKeySet;
63
64  // This enum is used for the launch type the user wants to use for an
65  // application.
66  // Do not remove items or re-order this enum as it is used in preferences
67  // and histograms.
68  enum LaunchType {
69    LAUNCH_PINNED,
70    LAUNCH_REGULAR,
71    LAUNCH_FULLSCREEN,
72    LAUNCH_WINDOW,
73
74    // Launch an app in the in the way a click on the NTP would,
75    // if no user pref were set.  Update this constant to change
76    // the default for the NTP and chrome.management.launchApp().
77    LAUNCH_DEFAULT = LAUNCH_REGULAR
78  };
79
80  // Creates base::Time classes. The default implementation is just to return
81  // the current time, but tests can inject alternative implementations.
82  class TimeProvider {
83   public:
84    TimeProvider();
85
86    virtual ~TimeProvider();
87
88    // By default, returns the current time (base::Time::Now()).
89    virtual base::Time GetCurrentTime() const;
90
91   private:
92    DISALLOW_COPY_AND_ASSIGN(TimeProvider);
93  };
94
95  // A wrapper around a ScopedUserPrefUpdate, which allows us to access the
96  // entry of a particular key for an extension. Use this if you need a mutable
97  // record of a dictionary or list in the current settings. Otherwise, prefer
98  // ReadPrefAsT() and UpdateExtensionPref() methods.
99  template <typename T, base::Value::Type type_enum_value>
100  class ScopedUpdate {
101   public:
102    ScopedUpdate(ExtensionPrefs* prefs,
103                 const std::string& extension_id,
104                 const std::string& key);
105    virtual ~ScopedUpdate();
106
107    // Returns a mutable value for the key (ownership remains with the prefs),
108    // if one exists. Otherwise, returns NULL.
109    virtual T* Get();
110
111    // Creates and returns a mutable value for the key (the prefs own the new
112    // value), if one does not already exist. Otherwise, returns the current
113    // value.
114    virtual T* Create();
115
116   private:
117    DISALLOW_COPY_AND_ASSIGN(ScopedUpdate);
118
119    DictionaryPrefUpdate update_;
120    const std::string extension_id_;
121    const std::string key_;
122  };
123  typedef ScopedUpdate<base::DictionaryValue, base::Value::TYPE_DICTIONARY>
124      ScopedDictionaryUpdate;
125  typedef ScopedUpdate<base::ListValue, base::Value::TYPE_LIST>
126      ScopedListUpdate;
127
128  // Creates and initializes an ExtensionPrefs object.
129  // Does not take ownership of |prefs| and |extension_pref_value_map|.
130  static scoped_ptr<ExtensionPrefs> Create(
131      PrefService* prefs,
132      const base::FilePath& root_dir,
133      ExtensionPrefValueMap* extension_pref_value_map,
134      bool extensions_disabled);
135
136  // A version of Create which allows injection of a custom base::Time provider.
137  // Use this as needed for testing.
138  static scoped_ptr<ExtensionPrefs> Create(
139      PrefService* prefs,
140      const base::FilePath& root_dir,
141      ExtensionPrefValueMap* extension_pref_value_map,
142      bool extensions_disabled,
143      scoped_ptr<TimeProvider> time_provider);
144
145  virtual ~ExtensionPrefs();
146
147  // Returns all installed extensions from extension preferences provided by
148  // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs
149  // access to the extension ID list before the ExtensionService is initialized.
150  static ExtensionIdList GetExtensionsFrom(const PrefService* pref_service);
151
152  // Returns true if the specified external extension was uninstalled by the
153  // user.
154  bool IsExternalExtensionUninstalled(const std::string& id) const;
155
156  // Checks whether |extension_id| is disabled. If there's no state pref for
157  // the extension, this will return false. Generally you should use
158  // ExtensionService::IsExtensionEnabled instead.
159  bool IsExtensionDisabled(const std::string& id) const;
160
161  // Get/Set the order that the browser actions appear in the toolbar.
162  ExtensionIdList GetToolbarOrder();
163  void SetToolbarOrder(const ExtensionIdList& extension_ids);
164
165  // Called when an extension is installed, so that prefs get created.
166  // If |page_ordinal| is an invalid ordinal, then a page will be found
167  // for the App.
168  void OnExtensionInstalled(const Extension* extension,
169                            Extension::State initial_state,
170                            const syncer::StringOrdinal& page_ordinal);
171
172  // Called when an extension is uninstalled, so that prefs get cleaned up.
173  void OnExtensionUninstalled(const std::string& extension_id,
174                              const Manifest::Location& location,
175                              bool external_uninstall);
176
177  // Called to change the extension's state when it is enabled/disabled.
178  void SetExtensionState(const std::string& extension_id, Extension::State);
179
180  // Populates |out| with the ids of all installed extensions.
181  void GetExtensions(ExtensionIdList* out);
182
183  // ExtensionScopedPrefs methods:
184  virtual void UpdateExtensionPref(const std::string& id,
185                                   const std::string& key,
186                                   base::Value* value) OVERRIDE;
187
188  virtual void DeleteExtensionPrefs(const std::string& id) OVERRIDE;
189
190  virtual bool ReadPrefAsBoolean(const std::string& extension_id,
191                                 const std::string& pref_key,
192                                 bool* out_value) const OVERRIDE;
193
194  virtual bool ReadPrefAsInteger(const std::string& extension_id,
195                                 const std::string& pref_key,
196                                 int* out_value) const OVERRIDE;
197
198  virtual bool ReadPrefAsString(const std::string& extension_id,
199                                const std::string& pref_key,
200                                std::string* out_value) const OVERRIDE;
201
202  virtual bool ReadPrefAsList(const std::string& extension_id,
203                              const std::string& pref_key,
204                              const base::ListValue** out_value) const OVERRIDE;
205
206  virtual bool ReadPrefAsDictionary(
207      const std::string& extension_id,
208      const std::string& pref_key,
209      const base::DictionaryValue** out_value) const OVERRIDE;
210
211  // Did the extension ask to escalate its permission during an upgrade?
212  bool DidExtensionEscalatePermissions(const std::string& id);
213
214  // If |did_escalate| is true, the preferences for |extension| will be set to
215  // require the install warning when the user tries to enable.
216  void SetDidExtensionEscalatePermissions(
217      const Extension* extension,
218      bool did_escalate);
219
220  // Getter and setters for disabled reason.
221  int GetDisableReasons(const std::string& extension_id);
222  void AddDisableReason(const std::string& extension_id,
223                        Extension::DisableReason disable_reason);
224  void RemoveDisableReason(const std::string& extension_id,
225                           Extension::DisableReason disable_reason);
226  void ClearDisableReasons(const std::string& extension_id);
227
228  // Gets the set of extensions that have been blacklisted in prefs.
229  std::set<std::string> GetBlacklistedExtensions();
230
231  // Sets whether the extension with |id| is blacklisted.
232  void SetExtensionBlacklisted(const std::string& extension_id,
233                               bool is_blacklisted);
234
235  // Returns the version string for the currently installed extension, or
236  // the empty string if not found.
237  std::string GetVersionString(const std::string& extension_id);
238
239  // Re-writes the extension manifest into the prefs.
240  // Called to change the extension's manifest when it's re-localized.
241  void UpdateManifest(const Extension* extension);
242
243  // Returns extension path based on extension ID, or empty FilePath on error.
244  base::FilePath GetExtensionPath(const std::string& extension_id);
245
246  // Returns base extensions install directory.
247  const base::FilePath& install_directory() const { return install_directory_; }
248
249  // Returns whether the extension with |id| has its blacklist bit set.
250  //
251  // WARNING: this only checks the extension's entry in prefs, so by definition
252  // can only check extensions that prefs knows about. There may be other
253  // sources of blacklist information, such as safebrowsing. You probably want
254  // to use Blacklist::GetBlacklistedIDs rather than this method.
255  bool IsExtensionBlacklisted(const std::string& id) const;
256
257  // Increment the count of how many times we prompted the user to acknowledge
258  // the given extension, and return the new count.
259  int IncrementAcknowledgePromptCount(const std::string& extension_id);
260
261  // Whether the user has acknowledged an external extension.
262  bool IsExternalExtensionAcknowledged(const std::string& extension_id);
263  void AcknowledgeExternalExtension(const std::string& extension_id);
264
265  // Whether the user has acknowledged a blacklisted extension.
266  bool IsBlacklistedExtensionAcknowledged(const std::string& extension_id);
267  void AcknowledgeBlacklistedExtension(const std::string& extension_id);
268
269  // Whether the external extension was installed during the first run
270  // of this profile.
271  bool IsExternalInstallFirstRun(const std::string& extension_id);
272  void SetExternalInstallFirstRun(const std::string& extension_id);
273
274  // Returns true if the extension notification code has already run for the
275  // first time for this profile. Currently we use this flag to mean that any
276  // extensions that would trigger notifications should get silently
277  // acknowledged. This is a fuse. Calling it the first time returns false.
278  // Subsequent calls return true. It's not possible through an API to ever
279  // reset it. Don't call it unless you mean it!
280  bool SetAlertSystemFirstRun();
281
282  // Checks if extensions are blacklisted by default, by policy.
283  // The ManagementPolicy::Provider methods also take this into account, and
284  // should be used instead when the extension ID is known.
285  bool ExtensionsBlacklistedByDefault() const;
286
287  // Returns the last value set via SetLastPingDay. If there isn't such a
288  // pref, the returned Time will return true for is_null().
289  base::Time LastPingDay(const std::string& extension_id) const;
290
291  // The time stored is based on the server's perspective of day start time, not
292  // the client's.
293  void SetLastPingDay(const std::string& extension_id, const base::Time& time);
294
295  // Similar to the 2 above, but for the extensions blacklist.
296  base::Time BlacklistLastPingDay() const;
297  void SetBlacklistLastPingDay(const base::Time& time);
298
299  // Similar to LastPingDay/SetLastPingDay, but for sending "days since active"
300  // ping.
301  base::Time LastActivePingDay(const std::string& extension_id);
302  void SetLastActivePingDay(const std::string& extension_id,
303                            const base::Time& time);
304
305  // A bit we use for determining if we should send the "days since active"
306  // ping. A value of true means the item has been active (launched) since the
307  // last update check.
308  bool GetActiveBit(const std::string& extension_id);
309  void SetActiveBit(const std::string& extension_id, bool active);
310
311  // Returns the granted permission set for the extension with |extension_id|,
312  // and NULL if no preferences were found for |extension_id|.
313  // This passes ownership of the returned set to the caller.
314  PermissionSet* GetGrantedPermissions(const std::string& extension_id);
315
316  // Adds |permissions| to the granted permissions set for the extension with
317  // |extension_id|. The new granted permissions set will be the union of
318  // |permissions| and the already granted permissions.
319  void AddGrantedPermissions(const std::string& extension_id,
320                             const PermissionSet* permissions);
321
322  // As above, but subtracts the given |permissions| from the granted set.
323  void RemoveGrantedPermissions(const std::string& extension_id,
324                                const PermissionSet* permissions);
325
326  // Gets the active permission set for the specified extension. This may
327  // differ from the permissions in the manifest due to the optional
328  // permissions API. This passes ownership of the set to the caller.
329  PermissionSet* GetActivePermissions(const std::string& extension_id);
330
331  // Sets the active |permissions| for the extension with |extension_id|.
332  void SetActivePermissions(const std::string& extension_id,
333                            const PermissionSet* permissions);
334
335  // Returns true if registered events are from this version of Chrome. Else,
336  // clear them, and return false.
337  bool CheckRegisteredEventsUpToDate();
338
339  // Returns the list of events that the given extension has registered for.
340  std::set<std::string> GetRegisteredEvents(const std::string& extension_id);
341  void SetRegisteredEvents(const std::string& extension_id,
342                           const std::set<std::string>& events);
343
344  // Adds a filter to an event.
345  void AddFilterToEvent(const std::string& event_name,
346                        const std::string& extension_id,
347                        const base::DictionaryValue* filter);
348
349  // Removes a filter from an event.
350  void RemoveFilterFromEvent(const std::string& event_name,
351                             const std::string& extension_id,
352                             const base::DictionaryValue* filter);
353
354  // Returns the dictionary of event filters that the given extension has
355  // registered.
356  const base::DictionaryValue* GetFilteredEvents(
357      const std::string& extension_id) const;
358
359  // Records whether or not this extension is currently running.
360  void SetExtensionRunning(const std::string& extension_id, bool is_running);
361
362  // Returns whether or not this extension is marked as running. This is used to
363  // restart apps across browser restarts.
364  bool IsExtensionRunning(const std::string& extension_id);
365
366  // Returns true if the user enabled this extension to be loaded in incognito
367  // mode.
368  bool IsIncognitoEnabled(const std::string& extension_id);
369  void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled);
370
371  // Returns true if the user has chosen to allow this extension to inject
372  // scripts into pages with file URLs.
373  bool AllowFileAccess(const std::string& extension_id);
374  void SetAllowFileAccess(const std::string& extension_id, bool allow);
375  bool HasAllowFileAccessSetting(const std::string& extension_id) const;
376
377  // Get the launch type preference.  If no preference is set, return
378  // |default_pref_value|.
379  LaunchType GetLaunchType(const Extension* extension,
380                           LaunchType default_pref_value);
381
382  void SetLaunchType(const std::string& extension_id, LaunchType launch_type);
383
384  // Find the right launch container based on the launch type.
385  // If |extension|'s prefs do not have a launch type set, then
386  // use |default_pref_value|.
387  extension_misc::LaunchContainer GetLaunchContainer(
388      const Extension* extension,
389      LaunchType default_pref_value);
390
391  // Saves ExtensionInfo for each installed extension with the path to the
392  // version directory and the location. Blacklisted extensions won't be saved
393  // and neither will external extensions the user has explicitly uninstalled.
394  // Caller takes ownership of returned structure.
395  scoped_ptr<ExtensionsInfo> GetInstalledExtensionsInfo() const;
396
397  // Returns the ExtensionInfo from the prefs for the given extension. If the
398  // extension is not present, NULL is returned.
399  scoped_ptr<ExtensionInfo> GetInstalledExtensionInfo(
400      const std::string& extension_id) const;
401
402  // We've downloaded an updated .crx file for the extension, but are waiting
403  // for idle time to install it.
404  void SetDelayedInstallInfo(const Extension* extension,
405                             Extension::State initial_state,
406                             const syncer::StringOrdinal& page_ordinal);
407
408  // Removes any delayed install information we have for the given
409  // |extension_id|. Returns true if there was info to remove; false otherwise.
410  bool RemoveDelayedInstallInfo(const std::string& extension_id);
411
412  // Update the prefs to finish the update for an extension.
413  bool FinishDelayedInstallInfo(const std::string& extension_id);
414
415  // Returns the ExtensionInfo from the prefs for delayed install information
416  // for |extension_id|, if we have any. Otherwise returns NULL.
417  scoped_ptr<ExtensionInfo> GetDelayedInstallInfo(
418      const std::string& extension_id) const;
419
420  // Returns information about all the extensions that have delayed install
421  // information.
422  scoped_ptr<ExtensionsInfo> GetAllDelayedInstallInfo() const;
423
424  // We allow the web store to set a string containing login information when a
425  // purchase is made, so that when a user logs into sync with a different
426  // account we can recognize the situation. The Get function returns true if
427  // there was previously stored data (placing it in |result|), or false
428  // otherwise. The Set will overwrite any previous login.
429  bool GetWebStoreLogin(std::string* result);
430  void SetWebStoreLogin(const std::string& login);
431
432  // Returns true if the user repositioned the app on the app launcher via drag
433  // and drop.
434  bool WasAppDraggedByUser(const std::string& extension_id);
435
436  // Sets a flag indicating that the user repositioned the app on the app
437  // launcher by drag and dropping it.
438  void SetAppDraggedByUser(const std::string& extension_id);
439
440  // The extension's update URL data.  If not empty, the ExtensionUpdater
441  // will append a ap= parameter to the URL when checking if a new version
442  // of the extension is available.
443  void SetUpdateUrlData(const std::string& extension_id,
444                        const std::string& data);
445  std::string GetUpdateUrlData(const std::string& extension_id);
446
447  // Sets a preference value that is controlled by the extension. In other
448  // words, this is not a pref value *about* the extension but something
449  // global the extension wants to override.
450  // Takes ownership of |value|.
451  void SetExtensionControlledPref(const std::string& extension_id,
452                                  const std::string& pref_key,
453                                  ExtensionPrefsScope scope,
454                                  base::Value* value);
455
456  void RemoveExtensionControlledPref(const std::string& extension_id,
457                                     const std::string& pref_key,
458                                     ExtensionPrefsScope scope);
459
460  // Returns true if currently no extension with higher precedence controls the
461  // preference.
462  bool CanExtensionControlPref(const std::string& extension_id,
463                               const std::string& pref_key,
464                               bool incognito);
465
466  // Returns true if extension |extension_id| currently controls the
467  // preference. If |from_incognito| is not NULL, looks at incognito preferences
468  // first, and |from_incognito| is set to true if the effective pref value is
469  // coming from the incognito preferences, false if it is coming from the
470  // normal ones.
471  bool DoesExtensionControlPref(const std::string& extension_id,
472                                const std::string& pref_key,
473                                bool* from_incognito);
474
475  // Returns true if there is an extension which controls the preference value
476  //  for |pref_key| *and* it is specific to incognito mode.
477  bool HasIncognitoPrefValue(const std::string& pref_key);
478
479  // Clears incognito session-only content settings for all extensions.
480  void ClearIncognitoSessionOnlyContentSettings();
481
482  // Returns the creation flags mask for the extension.
483  int GetCreationFlags(const std::string& extension_id) const;
484
485  // Returns true if the extension was installed from the Chrome Web Store.
486  bool IsFromWebStore(const std::string& extension_id) const;
487
488  // Returns true if the extension was installed from an App generated from a
489  // bookmark.
490  bool IsFromBookmark(const std::string& extension_id) const;
491
492  // Returns true if the extension was installed as a default app.
493  bool WasInstalledByDefault(const std::string& extension_id) const;
494
495  // Helper method to acquire the installation time of an extension.
496  // Returns base::Time() if the installation time could not be parsed or
497  // found.
498  base::Time GetInstallTime(const std::string& extension_id) const;
499
500  static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry);
501
502  ContentSettingsStore* content_settings_store() {
503    return content_settings_store_.get();
504  }
505
506  // The underlying PrefService.
507  PrefService* pref_service() const { return prefs_; }
508
509  // The underlying ExtensionSorting.
510  ExtensionSorting* extension_sorting() const {
511    return extension_sorting_.get();
512  }
513
514  // Describes the URLs that are able to install extensions. See
515  // prefs::kExtensionAllowedInstallSites for more information.
516  URLPatternSet GetAllowedInstallSites();
517
518  // Schedules garbage collection of an extension's on-disk data on the next
519  // start of this ExtensionService. Applies only to extensions with isolated
520  // storage.
521  void SetNeedsStorageGarbageCollection(bool value);
522  bool NeedsStorageGarbageCollection();
523
524  // Used by ShellWindowGeometryCache to persist its cache. These methods
525  // should not be called directly.
526  const base::DictionaryValue* GetGeometryCache(
527        const std::string& extension_id) const;
528  void SetGeometryCache(const std::string& extension_id,
529                        scoped_ptr<base::DictionaryValue> cache);
530
531  // The path of the directory containing the last file chosen by the user in
532  // response to a chrome.fileSystem.chooseEntry() call for this extension.
533  bool GetLastChooseEntryDirectory(const std::string& extension_id,
534                                   base::FilePath* result) const;
535  void SetLastChooseEntryDirectory(const std::string& extension_id,
536                                   const base::FilePath& value);
537
538 private:
539  friend class ExtensionPrefsBlacklistedExtensions;  // Unit test.
540  friend class ExtensionPrefsUninstallExtension;     // Unit test.
541
542  // See the Create methods.
543  ExtensionPrefs(PrefService* prefs,
544                 const base::FilePath& root_dir,
545                 ExtensionPrefValueMap* extension_pref_value_map,
546                 scoped_ptr<TimeProvider> time_provider);
547
548  // If |extensions_disabled| is true, extension controlled preferences and
549  // content settings do not become effective.
550  void Init(bool extensions_disabled);
551
552  // extensions::ContentSettingsStore::Observer methods:
553  virtual void OnContentSettingChanged(const std::string& extension_id,
554                                       bool incognito) OVERRIDE;
555
556  // Converts absolute paths in the pref to paths relative to the
557  // install_directory_.
558  void MakePathsRelative();
559
560  // Converts internal relative paths to be absolute. Used for export to
561  // consumers who expect full paths.
562  void MakePathsAbsolute(base::DictionaryValue* dict);
563
564  // Helper function used by GetInstalledExtensionInfo() and
565  // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided
566  // |extension| dictionary.
567  scoped_ptr<ExtensionInfo> GetInstalledInfoHelper(
568      const std::string& extension_id,
569      const base::DictionaryValue* extension) const;
570
571  // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a
572  // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns.
573  bool ReadPrefAsURLPatternSet(const std::string& extension_id,
574                               const std::string& pref_key,
575                               URLPatternSet* result,
576                               int valid_schemes);
577
578  // Converts |new_value| to a list of strings and sets the |pref_key| pref
579  // belonging to |extension_id|.
580  void SetExtensionPrefURLPatternSet(const std::string& extension_id,
581                                     const std::string& pref_key,
582                                     const URLPatternSet& new_value);
583
584  // Read the boolean preference entry and return true if the preference exists
585  // and the preference's value is true; false otherwise.
586  bool ReadPrefAsBooleanAndReturn(const std::string& extension_id,
587                                  const std::string& key) const;
588
589  // Interprets |pref_key| in |extension_id|'s preferences as an
590  // PermissionSet, and passes ownership of the set to the caller.
591  PermissionSet* ReadPrefAsPermissionSet(const std::string& extension_id,
592                                         const std::string& pref_key);
593
594  // Converts the |new_value| to its value and sets the |pref_key| pref
595  // belonging to |extension_id|.
596  void SetExtensionPrefPermissionSet(const std::string& extension_id,
597                                     const std::string& pref_key,
598                                     const PermissionSet* new_value);
599
600  // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it
601  // doesn't exist.
602  const base::DictionaryValue* GetExtensionPref(const std::string& id) const;
603
604  // Loads the preferences controlled by the specified extension from their
605  // dictionary and sets them in the |pref_value_map_|.
606  void LoadExtensionControlledPrefs(const std::string& id,
607                                    ExtensionPrefsScope scope);
608
609  // Fix missing preference entries in the extensions that are were introduced
610  // in a later Chrome version.
611  void FixMissingPrefs(const ExtensionIdList& extension_ids);
612
613  // Installs the persistent extension preferences into |prefs_|'s extension
614  // pref store. Does nothing if |extensions_disabled| is true.
615  void InitPrefStore(bool extensions_disabled);
616
617  // Migrates the permissions data in the pref store.
618  void MigratePermissions(const ExtensionIdList& extension_ids);
619
620  // Migrates the disable reasons from a single enum to a bit mask.
621  void MigrateDisableReasons(const ExtensionIdList& extension_ids);
622
623  // Checks whether there is a state pref for the extension and if so, whether
624  // it matches |check_state|.
625  bool DoesExtensionHaveState(const std::string& id,
626                              Extension::State check_state) const;
627
628  // Helper function to Get/Set array of strings from/to prefs.
629  ExtensionIdList GetExtensionPrefAsVector(const char* pref);
630  void SetExtensionPrefFromVector(const char* pref,
631                                  const ExtensionIdList& extension_ids);
632
633  // Helper function to populate |extension_dict| with the values needed
634  // by a newly installed extension. Work is broken up between this
635  // function and FinishExtensionInfoPrefs() to accomodate delayed
636  // installations.
637  void PopulateExtensionInfoPrefs(const Extension* extension,
638                                  const base::Time install_time,
639                                  Extension::State initial_state,
640                                  base::DictionaryValue* extension_dict);
641
642  // Helper function to complete initialization of the values in
643  // |extension_dict| for an extension install. Also see
644  // PopulateExtensionInfoPrefs().
645  void FinishExtensionInfoPrefs(
646      const std::string& extension_id,
647      const base::Time install_time,
648      bool needs_sort_ordinal,
649      const syncer::StringOrdinal& suggested_page_ordinal,
650      base::DictionaryValue* extension_dict);
651
652  // The pref service specific to this set of extension prefs. Owned by profile.
653  PrefService* prefs_;
654
655  // Base extensions install directory.
656  base::FilePath install_directory_;
657
658  // Weak pointer, owned by Profile.
659  ExtensionPrefValueMap* extension_pref_value_map_;
660
661  // Contains all the logic for handling the order for various extension
662  // properties.
663  scoped_ptr<ExtensionSorting> extension_sorting_;
664
665  scoped_refptr<ContentSettingsStore> content_settings_store_;
666
667  scoped_ptr<TimeProvider> time_provider_;
668
669  DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
670};
671
672}  // namespace extensions
673
674#endif  // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_
675