Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Side by Side Diff: extensions/browser/extension_prefs.h

Issue 1909773002: Convert //extensions/browser from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ 5 #ifndef EXTENSIONS_BROWSER_EXTENSION_PREFS_H_
6 #define EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ 6 #define EXTENSIONS_BROWSER_EXTENSION_PREFS_H_
7 7
8 #include <memory>
8 #include <set> 9 #include <set>
9 #include <string> 10 #include <string>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/linked_ptr.h" 14 #include "base/memory/linked_ptr.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/observer_list.h" 15 #include "base/observer_list.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "components/keyed_service/core/keyed_service.h" 18 #include "components/keyed_service/core/keyed_service.h"
19 #include "components/prefs/scoped_user_pref_update.h" 19 #include "components/prefs/scoped_user_pref_update.h"
20 #include "extensions/browser/blacklist_state.h" 20 #include "extensions/browser/blacklist_state.h"
21 #include "extensions/browser/extension_scoped_prefs.h" 21 #include "extensions/browser/extension_scoped_prefs.h"
22 #include "extensions/browser/install_flag.h" 22 #include "extensions/browser/install_flag.h"
23 #include "extensions/common/constants.h" 23 #include "extensions/common/constants.h"
24 #include "extensions/common/extension.h" 24 #include "extensions/common/extension.h"
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 139
140 // A version of Create which allows injection of a custom base::Time provider. 140 // A version of Create which allows injection of a custom base::Time provider.
141 // Use this as needed for testing. 141 // Use this as needed for testing.
142 static ExtensionPrefs* Create( 142 static ExtensionPrefs* Create(
143 content::BrowserContext* browser_context, 143 content::BrowserContext* browser_context,
144 PrefService* prefs, 144 PrefService* prefs,
145 const base::FilePath& root_dir, 145 const base::FilePath& root_dir,
146 ExtensionPrefValueMap* extension_pref_value_map, 146 ExtensionPrefValueMap* extension_pref_value_map,
147 bool extensions_disabled, 147 bool extensions_disabled,
148 const std::vector<ExtensionPrefsObserver*>& early_observers, 148 const std::vector<ExtensionPrefsObserver*>& early_observers,
149 scoped_ptr<TimeProvider> time_provider); 149 std::unique_ptr<TimeProvider> time_provider);
150 150
151 ~ExtensionPrefs() override; 151 ~ExtensionPrefs() override;
152 152
153 // Convenience function to get the ExtensionPrefs for a BrowserContext. 153 // Convenience function to get the ExtensionPrefs for a BrowserContext.
154 static ExtensionPrefs* Get(content::BrowserContext* context); 154 static ExtensionPrefs* Get(content::BrowserContext* context);
155 155
156 // Returns all installed extensions from extension preferences provided by 156 // Returns all installed extensions from extension preferences provided by
157 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs 157 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs
158 // access to the extension ID list before the ExtensionService is initialized. 158 // access to the extension ID list before the ExtensionService is initialized.
159 static ExtensionIdList GetExtensionsFrom(const PrefService* pref_service); 159 static ExtensionIdList GetExtensionsFrom(const PrefService* pref_service);
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 349
350 // A bit we use for determining if we should send the "days since active" 350 // A bit we use for determining if we should send the "days since active"
351 // ping. A value of true means the item has been active (launched) since the 351 // ping. A value of true means the item has been active (launched) since the
352 // last update check. 352 // last update check.
353 bool GetActiveBit(const std::string& extension_id) const; 353 bool GetActiveBit(const std::string& extension_id) const;
354 void SetActiveBit(const std::string& extension_id, bool active); 354 void SetActiveBit(const std::string& extension_id, bool active);
355 355
356 // Returns the granted permission set for the extension with |extension_id|, 356 // Returns the granted permission set for the extension with |extension_id|,
357 // and NULL if no preferences were found for |extension_id|. 357 // and NULL if no preferences were found for |extension_id|.
358 // This passes ownership of the returned set to the caller. 358 // This passes ownership of the returned set to the caller.
359 scoped_ptr<const PermissionSet> GetGrantedPermissions( 359 std::unique_ptr<const PermissionSet> GetGrantedPermissions(
360 const std::string& extension_id) const; 360 const std::string& extension_id) const;
361 361
362 // Adds |permissions| to the granted permissions set for the extension with 362 // Adds |permissions| to the granted permissions set for the extension with
363 // |extension_id|. The new granted permissions set will be the union of 363 // |extension_id|. The new granted permissions set will be the union of
364 // |permissions| and the already granted permissions. 364 // |permissions| and the already granted permissions.
365 void AddGrantedPermissions(const std::string& extension_id, 365 void AddGrantedPermissions(const std::string& extension_id,
366 const PermissionSet& permissions); 366 const PermissionSet& permissions);
367 367
368 // As above, but subtracts the given |permissions| from the granted set. 368 // As above, but subtracts the given |permissions| from the granted set.
369 void RemoveGrantedPermissions(const std::string& extension_id, 369 void RemoveGrantedPermissions(const std::string& extension_id,
370 const PermissionSet& permissions); 370 const PermissionSet& permissions);
371 371
372 // Gets the active permission set for the specified extension. This may 372 // Gets the active permission set for the specified extension. This may
373 // differ from the permissions in the manifest due to the optional 373 // differ from the permissions in the manifest due to the optional
374 // permissions API. This passes ownership of the set to the caller. 374 // permissions API. This passes ownership of the set to the caller.
375 scoped_ptr<const PermissionSet> GetActivePermissions( 375 std::unique_ptr<const PermissionSet> GetActivePermissions(
376 const std::string& extension_id) const; 376 const std::string& extension_id) const;
377 377
378 // Sets the active |permissions| for the extension with |extension_id|. 378 // Sets the active |permissions| for the extension with |extension_id|.
379 void SetActivePermissions(const std::string& extension_id, 379 void SetActivePermissions(const std::string& extension_id,
380 const PermissionSet& permissions); 380 const PermissionSet& permissions);
381 381
382 // Records whether or not this extension is currently running. 382 // Records whether or not this extension is currently running.
383 void SetExtensionRunning(const std::string& extension_id, bool is_running); 383 void SetExtensionRunning(const std::string& extension_id, bool is_running);
384 384
385 // Returns whether or not this extension is marked as running. This is used to 385 // Returns whether or not this extension is marked as running. This is used to
(...skipping 20 matching lines...) Expand all
406 // IMPORTANT: you probably want to use extensions::util::AllowFileAccess 406 // IMPORTANT: you probably want to use extensions::util::AllowFileAccess
407 // instead of this method. 407 // instead of this method.
408 bool AllowFileAccess(const std::string& extension_id) const; 408 bool AllowFileAccess(const std::string& extension_id) const;
409 void SetAllowFileAccess(const std::string& extension_id, bool allow); 409 void SetAllowFileAccess(const std::string& extension_id, bool allow);
410 bool HasAllowFileAccessSetting(const std::string& extension_id) const; 410 bool HasAllowFileAccessSetting(const std::string& extension_id) const;
411 411
412 // Saves ExtensionInfo for each installed extension with the path to the 412 // Saves ExtensionInfo for each installed extension with the path to the
413 // version directory and the location. Blacklisted extensions won't be saved 413 // version directory and the location. Blacklisted extensions won't be saved
414 // and neither will external extensions the user has explicitly uninstalled. 414 // and neither will external extensions the user has explicitly uninstalled.
415 // Caller takes ownership of returned structure. 415 // Caller takes ownership of returned structure.
416 scoped_ptr<ExtensionsInfo> GetInstalledExtensionsInfo() const; 416 std::unique_ptr<ExtensionsInfo> GetInstalledExtensionsInfo() const;
417 417
418 // Same as above, but only includes external extensions the user has 418 // Same as above, but only includes external extensions the user has
419 // explicitly uninstalled. 419 // explicitly uninstalled.
420 scoped_ptr<ExtensionsInfo> GetUninstalledExtensionsInfo() const; 420 std::unique_ptr<ExtensionsInfo> GetUninstalledExtensionsInfo() const;
421 421
422 // Returns the ExtensionInfo from the prefs for the given extension. If the 422 // Returns the ExtensionInfo from the prefs for the given extension. If the
423 // extension is not present, NULL is returned. 423 // extension is not present, NULL is returned.
424 scoped_ptr<ExtensionInfo> GetInstalledExtensionInfo( 424 std::unique_ptr<ExtensionInfo> GetInstalledExtensionInfo(
425 const std::string& extension_id) const; 425 const std::string& extension_id) const;
426 426
427 // We've downloaded an updated .crx file for the extension, but are waiting 427 // We've downloaded an updated .crx file for the extension, but are waiting
428 // to install it. 428 // to install it.
429 // 429 //
430 // |install_flags| are a bitmask of extension::InstallFlags. 430 // |install_flags| are a bitmask of extension::InstallFlags.
431 void SetDelayedInstallInfo(const Extension* extension, 431 void SetDelayedInstallInfo(const Extension* extension,
432 Extension::State initial_state, 432 Extension::State initial_state,
433 int install_flags, 433 int install_flags,
434 DelayReason delay_reason, 434 DelayReason delay_reason,
435 const syncer::StringOrdinal& page_ordinal, 435 const syncer::StringOrdinal& page_ordinal,
436 const std::string& install_parameter); 436 const std::string& install_parameter);
437 437
438 // Removes any delayed install information we have for the given 438 // Removes any delayed install information we have for the given
439 // |extension_id|. Returns true if there was info to remove; false otherwise. 439 // |extension_id|. Returns true if there was info to remove; false otherwise.
440 bool RemoveDelayedInstallInfo(const std::string& extension_id); 440 bool RemoveDelayedInstallInfo(const std::string& extension_id);
441 441
442 // Update the prefs to finish the update for an extension. 442 // Update the prefs to finish the update for an extension.
443 bool FinishDelayedInstallInfo(const std::string& extension_id); 443 bool FinishDelayedInstallInfo(const std::string& extension_id);
444 444
445 // Returns the ExtensionInfo from the prefs for delayed install information 445 // Returns the ExtensionInfo from the prefs for delayed install information
446 // for |extension_id|, if we have any. Otherwise returns NULL. 446 // for |extension_id|, if we have any. Otherwise returns NULL.
447 scoped_ptr<ExtensionInfo> GetDelayedInstallInfo( 447 std::unique_ptr<ExtensionInfo> GetDelayedInstallInfo(
448 const std::string& extension_id) const; 448 const std::string& extension_id) const;
449 449
450 DelayReason GetDelayedInstallReason(const std::string& extension_id) const; 450 DelayReason GetDelayedInstallReason(const std::string& extension_id) const;
451 451
452 // Returns information about all the extensions that have delayed install 452 // Returns information about all the extensions that have delayed install
453 // information. 453 // information.
454 scoped_ptr<ExtensionsInfo> GetAllDelayedInstallInfo() const; 454 std::unique_ptr<ExtensionsInfo> GetAllDelayedInstallInfo() const;
455 455
456 // Returns true if the user repositioned the app on the app launcher via drag 456 // Returns true if the user repositioned the app on the app launcher via drag
457 // and drop. 457 // and drop.
458 bool WasAppDraggedByUser(const std::string& extension_id) const; 458 bool WasAppDraggedByUser(const std::string& extension_id) const;
459 459
460 // Sets a flag indicating that the user repositioned the app on the app 460 // Sets a flag indicating that the user repositioned the app on the app
461 // launcher by drag and dropping it. 461 // launcher by drag and dropping it.
462 void SetAppDraggedByUser(const std::string& extension_id); 462 void SetAppDraggedByUser(const std::string& extension_id);
463 463
464 // Returns true if there is an extension which controls the preference value 464 // Returns true if there is an extension which controls the preference value
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 // start of this ExtensionService. Applies only to extensions with isolated 515 // start of this ExtensionService. Applies only to extensions with isolated
516 // storage. 516 // storage.
517 void SetNeedsStorageGarbageCollection(bool value); 517 void SetNeedsStorageGarbageCollection(bool value);
518 bool NeedsStorageGarbageCollection() const; 518 bool NeedsStorageGarbageCollection() const;
519 519
520 // Used by AppWindowGeometryCache to persist its cache. These methods 520 // Used by AppWindowGeometryCache to persist its cache. These methods
521 // should not be called directly. 521 // should not be called directly.
522 const base::DictionaryValue* GetGeometryCache( 522 const base::DictionaryValue* GetGeometryCache(
523 const std::string& extension_id) const; 523 const std::string& extension_id) const;
524 void SetGeometryCache(const std::string& extension_id, 524 void SetGeometryCache(const std::string& extension_id,
525 scoped_ptr<base::DictionaryValue> cache); 525 std::unique_ptr<base::DictionaryValue> cache);
526 526
527 // Used for verification of installed extension ids. For the Set method, pass 527 // Used for verification of installed extension ids. For the Set method, pass
528 // null to remove the preference. 528 // null to remove the preference.
529 const base::DictionaryValue* GetInstallSignature() const; 529 const base::DictionaryValue* GetInstallSignature() const;
530 void SetInstallSignature(const base::DictionaryValue* signature); 530 void SetInstallSignature(const base::DictionaryValue* signature);
531 531
532 // The installation parameter associated with the extension. 532 // The installation parameter associated with the extension.
533 std::string GetInstallParam(const std::string& extension_id) const; 533 std::string GetInstallParam(const std::string& extension_id) const;
534 void SetInstallParam(const std::string& extension_id, 534 void SetInstallParam(const std::string& extension_id,
535 const std::string& install_parameter); 535 const std::string& install_parameter);
(...skipping 19 matching lines...) Expand all
555 DISABLE_REASON_REMOVE, 555 DISABLE_REASON_REMOVE,
556 DISABLE_REASON_REPLACE, 556 DISABLE_REASON_REPLACE,
557 DISABLE_REASON_CLEAR 557 DISABLE_REASON_CLEAR
558 }; 558 };
559 559
560 // See the Create methods. 560 // See the Create methods.
561 ExtensionPrefs(content::BrowserContext* browser_context, 561 ExtensionPrefs(content::BrowserContext* browser_context,
562 PrefService* prefs, 562 PrefService* prefs,
563 const base::FilePath& root_dir, 563 const base::FilePath& root_dir,
564 ExtensionPrefValueMap* extension_pref_value_map, 564 ExtensionPrefValueMap* extension_pref_value_map,
565 scoped_ptr<TimeProvider> time_provider, 565 std::unique_ptr<TimeProvider> time_provider,
566 bool extensions_disabled, 566 bool extensions_disabled,
567 const std::vector<ExtensionPrefsObserver*>& early_observers); 567 const std::vector<ExtensionPrefsObserver*>& early_observers);
568 568
569 // Converts absolute paths in the pref to paths relative to the 569 // Converts absolute paths in the pref to paths relative to the
570 // install_directory_. 570 // install_directory_.
571 void MakePathsRelative(); 571 void MakePathsRelative();
572 572
573 // Converts internal relative paths to be absolute. Used for export to 573 // Converts internal relative paths to be absolute. Used for export to
574 // consumers who expect full paths. 574 // consumers who expect full paths.
575 void MakePathsAbsolute(base::DictionaryValue* dict); 575 void MakePathsAbsolute(base::DictionaryValue* dict);
576 576
577 // Helper function used by GetInstalledExtensionInfo() and 577 // Helper function used by GetInstalledExtensionInfo() and
578 // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided 578 // GetDelayedInstallInfo() to construct an ExtensionInfo from the provided
579 // |extension| dictionary. 579 // |extension| dictionary.
580 scoped_ptr<ExtensionInfo> GetInstalledInfoHelper( 580 std::unique_ptr<ExtensionInfo> GetInstalledInfoHelper(
581 const std::string& extension_id, 581 const std::string& extension_id,
582 const base::DictionaryValue* extension) const; 582 const base::DictionaryValue* extension) const;
583 583
584 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a 584 // Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a
585 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns. 585 // URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns.
586 bool ReadPrefAsURLPatternSet(const std::string& extension_id, 586 bool ReadPrefAsURLPatternSet(const std::string& extension_id,
587 const std::string& pref_key, 587 const std::string& pref_key,
588 URLPatternSet* result, 588 URLPatternSet* result,
589 int valid_schemes) const; 589 int valid_schemes) const;
590 590
591 // Converts |new_value| to a list of strings and sets the |pref_key| pref 591 // Converts |new_value| to a list of strings and sets the |pref_key| pref
592 // belonging to |extension_id|. 592 // belonging to |extension_id|.
593 void SetExtensionPrefURLPatternSet(const std::string& extension_id, 593 void SetExtensionPrefURLPatternSet(const std::string& extension_id,
594 const std::string& pref_key, 594 const std::string& pref_key,
595 const URLPatternSet& new_value); 595 const URLPatternSet& new_value);
596 596
597 // Read the boolean preference entry and return true if the preference exists 597 // Read the boolean preference entry and return true if the preference exists
598 // and the preference's value is true; false otherwise. 598 // and the preference's value is true; false otherwise.
599 bool ReadPrefAsBooleanAndReturn(const std::string& extension_id, 599 bool ReadPrefAsBooleanAndReturn(const std::string& extension_id,
600 const std::string& key) const; 600 const std::string& key) const;
601 601
602 // Interprets |pref_key| in |extension_id|'s preferences as an 602 // Interprets |pref_key| in |extension_id|'s preferences as an
603 // PermissionSet, and passes ownership of the set to the caller. 603 // PermissionSet, and passes ownership of the set to the caller.
604 scoped_ptr<const PermissionSet> ReadPrefAsPermissionSet( 604 std::unique_ptr<const PermissionSet> ReadPrefAsPermissionSet(
605 const std::string& extension_id, 605 const std::string& extension_id,
606 const std::string& pref_key) const; 606 const std::string& pref_key) const;
607 607
608 // Converts the |new_value| to its value and sets the |pref_key| pref 608 // Converts the |new_value| to its value and sets the |pref_key| pref
609 // belonging to |extension_id|. 609 // belonging to |extension_id|.
610 void SetExtensionPrefPermissionSet(const std::string& extension_id, 610 void SetExtensionPrefPermissionSet(const std::string& extension_id,
611 const std::string& pref_key, 611 const std::string& pref_key,
612 const PermissionSet& new_value); 612 const PermissionSet& new_value);
613 613
614 // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it 614 // Returns an immutable dictionary for extension |id|'s prefs, or NULL if it
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 // The pref service specific to this set of extension prefs. Owned by the 675 // The pref service specific to this set of extension prefs. Owned by the
676 // BrowserContext. 676 // BrowserContext.
677 PrefService* prefs_; 677 PrefService* prefs_;
678 678
679 // Base extensions install directory. 679 // Base extensions install directory.
680 base::FilePath install_directory_; 680 base::FilePath install_directory_;
681 681
682 // Weak pointer, owned by BrowserContext. 682 // Weak pointer, owned by BrowserContext.
683 ExtensionPrefValueMap* extension_pref_value_map_; 683 ExtensionPrefValueMap* extension_pref_value_map_;
684 684
685 scoped_ptr<TimeProvider> time_provider_; 685 std::unique_ptr<TimeProvider> time_provider_;
686 686
687 bool extensions_disabled_; 687 bool extensions_disabled_;
688 688
689 base::ObserverList<ExtensionPrefsObserver> observer_list_; 689 base::ObserverList<ExtensionPrefsObserver> observer_list_;
690 690
691 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); 691 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs);
692 }; 692 };
693 693
694 } // namespace extensions 694 } // namespace extensions
695 695
696 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_ 696 #endif // EXTENSIONS_BROWSER_EXTENSION_PREFS_H_
OLDNEW
« no previous file with comments | « extensions/browser/extension_pref_value_map_unittest.cc ('k') | extensions/browser/extension_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698