Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: chrome/browser/content_settings/cookie_settings.h

Issue 8383004: Adding CookieSettings for storing cookie content settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code review. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
6 #define CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
7 #pragma once
8
9 #include <string>
10
11 #include "base/compiler_specific.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/singleton.h"
14 #include "base/synchronization/lock.h"
15 #include "chrome/browser/content_settings/host_content_settings_map.h"
16 #include "chrome/browser/prefs/pref_change_registrar.h"
17 #include "chrome/browser/profiles/profile_keyed_service_factory.h"
18 #include "chrome/common/content_settings.h"
19 #include "content/public/browser/notification_observer.h"
20
21 class ContentSettingsPattern;
22 class CookieSettingsWrapper;
23 class GURL;
24 class PrefService;
25 class Profile;
26
27 // A frontend to the cookie settings of |HostContentSettingsMap|. Handles
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.
30
31 class CookieSettings
32 : public content::NotificationObserver,
33 public base::RefCountedThreadSafe<CookieSettings> {
34 public:
35 CookieSettings(
36 HostContentSettingsMap* host_content_settings_map,
37 PrefService* prefs);
38
39 virtual ~CookieSettings();
40
41 // Returns the |CookieSettings| associated with the |profile|.
42 //
43 // This should only be called on the UI thread.
44 static CookieSettings* GetForProfile(Profile* profile);
45
46 // Returns the default content setting (CONTENT_SETTING_ALLOW,
47 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. If
48 // |provider_id| is not NULL, the id of the provider which provided the
49 // default setting is assigned to it.
50 //
51 // This may be called on any thread.
52 ContentSetting GetDefaultCookieSetting(std::string* provider_id) const;
53
54 // Returns true if the page identified by (|url|, |first_party_url|) is
55 // allowed to read cookies.
56 //
57 // This may be called on any thread.
58 bool IsReadingCookieAllowed(const GURL& url,
59 const GURL& first_party_url) const;
60
61 // Returns true if the page identified by (|url|, |first_party_url|) is
62 // allowed to set cookies (permanent or session only).
63 //
64 // This may be called on any thread.
65 bool IsSettingCookieAllowed(const GURL& url,
66 const GURL& first_party_url) const;
67
68 // Returns true if the cookie set by a page identified by |url| should be
69 // session only. Querying this only makes sense if |IsSettingCookieAllowed|
70 // has returned true.
71 //
72 // This may be called on any thread.
73 bool IsCookieSessionOnly(const GURL& url) const;
74
75 // Returns all patterns with a non-default cookie setting, mapped to their
76 // actual settings, in the precedence order of the setting rules. |settings|
77 // must be a non-NULL outparam.
78 //
79 // This may be called on any thread.
80 void GetCookieSettings(
81 HostContentSettingsMap::SettingsForOneType* settings) const;
82
83 // Sets the default content setting (CONTENT_SETTING_ALLOW,
84 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies.
85 //
86 // This should only be called on the UI thread.
87 void SetDefaultCookieSetting(ContentSetting setting);
88
89 // Sets the cookie setting for the given patterns.
90 //
91 // This should only be called on the UI thread.
92 void SetCookieSetting(const ContentSettingsPattern& primary_pattern,
93 const ContentSettingsPattern& secondary_pattern,
94 ContentSetting setting);
95
96 // Resets the cookie setting for the given patterns.
97 //
98 // This should only be called on the UI thread.
99 void ResetCookieSetting(const ContentSettingsPattern& primary_pattern,
100 const ContentSettingsPattern& secondary_pattern);
101
102 // |NotificationObserver| implementation.
103 virtual void Observe(int type,
104 const content::NotificationSource& source,
105 const content::NotificationDetails& details) OVERRIDE;
106
107 // Detaches the |CookieSettings| from all |Profile|-related objects like
108 // |PrefService|. This methods needs to be called before destroying the
109 // |Profile|. Afterwards, only const methods can be called.
110 void ShutdownOnUIThread();
111
112 // A helper for applying third party cookie blocking rules.
113 ContentSetting GetCookieSetting(const GURL& url,
114 const GURL& first_party_url,
115 bool setting_cookie) const;
116
117 static void RegisterUserPrefs(PrefService* prefs);
118
119 class Factory : public ProfileKeyedServiceFactory {
120 public:
121 static Factory* GetInstance();
122 CookieSettingsWrapper* GetWrapperForProfile(Profile* profile);
123
124 private:
125 friend struct DefaultSingletonTraits<Factory>;
126
127 Factory();
128 virtual ~Factory() {}
129
130 // |ProfileKeyedServiceFactory| methods:
131 virtual ProfileKeyedService* BuildServiceInstanceFor(
132 Profile* profile) const OVERRIDE;
133 virtual bool ServiceRedirectedInIncognito() OVERRIDE { return true; }
134 };
135
136 private:
137 // Returns true if the "block third party cookies" preference is set.
138 //
139 // This method may be called on any thread.
140 bool ShouldBlockThirdPartyCookies() const;
141
142 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
143 PrefChangeRegistrar pref_change_registrar_;
144
145 // Used around accesses to |block_third_party_cookies_| to guarantee thread
146 // safety.
147 mutable base::Lock lock_;
148
149 bool block_third_party_cookies_;
150 };
151
152 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698