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

Side by Side Diff: components/content_settings/core/browser/content_settings_pref.h

Issue 976243002: Split content settings pref related logic into a separate class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_PROVIDER_ H_ 5 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_
6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_PROVIDER_ H_ 6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_
7 7
8 // A content settings provider that takes its settings out of the pref service. 8 #include <string>
9 9
10 #include <vector> 10 #include "base/callback.h"
11
12 #include "base/basictypes.h"
13 #include "base/prefs/pref_change_registrar.h"
14 #include "base/synchronization/lock.h" 11 #include "base/synchronization/lock.h"
15 #include "components/content_settings/core/browser/content_settings_observable_p rovider.h" 12 #include "base/threading/thread_checker.h"
13 #include "base/values.h"
16 #include "components/content_settings/core/browser/content_settings_origin_ident ifier_value_map.h" 14 #include "components/content_settings/core/browser/content_settings_origin_ident ifier_value_map.h"
17 #include "components/content_settings/core/browser/content_settings_utils.h" 15 #include "components/content_settings/core/browser/content_settings_provider.h"
16 #include "components/content_settings/core/common/content_settings_pattern.h"
17 #include "components/content_settings/core/common/content_settings_types.h"
18 18
19 class PrefService; 19 class PrefService;
20 class PrefChangeRegistrar;
20 21
21 namespace base { 22 namespace base {
22 class Clock; 23 class Clock;
23 class DictionaryValue; 24 class DictionaryValue;
24 } 25 }
25 26
26 namespace user_prefs { 27 namespace user_prefs {
27 class PrefRegistrySyncable; 28 class PrefRegistrySyncable;
28 } 29 }
29 30
30 namespace content_settings { 31 namespace content_settings {
31 32
32 // Content settings provider that provides content settings from the user 33 class RuleIterator;
33 // preference. 34
34 class PrefProvider : public ObservableProvider { 35 // Represents a single pref for reading/writing content settings.
36 // TODO(raymes): Currently all content settings types are stored in a single
37 // instance of one of these. But the intention is that there will be one
38 // instance of this class per content settings type.
39 class ContentSettingsPref {
35 public: 40 public:
36 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry); 41 typedef base::Callback<void(const ContentSettingsPattern&,
42 const ContentSettingsPattern&,
43 ContentSettingsType,
44 const std::string&)> NotifyObserversCallback;
37 45
38 PrefProvider(PrefService* prefs, bool incognito); 46 ContentSettingsPref(PrefService* prefs,
39 ~PrefProvider() override; 47 PrefChangeRegistrar* registrar,
48 base::Clock* clock,
49 bool incognito,
50 NotifyObserversCallback notify_callback);
51 ~ContentSettingsPref();
40 52
41 // ProviderInterface implementations.
42 RuleIterator* GetRuleIterator(ContentSettingsType content_type, 53 RuleIterator* GetRuleIterator(ContentSettingsType content_type,
43 const ResourceIdentifier& resource_identifier, 54 const ResourceIdentifier& resource_identifier,
44 bool incognito) const override; 55 bool incognito) const;
45 56
46 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern, 57 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern,
47 const ContentSettingsPattern& secondary_pattern, 58 const ContentSettingsPattern& secondary_pattern,
48 ContentSettingsType content_type, 59 ContentSettingsType content_type,
49 const ResourceIdentifier& resource_identifier, 60 const ResourceIdentifier& resource_identifier,
50 base::Value* value) override; 61 base::Value* value);
51 62
52 void ClearAllContentSettingsRules(ContentSettingsType content_type) override; 63 void ClearAllContentSettingsRules(ContentSettingsType content_type);
53 64
54 void ShutdownOnUIThread() override;
55
56 // Records the last time the given pattern has used a certain content setting.
57 void UpdateLastUsage(const ContentSettingsPattern& primary_pattern, 65 void UpdateLastUsage(const ContentSettingsPattern& primary_pattern,
58 const ContentSettingsPattern& secondary_pattern, 66 const ContentSettingsPattern& secondary_pattern,
59 ContentSettingsType content_type); 67 ContentSettingsType content_type);
60 68
61 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern, 69 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern,
62 const ContentSettingsPattern& secondary_pattern, 70 const ContentSettingsPattern& secondary_pattern,
63 ContentSettingsType content_type); 71 ContentSettingsType content_type);
64 72
65 // Gains ownership of |clock|. 73 size_t GetNumExceptions();
66 void SetClockForTesting(scoped_ptr<base::Clock> clock);
67 74
75 void SetClockForTesting(base::Clock* clock);
68 private: 76 private:
69 friend class DeadlockCheckerThread; // For testing. 77 friend class DeadlockCheckerThread; // For testing.
78
70 // Reads all content settings exceptions from the preference and load them 79 // Reads all content settings exceptions from the preference and load them
71 // into the |value_map_|. The |value_map_| is cleared first. 80 // into the |value_map_|. The |value_map_| is cleared first.
72 void ReadContentSettingsFromPref(); 81 void ReadContentSettingsFromPref();
73 82
74 // Callback for changes in the pref with the same name. 83 // Callback for changes in the pref with the same name.
75 void OnContentSettingsPatternPairsChanged(); 84 void OnContentSettingsPatternPairsChanged();
76 85
77 // Update the preference that stores content settings exceptions and syncs the 86 // Update the preference that stores content settings exceptions and syncs the
78 // value to the obsolete preference. When calling this function, |lock_| 87 // value to the obsolete preference. When calling this function, |lock_|
79 // should not be held, since this function will send out notifications of 88 // should not be held, since this function will send out notifications of
80 // preference changes. 89 // preference changes.
81 void UpdatePref( 90 void UpdatePref(
82 const ContentSettingsPattern& primary_pattern, 91 const ContentSettingsPattern& primary_pattern,
83 const ContentSettingsPattern& secondary_pattern, 92 const ContentSettingsPattern& secondary_pattern,
84 ContentSettingsType content_type, 93 ContentSettingsType content_type,
85 const ResourceIdentifier& resource_identifier, 94 const ResourceIdentifier& resource_identifier,
86 const base::Value* value); 95 const base::Value* value);
87 96
88 // Migrate the old media setting into new mic/camera content settings.
89 void MigrateObsoleteMediaContentSetting();
90
91 static void CanonicalizeContentSettingsExceptions( 97 static void CanonicalizeContentSettingsExceptions(
92 base::DictionaryValue* all_settings_dictionary); 98 base::DictionaryValue* all_settings_dictionary);
93 99
94 // In the debug mode, asserts that |lock_| is not held by this thread. It's 100 // In the debug mode, asserts that |lock_| is not held by this thread. It's
95 // ok if some other thread holds |lock_|, as long as it will eventually 101 // ok if some other thread holds |lock_|, as long as it will eventually
96 // release it. 102 // release it.
97 void AssertLockNotHeld() const; 103 void AssertLockNotHeld() const;
98 104
99 // Weak; owned by the Profile and reset in ShutdownOnUIThread. 105 // Weak; owned by the Profile and reset in ShutdownOnUIThread.
100 PrefService* prefs_; 106 PrefService* prefs_;
101 107
102 // Can be set for testing. 108 // Owned by the PrefProvider.
103 scoped_ptr<base::Clock> clock_; 109 base::Clock* clock_;
110
111 // Owned by the PrefProvider.
112 PrefChangeRegistrar* registrar_;
104 113
105 bool is_incognito_; 114 bool is_incognito_;
106 115
107 PrefChangeRegistrar pref_change_registrar_;
108
109 // Whether we are currently updating preferences, this is used to ignore 116 // Whether we are currently updating preferences, this is used to ignore
110 // notifications from the preferences service that we triggered ourself. 117 // notifications from the preferences service that we triggered ourself.
111 bool updating_preferences_; 118 bool updating_preferences_;
112 119
113 OriginIdentifierValueMap value_map_; 120 OriginIdentifierValueMap value_map_;
114 121
115 OriginIdentifierValueMap incognito_value_map_; 122 OriginIdentifierValueMap incognito_value_map_;
116 123
124 NotifyObserversCallback notify_callback_;
125
117 // Used around accesses to the value map objects to guarantee thread safety. 126 // Used around accesses to the value map objects to guarantee thread safety.
118 mutable base::Lock lock_; 127 mutable base::Lock lock_;
119 128
120 DISALLOW_COPY_AND_ASSIGN(PrefProvider); 129 base::ThreadChecker thread_checker_;
130
131 DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref);
121 }; 132 };
122 133
123 } // namespace content_settings 134 } // namespace content_settings
124 135
125 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_PROVID ER_H_ 136 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_
OLDNEW
« no previous file with comments | « components/content_settings/core/browser/BUILD.gn ('k') | components/content_settings/core/browser/content_settings_pref.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698