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 02ec6d58d8839806d00cccecf4f37a7d9324f86b..6094885b7902f07d1729c466cc70c65d362c278e 100644 |
| --- a/components/content_settings/core/browser/host_content_settings_map.cc |
| +++ b/components/content_settings/core/browser/host_content_settings_map.cc |
| @@ -166,6 +166,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 |
| @@ -467,6 +469,57 @@ 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. |
| + // TODO(lshang): Default is temporarily added here to pass the array size |
| + // 0 |
|
raymes
2016/03/29 04:43:46
nit: fill 80chars
lshang
2016/03/29 05:02:30
Done.
|
| + // error. Will add types that need to be migrated later. |
| + CONTENT_SETTINGS_TYPE_DEFAULT}; |
|
raymes
2016/03/29 04:43:46
Maybe just put KEYGEN in this CL?
lshang
2016/03/29 05:02:30
Done.
|
| + for (const ContentSettingsType& type : kMigrateContentSettingTypes) { |
| + if (type == CONTENT_SETTINGS_TYPE_DEFAULT) |
| + break; |
| + WebsiteSettingsInfo::ScopingType scoping_type = |
| + content_settings::ContentSettingsRegistry::GetInstance() |
| + ->Get(type) |
| + ->website_settings_info() |
| + ->scoping_type(); |
| + DCHECK_NE( |
| + scoping_type, |
| + WebsiteSettingsInfo::REQUESTING_ORIGIN_AND_TOP_LEVEL_ORIGIN_SCOPE); |
| + |
| + ContentSettingsForOneType settings; |
| + GetSettingsForOneType(type, std::string(), &settings); |
| + for (const ContentSettingPatternSource& setting_entry : settings) { |
| + // Migrate user preference settings only. |
| + if (setting_entry.source != "preference") |
| + continue; |
| + // 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. |
| + SetContentSettingDefaultScope(url, GURL(), type, std::string(), |
| + content_setting); |
| + } |
| + } |
| + } |
| +} |
| + |
| ContentSetting HostContentSettingsMap::GetContentSettingAndMaybeUpdateLastUsage( |
| const GURL& primary_url, |
| const GURL& secondary_url, |