OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 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 CHROME_BROWSER_CONTENT_SETTINGS_PREF_CONTENT_SETTINGS_PROVIDER_H_ | |
6 #define CHROME_BROWSER_CONTENT_SETTINGS_PREF_CONTENT_SETTINGS_PROVIDER_H_ | |
7 #pragma once | |
8 | |
9 // A content settings provider that takes its settings out of the pref service. | |
10 | |
11 #include "base/basictypes.h" | |
12 #include "base/lock.h" | |
13 #include "chrome/browser/content_settings/content_settings_provider.h" | |
14 #include "chrome/browser/prefs/pref_change_registrar.h" | |
15 #include "chrome/common/notification_observer.h" | |
16 #include "chrome/common/notification_registrar.h" | |
17 | |
18 class ContentSettingsDetails; | |
19 class DictionaryValue; | |
20 class PrefService; | |
21 class Profile; | |
22 | |
23 class PrefContentSettingsProvider : public ContentSettingsProviderInterface, | |
24 public NotificationObserver { | |
25 public: | |
26 PrefContentSettingsProvider(Profile* profile); | |
27 virtual ~PrefContentSettingsProvider(); | |
28 | |
29 // ContentSettingsProviderInterface implementation. | |
30 virtual bool CanProvideDefaultSetting(ContentSettingsType content_type) const; | |
31 virtual ContentSetting ProvideDefaultSetting( | |
32 ContentSettingsType content_type) const; | |
33 virtual void UpdateDefaultSetting(ContentSettingsType content_type, | |
34 ContentSetting setting); | |
35 virtual void ResetToDefaults(); | |
36 virtual bool DefaultSettingIsManaged(ContentSettingsType content_type) const; | |
37 | |
38 static void RegisterUserPrefs(PrefService* prefs); | |
39 | |
40 private: | |
41 // NotificationObserver implementation. | |
42 virtual void Observe(NotificationType type, | |
markusheintz_
2010/12/08 14:03:06
shoudn't the observe method be public?
jochen (gone - plz use gerrit)
2010/12/08 14:54:01
Done.
| |
43 const NotificationSource& source, | |
44 const NotificationDetails& details); | |
45 | |
46 // Informs observers that content settings have changed. Make sure that | |
47 // |lock_| is not held when calling this, as listeners will usually call one | |
48 // of the GetSettings functions in response, which would then lead to a | |
49 // mutex deadlock. | |
50 void NotifyObservers(const ContentSettingsDetails& details); | |
51 | |
52 void UnregisterObservers(); | |
53 | |
54 // Sets the fields of |settings| based on the values in |dictionary|. | |
55 void GetSettingsFromDictionary(const DictionaryValue* dictionary, | |
56 ContentSettings* settings); | |
57 | |
58 // Forces the default settings to be explicitly set instead of themselves | |
59 // being CONTENT_SETTING_DEFAULT. | |
60 void ForceDefaultsToBeExplicit(); | |
61 | |
62 // Reads the default settings from the prefereces service. If |overwrite| is | |
markusheintz_
2010/12/08 14:03:06
nit: s/prefereces/preference/
jochen (gone - plz use gerrit)
2010/12/08 14:54:01
Done.
| |
63 // true and the preference is missing, the local copy will be cleared as well. | |
64 void ReadDefaultSettings(bool overwrite); | |
65 | |
66 // Copies of the pref data, so that we can read it on the IO thread. | |
67 ContentSettings default_content_settings_; | |
68 | |
69 Profile* profile_; | |
70 | |
71 // Whether this settings map is for an OTR session. | |
72 bool is_off_the_record_; | |
73 | |
74 // Used around accesses to the settings_ object to guarantee thread safety. | |
75 mutable Lock lock_; | |
76 | |
77 PrefChangeRegistrar pref_change_registrar_; | |
78 NotificationRegistrar notification_registrar_; | |
79 | |
80 // Whether we are currently updating preferences, this is used to ignore | |
81 // notifications from the preferences service that we triggered ourself. | |
82 bool updating_preferences_; | |
83 | |
84 DISALLOW_COPY_AND_ASSIGN(PrefContentSettingsProvider); | |
85 }; | |
86 | |
87 #endif // CHROME_BROWSER_CONTENT_SETTINGS_PREF_CONTENT_SETTINGS_PROVIDER_H_ | |
OLD | NEW |