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 3dbb4f57c2e635169c58ad0faade19a2efb967ee..3edcdfac6cc80151275f23e831f348dc101fc825 100644 |
| --- a/components/content_settings/core/browser/host_content_settings_map.cc |
| +++ b/components/content_settings/core/browser/host_content_settings_map.cc |
| @@ -58,6 +58,24 @@ const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = { |
| {"default", content_settings::SETTING_SOURCE_USER}, |
| }; |
| +// Enum describing the status of domain to origin migration of content settings. |
| +// Migration will be done twice: once upon construction of the |
| +// HostContentSettingsMap (before syncing any content settings) and once after |
| +// sync has finished. We always migrate before sync to ensure that settings will |
| +// get migrated even if a user doesn't have sync enabled. We migrate after sync |
| +// to ensure that any sync'd settings will be migrated. Once these events have |
| +// occurred, we won't perform migration again. |
| +enum DomainToOriginMigrationStatus { |
| + // Haven't been migrated at all. |
| + NOT_MIGRATED, |
| + // Have done migration in the constructor of HostContentSettingsMap. |
| + MIGRATED_BEFORE_SYNC, |
| + // Have done migration both in HostContentSettingsMap construction and sync |
|
raymes
2016/07/25 03:56:38
nit: and after sync is finished. No migration will
lshang
2016/07/25 04:51:09
Done.
|
| + // process(this is a clean up after sync). Migration is all finished at this |
| + // stage. |
| + MIGRATED_AFTER_SYNC, |
| +}; |
| + |
| static_assert( |
| arraysize(kProviderNamesSourceMap) == |
| HostContentSettingsMap::NUM_PROVIDER_TYPES, |
| @@ -183,6 +201,8 @@ void HostContentSettingsMap::RegisterProfilePrefs( |
| content_settings::ContentSettingsRegistry::GetInstance(); |
| registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0); |
| + registry->RegisterIntegerPref(prefs::kDomainToOriginMigrationStatus, |
| + DomainToOriginMigrationStatus::NOT_MIGRATED); |
| // Register the prefs for the content settings providers. |
| content_settings::DefaultProvider::RegisterProfilePrefs(registry); |
| @@ -497,7 +517,14 @@ void HostContentSettingsMap::MigrateKeygenSettings() { |
| } |
| } |
| -void HostContentSettingsMap::MigrateDomainScopedSettings() { |
| +void HostContentSettingsMap::MigrateDomainScopedSettings(bool after_sync) { |
| + int status = prefs_->GetInteger(prefs::kDomainToOriginMigrationStatus); |
| + if (status == MIGRATED_AFTER_SYNC) |
| + return; |
| + if (status == MIGRATED_BEFORE_SYNC && !after_sync) |
| + return; |
| + DCHECK(status != NOT_MIGRATED || !after_sync); |
| + |
| const ContentSettingsType kDomainScopedTypes[] = { |
| CONTENT_SETTINGS_TYPE_COOKIES, |
| CONTENT_SETTINGS_TYPE_IMAGES, |
| @@ -562,6 +589,14 @@ void HostContentSettingsMap::MigrateDomainScopedSettings() { |
| CONTENT_SETTING_ALLOW); |
| } |
| } |
| + |
| + if (status == NOT_MIGRATED) { |
| + prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, |
| + DomainToOriginMigrationStatus::MIGRATED_BEFORE_SYNC); |
|
raymes
2016/07/25 03:56:38
nit: no need for the DomainToOriginMigrationStatus
lshang
2016/07/25 04:51:09
Done.
|
| + } else if (status == MIGRATED_BEFORE_SYNC) { |
| + prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus, |
| + DomainToOriginMigrationStatus::MIGRATED_AFTER_SYNC); |
| + } |
| } |
| void HostContentSettingsMap::RecordNumberOfExceptions() { |