Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Fix for settings migration (uplift to 1.19.x) #7588

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,16 @@ bool IsActive(const Rule& cookie_rule,

// static
void BravePrefProvider::CopyPluginSettingsForMigration(PrefService* prefs) {
if (!prefs->HasPrefPath("profile.content_settings.exceptions.plugins")) {
return;
}

auto* plugins =
prefs->GetDictionary("profile.content_settings.exceptions.plugins");
prefs->Set("brave.migrate.content_settings.exceptions.plugins", *plugins);

// Upstream won't clean this up for ANDROID, need to do it ourselves.
prefs->ClearPref("profile.content_settings.exceptions.plugins");
}

BravePrefProvider::BravePrefProvider(PrefService* prefs,
Expand Down Expand Up @@ -163,6 +170,13 @@ void BravePrefProvider::RegisterProfilePrefs(
// migration of obsolete plugin prefs
registry->RegisterDictionaryPref(
"brave.migrate.content_settings.exceptions.plugins");

#if defined(OS_ANDROID)
// This path is no longer registered upstream but we still need it to migrate
// Shields settings away from ResourceIdentifier on Android.
registry->RegisterDictionaryPref(
"profile.content_settings.exceptions.plugins");
#endif
}

void BravePrefProvider::MigrateShieldsSettings(bool incognito) {
Expand All @@ -179,12 +193,11 @@ void BravePrefProvider::MigrateShieldsSettings(bool incognito) {

// Now carry on with any other migration that we might need.
MigrateShieldsSettingsV1ToV2();

// Finally clean this up now that Shields' settings have been migrated.
prefs_->ClearPref("brave.migrate.content_settings.exceptions.plugins");
}

void BravePrefProvider::MigrateShieldsSettingsFromResourceIds() {
BravePrefProvider::CopyPluginSettingsForMigration(prefs_);

const base::DictionaryValue* plugins_dictionary = prefs_->GetDictionary(
"brave.migrate.content_settings.exceptions.plugins");
if (!plugins_dictionary)
Expand Down Expand Up @@ -244,6 +257,9 @@ void BravePrefProvider::MigrateShieldsSettingsFromResourceIds() {
}
}
}

// Finally clean this up now that Shields' settings have been migrated.
prefs_->ClearPref("brave.migrate.content_settings.exceptions.plugins");
}

void BravePrefProvider::MigrateShieldsSettingsFromResourceIdsForOneType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,6 @@ TEST_F(BravePrefProviderTest, TestShieldsSettingsMigrationFromResourceIDs) {
expected_last_modified,
expected_brave_com_settings_value);

BravePrefProvider::CopyPluginSettingsForMigration(pref_service);
provider.MigrateShieldsSettingsFromResourceIds();

// Check migration for all the settings has been properly done.
Expand Down