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

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

Issue 7713034: HostContentSettingsMap refactoring. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Code review comments. Created 9 years, 3 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
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 "base/memory/ref_counted.h"
13 #include "base/synchronization/lock.h"
14 #include "chrome/browser/prefs/pref_change_registrar.h"
15 #include "chrome/browser/profiles/profile_keyed_service.h"
16 #include "chrome/common/content_settings.h"
17 #include "content/common/notification_observer.h"
18
19 class ContentSettingsPattern;
20 class GURL;
21 class HostContentSettingsMap;
22
23 // A frontend to the cookie-specific settings of HostContentSettingsMap. Handles
24 // cookie-specific logic such as blocking third-party cookies.
25 class CookieSettings
26 : public NotificationObserver,
27 public ProfileKeyedService {
28 public:
29 CookieSettings(
30 HostContentSettingsMap* host_content_settings_map,
31 PrefService* prefs,
32 bool incognito);
33
34 // Returns the default content setting (CONTENT_SETTING_ALLOW,
35 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies.
36 //
37 // This may be called on any thread.
38 ContentSetting GetDefaultSetting() const;
39
40 // Returns true if the page identified by (url, first_party_url) is allowed to
41 // read cookies.
42 //
43 // This may be called on any thread.
44 bool IsReadingCookieAllowed(const GURL& url,
45 const GURL& first_party_url) const;
46
47 // Returns true if the page identified by (url, first_party_url) is allowed to
48 // set a cookie (permanent or session only).
49 //
50 // This may be called on any thread.
51 bool IsSettingCookieAllowed(const GURL& url,
52 const GURL& first_party_url) const;
53
54 // Returns true if the cookie set by a page identified by url should be
55 // session only. Querying this only makes sense if IsSettingCookieAllowed has
56 // returned true.
57 //
58 // This may be called on any thread.
59 bool IsCookieSessionOnly(const GURL& url) const;
60
61 // Sets the default content setting (CONTENT_SETTING_ALLOW,
62 // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies.
63 //
64 // This should only be called on the UI thread.
65 void SetDefaultSetting(ContentSetting setting);
66
67 // Sets the cookie setting to CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK or
68 // CONTENT_SETTING_SESSION_ONLY for (url, first_party_url) pairs where url
69 // matches primary_pattern.
70 //
71 // This should only be called on the UI thread.
72 void SetCookieSetting(const ContentSettingsPattern& primary_pattern,
73 ContentSetting setting);
74
75 // Resets the cookie setting for (url, first_party_url) pais where url matches
76 // primary_pattern.
77 //
78 // This should only be called on the UI thread.
79 void ResetCookieSetting(const ContentSettingsPattern& primary_pattern);
80
81 // This setting trumps any host-specific settings.
82 //
83 // These may be called on any thread.
84 bool BlockThirdPartyCookies() const { return block_third_party_cookies_; }
Bernhard Bauer 2011/09/01 11:41:54 Nit: We could call this method |ShouldBlockThirdPa
marja 2011/09/01 13:34:48 I renamed this, and left SetBlockThirdPartyCookies
85
86 // Sets whether we block all third-party cookies. This method must not be
87 // invoked on an incognito map.
88 //
89 // This should only be called on the UI thread.
90 void SetBlockThirdPartyCookies(bool block);
91
92 // NotificationObserver implementation.
93 virtual void Observe(int type,
94 const NotificationSource& source,
95 const NotificationDetails& details);
96
97 // Detaches the CookieSettings from all Profile-related objects like
98 // PrefService. This methods needs to be called before destroying the Profile.
99 // Afterwards, none of the methods above that should only be called on the UI
100 // thread should be called anymore.
101 void Shutdown();
Bernhard Bauer 2011/09/01 11:41:54 This is a ProfileKeyedService method, right? In th
marja 2011/09/01 13:34:48 It was, but is not any more. I changed it back to
102
103 private:
104 // A helper for retrieving data for CONTENT_TYPE_COOKIES and
105 // CONTENT_TYPE_COOKIES_SESSION_ONLY.
106 ContentSetting GetCookieContentSetting(const GURL& url,
107 const GURL& first_party_url,
108 ContentSettingsType content_type,
109 bool setting_cookie) const;
110
111 // Weak pointer to the data backend (which also owns this object).
Bernhard Bauer 2011/09/01 11:41:54 HostContentSettingsMap doesn't own this object any
marja 2011/09/01 13:34:48 Done.
112 HostContentSettingsMap* host_content_settings_map_;
113
114 // Weak; owned by the profile.
115 PrefService* prefs_;
116 PrefChangeRegistrar pref_change_registrar_;
117
118 bool is_off_the_record_;
119
120 // Used around accesses to the following objects to guarantee thread safety.
121 mutable base::Lock lock_;
122
123 bool block_third_party_cookies_;
124 };
125
126 #endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698