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

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

Issue 1257093002: Remove the migration code from content_settings::PrefProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Lock testing function. Created 5 years, 4 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 2015 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_H_ 5 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_
6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ 6 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 27 matching lines...) Expand all
38 typedef base::Callback<void(const ContentSettingsPattern&, 38 typedef base::Callback<void(const ContentSettingsPattern&,
39 const ContentSettingsPattern&, 39 const ContentSettingsPattern&,
40 ContentSettingsType, 40 ContentSettingsType,
41 const std::string&)> NotifyObserversCallback; 41 const std::string&)> NotifyObserversCallback;
42 42
43 ContentSettingsPref(ContentSettingsType content_type, 43 ContentSettingsPref(ContentSettingsType content_type,
44 PrefService* prefs, 44 PrefService* prefs,
45 PrefChangeRegistrar* registrar, 45 PrefChangeRegistrar* registrar,
46 const char* pref_name, 46 const char* pref_name,
47 bool incognito, 47 bool incognito,
48 bool* updating_old_preferences_flag,
49 NotifyObserversCallback notify_callback); 48 NotifyObserversCallback notify_callback);
50 ~ContentSettingsPref(); 49 ~ContentSettingsPref();
51 50
52 RuleIterator* GetRuleIterator(const ResourceIdentifier& resource_identifier, 51 RuleIterator* GetRuleIterator(const ResourceIdentifier& resource_identifier,
53 bool incognito) const; 52 bool incognito) const;
54 53
55 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern, 54 bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern,
56 const ContentSettingsPattern& secondary_pattern, 55 const ContentSettingsPattern& secondary_pattern,
57 const ResourceIdentifier& resource_identifier, 56 const ResourceIdentifier& resource_identifier,
58 base::Value* value); 57 base::Value* value);
59 58
60 void ClearAllContentSettingsRules(); 59 void ClearAllContentSettingsRules();
61 60
62 void UpdateLastUsage(const ContentSettingsPattern& primary_pattern, 61 void UpdateLastUsage(const ContentSettingsPattern& primary_pattern,
63 const ContentSettingsPattern& secondary_pattern, 62 const ContentSettingsPattern& secondary_pattern,
64 base::Clock* clock); 63 base::Clock* clock);
65 64
66 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern, 65 base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern,
67 const ContentSettingsPattern& secondary_pattern); 66 const ContentSettingsPattern& secondary_pattern);
68 67
69 size_t GetNumExceptions(); 68 size_t GetNumExceptions();
70 69
70 // Tries to lock |lock_|. If successful, returns true and releases the lock.
71 bool TryLockForTesting() const;
72
71 private: 73 private:
72 // Only to access static method CanonicalizeContentSettingsExceptions, 74 // TODO(msramek): Currently only needed in the unittest to get the
73 // so that we reduce duplicity between the two. 75 // corresponding pref name. Remove once pref names are in WebsiteSettingsInfo.
74 // TODO(msramek): Remove this after the migration is over. 76 friend class DeadlockCheckerObserver;
75 friend class PrefProvider;
76 77
77 // Reads all content settings exceptions from the preference and load them 78 // Reads all content settings exceptions from the preference and loads them
78 // into the |value_map_|. The |value_map_| is cleared first. 79 // into the |value_map_|. The |value_map_| is cleared first.
79 void ReadContentSettingsFromPrefAndWriteToOldPref(); 80 void ReadContentSettingsFromPref();
80 81
81 // Callback for changes in the pref with the same name. 82 // Callback for changes in the pref with the same name.
82 void OnPrefChanged(); 83 void OnPrefChanged();
83 84
84 // Update the preference that stores content settings exceptions and syncs the 85 // Update the preference that stores content settings exceptions and syncs the
85 // value to the obsolete preference. When calling this function, |lock_| 86 // value to the obsolete preference. When calling this function, |lock_|
86 // should not be held, since this function will send out notifications of 87 // should not be held, since this function will send out notifications of
87 // preference changes. 88 // preference changes.
88 void UpdatePref( 89 void UpdatePref(
89 const ContentSettingsPattern& primary_pattern, 90 const ContentSettingsPattern& primary_pattern,
90 const ContentSettingsPattern& secondary_pattern, 91 const ContentSettingsPattern& secondary_pattern,
91 const ResourceIdentifier& resource_identifier, 92 const ResourceIdentifier& resource_identifier,
92 const base::Value* value); 93 const base::Value* value);
93 94
94 static void CanonicalizeContentSettingsExceptions( 95 static void CanonicalizeContentSettingsExceptions(
95 base::DictionaryValue* all_settings_dictionary); 96 base::DictionaryValue* all_settings_dictionary);
96 97
97 // In the debug mode, asserts that |lock_| is not held by this thread. It's 98 // In the debug mode, asserts that |lock_| is not held by this thread. It's
98 // ok if some other thread holds |lock_|, as long as it will eventually 99 // ok if some other thread holds |lock_|, as long as it will eventually
99 // release it. 100 // release it.
100 void AssertLockNotHeld() const; 101 void AssertLockNotHeld() const;
101 102
102 // Update the old aggregate preference, so that the settings can be synced
103 // to old versions of Chrome.
104 // TODO(msramek): Remove after the migration is over.
105 void UpdateOldPref(
106 const ContentSettingsPattern& primary_pattern,
107 const ContentSettingsPattern& secondary_pattern,
108 const ResourceIdentifier& resource_identifier,
109 const base::Value* value);
110
111 // Remove all exceptions of |content_type_| from the old aggregate dictionary
112 // preference.
113 // TODO(msramek): Remove after the migration is over.
114 void ClearOldPreference();
115
116 // The type of content settings stored in this pref. 103 // The type of content settings stored in this pref.
117 ContentSettingsType content_type_; 104 ContentSettingsType content_type_;
118 105
119 // Weak; owned by the Profile and reset in ShutdownOnUIThread. 106 // Weak; owned by the Profile and reset in ShutdownOnUIThread.
120 PrefService* prefs_; 107 PrefService* prefs_;
121 108
122 // Owned by the PrefProvider. 109 // Owned by the PrefProvider.
123 PrefChangeRegistrar* registrar_; 110 PrefChangeRegistrar* registrar_;
124 111
125 // Name of the dictionary preference managed by this class. 112 // Name of the dictionary preference managed by this class.
126 const char* pref_name_; 113 const char* pref_name_;
127 114
128 bool is_incognito_; 115 bool is_incognito_;
129 116
130 // Whether we are currently updating preferences, this is used to ignore 117 // Whether we are currently updating preferences, this is used to ignore
131 // notifications from the preferences service that we triggered ourself. 118 // notifications from the preferences service that we triggered ourself.
132 bool updating_preferences_; 119 bool updating_preferences_;
133 120
134 // Whether we are currently updating the old aggregate dictionary preference.
135 // Owned by the parent |PrefProvider| and shared by all its children
136 // |ContentSettingsPref|s.
137 bool* updating_old_preferences_;
138
139 OriginIdentifierValueMap value_map_; 121 OriginIdentifierValueMap value_map_;
140 122
141 OriginIdentifierValueMap incognito_value_map_; 123 OriginIdentifierValueMap incognito_value_map_;
142 124
143 NotifyObserversCallback notify_callback_; 125 NotifyObserversCallback notify_callback_;
144 126
145 // Used around accesses to the value map objects to guarantee thread safety. 127 // Used around accesses to the value map objects to guarantee thread safety.
146 mutable base::Lock lock_; 128 mutable base::Lock lock_;
147 129
148 base::ThreadChecker thread_checker_; 130 base::ThreadChecker thread_checker_;
149 131
150 DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref); 132 DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref);
151 }; 133 };
152 134
153 } // namespace content_settings 135 } // namespace content_settings
154 136
155 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_ 137 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698