| 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" |
| 14 #include "base/synchronization/lock.h" | 15 #include "base/synchronization/lock.h" |
| 15 #include "chrome/browser/content_settings/host_content_settings_map.h" | 16 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 16 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" | 17 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" |
| 17 #include "chrome/browser/profiles/refcounted_profile_keyed_service_factory.h" | 18 #include "chrome/browser/profiles/refcounted_profile_keyed_service_factory.h" |
| 18 #include "chrome/common/content_settings.h" | 19 #include "chrome/common/content_settings.h" |
| 19 #include "content/public/browser/notification_observer.h" | |
| 20 | 20 |
| 21 class ContentSettingsPattern; | 21 class ContentSettingsPattern; |
| 22 class CookieSettingsWrapper; | 22 class CookieSettingsWrapper; |
| 23 class GURL; | 23 class GURL; |
| 24 class PrefService; | 24 class PrefService; |
| 25 class Profile; | 25 class Profile; |
| 26 | 26 |
| 27 // A frontend to the cookie settings of |HostContentSettingsMap|. Handles | 27 // A frontend to the cookie settings of |HostContentSettingsMap|. Handles |
| 28 // 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 |
| 29 // thread and read on any thread. One instance per profile. | 29 // thread and read on any thread. One instance per profile. |
| 30 | 30 |
| 31 class CookieSettings | 31 class CookieSettings |
| 32 : public content::NotificationObserver, | 32 : public PrefObserver, |
| 33 public RefcountedProfileKeyedService { | 33 public RefcountedProfileKeyedService { |
| 34 public: | 34 public: |
| 35 CookieSettings( | 35 CookieSettings( |
| 36 HostContentSettingsMap* host_content_settings_map, | 36 HostContentSettingsMap* host_content_settings_map, |
| 37 PrefService* prefs); | 37 PrefService* prefs); |
| 38 | 38 |
| 39 // Returns the default content setting (CONTENT_SETTING_ALLOW, | 39 // Returns the default content setting (CONTENT_SETTING_ALLOW, |
| 40 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. If | 40 // 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 | 41 // |provider_id| is not NULL, the id of the provider which provided the |
| 42 // default setting is assigned to it. | 42 // default setting is assigned to it. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 void SetCookieSetting(const ContentSettingsPattern& primary_pattern, | 84 void SetCookieSetting(const ContentSettingsPattern& primary_pattern, |
| 85 const ContentSettingsPattern& secondary_pattern, | 85 const ContentSettingsPattern& secondary_pattern, |
| 86 ContentSetting setting); | 86 ContentSetting setting); |
| 87 | 87 |
| 88 // Resets the cookie setting for the given patterns. | 88 // Resets the cookie setting for the given patterns. |
| 89 // | 89 // |
| 90 // This should only be called on the UI thread. | 90 // This should only be called on the UI thread. |
| 91 void ResetCookieSetting(const ContentSettingsPattern& primary_pattern, | 91 void ResetCookieSetting(const ContentSettingsPattern& primary_pattern, |
| 92 const ContentSettingsPattern& secondary_pattern); | 92 const ContentSettingsPattern& secondary_pattern); |
| 93 | 93 |
| 94 // |NotificationObserver| implementation. | 94 // |PrefObserver| implementation. |
| 95 virtual void Observe(int type, | 95 virtual void OnPreferenceChanged(PrefServiceBase* service, |
| 96 const content::NotificationSource& source, | 96 const std::string& pref_name) OVERRIDE; |
| 97 const content::NotificationDetails& details) OVERRIDE; | |
| 98 | 97 |
| 99 // Detaches the |CookieSettings| from all |Profile|-related objects like | 98 // Detaches the |CookieSettings| from all |Profile|-related objects like |
| 100 // |PrefService|. This methods needs to be called before destroying the | 99 // |PrefService|. This methods needs to be called before destroying the |
| 101 // |Profile|. Afterwards, only const methods can be called. | 100 // |Profile|. Afterwards, only const methods can be called. |
| 102 virtual void ShutdownOnUIThread() OVERRIDE; | 101 virtual void ShutdownOnUIThread() OVERRIDE; |
| 103 | 102 |
| 104 // A helper for applying third party cookie blocking rules. | 103 // A helper for applying third party cookie blocking rules. |
| 105 ContentSetting GetCookieSetting( | 104 ContentSetting GetCookieSetting( |
| 106 const GURL& url, | 105 const GURL& url, |
| 107 const GURL& first_party_url, | 106 const GURL& first_party_url, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 PrefChangeRegistrar pref_change_registrar_; | 143 PrefChangeRegistrar pref_change_registrar_; |
| 145 | 144 |
| 146 // Used around accesses to |block_third_party_cookies_| to guarantee thread | 145 // Used around accesses to |block_third_party_cookies_| to guarantee thread |
| 147 // safety. | 146 // safety. |
| 148 mutable base::Lock lock_; | 147 mutable base::Lock lock_; |
| 149 | 148 |
| 150 bool block_third_party_cookies_; | 149 bool block_third_party_cookies_; |
| 151 }; | 150 }; |
| 152 | 151 |
| 153 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ | 152 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_ |
| OLD | NEW |