Commit 305f182f authored by Dominick Ng's avatar Dominick Ng Committed by Commit Bot

Remove migration code for domain scoped settings.

This CL removes the domain to origin scoped migration code added for
crbug.com/604612. The pref used for the migration is now cleared on
startup to ensure that dead data is not retained.

BUG=621398

Change-Id: I053091ae9e6e5f816a5e5ece84bd7f46882904fa
Reviewed-on: https://chromium-review.googlesource.com/765554Reviewed-by: default avatarTimothy Loh <timloh@chromium.org>
Reviewed-by: default avatarMartin Šrámek <msramek@chromium.org>
Commit-Queue: Dominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/master@{#516089}
parent c5dcb848
......@@ -7,14 +7,12 @@
#include <utility>
#include "base/feature_list.h"
#include "chrome/browser/prefs/pref_service_syncable_util.h"
#include "chrome/browser/profiles/off_the_record_profile_impl.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_features.h"
#include "components/content_settings/core/browser/content_settings_pref_provider.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/features/features.h"
......@@ -89,14 +87,6 @@ scoped_refptr<RefcountedKeyedService>
profile->GetProfileType() == Profile::GUEST_PROFILE,
store_last_modified));
sync_preferences::PrefServiceSyncable* pref_service =
PrefServiceSyncableFromProfile(profile);
if (pref_service) {
pref_service->RegisterMergeDataFinishedCallback(
base::Bind(&HostContentSettingsMap::MigrateDomainScopedSettings,
settings_map->GetWeakPtr(), true /* after_sync */));
}
#if BUILDFLAG(ENABLE_EXTENSIONS)
// These must be registered before before the HostSettings are passed over to
// the IOThread. Simplest to do this on construction.
......
......@@ -1429,318 +1429,6 @@ TEST_F(HostContentSettingsMapTest, GuestProfileMigration) {
}
#endif // !defined(OS_ANDROID)
TEST_F(HostContentSettingsMapTest, MigrateDomainScopedSettings) {
TestingProfile profile;
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(&profile);
PrefService* prefs = profile.GetPrefs();
// Set the pref to its initial state so that migration can be done later in
// the test (normally it is done on construction of HostContentSettingsMap).
int default_value;
prefs->GetDefaultPrefValue(prefs::kDomainToOriginMigrationStatus)
->GetAsInteger(&default_value);
prefs->SetInteger(prefs::kDomainToOriginMigrationStatus, default_value);
// Set old formatted http settings.
GURL http_host("http://example.com/");
GURL http_host_narrower("http://a.example.com/");
// Change default setting to BLOCK.
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_BLOCK);
EXPECT_EQ(
CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
// Patterns generated for cookies used to be domain scoped.
host_content_settings_map->SetContentSettingCustomScope(
ContentSettingsPattern::FromURL(http_host),
ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS,
std::string(), CONTENT_SETTING_ALLOW);
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
// Settings also apply to subdomains.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http_host_narrower, http_host_narrower,
CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
ContentSettingsForOneType settings;
host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS,
std::string(), &settings);
// |host_content_settings_map| contains default setting and a domain scoped
// setting.
EXPECT_EQ(2U, settings.size());
EXPECT_TRUE(settings[0].primary_pattern.ToString() == "[*.]example.com");
EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*");
// Set old formatted https settings.
GURL https_host("https://example.com/");
GURL https_host_narrower("https://a.example.com/");
// Change default setting to BLOCK.
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, CONTENT_SETTING_BLOCK);
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
https_host, https_host, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string()));
// Patterns generated for popups used to be domain scoped.
host_content_settings_map->SetContentSettingCustomScope(
ContentSettingsPattern::FromURL(https_host),
ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string(), CONTENT_SETTING_ALLOW);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
https_host, https_host, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string()));
// Settings also apply to subdomains.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
https_host_narrower, https_host_narrower,
CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
host_content_settings_map->GetSettingsForOneType(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), &settings);
// |host_content_settings_map| contains default setting and a domain scoped
// setting.
EXPECT_EQ(2U, settings.size());
EXPECT_TRUE(settings[0].primary_pattern.ToString() ==
"https://[*.]example.com:443");
EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*");
// Set domain scoped settings for cookies.
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_COOKIES, CONTENT_SETTING_BLOCK);
EXPECT_EQ(
CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
host_content_settings_map->SetContentSettingCustomScope(
ContentSettingsPattern::FromURL(http_host),
ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES,
std::string(), CONTENT_SETTING_ALLOW);
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
host_content_settings_map->SetContentSettingCustomScope(
ContentSettingsPattern::FromURL(https_host),
ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_COOKIES,
std::string(), CONTENT_SETTING_ALLOW);
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
https_host, https_host, CONTENT_SETTINGS_TYPE_COOKIES,
std::string()));
// Settings also apply to subdomains.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http_host_narrower, http_host_narrower,
CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
https_host_narrower, https_host_narrower,
CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
host_content_settings_map->MigrateDomainScopedSettings(false);
// After migration, settings only affect origins.
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
http_host_narrower, http_host_narrower,
CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
host_content_settings_map->GetSettingsForOneType(CONTENT_SETTINGS_TYPE_POPUPS,
std::string(), &settings);
// |host_content_settings_map| contains default setting and a origin scoped
// setting.
EXPECT_EQ(2U, settings.size());
EXPECT_TRUE(settings[0].primary_pattern.ToString() ==
"http://example.com:80");
EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*");
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
https_host, https_host, CONTENT_SETTINGS_TYPE_JAVASCRIPT,
std::string()));
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
https_host_narrower, https_host_narrower,
CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string()));
host_content_settings_map->GetSettingsForOneType(
CONTENT_SETTINGS_TYPE_JAVASCRIPT, std::string(), &settings);
// |host_content_settings_map| contains default setting and a origin scoped
// setting.
EXPECT_EQ(2U, settings.size());
EXPECT_TRUE(settings[0].primary_pattern.ToString() ==
"https://example.com:443");
EXPECT_TRUE(settings[1].primary_pattern.ToString() == "*");
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http_host, http_host, CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
https_host, https_host, CONTENT_SETTINGS_TYPE_COOKIES,
std::string()));
// Settings still apply to subdomains. Cookie settings didn't get migrated.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http_host_narrower, http_host_narrower,
CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
https_host_narrower, https_host_narrower,
CONTENT_SETTINGS_TYPE_COOKIES, std::string()));
}
// Ensure that migration only happens once upon construction of the HCSM and
// once after syncing (even when these events occur multiple times).
TEST_F(HostContentSettingsMapTest, DomainToOriginMigrationStatus) {
TestingProfile profile;
// Construct the map now to make the various platforms equivalent. On Android
// the map is created with the profile (due to dependencies), while on other
// platforms it is created lazily. Note, migration should be run here.
HostContentSettingsMap* host_content_settings_map =
HostContentSettingsMapFactory::GetForProfile(&profile);
PrefService* prefs = profile.GetPrefs();
GURL http_host("http://example.com/");
GURL http_host_narrower("http://a.example.com/");
std::string host_pattern_string =
ContentSettingsPattern::FromURL(http_host).ToString();
{
DictionaryPrefUpdate update(prefs,
GetPrefName(CONTENT_SETTINGS_TYPE_POPUPS));
base::DictionaryValue* all_settings_dictionary = update.Get();
ASSERT_TRUE(NULL != all_settings_dictionary);
auto domain_setting = base::MakeUnique<base::DictionaryValue>();
domain_setting->SetInteger("setting", CONTENT_SETTING_ALLOW);
all_settings_dictionary->SetWithoutPathExpansion(host_pattern_string + ",*",
std::move(domain_setting));
}
const base::DictionaryValue* all_settings_dictionary =
prefs->GetDictionary(GetPrefName(CONTENT_SETTINGS_TYPE_POPUPS));
const base::DictionaryValue* result = NULL;
EXPECT_TRUE(all_settings_dictionary->GetDictionaryWithoutPathExpansion(
"[*.]example.com,*", &result));
// Migration is done on construction of HostContentSettingsMap. Try to run it
// again. This should not do anything as it has already ran.
host_content_settings_map->MigrateDomainScopedSettings(
false /* after_sync */);
// Change default setting to BLOCK.
host_content_settings_map->SetDefaultContentSetting(
CONTENT_SETTINGS_TYPE_POPUPS, CONTENT_SETTING_BLOCK);
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
// The setting should still be allow as it hasn't been migrated.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http_host_narrower, http_host_narrower,
CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
// Set the pref to its initial state so that migration can be triggered again,
// just for the sake of testing.
int default_value;
prefs->GetDefaultPrefValue(prefs::kDomainToOriginMigrationStatus)
->GetAsInteger(&default_value);
prefs->SetInteger(prefs::kDomainToOriginMigrationStatus, default_value);
// Now, do the migration. This should work as we've cleared the pref back to
// its default value.
host_content_settings_map->MigrateDomainScopedSettings(false);
// Now the settings should be migrated.
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http_host, http_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
// Settings only apply to origins. Migration got executed.
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
http_host_narrower, http_host_narrower,
CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
GURL https_host("https://example.com/");
GURL https_host_narrower("https://a.example.com/");
host_content_settings_map->SetContentSettingCustomScope(
ContentSettingsPattern::FromURL(https_host),
ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS,
std::string(), CONTENT_SETTING_ALLOW);
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
https_host, https_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
// Settings apply to subdomains.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
https_host_narrower, https_host_narrower,
CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
// Try to do migration again before sync.
host_content_settings_map->MigrateDomainScopedSettings(false);
// Settings still apply to subdomains. Migration didn't get executed.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
https_host_narrower, https_host_narrower,
CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
// Do migration after sync.
host_content_settings_map->MigrateDomainScopedSettings(true);
// Settings only apply to origins. Migration got executed.
EXPECT_EQ(CONTENT_SETTING_BLOCK,
host_content_settings_map->GetContentSetting(
https_host_narrower, https_host_narrower,
CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
GURL http1_host("http://google.com/");
GURL http1_host_narrower("http://a.google.com/");
host_content_settings_map->SetContentSettingCustomScope(
ContentSettingsPattern::FromURL(http1_host),
ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS,
std::string(), CONTENT_SETTING_ALLOW);
EXPECT_EQ(
CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http1_host, http1_host, CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
// Settings apply to subdomains.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http1_host_narrower, http1_host_narrower,
CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
// Try to do migration again after sync.
host_content_settings_map->MigrateDomainScopedSettings(true);
// Settings still apply to subdomains. Migration didn't get executed.
EXPECT_EQ(CONTENT_SETTING_ALLOW,
host_content_settings_map->GetContentSetting(
http1_host_narrower, http1_host_narrower,
CONTENT_SETTINGS_TYPE_POPUPS, std::string()));
}
TEST_F(HostContentSettingsMapTest, InvalidPattern) {
// This is a regression test for crbug.com/618529, which fixed a memory leak
// when a website setting was set under a URL that mapped to an invalid
......
......@@ -37,6 +37,9 @@ namespace content_settings {
namespace {
// These settings are no longer used, and should be deleted on profile startup.
const char kObsoleteDomainToOriginMigrationStatus[] =
"profile.content_settings.domain_to_origin_migration_status";
#if !defined(OS_IOS)
const char kObsoleteFullscreenExceptionsPref[] =
"profile.content_settings.exceptions.fullscreen";
......@@ -70,6 +73,7 @@ void PrefProvider::RegisterProfilePrefs(
// These prefs have been removed, but need to be registered so they can
// be deleted on startup.
registry->RegisterIntegerPref(kObsoleteDomainToOriginMigrationStatus, 0);
#if !defined(OS_IOS)
registry->RegisterDictionaryPref(
kObsoleteFullscreenExceptionsPref,
......@@ -221,6 +225,9 @@ void PrefProvider::Notify(
void PrefProvider::DiscardObsoletePreferences() {
if (is_incognito_)
return;
prefs_->ClearPref(kObsoleteDomainToOriginMigrationStatus);
// These prefs were never stored on iOS/Android so they don't need to be
// deleted.
#if !defined(OS_IOS)
......
......@@ -66,23 +66,6 @@ const ProviderNamesSourceMapEntry kProviderNamesSourceMap[] = {
{"tests_other", 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 and
// after sync is finished. No migration will happen after this point.
MIGRATED_AFTER_SYNC,
};
static_assert(
arraysize(kProviderNamesSourceMap) ==
HostContentSettingsMap::NUM_PROVIDER_TYPES,
......@@ -220,7 +203,6 @@ HostContentSettingsMap::HostContentSettingsMap(PrefService* prefs,
default_provider->AddObserver(this);
content_settings_providers_[DEFAULT_PROVIDER] = std::move(default_provider);
MigrateDomainScopedSettings(false);
RecordExceptionMetrics();
}
......@@ -231,8 +213,6 @@ void HostContentSettingsMap::RegisterProfilePrefs(
content_settings::ContentSettingsRegistry::GetInstance();
registry->RegisterIntegerPref(prefs::kContentSettingsWindowLastTabIndex, 0);
registry->RegisterIntegerPref(prefs::kDomainToOriginMigrationStatus,
NOT_MIGRATED);
// Register the prefs for the content settings providers.
content_settings::DefaultProvider::RegisterProfilePrefs(registry);
......@@ -516,89 +496,6 @@ void HostContentSettingsMap::SetContentSettingDefaultScope(
resource_identifier, setting);
}
void HostContentSettingsMap::MigrateDomainScopedSettings(bool after_sync) {
DomainToOriginMigrationStatus status =
static_cast<DomainToOriginMigrationStatus>(
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_IMAGES,
CONTENT_SETTINGS_TYPE_PLUGINS,
CONTENT_SETTINGS_TYPE_JAVASCRIPT,
CONTENT_SETTINGS_TYPE_AUTOMATIC_DOWNLOADS,
CONTENT_SETTINGS_TYPE_POPUPS};
for (const ContentSettingsType& type : kDomainScopedTypes) {
if (!content_settings::ContentSettingsRegistry::GetInstance()->Get(type))
continue;
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 ALLOW settings only.
if (setting_entry.GetContentSetting() != CONTENT_SETTING_ALLOW)
continue;
// Skip default settings.
if (setting_entry.primary_pattern == ContentSettingsPattern::Wildcard())
continue;
if (setting_entry.secondary_pattern !=
ContentSettingsPattern::Wildcard()) {
NOTREACHED();
continue;
}
ContentSettingsPattern origin_pattern;
if (!ContentSettingsPattern::MigrateFromDomainToOrigin(
setting_entry.primary_pattern, &origin_pattern)) {
continue;
}
if (!origin_pattern.IsValid())
continue;
GURL origin(origin_pattern.ToString());
DCHECK(origin.is_valid());
// Ensure that the current resolved content setting for this origin is
// allowed. Otherwise we may be overriding some narrower setting which is
// set to block.
ContentSetting origin_setting =
GetContentSetting(origin, origin, type, std::string());
// Remove the domain scoped pattern. If |origin_setting| is not
// CONTENT_SETTING_ALLOW it implies there is some narrower pattern in
// effect, so it's still safe to remove the domain-scoped pattern.
SetContentSettingCustomScope(setting_entry.primary_pattern,
setting_entry.secondary_pattern, type,
std::string(), CONTENT_SETTING_DEFAULT);
// If the current resolved content setting is allowed it's safe to set the
// origin-scoped pattern.
if (origin_setting == CONTENT_SETTING_ALLOW)
SetContentSettingCustomScope(
ContentSettingsPattern::FromURLNoWildcard(origin),
ContentSettingsPattern::Wildcard(), type, std::string(),
CONTENT_SETTING_ALLOW);
}
}
if (status == NOT_MIGRATED) {
prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus,
MIGRATED_BEFORE_SYNC);
} else if (status == MIGRATED_BEFORE_SYNC) {
prefs_->SetInteger(prefs::kDomainToOriginMigrationStatus,
MIGRATED_AFTER_SYNC);
}
}
base::WeakPtr<HostContentSettingsMap> HostContentSettingsMap::GetWeakPtr() {
return weak_ptr_factory_.GetWeakPtr();
}
......
......@@ -284,17 +284,6 @@ class HostContentSettingsMap : public content_settings::Observer,
// Schedules any pending lossy website settings to be written to disk.
void FlushLossyWebsiteSettings();
// Migrate old domain scoped ALLOW settings to be origin scoped for
// ContentSettingsTypes which are domain scoped. Only narrow down ALLOW
// domain settings to origins so that this will not cause privacy/security
// issues.
//
// |after_sync| will be false when called upon construction of this object and
// true when called by the sync layer after sync is completed.
// TODO(lshang): https://crbug.com/621398 Remove this when clients have
// migrated (~M56).
void MigrateDomainScopedSettings(bool after_sync);
base::WeakPtr<HostContentSettingsMap> GetWeakPtr();
// Injects a clock into the PrefProvider to allow control over the
......@@ -308,12 +297,6 @@ class HostContentSettingsMap : public content_settings::Observer,
private:
friend class base::RefCountedThreadSafe<HostContentSettingsMap>;
FRIEND_TEST_ALL_PREFIXES(HostContentSettingsMapTest,
DomainToOriginMigrationStatus);
FRIEND_TEST_ALL_PREFIXES(HostContentSettingsMapTest,
MigrateDomainScopedSettings);
friend class content_settings::TestUtils;
~HostContentSettingsMap() override;
......
......@@ -401,58 +401,6 @@ ContentSettingsPattern ContentSettingsPattern::FromString(
return builder.Build();
}
// static
bool ContentSettingsPattern::MigrateFromDomainToOrigin(
const ContentSettingsPattern& domain_pattern,
ContentSettingsPattern* origin_pattern) {
DCHECK(origin_pattern);
// Generated patterns with ::FromURL (which we want to migrate) must either
// have a scheme wildcard or be https.
if (domain_pattern.parts_.scheme != url::kHttpsScheme &&
!domain_pattern.parts_.is_scheme_wildcard) {
return false;
}
// Generated patterns using ::FromURL with the HTTPs scheme can not have a
// port wildcard.
if (domain_pattern.parts_.is_port_wildcard &&
domain_pattern.parts_.scheme == url::kHttpsScheme) {
return false;
}
// Patterns generated with ::FromURL will always have a domain wildcard. Those
// generated with ::FromURLNoWildcard don't.
if (!domain_pattern.parts_.has_domain_wildcard)
return false;
// Generated patterns with ::FromURL will always have a host.
if (domain_pattern.parts_.host.empty())
return false;
ContentSettingsPattern::Builder builder;
if (domain_pattern.parts_.is_scheme_wildcard)
builder.WithScheme(url::kHttpScheme);
else
builder.WithScheme(domain_pattern.parts_.scheme);
builder.WithHost(domain_pattern.parts_.host);
if (domain_pattern.parts_.is_port_wildcard) {
if (domain_pattern.parts_.scheme == url::kHttpsScheme) {
builder.WithPort(GetDefaultPort(url::kHttpsScheme));
} else {