OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/linked_ptr.h" | 12 #include "base/memory/linked_ptr.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" | 16 #include "chrome/browser/extensions/api/content_settings/content_settings_store.
h" |
17 #include "chrome/browser/extensions/extension_prefs_scope.h" | 17 #include "chrome/browser/extensions/extension_prefs_scope.h" |
18 #include "chrome/browser/extensions/extension_scoped_prefs.h" | 18 #include "chrome/browser/extensions/extension_scoped_prefs.h" |
19 #include "chrome/browser/media_gallery/media_galleries_preferences.h" | 19 #include "chrome/browser/media_gallery/media_galleries_preferences.h" |
20 #include "chrome/common/extensions/extension.h" | 20 #include "chrome/common/extensions/extension.h" |
21 #include "extensions/common/url_pattern_set.h" | 21 #include "extensions/common/url_pattern_set.h" |
22 #include "sync/api/string_ordinal.h" | 22 #include "sync/api/string_ordinal.h" |
23 | 23 |
24 class ExtensionPrefValueMap; | 24 class ExtensionPrefValueMap; |
25 class ExtensionSorting; | 25 class ExtensionSorting; |
26 class PrefService; | 26 class PrefService; |
27 class PrefServiceSyncable; | 27 class PrefRegistrySyncable; |
28 | 28 |
29 namespace extensions { | 29 namespace extensions { |
30 class ExtensionPrefsUninstallExtension; | 30 class ExtensionPrefsUninstallExtension; |
31 class URLPatternSet; | 31 class URLPatternSet; |
32 struct ExtensionOmniboxSuggestion; | 32 struct ExtensionOmniboxSuggestion; |
33 | 33 |
34 // Class for managing global and per-extension preferences. | 34 // Class for managing global and per-extension preferences. |
35 // | 35 // |
36 // This class distinguishes the following kinds of preferences: | 36 // This class distinguishes the following kinds of preferences: |
37 // - global preferences: | 37 // - global preferences: |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // By default, returns the current time (base::Time::Now()). | 86 // By default, returns the current time (base::Time::Now()). |
87 virtual base::Time GetCurrentTime() const; | 87 virtual base::Time GetCurrentTime() const; |
88 | 88 |
89 private: | 89 private: |
90 DISALLOW_COPY_AND_ASSIGN(TimeProvider); | 90 DISALLOW_COPY_AND_ASSIGN(TimeProvider); |
91 }; | 91 }; |
92 | 92 |
93 // Creates and initializes an ExtensionPrefs object. | 93 // Creates and initializes an ExtensionPrefs object. |
94 // Does not take ownership of |prefs| and |extension_pref_value_map|. | 94 // Does not take ownership of |prefs| and |extension_pref_value_map|. |
95 static scoped_ptr<ExtensionPrefs> Create( | 95 static scoped_ptr<ExtensionPrefs> Create( |
96 PrefServiceSyncable* prefs, | 96 PrefService* prefs, |
97 const base::FilePath& root_dir, | 97 const base::FilePath& root_dir, |
98 ExtensionPrefValueMap* extension_pref_value_map, | 98 ExtensionPrefValueMap* extension_pref_value_map, |
99 bool extensions_disabled); | 99 bool extensions_disabled); |
100 | 100 |
101 // A version of Create which allows injection of a custom base::Time provider. | 101 // A version of Create which allows injection of a custom base::Time provider. |
102 // Use this as needed for testing. | 102 // Use this as needed for testing. |
103 static scoped_ptr<ExtensionPrefs> Create( | 103 static scoped_ptr<ExtensionPrefs> Create( |
104 PrefServiceSyncable* prefs, | 104 PrefService* prefs, |
105 const base::FilePath& root_dir, | 105 const base::FilePath& root_dir, |
106 ExtensionPrefValueMap* extension_pref_value_map, | 106 ExtensionPrefValueMap* extension_pref_value_map, |
107 bool extensions_disabled, | 107 bool extensions_disabled, |
108 scoped_ptr<TimeProvider> time_provider); | 108 scoped_ptr<TimeProvider> time_provider); |
109 | 109 |
110 virtual ~ExtensionPrefs(); | 110 virtual ~ExtensionPrefs(); |
111 | 111 |
112 // Returns all installed extensions from extension preferences provided by | 112 // Returns all installed extensions from extension preferences provided by |
113 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs | 113 // |pref_service|. This is exposed for ProtectedPrefsWatcher because it needs |
114 // access to the extension ID list before the ExtensionService is initialized. | 114 // access to the extension ID list before the ExtensionService is initialized. |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 bool IsFromBookmark(const std::string& extension_id) const; | 472 bool IsFromBookmark(const std::string& extension_id) const; |
473 | 473 |
474 // Returns true if the extension was installed as a default app. | 474 // Returns true if the extension was installed as a default app. |
475 bool WasInstalledByDefault(const std::string& extension_id) const; | 475 bool WasInstalledByDefault(const std::string& extension_id) const; |
476 | 476 |
477 // Helper method to acquire the installation time of an extension. | 477 // Helper method to acquire the installation time of an extension. |
478 // Returns base::Time() if the installation time could not be parsed or | 478 // Returns base::Time() if the installation time could not be parsed or |
479 // found. | 479 // found. |
480 base::Time GetInstallTime(const std::string& extension_id) const; | 480 base::Time GetInstallTime(const std::string& extension_id) const; |
481 | 481 |
482 static void RegisterUserPrefs(PrefServiceSyncable* prefs); | 482 static void RegisterUserPrefs(PrefRegistrySyncable* registry); |
483 | 483 |
484 ContentSettingsStore* content_settings_store() { | 484 ContentSettingsStore* content_settings_store() { |
485 return content_settings_store_.get(); | 485 return content_settings_store_.get(); |
486 } | 486 } |
487 | 487 |
488 // The underlying PrefService. | 488 // The underlying PrefService. |
489 PrefServiceSyncable* pref_service() const { return prefs_; } | 489 PrefService* pref_service() const { return prefs_; } |
490 | 490 |
491 // The underlying ExtensionSorting. | 491 // The underlying ExtensionSorting. |
492 ExtensionSorting* extension_sorting() const { | 492 ExtensionSorting* extension_sorting() const { |
493 return extension_sorting_.get(); | 493 return extension_sorting_.get(); |
494 } | 494 } |
495 | 495 |
496 // Describes the URLs that are able to install extensions. See | 496 // Describes the URLs that are able to install extensions. See |
497 // prefs::kExtensionAllowedInstallSites for more information. | 497 // prefs::kExtensionAllowedInstallSites for more information. |
498 URLPatternSet GetAllowedInstallSites(); | 498 URLPatternSet GetAllowedInstallSites(); |
499 | 499 |
500 // Schedules garbage collection of an extension's on-disk data on the next | 500 // Schedules garbage collection of an extension's on-disk data on the next |
501 // start of this ExtensionService. Applies only to extensions with isolated | 501 // start of this ExtensionService. Applies only to extensions with isolated |
502 // storage. | 502 // storage. |
503 void SetNeedsStorageGarbageCollection(bool value); | 503 void SetNeedsStorageGarbageCollection(bool value); |
504 bool NeedsStorageGarbageCollection(); | 504 bool NeedsStorageGarbageCollection(); |
505 | 505 |
506 // Used by ShellWindowGeometryCache to persist its cache. These methods | 506 // Used by ShellWindowGeometryCache to persist its cache. These methods |
507 // should not be called directly. | 507 // should not be called directly. |
508 const base::DictionaryValue* GetGeometryCache( | 508 const base::DictionaryValue* GetGeometryCache( |
509 const std::string& extension_id) const; | 509 const std::string& extension_id) const; |
510 void SetGeometryCache(const std::string& extension_id, | 510 void SetGeometryCache(const std::string& extension_id, |
511 scoped_ptr<base::DictionaryValue> cache); | 511 scoped_ptr<base::DictionaryValue> cache); |
512 | 512 |
513 private: | 513 private: |
514 friend class ExtensionPrefsBlacklistedExtensions; // Unit test. | 514 friend class ExtensionPrefsBlacklistedExtensions; // Unit test. |
515 friend class ExtensionPrefsUninstallExtension; // Unit test. | 515 friend class ExtensionPrefsUninstallExtension; // Unit test. |
516 | 516 |
517 // See the Create methods. | 517 // See the Create methods. |
518 ExtensionPrefs(PrefServiceSyncable* prefs, | 518 ExtensionPrefs(PrefService* prefs, |
519 const base::FilePath& root_dir, | 519 const base::FilePath& root_dir, |
520 ExtensionPrefValueMap* extension_pref_value_map, | 520 ExtensionPrefValueMap* extension_pref_value_map, |
521 scoped_ptr<TimeProvider> time_provider); | 521 scoped_ptr<TimeProvider> time_provider); |
522 | 522 |
523 // If |extensions_disabled| is true, extension controlled preferences and | 523 // If |extensions_disabled| is true, extension controlled preferences and |
524 // content settings do not become effective. | 524 // content settings do not become effective. |
525 void Init(bool extensions_disabled); | 525 void Init(bool extensions_disabled); |
526 | 526 |
527 // extensions::ContentSettingsStore::Observer methods: | 527 // extensions::ContentSettingsStore::Observer methods: |
528 virtual void OnContentSettingChanged(const std::string& extension_id, | 528 virtual void OnContentSettingChanged(const std::string& extension_id, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
628 // |extension_dict| for an extension install. Also see | 628 // |extension_dict| for an extension install. Also see |
629 // PopulateExtensionInfoPrefs(). | 629 // PopulateExtensionInfoPrefs(). |
630 void FinishExtensionInfoPrefs( | 630 void FinishExtensionInfoPrefs( |
631 const std::string& extension_id, | 631 const std::string& extension_id, |
632 const base::Time install_time, | 632 const base::Time install_time, |
633 bool needs_sort_ordinal, | 633 bool needs_sort_ordinal, |
634 const syncer::StringOrdinal& suggested_page_ordinal, | 634 const syncer::StringOrdinal& suggested_page_ordinal, |
635 DictionaryValue* extension_dict); | 635 DictionaryValue* extension_dict); |
636 | 636 |
637 // The pref service specific to this set of extension prefs. Owned by profile. | 637 // The pref service specific to this set of extension prefs. Owned by profile. |
638 PrefServiceSyncable* prefs_; | 638 PrefService* prefs_; |
639 | 639 |
640 // Base extensions install directory. | 640 // Base extensions install directory. |
641 base::FilePath install_directory_; | 641 base::FilePath install_directory_; |
642 | 642 |
643 // Weak pointer, owned by Profile. | 643 // Weak pointer, owned by Profile. |
644 ExtensionPrefValueMap* extension_pref_value_map_; | 644 ExtensionPrefValueMap* extension_pref_value_map_; |
645 | 645 |
646 // Contains all the logic for handling the order for various extension | 646 // Contains all the logic for handling the order for various extension |
647 // properties. | 647 // properties. |
648 scoped_ptr<ExtensionSorting> extension_sorting_; | 648 scoped_ptr<ExtensionSorting> extension_sorting_; |
649 | 649 |
650 scoped_refptr<ContentSettingsStore> content_settings_store_; | 650 scoped_refptr<ContentSettingsStore> content_settings_store_; |
651 | 651 |
652 scoped_ptr<TimeProvider> time_provider_; | 652 scoped_ptr<TimeProvider> time_provider_; |
653 | 653 |
654 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); | 654 DISALLOW_COPY_AND_ASSIGN(ExtensionPrefs); |
655 }; | 655 }; |
656 | 656 |
657 } // namespace extensions | 657 } // namespace extensions |
658 | 658 |
659 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ | 659 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_PREFS_H_ |
OLD | NEW |