Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / content_settings / cookie_settings.h
blob77f66f3cbd688c79fc3164edb458e6d8e307a596
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
6 #define CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/singleton.h"
13 #include "base/prefs/public/pref_change_registrar.h"
14 #include "base/synchronization/lock.h"
15 #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_factory.h"
18 #include "chrome/common/content_settings.h"
20 class ContentSettingsPattern;
21 class CookieSettingsWrapper;
22 class GURL;
23 class PrefService;
24 class Profile;
26 // A frontend to the cookie settings of |HostContentSettingsMap|. Handles
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.
30 class CookieSettings
31 : public RefcountedProfileKeyedService {
32 public:
33 CookieSettings(
34 HostContentSettingsMap* host_content_settings_map,
35 PrefService* prefs);
37 // Returns the default content setting (CONTENT_SETTING_ALLOW,
38 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. If
39 // |provider_id| is not NULL, the id of the provider which provided the
40 // default setting is assigned to it.
42 // This may be called on any thread.
43 ContentSetting GetDefaultCookieSetting(std::string* provider_id) const;
45 // Returns true if the page identified by (|url|, |first_party_url|) is
46 // allowed to read cookies.
48 // This may be called on any thread.
49 bool IsReadingCookieAllowed(const GURL& url,
50 const GURL& first_party_url) const;
52 // Returns true if the page identified by (|url|, |first_party_url|) is
53 // allowed to set cookies (permanent or session only).
55 // This may be called on any thread.
56 bool IsSettingCookieAllowed(const GURL& url,
57 const GURL& first_party_url) const;
59 // Returns true if the cookie set by a page identified by |url| should be
60 // session only. Querying this only makes sense if |IsSettingCookieAllowed|
61 // has returned true.
63 // This may be called on any thread.
64 bool IsCookieSessionOnly(const GURL& url) const;
66 // Returns all patterns with a non-default cookie setting, mapped to their
67 // actual settings, in the precedence order of the setting rules. |settings|
68 // must be a non-NULL outparam.
70 // This may be called on any thread.
71 void GetCookieSettings(ContentSettingsForOneType* settings) const;
73 // Sets the default content setting (CONTENT_SETTING_ALLOW,
74 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies.
76 // This should only be called on the UI thread.
77 void SetDefaultCookieSetting(ContentSetting setting);
79 // Sets the cookie setting for the given patterns.
81 // This should only be called on the UI thread.
82 void SetCookieSetting(const ContentSettingsPattern& primary_pattern,
83 const ContentSettingsPattern& secondary_pattern,
84 ContentSetting setting);
86 // Resets the cookie setting for the given patterns.
88 // This should only be called on the UI thread.
89 void ResetCookieSetting(const ContentSettingsPattern& primary_pattern,
90 const ContentSettingsPattern& secondary_pattern);
92 // Detaches the |CookieSettings| from all |Profile|-related objects like
93 // |PrefService|. This methods needs to be called before destroying the
94 // |Profile|. Afterwards, only const methods can be called.
95 virtual void ShutdownOnUIThread() OVERRIDE;
97 // A helper for applying third party cookie blocking rules.
98 ContentSetting GetCookieSetting(
99 const GURL& url,
100 const GURL& first_party_url,
101 bool setting_cookie,
102 content_settings::SettingSource* source) const;
104 static void RegisterUserPrefs(PrefService* prefs);
106 class Factory : public RefcountedProfileKeyedServiceFactory {
107 public:
108 // Returns the |CookieSettings| associated with the |profile|.
110 // This should only be called on the UI thread.
111 static scoped_refptr<CookieSettings> GetForProfile(Profile* profile);
113 static Factory* GetInstance();
115 private:
116 friend struct DefaultSingletonTraits<Factory>;
118 Factory();
119 virtual ~Factory();
121 // |ProfileKeyedBaseFactory| methods:
122 virtual void RegisterUserPrefs(PrefService* user_prefs) OVERRIDE;
123 virtual bool ServiceRedirectedInIncognito() const OVERRIDE;
124 virtual scoped_refptr<RefcountedProfileKeyedService>
125 BuildServiceInstanceFor(Profile* profile) const OVERRIDE;
128 private:
129 virtual ~CookieSettings();
131 void OnBlockThirdPartyCookiesChanged();
133 // Returns true if the "block third party cookies" preference is set.
135 // This method may be called on any thread.
136 bool ShouldBlockThirdPartyCookies() const;
138 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
139 PrefChangeRegistrar pref_change_registrar_;
141 // Used around accesses to |block_third_party_cookies_| to guarantee thread
142 // safety.
143 mutable base::Lock lock_;
145 bool block_third_party_cookies_;
148 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_