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