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

Side by Side Diff: chrome/browser/content_settings/host_content_settings_map.h

Issue 7713034: HostContentSettingsMap refactoring. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Tiny fixes (unnecessary #includes, win + mac fixes). Created 9 years, 3 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 | Annotate | Revision Log
OLDNEW
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 // Maps hostnames to custom content settings. Written on the UI thread and read 5 // Maps hostnames to custom content settings. Written on the UI thread and read
6 // on any thread. One instance per profile. 6 // on any thread. One instance per profile.
7 7
8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ 8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_
9 #define CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ 9 #define CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_
10 #pragma once 10 #pragma once
11 11
12 #include <map> 12 #include <map>
13 #include <string> 13 #include <string>
14 #include <utility> 14 #include <utility>
15 #include <vector> 15 #include <vector>
16 16
17 #include "base/basictypes.h" 17 #include "base/basictypes.h"
18 #include "base/memory/linked_ptr.h" 18 #include "base/memory/linked_ptr.h"
19 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
20 #include "base/synchronization/lock.h" 20 #include "base/synchronization/lock.h"
21 #include "chrome/browser/content_settings/content_settings_pattern.h" 21 #include "chrome/browser/content_settings/content_settings_pattern.h"
22 #include "chrome/browser/content_settings/content_settings_observer.h" 22 #include "chrome/browser/content_settings/content_settings_observer.h"
23 #include "chrome/browser/prefs/pref_change_registrar.h"
24 #include "chrome/common/content_settings.h" 23 #include "chrome/common/content_settings.h"
25 #include "content/browser/browser_thread.h" 24 #include "content/browser/browser_thread.h"
26 #include "content/common/notification_observer.h" 25 #include "content/common/notification_observer.h"
27 #include "content/common/notification_registrar.h" 26 #include "content/common/notification_registrar.h"
28 27
29 namespace content_settings { 28 namespace content_settings {
30 class DefaultProviderInterface; 29 class DefaultProviderInterface;
31 class ProviderInterface; 30 class ProviderInterface;
32 } // namespace content_settings 31 } // namespace content_settings
33 32
34 class ContentSettingsDetails; 33 class ContentSettingsDetails;
35 class ExtensionService; 34 class ExtensionService;
36 class GURL; 35 class GURL;
37 class PrefService; 36 class PrefService;
38 class Profile; 37 class Profile;
39 38
40 class HostContentSettingsMap 39 class HostContentSettingsMap
41 : public content_settings::Observer, 40 : public content_settings::Observer,
42 public NotificationObserver,
43 public base::RefCountedThreadSafe<HostContentSettingsMap> { 41 public base::RefCountedThreadSafe<HostContentSettingsMap> {
44 public: 42 public:
45 // TODO(markusheintz): I sold my soul to the devil on order to add this tuple. 43 // TODO(markusheintz): I sold my soul to the devil on order to add this tuple.
46 // I really want my soul back, so I really will change this ASAP. 44 // I really want my soul back, so I really will change this ASAP.
47 typedef Tuple4<ContentSettingsPattern, 45 typedef Tuple4<ContentSettingsPattern,
48 ContentSettingsPattern, 46 ContentSettingsPattern,
49 ContentSetting, 47 ContentSetting,
50 std::string> PatternSettingSourceTuple; 48 std::string> PatternSettingSourceTuple;
51 typedef std::vector<PatternSettingSourceTuple> SettingsForOneType; 49 typedef std::vector<PatternSettingSourceTuple> SettingsForOneType;
52 50
(...skipping 19 matching lines...) Expand all
72 // require an resource identifier to be specified, the |resource_identifier| 70 // require an resource identifier to be specified, the |resource_identifier|
73 // must be non-empty. 71 // must be non-empty.
74 // 72 //
75 // This may be called on any thread. 73 // This may be called on any thread.
76 ContentSetting GetContentSetting( 74 ContentSetting GetContentSetting(
77 const GURL& primary_url, 75 const GURL& primary_url,
78 const GURL& secondary_url, 76 const GURL& secondary_url,
79 ContentSettingsType content_type, 77 ContentSettingsType content_type,
80 const std::string& resource_identifier) const; 78 const std::string& resource_identifier) const;
81 79
82 // Gets the content setting for cookies. This takes the third party cookie
83 // flag into account, and therefore needs to know whether we read or write a
84 // cookie.
85 //
86 // This may be called on any thread.
87 ContentSetting GetCookieContentSetting(
88 const GURL& url,
89 const GURL& first_party_url,
90 bool setting_cookie) const;
91
92 // Returns all ContentSettings which apply to the given URLs. For content 80 // Returns all ContentSettings which apply to the given URLs. For content
93 // setting types that require an additional resource identifier, the default 81 // setting types that require an additional resource identifier, the default
94 // content setting is returned. 82 // content setting is returned.
95 // 83 //
96 // This may be called on any thread. 84 // This may be called on any thread.
97 ContentSettings GetContentSettings( 85 ContentSettings GetContentSettings(
98 const GURL& primary_url, 86 const GURL& primary_url,
99 const GURL& secondary_url) const; 87 const GURL& secondary_url) const;
100 88
101 // For a given content type, returns all patterns with a non-default setting, 89 // For a given content type, returns all patterns with a non-default setting,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 ContentSetting setting); 131 ContentSetting setting);
144 132
145 // Clears all host-specific settings for one content type. 133 // Clears all host-specific settings for one content type.
146 // 134 //
147 // This should only be called on the UI thread. 135 // This should only be called on the UI thread.
148 void ClearSettingsForOneType(ContentSettingsType content_type); 136 void ClearSettingsForOneType(ContentSettingsType content_type);
149 137
150 static bool IsSettingAllowedForType(ContentSetting setting, 138 static bool IsSettingAllowedForType(ContentSetting setting,
151 ContentSettingsType content_type); 139 ContentSettingsType content_type);
152 140
153 // This setting trumps any host-specific settings.
154 bool BlockThirdPartyCookies() const { return block_third_party_cookies_; }
155 bool IsBlockThirdPartyCookiesManaged() const {
156 return is_block_third_party_cookies_managed_;
157 }
158
159 // Sets whether we block all third-party cookies. This method must not be
160 // invoked on an incognito map.
161 //
162 // This should only be called on the UI thread.
163 void SetBlockThirdPartyCookies(bool block);
164
165 // Returns true if the default setting for the |content_type| is managed. 141 // Returns true if the default setting for the |content_type| is managed.
166 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const; 142 bool IsDefaultContentSettingManaged(ContentSettingsType content_type) const;
167 143
168 // Detaches the HostContentSettingsMap from all Profile-related objects like 144 // Detaches the HostContentSettingsMap from all Profile-related objects like
169 // PrefService. This methods needs to be called before destroying the Profile. 145 // PrefService. This methods needs to be called before destroying the Profile.
170 // Afterwards, none of the methods above that should only be called on the UI 146 // Afterwards, none of the methods above that should only be called on the UI
171 // thread should be called anymore. 147 // thread should be called anymore.
172 void ShutdownOnUIThread(); 148 void ShutdownOnUIThread();
173 149
174 // content_settings::Observer implementation. 150 // content_settings::Observer implementation.
175 virtual void OnContentSettingChanged( 151 virtual void OnContentSettingChanged(
176 ContentSettingsPattern primary_pattern, 152 ContentSettingsPattern primary_pattern,
177 ContentSettingsPattern secondary_pattern, 153 ContentSettingsPattern secondary_pattern,
178 ContentSettingsType content_type, 154 ContentSettingsType content_type,
179 std::string resource_identifier); 155 std::string resource_identifier);
180 156
181 // NotificationObserver implementation. 157 static bool ShouldAllowAllContent(const GURL& url,
182 virtual void Observe(int type, 158 ContentSettingsType content_type);
183 const NotificationSource& source,
184 const NotificationDetails& details);
185 159
186 private: 160 private:
187 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; 161 friend class base::RefCountedThreadSafe<HostContentSettingsMap>;
162 friend class CookieSettings;
188 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; 163 friend class HostContentSettingsMapTest_NonDefaultSettings_Test;
189 164
190 virtual ~HostContentSettingsMap(); 165 virtual ~HostContentSettingsMap();
191 166
192 // Returns all non-default ContentSettings which apply to the given URLs. For 167 // Returns all non-default ContentSettings which apply to the given URLs. For
193 // content setting types that require an additional resource identifier, 168 // content setting types that require an additional resource identifier,
194 // CONTENT_SETTING_DEFAULT is returned. 169 // CONTENT_SETTING_DEFAULT is returned.
195 // 170 //
196 // This may be called on any thread. 171 // This may be called on any thread.
197 ContentSettings GetNonDefaultContentSettings( 172 ContentSettings GetNonDefaultContentSettings(
(...skipping 12 matching lines...) Expand all
210 const GURL& secondary_url, 185 const GURL& secondary_url,
211 ContentSettingsType content_type, 186 ContentSettingsType content_type,
212 const std::string& resource_identifier) const; 187 const std::string& resource_identifier) const;
213 188
214 ContentSetting GetContentSettingInternal( 189 ContentSetting GetContentSettingInternal(
215 const GURL& primary_url, 190 const GURL& primary_url,
216 const GURL& secondary_url, 191 const GURL& secondary_url,
217 ContentSettingsType content_type, 192 ContentSettingsType content_type,
218 const std::string& resource_identifier) const; 193 const std::string& resource_identifier) const;
219 194
220 // Various migration methods (old cookie, popup and per-host data gets
221 // migrated to the new format).
222 void MigrateObsoleteCookiePref();
223
224 // Weak; owned by the Profile. 195 // Weak; owned by the Profile.
225 PrefService* prefs_; 196 PrefService* prefs_;
226 197
227 PrefChangeRegistrar pref_change_registrar_;
228
229 // Whether this settings map is for an OTR session. 198 // Whether this settings map is for an OTR session.
230 bool is_off_the_record_; 199 bool is_off_the_record_;
231 200
232 // Whether we are currently updating preferences, this is used to ignore 201 // Whether we are currently updating preferences, this is used to ignore
233 // notifications from the preferences service that we triggered ourself. 202 // notifications from the preferences service that we triggered ourself.
234 bool updating_preferences_; 203 bool updating_preferences_;
235 204
236 // Default content setting providers. 205 // Default content setting providers.
237 std::vector<linked_ptr<content_settings::DefaultProviderInterface> > 206 std::vector<linked_ptr<content_settings::DefaultProviderInterface> >
238 default_content_settings_providers_; 207 default_content_settings_providers_;
239 208
240 // Content setting providers. 209 // Content setting providers.
241 std::vector<linked_ptr<content_settings::ProviderInterface> > 210 std::vector<linked_ptr<content_settings::ProviderInterface> >
242 content_settings_providers_; 211 content_settings_providers_;
243 212
244 // Used around accesses to the following objects to guarantee thread safety.
245 mutable base::Lock lock_;
246
247 // Misc global settings.
248 bool block_third_party_cookies_;
249 bool is_block_third_party_cookies_managed_;
250
251 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); 213 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap);
252 }; 214 };
253 215
254 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_ 216 #endif // CHROME_BROWSER_CONTENT_SETTINGS_HOST_CONTENT_SETTINGS_MAP_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698