| 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_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
| 7 | 7 |
| 8 // A content settings provider that takes its settings out of the pref service. | 8 // A content settings provider that takes its settings out of the pref service. |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/prefs/public/pref_change_registrar.h" | 13 #include "base/prefs/public/pref_change_registrar.h" |
| 14 #include "base/prefs/public/pref_observer.h" | |
| 15 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 16 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" | 15 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" |
| 17 #include "chrome/browser/content_settings/content_settings_origin_identifier_val
ue_map.h" | 16 #include "chrome/browser/content_settings/content_settings_origin_identifier_val
ue_map.h" |
| 18 #include "chrome/browser/content_settings/content_settings_utils.h" | 17 #include "chrome/browser/content_settings/content_settings_utils.h" |
| 19 | 18 |
| 20 class PrefService; | 19 class PrefService; |
| 21 | 20 |
| 22 namespace base { | 21 namespace base { |
| 23 class DictionaryValue; | 22 class DictionaryValue; |
| 24 } | 23 } |
| 25 | 24 |
| 26 namespace content_settings { | 25 namespace content_settings { |
| 27 | 26 |
| 28 // Content settings provider that provides content settings from the user | 27 // Content settings provider that provides content settings from the user |
| 29 // preference. | 28 // preference. |
| 30 class PrefProvider : public ObservableProvider, | 29 class PrefProvider : public ObservableProvider { |
| 31 public PrefObserver { | |
| 32 public: | 30 public: |
| 33 static void RegisterUserPrefs(PrefService* prefs); | 31 static void RegisterUserPrefs(PrefService* prefs); |
| 34 | 32 |
| 35 PrefProvider(PrefService* prefs, | 33 PrefProvider(PrefService* prefs, |
| 36 bool incognito); | 34 bool incognito); |
| 37 virtual ~PrefProvider(); | 35 virtual ~PrefProvider(); |
| 38 | 36 |
| 39 // ProviderInterface implementations. | 37 // ProviderInterface implementations. |
| 40 virtual RuleIterator* GetRuleIterator( | 38 virtual RuleIterator* GetRuleIterator( |
| 41 ContentSettingsType content_type, | 39 ContentSettingsType content_type, |
| 42 const ResourceIdentifier& resource_identifier, | 40 const ResourceIdentifier& resource_identifier, |
| 43 bool incognito) const OVERRIDE; | 41 bool incognito) const OVERRIDE; |
| 44 | 42 |
| 45 virtual bool SetWebsiteSetting( | 43 virtual bool SetWebsiteSetting( |
| 46 const ContentSettingsPattern& primary_pattern, | 44 const ContentSettingsPattern& primary_pattern, |
| 47 const ContentSettingsPattern& secondary_pattern, | 45 const ContentSettingsPattern& secondary_pattern, |
| 48 ContentSettingsType content_type, | 46 ContentSettingsType content_type, |
| 49 const ResourceIdentifier& resource_identifier, | 47 const ResourceIdentifier& resource_identifier, |
| 50 Value* value) OVERRIDE; | 48 Value* value) OVERRIDE; |
| 51 | 49 |
| 52 virtual void ClearAllContentSettingsRules( | 50 virtual void ClearAllContentSettingsRules( |
| 53 ContentSettingsType content_type) OVERRIDE; | 51 ContentSettingsType content_type) OVERRIDE; |
| 54 | 52 |
| 55 virtual void ShutdownOnUIThread() OVERRIDE; | 53 virtual void ShutdownOnUIThread() OVERRIDE; |
| 56 | 54 |
| 57 // PrefObserver implementation. | |
| 58 virtual void OnPreferenceChanged(PrefServiceBase* service, | |
| 59 const std::string& pref_name) OVERRIDE; | |
| 60 | |
| 61 private: | 55 private: |
| 62 friend class DeadlockCheckerThread; // For testing. | 56 friend class DeadlockCheckerThread; // For testing. |
| 63 // Reads all content settings exceptions from the preference and load them | 57 // Reads all content settings exceptions from the preference and load them |
| 64 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is | 58 // into the |value_map_|. The |value_map_| is cleared first if |overwrite| is |
| 65 // true. | 59 // true. |
| 66 void ReadContentSettingsFromPref(bool overwrite); | 60 void ReadContentSettingsFromPref(bool overwrite); |
| 67 | 61 |
| 62 // Callback for changes in the pref with the same name. |
| 63 void OnContentSettingsPatternPairsChanged(); |
| 64 |
| 68 // Update the preference that stores content settings exceptions and syncs the | 65 // Update the preference that stores content settings exceptions and syncs the |
| 69 // value to the obsolete preference. When calling this function, |lock_| | 66 // value to the obsolete preference. When calling this function, |lock_| |
| 70 // should not be held, since this function will send out notifications of | 67 // should not be held, since this function will send out notifications of |
| 71 // preference changes. | 68 // preference changes. |
| 72 void UpdatePref( | 69 void UpdatePref( |
| 73 const ContentSettingsPattern& primary_pattern, | 70 const ContentSettingsPattern& primary_pattern, |
| 74 const ContentSettingsPattern& secondary_pattern, | 71 const ContentSettingsPattern& secondary_pattern, |
| 75 ContentSettingsType content_type, | 72 ContentSettingsType content_type, |
| 76 const ResourceIdentifier& resource_identifier, | 73 const ResourceIdentifier& resource_identifier, |
| 77 const base::Value* value); | 74 const base::Value* value); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 112 |
| 116 // Used around accesses to the value map objects to guarantee thread safety. | 113 // Used around accesses to the value map objects to guarantee thread safety. |
| 117 mutable base::Lock lock_; | 114 mutable base::Lock lock_; |
| 118 | 115 |
| 119 DISALLOW_COPY_AND_ASSIGN(PrefProvider); | 116 DISALLOW_COPY_AND_ASSIGN(PrefProvider); |
| 120 }; | 117 }; |
| 121 | 118 |
| 122 } // namespace content_settings | 119 } // namespace content_settings |
| 123 | 120 |
| 124 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ | 121 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_PREF_PROVIDER_H_ |
| OLD | NEW |