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

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: . Created 9 years, 2 months 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 // Maps hostnames to cookie settings. Written on the UI thread and read on any
Bernhard Bauer 2011/10/25 13:11:21 Nit: If this is a class-level comment, you should
marja 2011/10/26 13:03:21 Done.
6 // thread. One instance per profile.
7
8 #ifndef CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
9 #define CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
10 #pragma once
11
12 #include <string>
13
14 #include "base/compiler_specific.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/synchronization/lock.h"
17 #include "chrome/browser/content_settings/host_content_settings_map.h"
18 #include "chrome/browser/prefs/pref_change_registrar.h"
19 #include "chrome/common/content_settings.h"
20 #include "content/public/browser/notification_observer.h"
21
22 class ContentSettingsPattern;
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.
29 class CookieSettings
30 : public content::NotificationObserver,
31 public base::RefCountedThreadSafe<CookieSettings> {
32 public:
33 CookieSettings(
34 HostContentSettingsMap* host_content_settings_map,
35 PrefService* prefs);
36
37 virtual ~CookieSettings();
38
39 // Returns the |CookieSettings| associated with the |profile|.
40 //
41 // This should only be called on the UI thread.
42 static CookieSettings* GetForProfile(Profile* profile);
43
44 // Returns the default content setting (CONTENT_SETTING_ALLOW,
45 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies. If
46 // |provider_id| is not NULL, the id of the provider which provided the
47 // default setting is assigned to it.
48 //
49 // This may be called on any thread.
50 ContentSetting GetDefaultCookieSetting(std::string* provider_id) const;
51
52 // Returns true if the page identified by (|url|, |first_party_url|) is
53 // allowed to read cookies.
54 //
55 // This may be called on any thread.
56 bool IsReadingCookieAllowed(const GURL& url,
57 const GURL& first_party_url) const;
58
59 // Returns true if the page identified by (|url|, |first_party_url|) is
60 // allowed to set cookies (permanent or session only).
61 //
62 // This may be called on any thread.
63 bool IsSettingCookieAllowed(const GURL& url,
64 const GURL& first_party_url) const;
65
66 // Returns true if the cookie set by a page identified by |url| should be
67 // session only. Querying this only makes sense if |IsSettingCookieAllowed|
68 // has returned true.
69 //
70 // This may be called on any thread.
71 bool IsCookieSessionOnly(const GURL& url) const;
72
73 // Returns all patterns with a non-default cookie setting, mapped to their
74 // actual settings, in the precedence order of the setting rules. |settings|
75 // must be a non-NULL outparam.
76 //
77 // This may be called on any thread.
78 void GetCookieSettings(
79 HostContentSettingsMap::SettingsForOneType* settings) const;
80
81 // Sets the default content setting (CONTENT_SETTING_ALLOW,
82 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies.
83 //
84 // This should only be called on the UI thread.
85 void SetDefaultCookieSetting(ContentSetting setting);
86
87 // Sets the cookie setting to CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK or
88 // CONTENT_SETTING_SESSION_ONLY for (url, first_party_url) pairs where url
Bernhard Bauer 2011/10/25 13:11:21 |first_party_url| does not exist here. Also, the c
marja 2011/10/26 13:03:21 Done.
89 // matches |primary_pattern|.
90 //
91 // This should only be called on the UI thread.
92 void SetCookieSetting(const ContentSettingsPattern& primary_pattern,
Bernhard Bauer 2011/10/25 13:11:21 We should not have two methods here.
marja 2011/10/26 13:03:21 Done.
93 ContentSetting setting);
94
95 // Sets the cookie setting to CONTENT_SETTING_ALLOW or CONTENT_SETTING_BLOCK
96 // for (url, first_party_url) pairs where url matches |primary_pattern| and
97 // first_party_url matches |secondary_pattern|.
Bernhard Bauer 2011/10/25 13:11:21 This comment is a bit redundant (you're describing
marja 2011/10/26 13:03:21 Done.
98 //
99 // This should only be called on the UI thread.
100 void SetCookieSetting(const ContentSettingsPattern& primary_pattern,
Bernhard Bauer 2011/10/25 13:11:21 Who calls this method, BTW?
marja 2011/10/26 13:03:21 Currently nobody was setting cookie settings where
Bernhard Bauer 2011/10/26 13:24:09 Yes, this is nicer than having overloaded methods,
101 const ContentSettingsPattern& secondary_pattern,
102 ContentSetting setting);
103
104 // Resets the cookie setting for (url, first_party_url) pairs where url
105 // matches |primary_pattern|.
106 //
107 // This should only be called on the UI thread.
108 void ResetCookieSetting(const ContentSettingsPattern& primary_pattern);
Bernhard Bauer 2011/10/25 13:11:21 We should not have two methods there either.
marja 2011/10/26 13:03:21 Done.
109
110 // Resets the cookie setting for (url, first_party_url) pairs where url
111 // matches |primary_pattern| and first_party_url matches |secondary_pattern|.
112 //
113 // This should only be called on the UI thread.
114 void ResetCookieSetting(const ContentSettingsPattern& primary_pattern,
115 const ContentSettingsPattern& secondary_pattern);
116
117 // |NotificationObserver| implementation.
118 virtual void Observe(int type,
119 const content::NotificationSource& source,
120 const content::NotificationDetails& details) OVERRIDE;
121
122 // Detaches the |CookieSettings| from all |Profile|-related objects like
123 // |PrefService|. This methods needs to be called before destroying the
124 // |Profile|. Afterwards, none of the methods above that should only be called
Bernhard Bauer 2011/10/25 13:11:21 I think we can simplify the comment to "Afterwards
marja 2011/10/26 13:03:21 Done.
125 // on the UI thread should be called anymore.
126 void ShutdownOnUIThread();
127
128 // A helper for applying third party cookie blocking rules.
129 ContentSetting GetCookieSetting(const GURL& url,
130 const GURL& first_party_url,
131 bool setting_cookie) const;
132 private:
133 class Factory;
134
135 // This setting trumps any host-specific settings.
Bernhard Bauer 2011/10/25 13:11:21 This comment isn't true anymore.
marja 2011/10/26 13:03:21 Done.
136 //
137 // This method may be called on any thread.
138 bool ShouldBlockThirdPartyCookies() const;
139
140 scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
141 PrefChangeRegistrar pref_change_registrar_;
142
143 // Used around accesses to |block_third_party_cookies_| to guarantee thread
144 // safety.
145 mutable base::Lock lock_;
146
147 bool block_third_party_cookies_;
148 };
149
150 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698