OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ | 8 #ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ |
9 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ | 9 #define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
18 #include "base/prefs/pref_change_registrar.h" | 18 #include "base/prefs/pref_change_registrar.h" |
19 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
21 #include "components/content_settings/core/browser/content_settings_observer.h" | 21 #include "components/content_settings/core/browser/content_settings_observer.h" |
| 22 #include "components/content_settings/core/browser/content_settings_utils.h" |
22 #include "components/content_settings/core/common/content_settings.h" | 23 #include "components/content_settings/core/common/content_settings.h" |
23 #include "components/content_settings/core/common/content_settings_pattern.h" | 24 #include "components/content_settings/core/common/content_settings_pattern.h" |
24 #include "components/content_settings/core/common/content_settings_types.h" | 25 #include "components/content_settings/core/common/content_settings_types.h" |
25 #include "components/keyed_service/core/refcounted_keyed_service.h" | 26 #include "components/keyed_service/core/refcounted_keyed_service.h" |
26 | 27 |
27 class ExtensionService; | 28 class ExtensionService; |
28 class GURL; | 29 class GURL; |
29 class PrefService; | 30 class PrefService; |
30 | 31 |
31 namespace base { | 32 namespace base { |
32 class Clock; | 33 class Clock; |
33 class Value; | 34 class Value; |
34 } | 35 } |
35 | 36 |
36 namespace content_settings { | 37 namespace content_settings { |
37 class ObservableProvider; | 38 class ObservableProvider; |
38 class ProviderInterface; | 39 class ProviderInterface; |
39 class PrefProvider; | 40 class PrefProvider; |
| 41 class TestUtils; |
40 } | 42 } |
41 | 43 |
42 namespace user_prefs { | 44 namespace user_prefs { |
43 class PrefRegistrySyncable; | 45 class PrefRegistrySyncable; |
44 } | 46 } |
45 | 47 |
46 class HostContentSettingsMap : public content_settings::Observer, | 48 class HostContentSettingsMap : public content_settings::Observer, |
47 public RefcountedKeyedService { | 49 public RefcountedKeyedService { |
48 public: | 50 public: |
49 enum ProviderType { | 51 enum ProviderType { |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 | 238 |
237 // Schedules any pending lossy website settings to be written to disk. | 239 // Schedules any pending lossy website settings to be written to disk. |
238 void FlushLossyWebsiteSettings(); | 240 void FlushLossyWebsiteSettings(); |
239 | 241 |
240 // Passes ownership of |clock|. | 242 // Passes ownership of |clock|. |
241 void SetPrefClockForTesting(scoped_ptr<base::Clock> clock); | 243 void SetPrefClockForTesting(scoped_ptr<base::Clock> clock); |
242 | 244 |
243 private: | 245 private: |
244 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; | 246 friend class base::RefCountedThreadSafe<HostContentSettingsMap>; |
245 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; | 247 friend class HostContentSettingsMapTest_NonDefaultSettings_Test; |
| 248 friend class content_settings::TestUtils; |
246 | 249 |
247 typedef std::map<ProviderType, content_settings::ProviderInterface*> | 250 typedef std::map<ProviderType, content_settings::ProviderInterface*> |
248 ProviderMap; | 251 ProviderMap; |
249 typedef ProviderMap::iterator ProviderIterator; | 252 typedef ProviderMap::iterator ProviderIterator; |
250 typedef ProviderMap::const_iterator ConstProviderIterator; | 253 typedef ProviderMap::const_iterator ConstProviderIterator; |
251 | 254 |
252 ~HostContentSettingsMap() override; | 255 ~HostContentSettingsMap() override; |
253 | 256 |
254 // Sets a rule to apply the |value| for all sites matching |pattern|, | 257 // Sets a rule to apply the |value| for all sites matching |pattern|, |
255 // |content_type| and |resource_identifier|. Setting the value to null removes | 258 // |content_type| and |resource_identifier|. Setting the value to null removes |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 290 |
288 // Returns the single content setting |value| with a toggle for if it | 291 // Returns the single content setting |value| with a toggle for if it |
289 // takes the global on/off switch into account. | 292 // takes the global on/off switch into account. |
290 scoped_ptr<base::Value> GetWebsiteSettingInternal( | 293 scoped_ptr<base::Value> GetWebsiteSettingInternal( |
291 const GURL& primary_url, | 294 const GURL& primary_url, |
292 const GURL& secondary_url, | 295 const GURL& secondary_url, |
293 ContentSettingsType content_type, | 296 ContentSettingsType content_type, |
294 const std::string& resource_identifier, | 297 const std::string& resource_identifier, |
295 content_settings::SettingInfo* info) const; | 298 content_settings::SettingInfo* info) const; |
296 | 299 |
| 300 static scoped_ptr<base::Value> GetContentSettingValueAndPatterns( |
| 301 const content_settings::ProviderInterface* provider, |
| 302 const GURL& primary_url, |
| 303 const GURL& secondary_url, |
| 304 ContentSettingsType content_type, |
| 305 const std::string& resource_identifier, |
| 306 bool include_incognito, |
| 307 ContentSettingsPattern* primary_pattern, |
| 308 ContentSettingsPattern* secondary_pattern); |
| 309 |
| 310 static scoped_ptr<base::Value> GetContentSettingValueAndPatterns( |
| 311 content_settings::RuleIterator* rule_iterator, |
| 312 const GURL& primary_url, |
| 313 const GURL& secondary_url, |
| 314 ContentSettingsPattern* primary_pattern, |
| 315 ContentSettingsPattern* secondary_pattern); |
| 316 |
297 content_settings::PrefProvider* GetPrefProvider(); | 317 content_settings::PrefProvider* GetPrefProvider(); |
298 | 318 |
299 #ifndef NDEBUG | 319 #ifndef NDEBUG |
300 // This starts as the thread ID of the thread that constructs this | 320 // This starts as the thread ID of the thread that constructs this |
301 // object, and remains until used by a different thread, at which | 321 // object, and remains until used by a different thread, at which |
302 // point it is set to base::kInvalidThreadId. This allows us to | 322 // point it is set to base::kInvalidThreadId. This allows us to |
303 // DCHECK on unsafe usage of content_settings_providers_ (they | 323 // DCHECK on unsafe usage of content_settings_providers_ (they |
304 // should be set up on a single thread, after which they are | 324 // should be set up on a single thread, after which they are |
305 // immutable). | 325 // immutable). |
306 mutable base::PlatformThreadId used_from_thread_id_; | 326 mutable base::PlatformThreadId used_from_thread_id_; |
(...skipping 11 matching lines...) Expand all Loading... |
318 ProviderMap content_settings_providers_; | 338 ProviderMap content_settings_providers_; |
319 | 339 |
320 base::ThreadChecker thread_checker_; | 340 base::ThreadChecker thread_checker_; |
321 | 341 |
322 base::ObserverList<content_settings::Observer> observers_; | 342 base::ObserverList<content_settings::Observer> observers_; |
323 | 343 |
324 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); | 344 DISALLOW_COPY_AND_ASSIGN(HostContentSettingsMap); |
325 }; | 345 }; |
326 | 346 |
327 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ | 347 #endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_HOST_CONTENT_SETTINGS_MAP_H_ |
OLD | NEW |