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/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/browser/profiles/refcounted_profile_keyed_service.h" | 16 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" |
17 #include "chrome/browser/profiles/refcounted_profile_keyed_service_factory.h" | 17 #include "chrome/browser/profiles/refcounted_profile_keyed_service_factory.h" |
18 #include "chrome/common/content_settings.h" | 18 #include "chrome/common/content_settings.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 PrefServiceSyncable; |
24 class Profile; | 25 class Profile; |
25 | 26 |
26 // A frontend to the cookie settings of |HostContentSettingsMap|. Handles | 27 // A frontend to the cookie settings of |HostContentSettingsMap|. Handles |
27 // cookie-specific logic such as blocking third-party cookies. Written on the UI | 28 // cookie-specific logic such as blocking third-party cookies. Written on the UI |
28 // thread and read on any thread. One instance per profile. | 29 // thread and read on any thread. One instance per profile. |
29 | 30 |
30 class CookieSettings | 31 class CookieSettings |
31 : public RefcountedProfileKeyedService { | 32 : public RefcountedProfileKeyedService { |
32 public: | 33 public: |
33 CookieSettings( | 34 CookieSettings( |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 // |Profile|. Afterwards, only const methods can be called. | 95 // |Profile|. Afterwards, only const methods can be called. |
95 virtual void ShutdownOnUIThread() OVERRIDE; | 96 virtual void ShutdownOnUIThread() OVERRIDE; |
96 | 97 |
97 // A helper for applying third party cookie blocking rules. | 98 // A helper for applying third party cookie blocking rules. |
98 ContentSetting GetCookieSetting( | 99 ContentSetting GetCookieSetting( |
99 const GURL& url, | 100 const GURL& url, |
100 const GURL& first_party_url, | 101 const GURL& first_party_url, |
101 bool setting_cookie, | 102 bool setting_cookie, |
102 content_settings::SettingSource* source) const; | 103 content_settings::SettingSource* source) const; |
103 | 104 |
104 static void RegisterUserPrefs(PrefService* prefs); | 105 static void RegisterUserPrefs(PrefServiceSyncable* prefs); |
105 | 106 |
106 class Factory : public RefcountedProfileKeyedServiceFactory { | 107 class Factory : public RefcountedProfileKeyedServiceFactory { |
107 public: | 108 public: |
108 // Returns the |CookieSettings| associated with the |profile|. | 109 // Returns the |CookieSettings| associated with the |profile|. |
109 // | 110 // |
110 // This should only be called on the UI thread. | 111 // This should only be called on the UI thread. |
111 static scoped_refptr<CookieSettings> GetForProfile(Profile* profile); | 112 static scoped_refptr<CookieSettings> GetForProfile(Profile* profile); |
112 | 113 |
113 static Factory* GetInstance(); | 114 static Factory* GetInstance(); |
114 | 115 |
115 private: | 116 private: |
116 friend struct DefaultSingletonTraits<Factory>; | 117 friend struct DefaultSingletonTraits<Factory>; |
117 | 118 |
118 Factory(); | 119 Factory(); |
119 virtual ~Factory(); | 120 virtual ~Factory(); |
120 | 121 |
121 // |ProfileKeyedBaseFactory| methods: | 122 // |ProfileKeyedBaseFactory| methods: |
122 virtual void RegisterUserPrefs(PrefService* user_prefs) OVERRIDE; | 123 virtual void RegisterUserPrefs(PrefServiceSyncable* user_prefs) OVERRIDE; |
123 virtual bool ServiceRedirectedInIncognito() const OVERRIDE; | 124 virtual bool ServiceRedirectedInIncognito() const OVERRIDE; |
124 virtual scoped_refptr<RefcountedProfileKeyedService> | 125 virtual scoped_refptr<RefcountedProfileKeyedService> |
125 BuildServiceInstanceFor(Profile* profile) const OVERRIDE; | 126 BuildServiceInstanceFor(Profile* profile) const OVERRIDE; |
126 }; | 127 }; |
127 | 128 |
128 private: | 129 private: |
129 virtual ~CookieSettings(); | 130 virtual ~CookieSettings(); |
130 | 131 |
131 void OnBlockThirdPartyCookiesChanged(); | 132 void OnBlockThirdPartyCookiesChanged(); |
132 | 133 |
133 // Returns true if the "block third party cookies" preference is set. | 134 // Returns true if the "block third party cookies" preference is set. |
134 // | 135 // |
135 // This method may be called on any thread. | 136 // This method may be called on any thread. |
136 bool ShouldBlockThirdPartyCookies() const; | 137 bool ShouldBlockThirdPartyCookies() const; |
137 | 138 |
138 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; | 139 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; |
139 PrefChangeRegistrar pref_change_registrar_; | 140 PrefChangeRegistrar pref_change_registrar_; |
140 | 141 |
141 // Used around accesses to |block_third_party_cookies_| to guarantee thread | 142 // Used around accesses to |block_third_party_cookies_| to guarantee thread |
142 // safety. | 143 // safety. |
143 mutable base::Lock lock_; | 144 mutable base::Lock lock_; |
144 | 145 |
145 bool block_third_party_cookies_; | 146 bool block_third_party_cookies_; |
146 }; | 147 }; |
147 | 148 |
148 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ | 149 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ |
OLD | NEW |