Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / extensions / browser / extension_prefs.h
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.
4
5 #ifndef EXTENSIONS_BROWSER_EXTENSION_PREFS_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_PREFS_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h"
16 #include "base/prefs/scoped_user_pref_update.h"
17 #include "base/time/time.h"
18 #include "base/values.h"
19 #include "components/keyed_service/core/keyed_service.h"
20 #include "extensions/browser/app_sorting.h"
21 #include "extensions/browser/blacklist_state.h"
22 #include "extensions/browser/extension_scoped_prefs.h"
23 #include "extensions/browser/install_flag.h"
24 #include "extensions/common/constants.h"
25 #include "extensions/common/extension.h"
26 #include "extensions/common/url_pattern_set.h"
27 #include "sync/api/string_ordinal.h"
28
29 class ExtensionPrefValueMap;
30 class PrefService;
31
32 namespace content {
33 class BrowserContext;
34 }
35
36 namespace user_prefs {
37 class PrefRegistrySyncable;
38 }
39
40 namespace extensions {
41
42 class AppSorting;
43 class ExtensionPrefsObserver;
44 class ExtensionPrefsUninstallExtension;
45 class URLPatternSet;
46
47 // Class for managing global and per-extension preferences.
48 //
49 // This class distinguishes the following kinds of preferences:
50 // - global preferences:
51 //       internal state for the extension system in general, not associated
52 //       with an individual extension, such as lastUpdateTime.
53 // - per-extension preferences:
54 //       meta-preferences describing properties of the extension like
55 //       installation time, whether the extension is enabled, etc.
56 // - extension controlled preferences:
57 //       browser preferences that an extension controls. For example, an
58 //       extension could use the proxy API to specify the browser's proxy
59 //       preference. Extension-controlled preferences are stored in
60 //       PrefValueStore::extension_prefs(), which this class populates and
61 //       maintains as the underlying extensions change.
62 class ExtensionPrefs : public ExtensionScopedPrefs, public KeyedService {
63  public:
64   typedef std::vector<linked_ptr<ExtensionInfo> > ExtensionsInfo;
65
66   // Vector containing identifiers for preferences.
67   typedef std::set<std::string> PrefKeySet;
68
69   // This enum is used to store the reason an extension's install has been
70   // delayed.  Do not remove items or re-order this enum as it is used in
71   // preferences.
72   enum DelayReason {
73     DELAY_REASON_NONE = 0,
74     DELAY_REASON_GC = 1,
75     DELAY_REASON_WAIT_FOR_IDLE = 2,
76     DELAY_REASON_WAIT_FOR_IMPORTS = 3,
77   };
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     DictionaryPrefUpdate update_;
118     const std::string extension_id_;
119     const std::string key_;
120
121     DISALLOW_COPY_AND_ASSIGN(ScopedUpdate);
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 an ExtensionPrefs object.
129   // Does not take ownership of |prefs| or |extension_pref_value_map|.
130   // If |extensions_disabled| is true, extension controlled preferences and
131   // content settings do not become effective. ExtensionPrefsObservers should be
132   // included in |early_observers| if they need to observe events which occur
133   // during initialization of the ExtensionPrefs object.
134   static ExtensionPrefs* Create(
135       PrefService* prefs,
136       const base::FilePath& root_dir,
137       ExtensionPrefValueMap* extension_pref_value_map,
138       scoped_ptr<AppSorting> app_sorting,
139       bool extensions_disabled,
140       const std::vector<ExtensionPrefsObserver*>& early_observers);
141
142   // A version of Create which allows injection of a custom base::Time provider.
143   // Use this as needed for testing.
144   static ExtensionPrefs* Create(
145       PrefService* prefs,
146       const base::FilePath& root_dir,
147       ExtensionPrefValueMap* extension_pref_value_map,
148       scoped_ptr<AppSorting> app_sorting,
149       bool extensions_disabled,
150       const std::vector<ExtensionPrefsObserver*>& early_observers,
151       scoped_ptr<TimeProvider> time_provider);
152
153   virtual ~ExtensionPrefs();
154
155   // Convenience function to get the ExtensionPrefs for a BrowserContext.
156   static ExtensionPrefs* Get(content::BrowserContext* context);
157
158   // Returns all installed extensions from extension preferences provided by
159   // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs
160   // access to the extension ID list before the ExtensionService is initialized.
161   static ExtensionIdList GetExtensionsFrom(const PrefService* pref_service);
162
163   // Add or remove an observer from the ExtensionPrefs.
164   void AddObserver(ExtensionPrefsObserver* observer);
165   void RemoveObserver(ExtensionPrefsObserver* observer);
166
167   // Returns true if the specified external extension was uninstalled by the
168   // user.
169   bool IsExternalExtensionUninstalled(const std::string& id) const;
170
171   // Checks whether |extension_id| is disabled. If there's no state pref for
172   // the extension, this will return false. Generally you should use
173   // ExtensionService::IsExtensionEnabled instead.
174   bool IsExtensionDisabled(const std::string& id) const;
175
176   // Get/Set the order that the browser actions appear in the toolbar.
177   ExtensionIdList GetToolbarOrder();
178   void SetToolbarOrder(const ExtensionIdList& extension_ids);
179
180   // Called when an extension is installed, so that prefs get created.
181   // If |page_ordinal| is invalid then a page will be found for the App.
182   // |install_flags| are a bitmask of extension::InstallFlags.
183   void OnExtensionInstalled(const Extension* extension,
184                             Extension::State initial_state,
185                             const syncer::StringOrdinal& page_ordinal,
186                             int install_flags,
187                             const std::string& install_parameter);
188   // OnExtensionInstalled with no install flags.
189   void OnExtensionInstalled(const Extension* extension,
190                             Extension::State initial_state,
191                             const syncer::StringOrdinal& page_ordinal,
192                             const std::string& install_parameter) {
193     OnExtensionInstalled(extension,
194                          initial_state,
195                          page_ordinal,
196                          kInstallFlagNone,
197                          install_parameter);
198   }
199
200   // Called when an extension is uninstalled, so that prefs get cleaned up.
201   void OnExtensionUninstalled(const std::string& extension_id,
202                               const Manifest::Location& location,
203                               bool external_uninstall);
204
205   // Called to change the extension's state when it is enabled/disabled.
206   void SetExtensionState(const std::string& extension_id, Extension::State);
207
208   // Called to change the extension's BlacklistState. Currently only used for
209   // non-malicious extensions.
210   // TODO(oleg): replace SetExtensionBlacklisted by this function.
211   void SetExtensionBlacklistState(const std::string& extension_id,
212                                   BlacklistState state);
213
214   // Checks whether |extension_id| is marked as greylisted.
215   // TODO(oleg): Replace IsExtensionBlacklisted by this method.
216   BlacklistState GetExtensionBlacklistState(const std::string& extension_id);
217
218   // Populates |out| with the ids of all installed extensions.
219   void GetExtensions(ExtensionIdList* out);
220
221   // ExtensionScopedPrefs methods:
222   virtual void UpdateExtensionPref(const std::string& id,
223                                    const std::string& key,
224                                    base::Value* value) OVERRIDE;
225
226   virtual void DeleteExtensionPrefs(const std::string& id) OVERRIDE;
227
228   virtual bool ReadPrefAsBoolean(const std::string& extension_id,
229                                  const std::string& pref_key,
230                                  bool* out_value) const OVERRIDE;
231
232   virtual bool ReadPrefAsInteger(const std::string& extension_id,
233                                  const std::string& pref_key,
234                                  int* out_value) const OVERRIDE;
235
236   virtual bool ReadPrefAsString(const std::string& extension_id,
237                                 const std::string& pref_key,
238                                 std::string* out_value) const OVERRIDE;
239
240   virtual bool ReadPrefAsList(const std::string& extension_id,
241                               const std::string& pref_key,
242                               const base::ListValue** out_value) const OVERRIDE;
243
244   virtual bool ReadPrefAsDictionary(
245       const std::string& extension_id,
246       const std::string& pref_key,
247       const base::DictionaryValue** out_value) const OVERRIDE;
248
249   virtual bool HasPrefForExtension(const std::string& extension_id) const
250       OVERRIDE;
251
252   // Did the extension ask to escalate its permission during an upgrade?
253   bool DidExtensionEscalatePermissions(const std::string& id);
254
255   // If |did_escalate| is true, the preferences for |extension| will be set to
256   // require the install warning when the user tries to enable.
257   void SetDidExtensionEscalatePermissions(
258       const Extension* extension,
259       bool did_escalate);
260
261   // Getters and setters for disabled reason.
262   int GetDisableReasons(const std::string& extension_id) const;
263   bool HasDisableReason(const std::string& extension_id,
264                         Extension::DisableReason disable_reason) const;
265   void AddDisableReason(const std::string& extension_id,
266                         Extension::DisableReason disable_reason);
267   void RemoveDisableReason(const std::string& extension_id,
268                            Extension::DisableReason disable_reason);
269   void ClearDisableReasons(const std::string& extension_id);
270
271   // Gets the set of extensions that have been blacklisted in prefs. This will
272   // return only the blocked extensions, not the "greylist" extensions.
273   // TODO(oleg): Make method names consistent here, in extension service and in
274   // blacklist.
275   std::set<std::string> GetBlacklistedExtensions();
276
277   // Sets whether the extension with |id| is blacklisted.
278   void SetExtensionBlacklisted(const std::string& extension_id,
279                                bool is_blacklisted);
280
281   // Returns the version string for the currently installed extension, or
282   // the empty string if not found.
283   std::string GetVersionString(const std::string& extension_id);
284
285   // Re-writes the extension manifest into the prefs.
286   // Called to change the extension's manifest when it's re-localized.
287   void UpdateManifest(const Extension* extension);
288
289   // Returns base extensions install directory.
290   const base::FilePath& install_directory() const { return install_directory_; }
291
292   // Returns whether the extension with |id| has its blacklist bit set.
293   //
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;
299
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);
303
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);
307
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);
311
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);
316
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);
321
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);
328
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);
334
335   // Whether the user has been notified about extension with |extension_id|
336   // overriding the proxy.
337   bool HasProxyOverriddenBubbleBeenAcknowledged(
338       const std::string& extension_id);
339   void SetProxyOverriddenBubbleBeenAcknowledged(const std::string& extension_id,
340                                                 bool value);
341
342   // Returns true if the extension notification code has already run for the
343   // first time for this profile. Currently we use this flag to mean that any
344   // extensions that would trigger notifications should get silently
345   // acknowledged. This is a fuse. Calling it the first time returns false.
346   // Subsequent calls return true. It's not possible through an API to ever
347   // reset it. Don't call it unless you mean it!
348   bool SetAlertSystemFirstRun();
349
350   // Returns the last value set via SetLastPingDay. If there isn't such a
351   // pref, the returned Time will return true for is_null().
352   base::Time LastPingDay(const std::string& extension_id) const;
353
354   // The time stored is based on the server's perspective of day start time, not
355   // the client's.
356   void SetLastPingDay(const std::string& extension_id, const base::Time& time);
357
358   // Similar to the 2 above, but for the extensions blacklist.
359   base::Time BlacklistLastPingDay() const;
360   void SetBlacklistLastPingDay(const base::Time& time);
361
362   // Similar to LastPingDay/SetLastPingDay, but for sending "days since active"
363   // ping.
364   base::Time LastActivePingDay(const std::string& extension_id);
365   void SetLastActivePingDay(const std::string& extension_id,
366                             const base::Time& time);
367
368   // A bit we use for determining if we should send the "days since active"
369   // ping. A value of true means the item has been active (launched) since the
370   // last update check.
371   bool GetActiveBit(const std::string& extension_id);
372   void SetActiveBit(const std::string& extension_id, bool active);
373
374   // Returns the granted permission set for the extension with |extension_id|,
375   // and NULL if no preferences were found for |extension_id|.
376   // This passes ownership of the returned set to the caller.
377   PermissionSet* GetGrantedPermissions(const std::string& extension_id);
378
379   // Adds |permissions| to the granted permissions set for the extension with
380   // |extension_id|. The new granted permissions set will be the union of
381   // |permissions| and the already granted permissions.
382   void AddGrantedPermissions(const std::string& extension_id,
383                              const PermissionSet* permissions);
384
385   // As above, but subtracts the given |permissions| from the granted set.
386   void RemoveGrantedPermissions(const std::string& extension_id,
387                                 const PermissionSet* permissions);
388
389   // Gets the active permission set for the specified extension. This may
390   // differ from the permissions in the manifest due to the optional
391   // permissions API. This passes ownership of the set to the caller.
392   PermissionSet* GetActivePermissions(const std::string& extension_id);
393
394   // Sets the active |permissions| for the extension with |extension_id|.
395   void SetActivePermissions(const std::string& extension_id,
396                             const PermissionSet* permissions);
397
398   // Records whether or not this extension is currently running.
399   void SetExtensionRunning(const std::string& extension_id, bool is_running);
400
401   // Returns whether or not this extension is marked as running. This is used to
402   // restart apps across browser restarts.
403   bool IsExtensionRunning(const std::string& extension_id);
404
405   // Set/Get whether or not the app is active. Used to force a launch of apps
406   // that don't handle onRestarted() on a restart. We can only safely do that if
407   // the app was active when it was last running.
408   void SetIsActive(const std::string& extension_id, bool is_active);
409   bool IsActive(const std::string& extension_id);
410
411   // Returns true if the user enabled this extension to be loaded in incognito
412   // mode.
413   //
414   // IMPORTANT: you probably want to use extensions::util::IsIncognitoEnabled
415   // instead of this method.
416   bool IsIncognitoEnabled(const std::string& extension_id) const;
417   void SetIsIncognitoEnabled(const std::string& extension_id, bool enabled);
418
419   // Returns true if the user has chosen to allow this extension to inject
420   // scripts into pages with file URLs.
421   //
422   // IMPORTANT: you probably want to use extensions::util::AllowFileAccess
423   // instead of this method.
424   bool AllowFileAccess(const std::string& extension_id) const;
425   void SetAllowFileAccess(const std::string& extension_id, bool allow);
426   bool HasAllowFileAccessSetting(const std::string& extension_id) const;
427
428   // Saves ExtensionInfo for each installed extension with the path to the
429   // version directory and the location. Blacklisted extensions won't be saved
430   // and neither will external extensions the user has explicitly uninstalled.
431   // Caller takes ownership of returned structure.
432   scoped_ptr<ExtensionsInfo> GetInstalledExtensionsInfo() const;
433
434   // Same as above, but only includes external extensions the user has
435   // explicitly uninstalled.
436   scoped_ptr<ExtensionsInfo> GetUninstalledExtensionsInfo() const;
437
438   // Returns the ExtensionInfo from the prefs for the given extension. If the
439   // extension is not present, NULL is returned.
440   scoped_ptr<ExtensionInfo> GetInstalledExtensionInfo(
441       const std::string& extension_id) const;
442
443   // We've downloaded an updated .crx file for the extension, but are waiting
444   // to install it.
445   //
446   // |install_flags| are a bitmask of extension::InstallFlags.
447   void SetDelayedInstallInfo(const Extension* extension,
448                              Extension::State initial_state,
449                              int install_flags,
450                              DelayReason delay_reason,
451                              const syncer::StringOrdinal& page_ordinal,
452                              const std::string& install_parameter);
453
454   // Removes any delayed install information we have for the given
455   // |extension_id|. Returns true if there was info to remove; false otherwise.
456   bool RemoveDelayedInstallInfo(const std::string& extension_id);
457
458   // Update the prefs to finish the update for an extension.
459   bool FinishDelayedInstallInfo(const std::string& extension_id);
460
461   // Returns the ExtensionInfo from the prefs for delayed install information
462   // for |extension_id|, if we have any. Otherwise returns NULL.
463   scoped_ptr<ExtensionInfo> GetDelayedInstallInfo(
464       const std::string& extension_id) const;
465
466   DelayReason GetDelayedInstallReason(const std::string& extension_id) const;
467
468   // Returns information about all the extensions that have delayed install
469   // information.
470   scoped_ptr<ExtensionsInfo> GetAllDelayedInstallInfo() const;
471
472   // Returns true if the extension is an ephemeral app.
473   bool IsEphemeralApp(const std::string& extension_id) const;
474
475   // Promotes an ephemeral app to a regular installed app.
476   void OnEphemeralAppPromoted(const std::string& extension_id);
477
478   // Returns true if the user repositioned the app on the app launcher via drag
479   // and drop.
480   bool WasAppDraggedByUser(const std::string& extension_id);
481
482   // Sets a flag indicating that the user repositioned the app on the app
483   // launcher by drag and dropping it.
484   void SetAppDraggedByUser(const std::string& extension_id);
485
486   // Returns true if there is an extension which controls the preference value
487   //  for |pref_key| *and* it is specific to incognito mode.
488   bool HasIncognitoPrefValue(const std::string& pref_key);
489
490   // Returns the creation flags mask for the extension.
491   int GetCreationFlags(const std::string& extension_id) const;
492
493   // Returns the creation flags mask for a delayed install extension.
494   int GetDelayedInstallCreationFlags(const std::string& extension_id) const;
495
496   // Returns true if the extension was installed from the Chrome Web Store.
497   bool IsFromWebStore(const std::string& extension_id) const;
498
499   // Returns true if the extension was installed from an App generated from a
500   // bookmark.
501   bool IsFromBookmark(const std::string& extension_id) const;
502
503   // Returns true if the extension was installed as a default app.
504   bool WasInstalledByDefault(const std::string& extension_id) const;
505
506   // Returns true if the extension was installed as an oem app.
507   bool WasInstalledByOem(const std::string& extension_id) const;
508
509   // Helper method to acquire the installation time of an extension.
510   // Returns base::Time() if the installation time could not be parsed or
511   // found.
512   base::Time GetInstallTime(const std::string& extension_id) const;
513
514   // Returns true if the extension should not be synced.
515   bool DoNotSync(const std::string& extension_id) const;
516
517   // Gets/sets the last launch time of an extension.
518   base::Time GetLastLaunchTime(const std::string& extension_id) const;
519   void SetLastLaunchTime(const std::string& extension_id,
520                          const base::Time& time);
521
522   static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
523
524   bool extensions_disabled() const { return extensions_disabled_; }
525
526   // The underlying PrefService.
527   PrefService* pref_service() const { return prefs_; }
528
529   // The underlying AppSorting.
530   AppSorting* app_sorting() const { return app_sorting_.get(); }
531
532   // Schedules garbage collection of an extension's on-disk data on the next
533   // start of this ExtensionService. Applies only to extensions with isolated
534   // storage.
535   void SetNeedsStorageGarbageCollection(bool value);
536   bool NeedsStorageGarbageCollection();
537
538   // Used by AppWindowGeometryCache to persist its cache. These methods
539   // should not be called directly.
540   const base::DictionaryValue* GetGeometryCache(
541         const std::string& extension_id) const;
542   void SetGeometryCache(const std::string& extension_id,
543                         scoped_ptr<base::DictionaryValue> cache);
544
545   // Used for verification of installed extension ids. For the Set method, pass
546   // null to remove the preference.
547   const base::DictionaryValue* GetInstallSignature();
548   void SetInstallSignature(const base::DictionaryValue* signature);
549
550   // The installation parameter associated with the extension.
551   std::string GetInstallParam(const std::string& extension_id) const;
552   void SetInstallParam(const std::string& extension_id,
553                        const std::string& install_parameter);
554
555   // The total number of times we've disabled an extension due to corrupted
556   // contents.
557   int GetCorruptedDisableCount();
558   void IncrementCorruptedDisableCount();
559
560  private:
561   friend class ExtensionPrefsBlacklistedExtensions;  // Unit test.
562   friend class ExtensionPrefsUninstallExtension;     // Unit test.
563
564   enum DisableReasonChange {
565     DISABLE_REASON_ADD,
566     DISABLE_REASON_REMOVE,
567     DISABLE_REASON_CLEAR
568   };
569
570   // See the Create methods.
571   ExtensionPrefs(PrefService* prefs,
572                  const base::FilePath& root_dir,
573                  ExtensionPrefValueMap* extension_pref_value_map,
574                  scoped_ptr<AppSorting> app_sorting,
575                  scoped_ptr<TimeProvider> time_provider,
576                  bool extensions_disabled,
577                  const std::vector<ExtensionPrefsObserver*>& early_observers);
578
579   // Converts absolute paths in the pref to paths relative to the
580   // install_directory_.
581   void MakePathsRelative();
582
583   // Converts internal relative paths to be absolute. Used for export to
584   // consumers who expect full paths.
585   void MakePathsAbsolute(base::DictionaryValue* dict);
586
587   // Helper function used by GetInstalledExtensionInfo() and
588   // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided
589   // |extension| dictionary.
590   scoped_ptr<ExtensionInfo> GetInstalledInfoHelper(
591       const std::string& extension_id,
592       const base::DictionaryValue* extension) const;
593
594   // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a
595   // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns.
596   bool ReadPrefAsURLPatternSet(const std::string& extension_id,
597                                const std::string& pref_key,
598                                URLPatternSet* result,
599                                int valid_schemes);
600
601   // Converts |new_value| to a list of strings and sets the |pref_key| pref
602   // belonging to |extension_id|.
603   void SetExtensionPrefURLPatternSet(const std::string& extension_id,
604                                      const std::string& pref_key,
605                                      const URLPatternSet& new_value);
606
607   // Read the boolean preference entry and return true if the preference exists
608   // and the preference's value is true; false otherwise.
609   bool ReadPrefAsBooleanAndReturn(const std::string& extension_id,
610                                   const std::string& key) const;
611
612   // Interprets |pref_key| in |extension_id|'s preferences as an
613   // PermissionSet, and passes ownership of the set to the caller.
614   PermissionSet* ReadPrefAsPermissionSet(const std::string& extension_id,
615                                          const std::string& pref_key);
616
617   // Converts the |new_value| to its value and sets the |pref_key| pref
618   // belonging to |extension_id|.
619   void SetExtensionPrefPermissionSet(const std::string& extension_id,
620                                      const std::string& pref_key,
621                                      const PermissionSet* new_value);
622
623   // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it
624   // doesn't exist.
625   const base::DictionaryValue* GetExtensionPref(const std::string& id) const;
626
627   // Modifies the extensions disable reasons to add a new reason, remove an
628   // existing reason, or clear all reasons. Notifies observers if the set of
629   // DisableReasons has changed.
630   // If |change| is DISABLE_REASON_CLEAR, then |reason| is ignored.
631   void ModifyDisableReason(const std::string& extension_id,
632                            Extension::DisableReason reason,
633                            DisableReasonChange change);
634
635   // Fix missing preference entries in the extensions that are were introduced
636   // in a later Chrome version.
637   void FixMissingPrefs(const ExtensionIdList& extension_ids);
638
639   // Installs the persistent extension preferences into |prefs_|'s extension
640   // pref store. Does nothing if extensions_disabled_ is true.
641   void InitPrefStore();
642
643   // Migrates the permissions data in the pref store.
644   void MigratePermissions(const ExtensionIdList& extension_ids);
645
646   // Migrates the disable reasons from a single enum to a bit mask.
647   void MigrateDisableReasons(const ExtensionIdList& extension_ids);
648
649   // Checks whether there is a state pref for the extension and if so, whether
650   // it matches |check_state|.
651   bool DoesExtensionHaveState(const std::string& id,
652                               Extension::State check_state) const;
653
654   // Reads the list of strings for |pref| from user prefs into
655   // |id_container_out|. Returns false if the pref wasn't found in the user
656   // pref store.
657   template <class ExtensionIdContainer>
658   bool GetUserExtensionPrefIntoContainer(
659       const char* pref,
660       ExtensionIdContainer* id_container_out);
661
662   // Writes the list of strings contained in |strings| to |pref| in prefs.
663   template <class ExtensionIdContainer>
664   void SetExtensionPrefFromContainer(const char* pref,
665                                      const ExtensionIdContainer& strings);
666
667   // Helper function to populate |extension_dict| with the values needed
668   // by a newly installed extension. Work is broken up between this
669   // function and FinishExtensionInfoPrefs() to accomodate delayed
670   // installations.
671   //
672   // |install_flags| are a bitmask of extension::InstallFlags.
673   void PopulateExtensionInfoPrefs(const Extension* extension,
674                                   const base::Time install_time,
675                                   Extension::State initial_state,
676                                   int install_flags,
677                                   const std::string& install_parameter,
678                                   base::DictionaryValue* extension_dict);
679
680   void InitExtensionControlledPrefs(ExtensionPrefValueMap* value_map);
681
682   // Helper function to complete initialization of the values in
683   // |extension_dict| for an extension install. Also see
684   // PopulateExtensionInfoPrefs().
685   void FinishExtensionInfoPrefs(
686       const std::string& extension_id,
687       const base::Time install_time,
688       bool needs_sort_ordinal,
689       const syncer::StringOrdinal& suggested_page_ordinal,
690       base::DictionaryValue* extension_dict);
691
692   // The pref service specific to this set of extension prefs. Owned by the
693   // BrowserContext.
694   PrefService* prefs_;
695
696   // Base extensions install directory.
697   base::FilePath install_directory_;
698
699   // Weak pointer, owned by BrowserContext.
700   ExtensionPrefValueMap* extension_pref_value_map_;
701
702   // Contains all the logic for handling the order for various extension
703   // properties.
704   scoped_ptr<AppSorting> app_sorting_;
705
706   scoped_ptr<TimeProvider> time_provider_;
707
708   bool extensions_disabled_;
709
710   ObserverList<ExtensionPrefsObserver> observer_list_;
711
712   DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
713 };
714
715 }  // namespace extensions
716
717 #endif  // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_