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