Commit 1cea520b authored by ivankr@chromium.org's avatar ivankr@chromium.org

[protector] Bump Preferences backup version to 3 to mitigate the startup prefs migration.

Since r134147 (https://chromiumcodereview.appspot.com/10213009), startup prefs migration is more complex and may trigger the protector for users on M19.


BUG=122936
TEST=ProtectedPrefsWatcherTest.*


Review URL: http://codereview.chromium.org/10170046

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@134698 0039d316-1c4b-4281-b951-d872f2087c98
parent bfb15ed3
......@@ -63,7 +63,7 @@ void StringAppendStringDictionary(const base::DictionaryValue* dict,
} // namespace
// static
const int ProtectedPrefsWatcher::kCurrentVersionNumber = 2;
const int ProtectedPrefsWatcher::kCurrentVersionNumber = 3;
ProtectedPrefsWatcher::ProtectedPrefsWatcher(Profile* profile)
: is_backup_valid_(true),
......@@ -208,8 +208,18 @@ void ProtectedPrefsWatcher::MigrateOldBackupIfNeeded() {
switch (current_version) {
case 1:
// Add pinned tabs.
prefs->Set(kBackupPinnedTabs, *prefs->GetList(prefs::kPinnedTabs));
// FALL THROUGH
case 2:
// SessionStartupPref migration.
DCHECK(prefs->GetBoolean(prefs::kRestoreOnStartupMigrated));
prefs->SetInteger(kBackupRestoreOnStartup,
prefs->GetInteger(prefs::kRestoreOnStartup));
prefs->Set(kBackupURLsToRestoreOnStartup,
*prefs->GetList(prefs::kURLsToRestoreOnStartup));
// FALL THROUGH
}
prefs->SetInteger(kBackupVersion, kCurrentVersionNumber);
......
......@@ -189,4 +189,34 @@ TEST_F(ProtectedPrefsWatcherTest, MigrationToVersion2) {
prefs_->GetInteger("backup._version"));
}
// Verify that SessionStartupPref migration doesn't trigger Protector
// (version 3 migration).
TEST_F(ProtectedPrefsWatcherTest, MigrationToVersion3) {
EXPECT_TRUE(prefs_watcher_->is_backup_valid());
// Bring startup prefs to an old (pre-migration) version.
prefs_->SetBoolean(prefs::kHomePageIsNewTabPage, false);
prefs_->SetString(prefs::kHomePage, "http://example.com/");
prefs_->ClearPref(prefs::kRestoreOnStartupMigrated);
// Reset version to 2 and overwrite the signature.
prefs_->SetInteger("backup._version", 2);
ForceUpdateSignature();
EXPECT_TRUE(IsSignatureValid());
// Take down the old instance and create a new ProtectedPrefsWatcher from
// current prefs.
ProtectorServiceFactory::GetForProfile(&profile_)->
StopWatchingPrefsForTesting();
scoped_ptr<ProtectedPrefsWatcher> prefs_watcher2(
new ProtectedPrefsWatcher(&profile_));
EXPECT_TRUE(prefs_watcher2->is_backup_valid());
// Startup settings shouldn't be reported as changed.
EXPECT_FALSE(prefs_watcher2->DidPrefChange(prefs::kRestoreOnStartup));
EXPECT_FALSE(prefs_watcher2->DidPrefChange(prefs::kURLsToRestoreOnStartup));
EXPECT_EQ(ProtectedPrefsWatcher::kCurrentVersionNumber,
prefs_->GetInteger("backup._version"));
}
} // namespace protector
......@@ -119,6 +119,10 @@ ProtectedPrefsWatcher* ProtectorService::GetPrefsWatcher() {
return prefs_watcher_.get();
}
void ProtectorService::StopWatchingPrefsForTesting() {
prefs_watcher_.reset();
}
ProtectorService::Item* ProtectorService::FindItemToMergeWith(
const BaseSettingChange* change) {
if (!change->CanBeMerged())
......
......@@ -62,6 +62,10 @@ class ProtectorService : public ProfileKeyedService,
// backup.
ProtectedPrefsWatcher* GetPrefsWatcher();
// Stops observing pref changes and updating the backup. Should be used in
// tests only.
void StopWatchingPrefsForTesting();
// Returns the most recent change instance or NULL if there are no changes.
BaseSettingChange* GetLastChange();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment