| 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/pref_change_registrar.h" | 13 #include "base/prefs/pref_change_registrar.h" |
| 14 #include "base/synchronization/lock.h" | 14 #include "base/synchronization/lock.h" |
| 15 #include "chrome/browser/content_settings/host_content_settings_map.h" | 15 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 16 #include "chrome/common/content_settings.h" | 16 #include "chrome/common/content_settings.h" |
| 17 #include "components/browser_context_keyed_service/refcounted_browser_context_ke
yed_service.h" | 17 #include "components/browser_context_keyed_service/refcounted_browser_context_ke
yed_service.h" |
| 18 #include "components/browser_context_keyed_service/refcounted_browser_context_ke
yed_service_factory.h" | 18 #include "components/browser_context_keyed_service/refcounted_browser_context_ke
yed_service_factory.h" |
| 19 | 19 |
| 20 class ContentSettingsPattern; | 20 class ContentSettingsPattern; |
| 21 class CookieSettingsWrapper; | 21 class CookieSettingsWrapper; |
| 22 class GURL; | 22 class GURL; |
| 23 class PrefService; | 23 class PrefService; |
| 24 class Profile; | 24 class Profile; |
| 25 | 25 |
| 26 // A frontend to the cookie settings of |HostContentSettingsMap|. Handles | 26 // A frontend to the cookie settings of |HostContentSettingsMap|. Handles |
| 27 // 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 |
| 28 // thread and read on any thread. One instance per profile. | 28 // thread and read on any thread. One instance per profile. |
| 29 class CookieSettings : public RefcountedProfileKeyedService { | 29 class CookieSettings : public RefcountedBrowserContextKeyedService { |
| 30 public: | 30 public: |
| 31 CookieSettings( | 31 CookieSettings( |
| 32 HostContentSettingsMap* host_content_settings_map, | 32 HostContentSettingsMap* host_content_settings_map, |
| 33 PrefService* prefs); | 33 PrefService* prefs); |
| 34 | 34 |
| 35 // Returns the default content setting (CONTENT_SETTING_ALLOW, | 35 // Returns the default content setting (CONTENT_SETTING_ALLOW, |
| 36 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. If | 36 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. If |
| 37 // |provider_id| is not NULL, the id of the provider which provided the | 37 // |provider_id| is not NULL, the id of the provider which provided the |
| 38 // default setting is assigned to it. | 38 // default setting is assigned to it. |
| 39 // | 39 // |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 // A helper for applying third party cookie blocking rules. | 95 // A helper for applying third party cookie blocking rules. |
| 96 ContentSetting GetCookieSetting( | 96 ContentSetting GetCookieSetting( |
| 97 const GURL& url, | 97 const GURL& url, |
| 98 const GURL& first_party_url, | 98 const GURL& first_party_url, |
| 99 bool setting_cookie, | 99 bool setting_cookie, |
| 100 content_settings::SettingSource* source) const; | 100 content_settings::SettingSource* source) const; |
| 101 | 101 |
| 102 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); | 102 static void RegisterUserPrefs(user_prefs::PrefRegistrySyncable* registry); |
| 103 | 103 |
| 104 class Factory : public RefcountedProfileKeyedServiceFactory { | 104 class Factory : public RefcountedBrowserContextKeyedServiceFactory { |
| 105 public: | 105 public: |
| 106 // Returns the |CookieSettings| associated with the |profile|. | 106 // Returns the |CookieSettings| associated with the |profile|. |
| 107 // | 107 // |
| 108 // This should only be called on the UI thread. | 108 // This should only be called on the UI thread. |
| 109 static scoped_refptr<CookieSettings> GetForProfile(Profile* profile); | 109 static scoped_refptr<CookieSettings> GetForProfile(Profile* profile); |
| 110 | 110 |
| 111 static Factory* GetInstance(); | 111 static Factory* GetInstance(); |
| 112 | 112 |
| 113 private: | 113 private: |
| 114 friend struct DefaultSingletonTraits<Factory>; | 114 friend struct DefaultSingletonTraits<Factory>; |
| 115 | 115 |
| 116 Factory(); | 116 Factory(); |
| 117 virtual ~Factory(); | 117 virtual ~Factory(); |
| 118 | 118 |
| 119 // |ProfileKeyedBaseFactory| methods: | 119 // |BrowserContextKeyedBaseFactory| methods: |
| 120 virtual void RegisterUserPrefs( | 120 virtual void RegisterUserPrefs( |
| 121 user_prefs::PrefRegistrySyncable* registry) OVERRIDE; | 121 user_prefs::PrefRegistrySyncable* registry) OVERRIDE; |
| 122 virtual content::BrowserContext* GetBrowserContextToUse( | 122 virtual content::BrowserContext* GetBrowserContextToUse( |
| 123 content::BrowserContext* context) const OVERRIDE; | 123 content::BrowserContext* context) const OVERRIDE; |
| 124 virtual scoped_refptr<RefcountedProfileKeyedService> | 124 virtual scoped_refptr<RefcountedBrowserContextKeyedService> |
| 125 BuildServiceInstanceFor( | 125 BuildServiceInstanceFor( |
| 126 content::BrowserContext* context) const OVERRIDE; | 126 content::BrowserContext* context) const OVERRIDE; |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 private: | 129 private: |
| 130 virtual ~CookieSettings(); | 130 virtual ~CookieSettings(); |
| 131 | 131 |
| 132 void OnBlockThirdPartyCookiesChanged(); | 132 void OnBlockThirdPartyCookiesChanged(); |
| 133 | 133 |
| 134 // Returns true if the "block third party cookies" preference is set. | 134 // Returns true if the "block third party cookies" preference is set. |
| 135 // | 135 // |
| 136 // This method may be called on any thread. | 136 // This method may be called on any thread. |
| 137 bool ShouldBlockThirdPartyCookies() const; | 137 bool ShouldBlockThirdPartyCookies() const; |
| 138 | 138 |
| 139 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; | 139 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; |
| 140 PrefChangeRegistrar pref_change_registrar_; | 140 PrefChangeRegistrar pref_change_registrar_; |
| 141 | 141 |
| 142 // Used around accesses to |block_third_party_cookies_| to guarantee thread | 142 // Used around accesses to |block_third_party_cookies_| to guarantee thread |
| 143 // safety. | 143 // safety. |
| 144 mutable base::Lock lock_; | 144 mutable base::Lock lock_; |
| 145 | 145 |
| 146 bool block_third_party_cookies_; | 146 bool block_third_party_cookies_; |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ | 149 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ |
| OLD | NEW |