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

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_provider.h b/components/content_settings/core/browser/content_settings_pref.h
similarity index 66%
copy from components/content_settings/core/browser/content_settings_pref_provider.h
copy to components/content_settings/core/browser/content_settings_pref.h
index 0727e101837ac745559ccf411a39f428c61dbef4..a571a2a8ec6a90acb2df48ec6599933c1d20d900 100644
--- a/components/content_settings/core/browser/content_settings_pref_provider.h
+++ b/components/content_settings/core/browser/content_settings_pref.h
@@ -1,22 +1,23 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// 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_PROVIDER_H_
-#define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_PROVIDER_H_
+#ifndef COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_
+#define COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_
-// A content settings provider that takes its settings out of the pref service.
+#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/prefs/pref_change_registrar.h"
+#include "base/callback.h"
#include "base/synchronization/lock.h"
-#include "components/content_settings/core/browser/content_settings_observable_provider.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_utils.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;
@@ -29,31 +30,38 @@ class PrefRegistrySyncable;
namespace content_settings {
-// Content settings provider that provides content settings from the user
-// preference.
-class PrefProvider : public ObservableProvider {
- public:
- static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
+class RuleIterator;
- PrefProvider(PrefService* prefs, bool incognito);
- ~PrefProvider() override;
+// 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();
- // ProviderInterface implementations.
RuleIterator* GetRuleIterator(ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
- bool incognito) const override;
+ bool incognito) const;
bool SetWebsiteSetting(const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
- base::Value* value) override;
+ base::Value* value);
- void ClearAllContentSettingsRules(ContentSettingsType content_type) override;
+ void ClearAllContentSettingsRules(ContentSettingsType content_type);
- void ShutdownOnUIThread() override;
-
- // Records the last time the given pattern has used a certain content setting.
void UpdateLastUsage(const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type);
@@ -62,11 +70,12 @@ class PrefProvider : public ObservableProvider {
const ContentSettingsPattern& secondary_pattern,
ContentSettingsType content_type);
- // Gains ownership of |clock|.
- void SetClockForTesting(scoped_ptr<base::Clock> clock);
+ 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();
@@ -85,9 +94,6 @@ class PrefProvider : public ObservableProvider {
const ResourceIdentifier& resource_identifier,
const base::Value* value);
- // Migrate the old media setting into new mic/camera content settings.
- void MigrateObsoleteMediaContentSetting();
-
static void CanonicalizeContentSettingsExceptions(
base::DictionaryValue* all_settings_dictionary);
@@ -99,12 +105,13 @@ class PrefProvider : public ObservableProvider {
// Weak; owned by the Profile and reset in ShutdownOnUIThread.
PrefService* prefs_;
- // Can be set for testing.
- scoped_ptr<base::Clock> clock_;
+ // Owned by the PrefProvider.
+ base::Clock* clock_;
- bool is_incognito_;
+ // Owned by the PrefProvider.
+ PrefChangeRegistrar* registrar_;
- PrefChangeRegistrar pref_change_registrar_;
+ bool is_incognito_;
// Whether we are currently updating preferences, this is used to ignore
// notifications from the preferences service that we triggered ourself.
@@ -114,12 +121,16 @@ class PrefProvider : public ObservableProvider {
OriginIdentifierValueMap incognito_value_map_;
+ NotifyObserversCallback notify_callback_;
+
// Used around accesses to the value map objects to guarantee thread safety.
mutable base::Lock lock_;
- DISALLOW_COPY_AND_ASSIGN(PrefProvider);
+ base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContentSettingsPref);
};
} // namespace content_settings
-#endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_PROVIDER_H_
+#endif // COMPONENTS_CONTENT_SETTINGS_CORE_BROWSER_CONTENT_SETTINGS_PREF_H_
« no previous file with comments | « components/content_settings/core/browser/BUILD.gn ('k') | components/content_settings/core/browser/content_settings_pref.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698