| 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 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ | 5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ |
| 6 #define CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ | 6 #define CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/prefs/public/pref_change_registrar.h" | 13 #include "base/prefs/public/pref_change_registrar.h" |
| 14 #include "base/prefs/public/pref_observer.h" | |
| 15 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 16 #include "chrome/browser/content_settings/host_content_settings_map.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 17 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" | 16 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" |
| 18 #include "chrome/browser/profiles/refcounted_profile_keyed_service_factory.h" | 17 #include "chrome/browser/profiles/refcounted_profile_keyed_service_factory.h" |
| 19 #include "chrome/common/content_settings.h" | 18 #include "chrome/common/content_settings.h" |
| 20 | 19 |
| 21 class ContentSettingsPattern; | 20 class ContentSettingsPattern; |
| 22 class CookieSettingsWrapper; | 21 class CookieSettingsWrapper; |
| 23 class GURL; | 22 class GURL; |
| 24 class PrefService; | 23 class PrefService; |
| 25 class Profile; | 24 class Profile; |
| 26 | 25 |
| 27 // A frontend to the cookie settings of |HostContentSettingsMap|. Handles | 26 // A frontend to the cookie settings of |HostContentSettingsMap|. Handles |
| 28 // cookie-specific logic such as blocking third-party cookies. Written on the UI | 27 // cookie-specific logic such as blocking third-party cookies. Written on the UI |
| 29 // thread and read on any thread. One instance per profile. | 28 // thread and read on any thread. One instance per profile. |
| 30 | 29 |
| 31 class CookieSettings | 30 class CookieSettings |
| 32 : public PrefObserver, | 31 : public RefcountedProfileKeyedService { |
| 33 public RefcountedProfileKeyedService { | |
| 34 public: | 32 public: |
| 35 CookieSettings( | 33 CookieSettings( |
| 36 HostContentSettingsMap* host_content_settings_map, | 34 HostContentSettingsMap* host_content_settings_map, |
| 37 PrefService* prefs); | 35 PrefService* prefs); |
| 38 | 36 |
| 39 // Returns the default content setting (CONTENT_SETTING_ALLOW, | 37 // Returns the default content setting (CONTENT_SETTING_ALLOW, |
| 40 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. If | 38 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. If |
| 41 // |provider_id| is not NULL, the id of the provider which provided the | 39 // |provider_id| is not NULL, the id of the provider which provided the |
| 42 // default setting is assigned to it. | 40 // default setting is assigned to it. |
| 43 // | 41 // |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 void SetCookieSetting(const ContentSettingsPattern& primary_pattern, | 82 void SetCookieSetting(const ContentSettingsPattern& primary_pattern, |
| 85 const ContentSettingsPattern& secondary_pattern, | 83 const ContentSettingsPattern& secondary_pattern, |
| 86 ContentSetting setting); | 84 ContentSetting setting); |
| 87 | 85 |
| 88 // Resets the cookie setting for the given patterns. | 86 // Resets the cookie setting for the given patterns. |
| 89 // | 87 // |
| 90 // This should only be called on the UI thread. | 88 // This should only be called on the UI thread. |
| 91 void ResetCookieSetting(const ContentSettingsPattern& primary_pattern, | 89 void ResetCookieSetting(const ContentSettingsPattern& primary_pattern, |
| 92 const ContentSettingsPattern& secondary_pattern); | 90 const ContentSettingsPattern& secondary_pattern); |
| 93 | 91 |
| 94 // |PrefObserver| implementation. | |
| 95 virtual void OnPreferenceChanged(PrefServiceBase* service, | |
| 96 const std::string& pref_name) OVERRIDE; | |
| 97 | |
| 98 // Detaches the |CookieSettings| from all |Profile|-related objects like | 92 // Detaches the |CookieSettings| from all |Profile|-related objects like |
| 99 // |PrefService|. This methods needs to be called before destroying the | 93 // |PrefService|. This methods needs to be called before destroying the |
| 100 // |Profile|. Afterwards, only const methods can be called. | 94 // |Profile|. Afterwards, only const methods can be called. |
| 101 virtual void ShutdownOnUIThread() OVERRIDE; | 95 virtual void ShutdownOnUIThread() OVERRIDE; |
| 102 | 96 |
| 103 // A helper for applying third party cookie blocking rules. | 97 // A helper for applying third party cookie blocking rules. |
| 104 ContentSetting GetCookieSetting( | 98 ContentSetting GetCookieSetting( |
| 105 const GURL& url, | 99 const GURL& url, |
| 106 const GURL& first_party_url, | 100 const GURL& first_party_url, |
| 107 bool setting_cookie, | 101 bool setting_cookie, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 127 // |ProfileKeyedBaseFactory| methods: | 121 // |ProfileKeyedBaseFactory| methods: |
| 128 virtual void RegisterUserPrefs(PrefService* user_prefs) OVERRIDE; | 122 virtual void RegisterUserPrefs(PrefService* user_prefs) OVERRIDE; |
| 129 virtual bool ServiceRedirectedInIncognito() const OVERRIDE; | 123 virtual bool ServiceRedirectedInIncognito() const OVERRIDE; |
| 130 virtual scoped_refptr<RefcountedProfileKeyedService> | 124 virtual scoped_refptr<RefcountedProfileKeyedService> |
| 131 BuildServiceInstanceFor(Profile* profile) const OVERRIDE; | 125 BuildServiceInstanceFor(Profile* profile) const OVERRIDE; |
| 132 }; | 126 }; |
| 133 | 127 |
| 134 private: | 128 private: |
| 135 virtual ~CookieSettings(); | 129 virtual ~CookieSettings(); |
| 136 | 130 |
| 131 void OnBlockThirdPartyCookiesChanged(); |
| 132 |
| 137 // Returns true if the "block third party cookies" preference is set. | 133 // Returns true if the "block third party cookies" preference is set. |
| 138 // | 134 // |
| 139 // This method may be called on any thread. | 135 // This method may be called on any thread. |
| 140 bool ShouldBlockThirdPartyCookies() const; | 136 bool ShouldBlockThirdPartyCookies() const; |
| 141 | 137 |
| 142 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; | 138 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; |
| 143 PrefChangeRegistrar pref_change_registrar_; | 139 PrefChangeRegistrar pref_change_registrar_; |
| 144 | 140 |
| 145 // Used around accesses to |block_third_party_cookies_| to guarantee thread | 141 // Used around accesses to |block_third_party_cookies_| to guarantee thread |
| 146 // safety. | 142 // safety. |
| 147 mutable base::Lock lock_; | 143 mutable base::Lock lock_; |
| 148 | 144 |
| 149 bool block_third_party_cookies_; | 145 bool block_third_party_cookies_; |
| 150 }; | 146 }; |
| 151 | 147 |
| 152 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ | 148 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ |
| OLD | NEW |