Chromium Code Reviews| Index: components/content_settings/core/browser/host_content_settings_map.cc |
| diff --git a/components/content_settings/core/browser/host_content_settings_map.cc b/components/content_settings/core/browser/host_content_settings_map.cc |
| index d1151eab85af2a51fa622b979cda1d05674ff2a3..4d4edab7cf37158d6b821eb3ca684c4d891a54ce 100644 |
| --- a/components/content_settings/core/browser/host_content_settings_map.cc |
| +++ b/components/content_settings/core/browser/host_content_settings_map.cc |
| @@ -164,6 +164,8 @@ HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs, |
| new content_settings::DefaultProvider(prefs_, is_off_the_record_); |
| default_provider->AddObserver(this); |
| content_settings_providers_[DEFAULT_PROVIDER] = default_provider; |
| + |
| + MigrateOldSettings(); |
| } |
| // static |
| @@ -465,6 +467,51 @@ void HostContentSettingsMap::SetContentSettingDefaultScope( |
| resource_identifier, setting); |
| } |
| +void HostContentSettingsMap::MigrateOldSettings() { |
| + const ContentSettingsType kMigrateContentSettingTypes[] = { |
| + // Only content types of scoping type: REQUESTING_DOMAIN_ONLY_SCOPE, |
| + // REQUESTING_ORIGIN_ONLY_SCOPE and TOP_LEVEL_DOMAIN_ONLY_SCOPE need to be |
| + // migrated. |
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| + }; |
| + for (const ContentSettingsType& type : kMigrateContentSettingTypes) { |
| + WebsiteSettingsInfo::ScopingType scoping_type = |
| + content_settings::ContentSettingsRegistry::GetInstance() |
| + ->Get(type) |
| + ->website_settings_info() |
| + ->scoping_type(); |
| + if (scoping_type == |
| + WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE) |
| + return; |
|
raymes
2016/03/07 01:47:55
I think we should make this a DCHECK_NE (instead o
lshang
2016/03/23 13:58:36
Done.
|
| + ContentSettingsForOneType settings; |
| + GetSettingsForOneType(type, std::string(), &settings); |
| + for (const ContentSettingPatternSource& setting_entry : settings) { |
| + // Migrate old-format settings only. |
| + if (setting_entry.secondary_pattern != |
| + ContentSettingsPattern::Wildcard()) { |
| + GURL url(setting_entry.primary_pattern.ToString()); |
| + // Pull out the value of the old-format setting. Only do this if the |
| + // patterns are as we expect them to be, otherwise the setting will just |
| + // be removed for safety. |
| + ContentSetting content_setting = CONTENT_SETTING_DEFAULT; |
| + if (setting_entry.primary_pattern == setting_entry.secondary_pattern && |
| + url.is_valid()) { |
| + content_setting = GetContentSetting(url, url, type, std::string()); |
| + } |
| + // Remove the old pattern. |
| + SetContentSetting(setting_entry.primary_pattern, |
| + setting_entry.secondary_pattern, type, std::string(), |
| + CONTENT_SETTING_DEFAULT); |
| + // Set the new pattern. |
| + if (content_setting) { |
|
raymes
2016/03/07 01:47:55
I think you can remove this check (the branch will
lshang
2016/03/23 13:58:36
Done.
|
| + SetContentSettingDefaultScope(url, GURL(), type, std::string(), |
| + content_setting); |
| + } |
| + } |
| + } |
| + } |
| +} |
| + |
| ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
| const GURL& primary_url, |
| const GURL& secondary_url, |