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

Unified 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. Threading fixes. Mac + win fixes. Created 9 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/content_settings/cookie_settings.h
diff --git a/chrome/browser/content_settings/cookie_settings.h b/chrome/browser/content_settings/cookie_settings.h
new file mode 100644
index 0000000000000000000000000000000000000000..8224d454dcbebf28a304b90227273d329fbcfa83
--- /dev/null
+++ b/chrome/browser/content_settings/cookie_settings.h
@@ -0,0 +1,137 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Maps hostnames to cookie settings. Written on the UI thread and read on any
+// thread. One instance per profile.
+
+#ifndef CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
+#define CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
+#pragma once
+
+#include "base/memory/ref_counted.h"
+#include "base/synchronization/lock.h"
+#include "chrome/browser/prefs/pref_change_registrar.h"
+#include "chrome/common/content_settings.h"
+#include "content/common/notification_observer.h"
+
+class ContentSettingsPattern;
+class GURL;
+class HostContentSettingsMap;
+class Profile;
+
+// A frontend to the cookie-specific settings of HostContentSettingsMap. Handles
+// cookie-specific logic such as blocking third-party cookies.
+class CookieSettings
+ : public NotificationObserver,
+ public base::RefCountedThreadSafe<CookieSettings> {
+ public:
+ CookieSettings(
+ HostContentSettingsMap* host_content_settings_map,
+ PrefService* prefs,
+ bool incognito);
+
+ virtual ~CookieSettings();
+
+ // Returns the CookieSettings associated with the profile.
+ //
+ // This should only be called on the UI thread.
+ static CookieSettings* GetForProfile(Profile* profile);
+
+ // Returns the default content setting (CONTENT_SETTING_ALLOW,
+ // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies.
+ //
+ // This may be called on any thread.
+ ContentSetting GetDefaultSetting() const;
+
+ // Returns true if the page identified by (url, first_party_url) is allowed to
+ // read cookies.
+ //
+ // This may be called on any thread.
+ bool IsReadingCookieAllowed(const GURL& url,
+ const GURL& first_party_url) const;
+
+ // Returns true if the page identified by (url, first_party_url) is allowed to
+ // set a cookie (permanent or session only).
+ //
+ // This may be called on any thread.
+ bool IsSettingCookieAllowed(const GURL& url,
+ const GURL& first_party_url) const;
+
+ // Returns true if the cookie set by a page identified by url should be
+ // session only. Querying this only makes sense if IsSettingCookieAllowed has
+ // returned true.
+ //
+ // This may be called on any thread.
+ bool IsCookieSessionOnly(const GURL& url) const;
+
+ // Sets the default content setting (CONTENT_SETTING_ALLOW,
+ // CONTENT_SETTING_BLOCK, or CONTENT_SETTING_SESSION_ONLY) for cookies.
+ //
+ // This should only be called on the UI thread.
+ void SetDefaultSetting(ContentSetting setting);
+
+ // Sets the cookie setting to CONTENT_SETTING_ALLOW, CONTENT_SETTING_BLOCK or
+ // CONTENT_SETTING_SESSION_ONLY for (url, first_party_url) pairs where url
+ // matches primary_pattern.
+ //
+ // This should only be called on the UI thread.
+ void SetCookieSetting(const ContentSettingsPattern& primary_pattern,
+ ContentSetting setting);
+
+ // Resets the cookie setting for (url, first_party_url) pais where url matches
+ // primary_pattern.
+ //
+ // This should only be called on the UI thread.
+ void ResetCookieSetting(const ContentSettingsPattern& primary_pattern);
+
+ // This setting trumps any host-specific settings.
+ //
+ // These may be called on any thread.
+ bool ShouldBlockThirdPartyCookies() const {
+ return block_third_party_cookies_;
+ }
+
+ // Sets whether we block all third-party cookies. This method must not be
+ // invoked on an incognito map.
+ // TODO(bauerb): Remove this and use PrefService directly.
+ //
+ // This should only be called on the UI thread.
+ void SetBlockThirdPartyCookies(bool block);
+
+ // NotificationObserver implementation.
+ virtual void Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ // Detaches the CookieSettings from all Profile-related objects like
+ // PrefService. This methods needs to be called before destroying the Profile.
+ // Afterwards, none of the methods above that should only be called on the UI
+ // thread should be called anymore.
+ void ShutdownOnUIThread();
+
+ private:
+ class Factory;
Bernhard Bauer 2011/09/01 13:58:50 You should initialize the factory in profile_depen
+
+ // A helper for retrieving data for CONTENT_TYPE_COOKIES and
+ // CONTENT_TYPE_COOKIES_SESSION_ONLY.
+ ContentSetting GetCookieContentSetting(const GURL& url,
+ const GURL& first_party_url,
+ ContentSettingsType content_type,
+ bool setting_cookie) const;
+
+ scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
+
+ // Weak; owned by the profile.
+ PrefService* prefs_;
+ PrefChangeRegistrar pref_change_registrar_;
+
+ bool is_off_the_record_;
+
+ // Used around accesses to the following objects to guarantee thread safety.
+ mutable base::Lock lock_;
+
+ bool block_third_party_cookies_;
+};
+
+#endif // CHROME_BROWSER_CONTENT_SETTINGS_COOKIE_SETTINGS_H_
« no previous file with comments | « chrome/browser/content_settings/content_settings_pref_provider.cc ('k') | chrome/browser/content_settings/cookie_settings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698