| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_DEFAULT_PROVIDER_H_ | 5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_ | 6 #define CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <map> |
| 8 #include <string> | 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/memory/linked_ptr.h" |
| 12 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 13 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" | 15 #include "chrome/browser/content_settings/content_settings_observable_provider.h
" |
| 14 #include "chrome/browser/prefs/pref_change_registrar.h" | 16 #include "chrome/browser/prefs/pref_change_registrar.h" |
| 15 #include "content/public/browser/notification_observer.h" | 17 #include "content/public/browser/notification_observer.h" |
| 16 #include "content/public/browser/notification_registrar.h" | 18 #include "content/public/browser/notification_registrar.h" |
| 17 | 19 |
| 18 class PrefService; | 20 class PrefService; |
| 19 | 21 |
| 20 namespace content_settings { | 22 namespace content_settings { |
| 21 | 23 |
| 22 // Provider that provides default content settings based on | 24 // Provider that provides default content settings based on |
| 23 // user prefs. If no default values are set by the user we use the hard coded | 25 // user prefs. If no default values are set by the user we use the hard coded |
| 24 // default values. | 26 // default values. |
| 25 class DefaultProvider : public ObservableProvider, | 27 class DefaultProvider : public ObservableProvider, |
| 26 public content::NotificationObserver { | 28 public content::NotificationObserver { |
| 27 public: | 29 public: |
| 28 static void RegisterUserPrefs(PrefService* prefs); | 30 static void RegisterUserPrefs(PrefService* prefs); |
| 29 | 31 |
| 30 DefaultProvider(PrefService* prefs, | 32 DefaultProvider(PrefService* prefs, |
| 31 bool incognito); | 33 bool incognito); |
| 32 virtual ~DefaultProvider(); | 34 virtual ~DefaultProvider(); |
| 33 | 35 |
| 34 // ProviderInterface implementations. | 36 // ProviderInterface implementations. |
| 35 virtual RuleIterator* GetRuleIterator( | 37 virtual RuleIterator* GetRuleIterator( |
| 36 ContentSettingsType content_type, | 38 ContentSettingsType content_type, |
| 37 const ResourceIdentifier& resource_identifier, | 39 const ResourceIdentifier& resource_identifier, |
| 38 bool incognito) const OVERRIDE; | 40 bool incognito) const OVERRIDE; |
| 39 | 41 |
| 40 virtual void SetContentSetting( | 42 virtual void SetWebsiteSetting( |
| 41 const ContentSettingsPattern& primary_pattern, | 43 const ContentSettingsPattern& primary_pattern, |
| 42 const ContentSettingsPattern& secondary_pattern, | 44 const ContentSettingsPattern& secondary_pattern, |
| 43 ContentSettingsType content_type, | 45 ContentSettingsType content_type, |
| 44 const ResourceIdentifier& resource_identifier, | 46 const ResourceIdentifier& resource_identifier, |
| 45 ContentSetting content_setting) OVERRIDE; | 47 const Value* value) OVERRIDE; |
| 46 | 48 |
| 47 virtual void ClearAllContentSettingsRules( | 49 virtual void ClearAllContentSettingsRules( |
| 48 ContentSettingsType content_type) OVERRIDE; | 50 ContentSettingsType content_type) OVERRIDE; |
| 49 | 51 |
| 50 virtual void ShutdownOnUIThread() OVERRIDE; | 52 virtual void ShutdownOnUIThread() OVERRIDE; |
| 51 | 53 |
| 52 // content::NotificationObserver implementation. | 54 // content::NotificationObserver implementation. |
| 53 virtual void Observe(int type, | 55 virtual void Observe(int type, |
| 54 const content::NotificationSource& source, | 56 const content::NotificationSource& source, |
| 55 const content::NotificationDetails& details) OVERRIDE; | 57 const content::NotificationDetails& details) OVERRIDE; |
| 56 | 58 |
| 57 private: | 59 private: |
| 58 // Sets the fields of |settings| based on the values in |dictionary|. | 60 // Sets the fields of |settings| based on the values in |dictionary|. |
| 59 void GetSettingsFromDictionary(const base::DictionaryValue* dictionary, | 61 void GetSettingsFromDictionary(const base::DictionaryValue* dictionary); |
| 60 ContentSettings* settings); | |
| 61 | 62 |
| 62 // Forces the default settings to be explicitly set instead of themselves | 63 // Forces the default settings to be explicitly set instead of themselves |
| 63 // being CONTENT_SETTING_DEFAULT. | 64 // being CONTENT_SETTING_DEFAULT. |
| 64 void ForceDefaultsToBeExplicit(); | 65 void ForceDefaultsToBeExplicit(); |
| 65 | 66 |
| 66 // Reads the default settings from the preferences service. If |overwrite| is | 67 // Reads the default settings from the preferences service. If |overwrite| is |
| 67 // true and the preference is missing, the local copy will be cleared as well. | 68 // true and the preference is missing, the local copy will be cleared as well. |
| 68 void ReadDefaultSettings(bool overwrite); | 69 void ReadDefaultSettings(bool overwrite); |
| 69 | 70 |
| 70 void MigrateObsoleteNotificationPref(); | 71 void MigrateObsoleteNotificationPref(); |
| 71 void MigrateObsoleteGeolocationPref(); | 72 void MigrateObsoleteGeolocationPref(); |
| 72 | 73 |
| 74 typedef linked_ptr<base::Value> ValuePtr; |
| 75 typedef std::map<ContentSettingsType, ValuePtr> ValueMap; |
| 73 // Copies of the pref data, so that we can read it on the IO thread. | 76 // Copies of the pref data, so that we can read it on the IO thread. |
| 74 ContentSettings default_content_settings_; | 77 ValueMap default_settings_; |
| 75 | 78 |
| 76 PrefService* prefs_; | 79 PrefService* prefs_; |
| 77 | 80 |
| 78 // Whether this settings map is for an Incognito session. | 81 // Whether this settings map is for an Incognito session. |
| 79 bool is_incognito_; | 82 bool is_incognito_; |
| 80 | 83 |
| 81 // Used around accesses to the |default_content_settings_| object to guarantee | 84 // Used around accesses to the |default_content_settings_| object to guarantee |
| 82 // thread safety. | 85 // thread safety. |
| 83 mutable base::Lock lock_; | 86 mutable base::Lock lock_; |
| 84 | 87 |
| 85 PrefChangeRegistrar pref_change_registrar_; | 88 PrefChangeRegistrar pref_change_registrar_; |
| 86 | 89 |
| 87 // Whether we are currently updating preferences, this is used to ignore | 90 // Whether we are currently updating preferences, this is used to ignore |
| 88 // notifications from the preferences service that we triggered ourself. | 91 // notifications from the preferences service that we triggered ourself. |
| 89 bool updating_preferences_; | 92 bool updating_preferences_; |
| 90 | 93 |
| 91 DISALLOW_COPY_AND_ASSIGN(DefaultProvider); | 94 DISALLOW_COPY_AND_ASSIGN(DefaultProvider); |
| 92 }; | 95 }; |
| 93 | 96 |
| 94 } // namespace content_settings | 97 } // namespace content_settings |
| 95 | 98 |
| 96 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_ | 99 #endif // CHROME_BROWSER_CONTENT_SETTINGS_CONTENT_SETTINGS_DEFAULT_PROVIDER_H_ |
| OLD | NEW |