summaryrefslogtreecommitdiffstats
path: root/components/content_settings
diff options
context:
space:
mode:
authormsramek <msramek@chromium.org>2015-08-04 07:24:46 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-04 14:28:18 +0000
commitc7fbbdb4e1fd03699682ce30a795e35aa0eeb3dd (patch)
tree84aea54c4b1e67050657e80af6dfc7315a6f97dc /components/content_settings
parente06839cf7339c40971d9e9bd50a8b1b5560070f2 (diff)
downloadchromium_src-c7fbbdb4e1fd03699682ce30a795e35aa0eeb3dd.zip
chromium_src-c7fbbdb4e1fd03699682ce30a795e35aa0eeb3dd.tar.gz
chromium_src-c7fbbdb4e1fd03699682ce30a795e35aa0eeb3dd.tar.bz2
Remove the migration code from content_settings::PrefProvider.
This is a follow-up to https://codereview.chromium.org/1252973002/. The situation is equivalent: 1. We expect most users to have been migrated from the old preferences, as the migration code has been live for 3 milestones. 2. We can remove the media and cookies migration code, as they are older and the deprecated values could not have made it to the new preferences. TESTED=Effects on websites in the regular mode and incognito, syncing between two machines BUG=452388 Review URL: https://codereview.chromium.org/1257093002 Cr-Commit-Position: refs/heads/master@{#341720}
Diffstat (limited to 'components/content_settings')
-rw-r--r--components/content_settings/core/browser/content_settings_pref.cc177
-rw-r--r--components/content_settings/core/browser/content_settings_pref.h34
-rw-r--r--components/content_settings/core/browser/content_settings_pref_provider.cc347
-rw-r--r--components/content_settings/core/browser/content_settings_pref_provider.h67
-rw-r--r--components/content_settings/core/common/pref_names.cc12
-rw-r--r--components/content_settings/core/common/pref_names.h3
6 files changed, 58 insertions, 582 deletions
diff --git a/components/content_settings/core/browser/content_settings_pref.cc b/components/content_settings/core/browser/content_settings_pref.cc
index a519cef..535bcc6 100644
--- a/components/content_settings/core/browser/content_settings_pref.cc
+++ b/components/content_settings/core/browser/content_settings_pref.cc
@@ -23,7 +23,6 @@ namespace {
const char kSettingPath[] = "setting";
const char kPerResourceIdentifierPrefName[] = "per_resource";
-const char kPerPluginPrefName[] = "per_plugin";
const char kLastUsed[] = "last_used";
ContentSetting FixObsoleteCookiePromptMode(ContentSettingsType content_type,
@@ -53,7 +52,6 @@ ContentSettingsPref::ContentSettingsPref(
PrefChangeRegistrar* registrar,
const char* pref_name,
bool incognito,
- bool* updating_old_preferences_flag,
NotifyObserversCallback notify_callback)
: content_type_(content_type),
prefs_(prefs),
@@ -61,23 +59,10 @@ ContentSettingsPref::ContentSettingsPref(
pref_name_(pref_name),
is_incognito_(incognito),
updating_preferences_(false),
- updating_old_preferences_(updating_old_preferences_flag),
notify_callback_(notify_callback) {
DCHECK(prefs_);
- // If the migration hasn't happened yet, or if this content setting
- // is syncable, the parent |PrefProvider| is going to copy the contents
- // of the old preference to this new preference. There is no need
- // to initialize this preference separately (in fact, in the case
- // of migration, we would be writing the empty new preference back to the
- // old one, erasing it). Since copying between preferences is disallowed
- // in incognito, |ContentSettingsPref| needs to be initialized from the new
- // preference in incognito as well.
- if ((prefs_->GetBoolean(prefs::kMigratedContentSettingsPatternPairs) &&
- !IsContentSettingsTypeSyncable(content_type_))
- || is_incognito_) {
- ReadContentSettingsFromPrefAndWriteToOldPref();
- }
+ ReadContentSettingsFromPref();
registrar_->Add(
pref_name_,
@@ -139,12 +124,6 @@ bool ContentSettingsPref::SetWebsiteSetting(
secondary_pattern,
resource_identifier,
value.get());
- if (IsContentSettingsTypeSyncable(content_type_)) {
- UpdateOldPref(primary_pattern,
- secondary_pattern,
- resource_identifier,
- value.get());
- }
}
notify_callback_.Run(
@@ -167,16 +146,13 @@ void ContentSettingsPref::ClearAllContentSettingsRules() {
}
if (!is_incognito_) {
- // Clear the new preference.
+ // Clear the preference.
{
base::AutoReset<bool> auto_reset(&updating_preferences_, true);
DictionaryPrefUpdate update(prefs_, pref_name_);
base::DictionaryValue* pattern_pairs_settings = update.Get();
pattern_pairs_settings->Clear();
}
-
- if (IsContentSettingsTypeSyncable(content_type_))
- ClearOldPreference();
}
notify_callback_.Run(ContentSettingsPattern(),
@@ -249,14 +225,14 @@ size_t ContentSettingsPref::GetNumExceptions() {
return value_map_.size();
}
-void ContentSettingsPref::ReadContentSettingsFromPrefAndWriteToOldPref() {
- // Clear the old preference, so we can copy the exceptions from the new
- // preference into it. Note that copying in this direction is disallowed
- // in incognito, to avoid the echo effect: New preference -> PrefProvider ->
- // Old preference -> Incognito PrefProvider -> New preference -> etc.
- if (!is_incognito_ && IsContentSettingsTypeSyncable(content_type_))
- ClearOldPreference();
+bool ContentSettingsPref::TryLockForTesting() const {
+ if (!lock_.Try())
+ return false;
+ lock_.Release();
+ return true;
+}
+void ContentSettingsPref::ReadContentSettingsFromPref() {
// |DictionaryPrefUpdate| sends out notifications when destructed. This
// construction order ensures |AutoLock| gets destroyed first and |lock_| is
// not held when the notifications are sent. Also, |auto_reset| must be still
@@ -328,12 +304,6 @@ void ContentSettingsPref::ReadContentSettingsFromPrefAndWriteToOldPref() {
content_type_,
resource_identifier,
setting_ptr->DeepCopy());
- if (!is_incognito_ && IsContentSettingsTypeSyncable(content_type_)) {
- UpdateOldPref(pattern_pair.first,
- pattern_pair.second,
- resource_identifier,
- setting_ptr.get());
- }
}
}
}
@@ -364,12 +334,6 @@ void ContentSettingsPref::ReadContentSettingsFromPrefAndWriteToOldPref() {
content_type_,
ResourceIdentifier(),
value->DeepCopy());
- if (!is_incognito_ && IsContentSettingsTypeSyncable(content_type_)) {
- UpdateOldPref(pattern_pair.first,
- pattern_pair.second,
- ResourceIdentifier(),
- value_ptr.get());
- }
if (content_type_ == CONTENT_SETTINGS_TYPE_COOKIES) {
ContentSetting s = ValueToContentSetting(value);
switch (s) {
@@ -407,7 +371,7 @@ void ContentSettingsPref::OnPrefChanged() {
if (updating_preferences_)
return;
- ReadContentSettingsFromPrefAndWriteToOldPref();
+ ReadContentSettingsFromPref();
notify_callback_.Run(ContentSettingsPattern(),
ContentSettingsPattern(),
@@ -486,127 +450,6 @@ void ContentSettingsPref::UpdatePref(
}
}
-void ContentSettingsPref::UpdateOldPref(
- const ContentSettingsPattern& primary_pattern,
- const ContentSettingsPattern& secondary_pattern,
- const ResourceIdentifier& resource_identifier,
- const base::Value* value) {
- DCHECK(IsContentSettingsTypeSyncable(content_type_));
-
- // The incognito provider cannot write the settings to avoid echo effect:
- // New preference -> PrefProvider -> Old preference ->
- // -> Incognito PrefProvider -> New preference -> etc.
- DCHECK(!is_incognito_);
-
- if (*updating_old_preferences_)
- return;
-
- base::AutoReset<bool> auto_reset(updating_old_preferences_, true);
- {
- DictionaryPrefUpdate update(prefs_,
- prefs::kContentSettingsPatternPairs);
- base::DictionaryValue* pattern_pairs_settings = update.Get();
-
- // Get settings dictionary for the given patterns.
- std::string pattern_str(CreatePatternString(primary_pattern,
- secondary_pattern));
- base::DictionaryValue* settings_dictionary = NULL;
- bool found = pattern_pairs_settings->GetDictionaryWithoutPathExpansion(
- pattern_str, &settings_dictionary);
-
- if (!found && value) {
- settings_dictionary = new base::DictionaryValue;
- pattern_pairs_settings->SetWithoutPathExpansion(
- pattern_str, settings_dictionary);
- }
-
- if (settings_dictionary) {
- if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS &&
- !resource_identifier.empty()) {
- base::DictionaryValue* resource_dictionary = NULL;
- found = settings_dictionary->GetDictionary(
- kPerPluginPrefName, &resource_dictionary);
- if (!found) {
- if (value == NULL)
- return; // Nothing to remove. Exit early.
- resource_dictionary = new base::DictionaryValue;
- settings_dictionary->Set(kPerPluginPrefName, resource_dictionary);
- }
- // Update resource dictionary.
- if (value == NULL) {
- resource_dictionary->RemoveWithoutPathExpansion(resource_identifier,
- NULL);
- if (resource_dictionary->empty()) {
- settings_dictionary->RemoveWithoutPathExpansion(
- kPerPluginPrefName, NULL);
- }
- } else {
- resource_dictionary->SetWithoutPathExpansion(
- resource_identifier, value->DeepCopy());
- }
- } else {
- // Update settings dictionary.
- std::string setting_path = GetTypeName(content_type_);
- if (value == NULL) {
- settings_dictionary->RemoveWithoutPathExpansion(setting_path,
- NULL);
- settings_dictionary->RemoveWithoutPathExpansion(kLastUsed, NULL);
- } else {
- settings_dictionary->SetWithoutPathExpansion(
- setting_path, value->DeepCopy());
- }
- }
- // Remove the settings dictionary if it is empty.
- if (settings_dictionary->empty()) {
- pattern_pairs_settings->RemoveWithoutPathExpansion(
- pattern_str, NULL);
- }
- }
- }
-}
-
-void ContentSettingsPref::ClearOldPreference() {
- DCHECK(IsContentSettingsTypeSyncable(content_type_));
-
- if (*updating_old_preferences_)
- return;
-
- std::vector<std::string> keys;
-
- base::AutoReset<bool> auto_reset(updating_old_preferences_, true);
- DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs);
- base::DictionaryValue* old_dictionary = update.Get();
-
- for (base::DictionaryValue::Iterator it(*old_dictionary);
- !it.IsAtEnd(); it.Advance()) {
- keys.push_back(it.key());
- }
-
- for (const std::string& key : keys) {
- base::DictionaryValue* exception;
- bool is_dictionary =
- old_dictionary->GetDictionaryWithoutPathExpansion(key, &exception);
- DCHECK(is_dictionary);
-
- exception->RemoveWithoutPathExpansion(GetTypeName(content_type_), NULL);
-
- base::DictionaryValue* last_used;
- if (exception->GetDictionaryWithoutPathExpansion(kLastUsed, &last_used)) {
- last_used->RemoveWithoutPathExpansion(GetTypeName(content_type_), NULL);
-
- if (last_used->empty())
- exception->RemoveWithoutPathExpansion(kLastUsed, NULL);
- }
-
- if (content_type_ == CONTENT_SETTINGS_TYPE_PLUGINS)
- exception->RemoveWithoutPathExpansion(kPerPluginPrefName, NULL);
-
- if (exception->empty())
- old_dictionary->RemoveWithoutPathExpansion(key, NULL);
- }
-
-}
-
// static
void ContentSettingsPref::CanonicalizeContentSettingsExceptions(
base::DictionaryValue* all_settings_dictionary) {
diff --git a/components/content_settings/core/browser/content_settings_pref.h b/components/content_settings/core/browser/content_settings_pref.h
index 1314e16..2dd554b 100644
--- a/components/content_settings/core/browser/content_settings_pref.h
+++ b/components/content_settings/core/browser/content_settings_pref.h
@@ -45,7 +45,6 @@ class ContentSettingsPref {
PrefChangeRegistrar* registrar,
const char* pref_name,
bool incognito,
- bool* updating_old_preferences_flag,
NotifyObserversCallback notify_callback);
~ContentSettingsPref();
@@ -68,15 +67,17 @@ class ContentSettingsPref {
size_t GetNumExceptions();
+ // Tries to lock |lock_|. If successful, returns true and releases the lock.
+ bool TryLockForTesting() const;
+
private:
- // Only to access static method CanonicalizeContentSettingsExceptions,
- // so that we reduce duplicity between the two.
- // TODO(msramek): Remove this after the migration is over.
- friend class PrefProvider;
+ // TODO(msramek): Currently only needed in the unittest to get the
+ // corresponding pref name. Remove once pref names are in WebsiteSettingsInfo.
+ friend class DeadlockCheckerObserver;
- // Reads all content settings exceptions from the preference and load them
+ // Reads all content settings exceptions from the preference and loads them
// into the |value_map_|. The |value_map_| is cleared first.
- void ReadContentSettingsFromPrefAndWriteToOldPref();
+ void ReadContentSettingsFromPref();
// Callback for changes in the pref with the same name.
void OnPrefChanged();
@@ -99,20 +100,6 @@ class ContentSettingsPref {
// release it.
void AssertLockNotHeld() const;
- // Update the old aggregate preference, so that the settings can be synced
- // to old versions of Chrome.
- // TODO(msramek): Remove after the migration is over.
- void UpdateOldPref(
- const ContentSettingsPattern& primary_pattern,
- const ContentSettingsPattern& secondary_pattern,
- const ResourceIdentifier& resource_identifier,
- const base::Value* value);
-
- // Remove all exceptions of |content_type_| from the old aggregate dictionary
- // preference.
- // TODO(msramek): Remove after the migration is over.
- void ClearOldPreference();
-
// The type of content settings stored in this pref.
ContentSettingsType content_type_;
@@ -131,11 +118,6 @@ class ContentSettingsPref {
// notifications from the preferences service that we triggered ourself.
bool updating_preferences_;
- // Whether we are currently updating the old aggregate dictionary preference.
- // Owned by the parent |PrefProvider| and shared by all its children
- // |ContentSettingsPref|s.
- bool* updating_old_preferences_;
-
OriginIdentifierValueMap value_map_;
OriginIdentifierValueMap incognito_value_map_;
diff --git a/components/content_settings/core/browser/content_settings_pref_provider.cc b/components/content_settings/core/browser/content_settings_pref_provider.cc
index ef80480..8e77612 100644
--- a/components/content_settings/core/browser/content_settings_pref_provider.cc
+++ b/components/content_settings/core/browser/content_settings_pref_provider.cc
@@ -30,40 +30,12 @@
namespace {
-const char kPerPluginPrefName[] = "per_plugin";
-
-// Returns true and sets |pref_key| to the key in the content settings
-// dictionary under which per-resource content settings are stored,
-// if the given content type supports resource identifiers in user preferences.
-bool GetResourceTypeName(ContentSettingsType content_type,
- std::string* pref_key) {
- if (content_type == CONTENT_SETTINGS_TYPE_PLUGINS) {
- *pref_key = kPerPluginPrefName;
- return true;
- }
- return false;
-}
-
-// TODO(msramek): Check if we still need this migration code. If not, remove it.
-ContentSetting FixObsoleteCookiePromptMode(ContentSettingsType content_type,
- ContentSetting setting) {
- if (content_type == CONTENT_SETTINGS_TYPE_COOKIES &&
- setting == CONTENT_SETTING_ASK) {
- return CONTENT_SETTING_BLOCK;
- }
- return setting;
-}
-
-// A helper function to duplicate |ContentSettingsPattern|, so that
-// |ReadContentSettingsFromOldPref| can export them in a vector. We cannot pass
-// them by pointer, because the original values will go out of scope when
-// the vector is used in |WriteSettingsToNewPreferences|.
-ContentSettingsPattern CopyPattern(const ContentSettingsPattern& pattern) {
- return ContentSettingsPattern::FromString(pattern.ToString());
-}
-
-const char kAudioKey[] = "audio";
-const char kVideoKey[] = "video";
+// Obsolete prefs.
+// TODO(msramek): Remove the cleanup code after two releases (i.e. in M48).
+const char kObsoleteContentSettingsPatternPairs[] =
+ "profile.content_settings.pattern_pairs";
+const char kObsoleteMigratedContentSettingsPatternPairs[] =
+ "profile.migrated_content_settings_exceptions";
// A list of exception preferences corresponding to individual content settings
// types. Must be kept in sync with the enum |ContentSettingsType|.
@@ -116,29 +88,41 @@ void PrefProvider::RegisterProfilePrefs(
registry->RegisterIntegerPref(
prefs::kContentSettingsVersion,
ContentSettingsPattern::kContentSettingsPatternVersion);
- registry->RegisterDictionaryPref(
- prefs::kContentSettingsPatternPairs,
- user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
- registry->RegisterBooleanPref(prefs::kMigratedContentSettingsPatternPairs,
- false);
for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
registry->RegisterDictionaryPref(
kContentSettingsExceptionsPrefs[i],
PrefRegistrationFlagsForType(ContentSettingsType(i)));
}
+
+ // Obsolete prefs ----------------------------------------------------------
+
+ registry->RegisterDictionaryPref(
+ kObsoleteContentSettingsPatternPairs,
+ user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
+ registry->RegisterBooleanPref(
+ kObsoleteMigratedContentSettingsPatternPairs, false);
+}
+
+// static
+bool PrefProvider::IsContentSettingsExceptionsPref(
+ const std::string& pref_name) {
+ for (const char* pref : kContentSettingsExceptionsPrefs) {
+ if (pref_name == pref)
+ return true;
+ }
+ return false;
}
PrefProvider::PrefProvider(PrefService* prefs, bool incognito)
: prefs_(prefs),
clock_(new base::DefaultClock()),
- is_incognito_(incognito),
- updating_old_preferences_(false) {
+ is_incognito_(incognito) {
DCHECK(prefs_);
// Verify preferences version.
if (!prefs_->HasPrefPath(prefs::kContentSettingsVersion)) {
prefs_->SetInteger(prefs::kContentSettingsVersion,
- ContentSettingsPattern::kContentSettingsPatternVersion);
+ ContentSettingsPattern::kContentSettingsPatternVersion);
}
if (prefs_->GetInteger(prefs::kContentSettingsVersion) >
ContentSettingsPattern::kContentSettingsPatternVersion) {
@@ -146,28 +130,11 @@ PrefProvider::PrefProvider(PrefService* prefs, bool incognito)
}
pref_change_registrar_.Init(prefs_);
-
- pref_change_registrar_.Add(prefs::kContentSettingsPatternPairs, base::Bind(
- &PrefProvider::OnOldContentSettingsPatternPairsChanged,
- base::Unretained(this)));
-
for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
content_settings_prefs_.push_back(new ContentSettingsPref(
ContentSettingsType(i), prefs_, &pref_change_registrar_,
kContentSettingsExceptionsPrefs[i], is_incognito_,
- &updating_old_preferences_, base::Bind(&PrefProvider::Notify,
- base::Unretained(this))));
- }
-
- // Migrate all the exceptions from the aggregate dictionary preference
- // to the separate dictionaries, if this hasn't been done before.
- if (!prefs_->GetBoolean(prefs::kMigratedContentSettingsPatternPairs)) {
- WriteSettingsToNewPreferences(false);
- prefs_->SetBoolean(prefs::kMigratedContentSettingsPatternPairs, true);
- } else {
- // Trigger the update of old preference, and as a result,
- // the new preferences as well.
- OnOldContentSettingsPatternPairsChanged();
+ base::Bind(&PrefProvider::Notify, base::Unretained(this))));
}
if (!is_incognito_) {
@@ -177,12 +144,9 @@ PrefProvider::PrefProvider(PrefService* prefs, bool incognito)
UMA_HISTOGRAM_COUNTS("ContentSettings.NumberOfExceptions",
num_exceptions);
-
- // Migrate the obsolete media content setting exceptions to the new
- // settings.
- MigrateObsoleteMediaContentSetting();
}
+ DiscardObsoletePreferences();
}
PrefProvider::~PrefProvider() {
@@ -261,88 +225,6 @@ base::Time PrefProvider::GetLastUsage(
// ////////////////////////////////////////////////////////////////////////////
// Private
-PrefProvider::ContentSettingsPrefEntry::ContentSettingsPrefEntry(
- const ContentSettingsPattern primary_pattern,
- const ContentSettingsPattern secondary_pattern,
- const ResourceIdentifier resource_identifier,
- base::Value* value)
- : primary_pattern(CopyPattern(primary_pattern)),
- secondary_pattern(CopyPattern(secondary_pattern)),
- resource_identifier(resource_identifier),
- value(value) {
-}
-
-PrefProvider::ContentSettingsPrefEntry::ContentSettingsPrefEntry(
- const ContentSettingsPrefEntry& entry)
- : primary_pattern(CopyPattern(entry.primary_pattern)),
- secondary_pattern(CopyPattern(entry.secondary_pattern)),
- resource_identifier(entry.resource_identifier),
- value(entry.value->DeepCopy()) {
-}
-
-PrefProvider::ContentSettingsPrefEntry&
- PrefProvider::ContentSettingsPrefEntry::operator=(
- const ContentSettingsPrefEntry& entry) {
- this->primary_pattern = CopyPattern(entry.primary_pattern);
- this->secondary_pattern = CopyPattern(entry.secondary_pattern);
- this->resource_identifier = entry.resource_identifier;
- this->value.reset(entry.value->DeepCopy());
-
- return *this;
-}
-
-PrefProvider::ContentSettingsPrefEntry::~ContentSettingsPrefEntry() {}
-
-void PrefProvider::MigrateObsoleteMediaContentSetting() {
- std::vector<Rule> rules_to_delete;
- {
- scoped_ptr<RuleIterator> rule_iterator(GetRuleIterator(
- CONTENT_SETTINGS_TYPE_MEDIASTREAM, ResourceIdentifier(), false));
- while (rule_iterator->HasNext()) {
- // Skip default setting and rules without a value.
- const content_settings::Rule& rule = rule_iterator->Next();
- DCHECK(rule.primary_pattern != ContentSettingsPattern::Wildcard());
- if (!rule.value.get())
- continue;
- rules_to_delete.push_back(rule);
- }
- }
-
- for (std::vector<Rule>::const_iterator it = rules_to_delete.begin();
- it != rules_to_delete.end(); ++it) {
- const base::DictionaryValue* value_dict = NULL;
- if (!it->value->GetAsDictionary(&value_dict) || value_dict->empty())
- return;
-
- std::string audio_device, video_device;
- value_dict->GetString(kAudioKey, &audio_device);
- value_dict->GetString(kVideoKey, &video_device);
- // Add the exception to the new microphone content setting.
- if (!audio_device.empty()) {
- SetWebsiteSetting(it->primary_pattern,
- it->secondary_pattern,
- CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC,
- ResourceIdentifier(),
- new base::FundamentalValue(CONTENT_SETTING_ALLOW));
- }
- // Add the exception to the new camera content setting.
- if (!video_device.empty()) {
- SetWebsiteSetting(it->primary_pattern,
- it->secondary_pattern,
- CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA,
- ResourceIdentifier(),
- new base::FundamentalValue(CONTENT_SETTING_ALLOW));
- }
-
- // Remove the old exception in CONTENT_SETTINGS_TYPE_MEDIASTREAM.
- SetWebsiteSetting(it->primary_pattern,
- it->secondary_pattern,
- CONTENT_SETTINGS_TYPE_MEDIASTREAM,
- ResourceIdentifier(),
- NULL);
- }
-}
-
void PrefProvider::Notify(
const ContentSettingsPattern& primary_pattern,
const ContentSettingsPattern& secondary_pattern,
@@ -354,180 +236,13 @@ void PrefProvider::Notify(
resource_identifier);
}
-void PrefProvider::ReadContentSettingsFromOldPref() {
- // |DictionaryPrefUpdate| sends out notifications when destructed. This
- // construction order ensures |AutoLock| gets destroyed first and |old_lock_|
- // is not held when the notifications are sent. Also, |auto_reset| must be
- // still valid when the notifications are sent, so that |Observe| skips the
- // notification.
- base::AutoReset<bool> auto_reset(&updating_old_preferences_, true);
- DictionaryPrefUpdate update(prefs_, prefs::kContentSettingsPatternPairs);
-
- ClearPrefEntryMap();
-
- const base::DictionaryValue* all_settings_dictionary =
- prefs_->GetDictionary(prefs::kContentSettingsPatternPairs);
-
- // Careful: The returned value could be NULL if the pref has never been set.
- if (!all_settings_dictionary)
- return;
-
- base::DictionaryValue* mutable_settings;
- scoped_ptr<base::DictionaryValue> mutable_settings_scope;
-
- if (!is_incognito_) {
- mutable_settings = update.Get();
- } else {
- // Create copy as we do not want to persist anything in OTR prefs.
- mutable_settings = all_settings_dictionary->DeepCopy();
- mutable_settings_scope.reset(mutable_settings);
- }
- // Convert all Unicode patterns into punycode form, then read.
- ContentSettingsPref::CanonicalizeContentSettingsExceptions(mutable_settings);
-
- for (base::DictionaryValue::Iterator i(*mutable_settings); !i.IsAtEnd();
- i.Advance()) {
- const std::string& pattern_str(i.key());
- std::pair<ContentSettingsPattern, ContentSettingsPattern> pattern_pair =
- ParsePatternString(pattern_str);
- if (!pattern_pair.first.IsValid() ||
- !pattern_pair.second.IsValid()) {
- // TODO: Change this to DFATAL when crbug.com/132659 is fixed.
- LOG(ERROR) << "Invalid pattern strings: " << pattern_str;
- continue;
- }
-
- // Get settings dictionary for the current pattern string, and read
- // settings from the dictionary.
- const base::DictionaryValue* settings_dictionary = NULL;
- bool is_dictionary = i.value().GetAsDictionary(&settings_dictionary);
- DCHECK(is_dictionary);
-
- for (size_t k = 0; k < CONTENT_SETTINGS_NUM_TYPES; ++k) {
- ContentSettingsType content_type = static_cast<ContentSettingsType>(k);
-
- std::string res_dictionary_path;
- if (GetResourceTypeName(content_type, &res_dictionary_path)) {
- const base::DictionaryValue* resource_dictionary = NULL;
- if (settings_dictionary->GetDictionary(
- res_dictionary_path, &resource_dictionary)) {
- for (base::DictionaryValue::Iterator j(*resource_dictionary);
- !j.IsAtEnd();
- j.Advance()) {
- const std::string& resource_identifier(j.key());
- int setting = CONTENT_SETTING_DEFAULT;
- bool is_integer = j.value().GetAsInteger(&setting);
- DCHECK(is_integer);
- DCHECK_NE(CONTENT_SETTING_DEFAULT, setting);
-
- pref_entry_map_[content_type].push_back(
- new ContentSettingsPrefEntry(
- pattern_pair.first,
- pattern_pair.second,
- resource_identifier,
- new base::FundamentalValue(setting)));
- }
- }
- }
- base::Value* value = NULL;
- if (HostContentSettingsMap::ContentTypeHasCompoundValue(content_type)) {
- const base::DictionaryValue* setting = NULL;
- // TODO(xians): Handle the non-dictionary types.
- if (settings_dictionary->GetDictionaryWithoutPathExpansion(
- GetTypeName(content_type), &setting)) {
- DCHECK(!setting->empty());
- value = setting->DeepCopy();
- }
- } else {
- int setting = CONTENT_SETTING_DEFAULT;
- if (settings_dictionary->GetIntegerWithoutPathExpansion(
- GetTypeName(content_type), &setting)) {
- DCHECK_NE(CONTENT_SETTING_DEFAULT, setting);
- setting = FixObsoleteCookiePromptMode(content_type,
- ContentSetting(setting));
- value = new base::FundamentalValue(setting);
- }
- }
-
- // |pref_entry_map_| will take the ownership of |value|.
- if (value != NULL) {
- pref_entry_map_[content_type].push_back(
- new ContentSettingsPrefEntry(
- pattern_pair.first,
- pattern_pair.second,
- ResourceIdentifier(),
- value));
- }
- }
- }
-}
-
-void PrefProvider::WriteSettingsToNewPreferences(bool syncable_only) {
- // The incognito provider cannot write the settings to avoid echo effect:
- // New preference -> PrefProvider -> Old preference ->
- // -> Incognito PrefProvider -> New preference -> etc.
- if (is_incognito_)
- return;
-
- if (updating_old_preferences_)
- return;
-
- base::AutoReset<bool> auto_reset(&updating_old_preferences_, true);
- base::AutoLock auto_lock(old_lock_);
-
- ReadContentSettingsFromOldPref();
-
- for (int k = 0; k < CONTENT_SETTINGS_NUM_TYPES; ++k) {
- ContentSettingsType content_type = ContentSettingsType(k);
-
- if (syncable_only && !IsContentSettingsTypeSyncable(content_type))
- continue;
-
- content_settings_prefs_[content_type]->ClearAllContentSettingsRules();
-
- for (size_t i = 0; i < pref_entry_map_[content_type].size(); ++i) {
-#if defined(OS_CHROMEOS) || defined(OS_ANDROID)
- // Protected Media Identifier "Allow" exceptions can not be migrated.
- const base::FundamentalValue allow_value(CONTENT_SETTING_ALLOW);
- if (content_type == CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER &&
- pref_entry_map_[content_type][i]->value->Equals(&allow_value)) {
- continue;
- }
-#endif
-
- content_settings_prefs_[content_type]->SetWebsiteSetting(
- pref_entry_map_[content_type][i]->primary_pattern,
- pref_entry_map_[content_type][i]->secondary_pattern,
- pref_entry_map_[content_type][i]->resource_identifier,
- pref_entry_map_[content_type][i]->value.release());
- }
- }
-
- ClearPrefEntryMap();
-}
-
-void PrefProvider::ClearPrefEntryMap() {
- for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i)
- pref_entry_map_[i].clear();
-}
-
-void PrefProvider::OnOldContentSettingsPatternPairsChanged() {
- DCHECK(thread_checker_.CalledOnValidThread());
-
- WriteSettingsToNewPreferences(true);
-}
-
void PrefProvider::SetClockForTesting(scoped_ptr<base::Clock> clock) {
clock_ = clock.Pass();
}
-bool PrefProvider::TestAllLocks() const {
- for (size_t i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) {
- if (!content_settings_prefs_[i]->lock_.Try())
- return false;
- content_settings_prefs_[i]->lock_.Release();
- }
- return true;
+void PrefProvider::DiscardObsoletePreferences() {
+ prefs_->ClearPref(kObsoleteContentSettingsPatternPairs);
+ prefs_->ClearPref(kObsoleteMigratedContentSettingsPatternPairs);
}
} // namespace content_settings
diff --git a/components/content_settings/core/browser/content_settings_pref_provider.h b/components/content_settings/core/browser/content_settings_pref_provider.h
index ec235a9..7a64603 100644
--- a/components/content_settings/core/browser/content_settings_pref_provider.h
+++ b/components/content_settings/core/browser/content_settings_pref_provider.h
@@ -39,6 +39,10 @@ class PrefProvider : public ObservableProvider {
PrefProvider(PrefService* prefs, bool incognito);
~PrefProvider() override;
+ // Whether |pref_name| is a name of one of the preferences for content
+ // settings exceptions.
+ static bool IsContentSettingsExceptionsPref(const std::string& pref_name);
+
// ProviderInterface implementations.
RuleIterator* GetRuleIterator(ContentSettingsType content_type,
const ResourceIdentifier& resource_identifier,
@@ -72,18 +76,10 @@ class PrefProvider : public ObservableProvider {
void SetClockForTesting(scoped_ptr<base::Clock> clock);
private:
- friend class DeadlockCheckerThread; // For testing.
-
- // Migrate the old media setting into new mic/camera content settings.
- void MigrateObsoleteMediaContentSetting();
+ friend class DeadlockCheckerObserver; // For testing.
- // Migrate the settings from the old aggregate dictionary into the new format.
- void MigrateAllExceptions();
-
- // Writes the contents of the old aggregate dictionary preferences into
- // separate dictionaries for content types. If |syncable_only| is true,
- // only syncable content types will be written.
- void WriteSettingsToNewPreferences(bool syncable_only);
+ // Clean up the obsolete preferences from the user's profile.
+ void DiscardObsoletePreferences();
// Weak; owned by the Profile and reset in ShutdownOnUIThread.
PrefService* prefs_;
@@ -97,54 +93,9 @@ class PrefProvider : public ObservableProvider {
ScopedVector<ContentSettingsPref> content_settings_prefs_;
- DISALLOW_COPY_AND_ASSIGN(PrefProvider);
-
- bool TestAllLocks() const;
-
- // All functionality regarding reading and writing of preferences has been
- // moved to |ContentSettingsPref|, which manages one content type per
- // instance. However, for backward compatibility, we need to be able to write
- // to the old and deprecated aggregate dictionary preference which maintains
- // all content types. Therefore, |ContentSettingsPrefProvider| must still
- // retain some of the functionality of |ContentSettingsPref|. The following
- // attributes and methods serve this purpose.
- // TODO(msramek): Remove this migration code after two stable releases.
- struct ContentSettingsPrefEntry {
- ContentSettingsPrefEntry(const ContentSettingsPattern primary_pattern,
- const ContentSettingsPattern secondary_pattern,
- const ResourceIdentifier resource_identifier,
- base::Value* value);
- ContentSettingsPrefEntry(const ContentSettingsPrefEntry& entry);
- ContentSettingsPrefEntry& operator=(const ContentSettingsPrefEntry& entry);
- ~ContentSettingsPrefEntry();
-
- ContentSettingsPattern primary_pattern;
- ContentSettingsPattern secondary_pattern;
- ResourceIdentifier resource_identifier;
- scoped_ptr<base::Value> value;
- };
-
- // Stores exceptions read from the old preference before writing them
- // to the new one.
- ScopedVector<ContentSettingsPrefEntry>
- pref_entry_map_[CONTENT_SETTINGS_NUM_TYPES];
-
- // Clears |pref_entry_map_|.
- void ClearPrefEntryMap();
-
- // Guards access to |pref_entry_map_|.
- mutable base::Lock old_lock_;
-
- // Indicates whether the old preferences are updated.
- bool updating_old_preferences_;
-
- // Called when the old preference changes.
- void OnOldContentSettingsPatternPairsChanged();
-
- // Reads the old preference and writes it to |pref_entry_map_|.
- void ReadContentSettingsFromOldPref();
-
base::ThreadChecker thread_checker_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrefProvider);
};
} // namespace content_settings
diff --git a/components/content_settings/core/common/pref_names.cc b/components/content_settings/core/common/pref_names.cc
index 4c0ffb2..0bf3013 100644
--- a/components/content_settings/core/common/pref_names.cc
+++ b/components/content_settings/core/common/pref_names.cc
@@ -13,12 +13,6 @@ const char kBlockThirdPartyCookies[] = "profile.block_third_party_cookies";
// Version of the pattern format used to define content settings.
const char kContentSettingsVersion[] = "profile.content_settings.pref_version";
-// Patterns for mapping origins to origin related settings. Default settings
-// will be applied to origins that don't match any of the patterns. The pattern
-// format used is defined by kContentSettingsVersion.
-const char kContentSettingsPatternPairs[] =
- "profile.content_settings.pattern_pairs";
-
// Integer that specifies the index of the tab the user was on when they
// last visited the content settings window.
const char kContentSettingsWindowLastTabIndex[] =
@@ -139,12 +133,6 @@ const char kContentSettingsSiteEngagementPatternPairs[] =
const char kContentSettingsDurableStoragePatternPairs[] =
"profile.content_settings.exceptions.durable_storage";
-// Whether the patern pairs have been migrated from the deprecated aggregate
-// preference |kContentSettingsPatternPairs| to the separate preferences
-// |kContentSettings<type>PatternPairs|.
-const char kMigratedContentSettingsPatternPairs[] =
- "profile.migrated_content_settings_exceptions";
-
// Preferences that are exclusively used to store managed values for default
// content settings.
const char kManagedDefaultCookiesSetting[] =
diff --git a/components/content_settings/core/common/pref_names.h b/components/content_settings/core/common/pref_names.h
index c7ee72d..ba3862c 100644
--- a/components/content_settings/core/common/pref_names.h
+++ b/components/content_settings/core/common/pref_names.h
@@ -11,7 +11,6 @@ namespace prefs {
extern const char kBlockThirdPartyCookies[];
extern const char kContentSettingsVersion[];
-extern const char kContentSettingsPatternPairs[];
extern const char kContentSettingsWindowLastTabIndex[];
extern const char kDefaultCookiesSetting[];
@@ -75,8 +74,6 @@ extern const char kContentSettingsAppBannerPatternPairs[];
extern const char kContentSettingsSiteEngagementPatternPairs[];
extern const char kContentSettingsDurableStoragePatternPairs[];
-extern const char kMigratedContentSettingsPatternPairs[];
-
extern const char kManagedDefaultCookiesSetting[];
extern const char kManagedDefaultImagesSetting[];
extern const char kManagedDefaultJavaScriptSetting[];