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

Unified Diff: components/content_settings/core/browser/content_settings_pref.h

Issue 976243002: Split content settings pref related logic into a separate class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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: components/content_settings/core/browser/content_settings_pref.h
diff --git a/components/content_settings/core/browser/content_settings_pref.h b/components/content_settings/core/browser/content_settings_pref.h
new file mode 100644
index 0000000000000000000000000000000000000000..a571a2a8ec6a90acb2df48ec6599933c1d20d900
--- /dev/null
+++ b/components/content_settings/core/browser/content_settings_pref.h
@@ -0,0 +1,136 @@
+// Copyright 2015 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.
+
+#ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_
+#define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_
+
+#include <string>
+
+#include "base/callback.h"
+#include "base/synchronization/lock.h"
+#include "base/threading/thread_checker.h"
+#include "base/values.h"
+#include "components/content_settings/core/browser/content_settings_origin_identifier_value_map.h"
+#include "components/content_settings/core/browser/content_settings_provider.h"
+#include "components/content_settings/core/common/content_settings_pattern.h"
+#include "components/content_settings/core/common/content_settings_types.h"
+
+class PrefService;
+class PrefChangeRegistrar;
+
+namespace base {
+class Clock;
+class DictionaryValue;
+}
+
+namespace user_prefs {
+class PrefRegistrySyncable;
+}
+
+namespace content_settings {
+
+class RuleIterator;
+
+// Represents a single pref for reading/writing content settings.
+// TODO(raymes): Currently all content settings types are stored in a single
+// instance of one of these. But the intention is that there will be one
+// instance of this class per content settings type.
+class ContentSettingsPref {
+ public:
+ typedef base::Callback<void(const ContentSettingsPattern&,
+ const ContentSettingsPattern&,
+ ContentSettingsType,
+ const std::string&)> NotifyObserversCallback;
+
+ ContentSettingsPref(PrefService* prefs,
+ PrefChangeRegistrar* registrar,
+ base::Clock* clock,
+ bool incognito,
+ NotifyObserversCallback notify_callback);
+ ~ContentSettingsPref();
+
+ RuleIterator* GetRuleIterator(ContentSettingsType content_type,
+ const ResourceIdentifier& resource_identifier,
+ bool incognito) const;
+
+ bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern,
+ const ContentSettingsPattern& secondary_pattern,
+ ContentSettingsType content_type,
+ const ResourceIdentifier& resource_identifier,
+ base::Value* value);
+
+ void ClearAllContentSettingsRules(ContentSettingsType content_type);
+
+ void UpdateLastUsage(const ContentSettingsPattern& primary_pattern,
+ const ContentSettingsPattern& secondary_pattern,
+ ContentSettingsType content_type);
+
+ base::Time GetLastUsage(const ContentSettingsPattern& primary_pattern,
+ const ContentSettingsPattern& secondary_pattern,
+ ContentSettingsType content_type);
+
+ size_t GetNumExceptions();
+
+ void SetClockForTesting(base::Clock* clock);
+ private:
+ friend class DeadlockCheckerThread; // For testing.
+
+ // Reads all content settings exceptions from the preference and load them
+ // into the |value_map_|. The |value_map_| is cleared first.
+ void ReadContentSettingsFromPref();
+
+ // Callback for changes in the pref with the same name.
+ void OnContentSettingsPatternPairsChanged();
+
+ // Update the preference that stores content settings exceptions and syncs the
+ // value to the obsolete preference. When calling this function, |lock_|
+ // should not be held, since this function will send out notifications of
+ // preference changes.
+ void UpdatePref(
+ const ContentSettingsPattern& primary_pattern,
+ const ContentSettingsPattern& secondary_pattern,
+ ContentSettingsType content_type,
+ const ResourceIdentifier& resource_identifier,
+ const base::Value* value);
+
+ static void CanonicalizeContentSettingsExceptions(
+ base::DictionaryValue* all_settings_dictionary);
+
+ // In the debug mode, asserts that |lock_| is not held by this thread. It's
+ // ok if some other thread holds |lock_|, as long as it will eventually
+ // release it.
+ void AssertLockNotHeld() const;
+
+ // Weak; owned by the Profile and reset in ShutdownOnUIThread.
+ PrefService* prefs_;
+
+ // Owned by the PrefProvider.
+ base::Clock* clock_;
+
+ // Owned by the PrefProvider.
+ PrefChangeRegistrar* registrar_;
+
+ bool is_incognito_;
+
+ // Whether we are currently updating preferences, this is used to ignore
+ // notifications from the preferences service that we triggered ourself.
+ bool updating_preferences_;
+
+ OriginIdentifierValueMap value_map_;
+
+ OriginIdentifierValueMap incognito_value_map_;
+
+ NotifyObserversCallback notify_callback_;
+
+ // Used around accesses to the value map objects to guarantee thread safety.
+ mutable base::Lock lock_;
+
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref);
+};
+
+} // namespace content_settings
+
+#endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_

Powered by Google App Engine
This is Rietveld 408576698