Commit dbe2ca2b authored by gcasto@chromium.org's avatar gcasto@chromium.org

[Password Manager] Remove dead profile migration code for GNOME/KWallet

This code has been unused for around 2 years.

BUG=355145

Review URL: https://codereview.chromium.org/196173023

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@260378 0039d316-1c4b-4281-b951-d872f2087c98
parent aa669a6b
...@@ -495,19 +495,9 @@ void GKRMethod::OnOperationGetList(GnomeKeyringResult result, GList* list, ...@@ -495,19 +495,9 @@ void GKRMethod::OnOperationGetList(GnomeKeyringResult result, GList* list,
} // namespace } // namespace
NativeBackendGnome::NativeBackendGnome(LocalProfileId id, PrefService* prefs) NativeBackendGnome::NativeBackendGnome(LocalProfileId id)
: profile_id_(id), prefs_(prefs) { : profile_id_(id) {
// TODO(mdm): after a few more releases, remove the code which is now dead due app_string_ = GetProfileSpecificAppString();
// to the true || here, and simplify this code. We don't do it yet to make it
// easier to revert if necessary.
if (true || PasswordStoreX::PasswordsUseLocalProfileId(prefs)) {
app_string_ = GetProfileSpecificAppString();
// We already did the migration previously. Don't try again.
migrate_tried_ = true;
} else {
app_string_ = kGnomeKeyringAppString;
migrate_tried_ = false;
}
} }
NativeBackendGnome::~NativeBackendGnome() { NativeBackendGnome::~NativeBackendGnome() {
...@@ -530,9 +520,6 @@ bool NativeBackendGnome::RawAddLogin(const PasswordForm& form) { ...@@ -530,9 +520,6 @@ bool NativeBackendGnome::RawAddLogin(const PasswordForm& form) {
<< gnome_keyring_result_to_message(result); << gnome_keyring_result_to_message(result);
return false; return false;
} }
// Successful write. Try migration if necessary.
if (!migrate_tried_)
MigrateToProfileSpecificLogins();
return true; return true;
} }
...@@ -562,11 +549,6 @@ bool NativeBackendGnome::AddLogin(const PasswordForm& form) { ...@@ -562,11 +549,6 @@ bool NativeBackendGnome::AddLogin(const PasswordForm& form) {
<< " matching logins already! Will replace only the first."; << " matching logins already! Will replace only the first.";
} }
// We try migration before updating the existing logins, since otherwise
// we'd do it after making some but not all of the changes below.
if (forms.size() > 0 && !migrate_tried_)
MigrateToProfileSpecificLogins();
RemoveLogin(*forms[0]); RemoveLogin(*forms[0]);
for (size_t i = 0; i < forms.size(); ++i) for (size_t i = 0; i < forms.size(); ++i)
delete forms[i]; delete forms[i];
...@@ -595,11 +577,6 @@ bool NativeBackendGnome::UpdateLogin(const PasswordForm& form) { ...@@ -595,11 +577,6 @@ bool NativeBackendGnome::UpdateLogin(const PasswordForm& form) {
return false; return false;
} }
// We try migration before updating the existing logins, since otherwise
// we'd do it after making some but not all of the changes below.
if (forms.size() > 0 && !migrate_tried_)
MigrateToProfileSpecificLogins();
bool ok = true; bool ok = true;
for (size_t i = 0; i < forms.size(); ++i) { for (size_t i = 0; i < forms.size(); ++i) {
if (forms[i]->action != form.action || if (forms[i]->action != form.action ||
...@@ -637,11 +614,6 @@ bool NativeBackendGnome::RemoveLogin(const PasswordForm& form) { ...@@ -637,11 +614,6 @@ bool NativeBackendGnome::RemoveLogin(const PasswordForm& form) {
<< gnome_keyring_result_to_message(result); << gnome_keyring_result_to_message(result);
return false; return false;
} }
// Successful write. Try migration if necessary. Note that presumably if we've
// been asked to delete a login, it's because we returned it previously; thus,
// this will probably never happen since we'd have already tried migration.
if (!migrate_tried_)
MigrateToProfileSpecificLogins();
return true; return true;
} }
...@@ -655,7 +627,6 @@ bool NativeBackendGnome::RemoveLoginsCreatedBetween( ...@@ -655,7 +627,6 @@ bool NativeBackendGnome::RemoveLoginsCreatedBetween(
PasswordFormList forms; PasswordFormList forms;
if (!GetAllLogins(&forms)) if (!GetAllLogins(&forms))
return false; return false;
// No need to try migration here: GetAllLogins() does it.
for (size_t i = 0; i < forms.size(); ++i) { for (size_t i = 0; i < forms.size(); ++i) {
if (delete_begin <= forms[i]->date_created && if (delete_begin <= forms[i]->date_created &&
...@@ -684,9 +655,6 @@ bool NativeBackendGnome::GetLogins(const PasswordForm& form, ...@@ -684,9 +655,6 @@ bool NativeBackendGnome::GetLogins(const PasswordForm& form,
<< gnome_keyring_result_to_message(result); << gnome_keyring_result_to_message(result);
return false; return false;
} }
// Successful read of actual data. Try migration if necessary.
if (!migrate_tried_)
MigrateToProfileSpecificLogins();
return true; return true;
} }
...@@ -699,7 +667,6 @@ bool NativeBackendGnome::GetLoginsCreatedBetween(const base::Time& get_begin, ...@@ -699,7 +667,6 @@ bool NativeBackendGnome::GetLoginsCreatedBetween(const base::Time& get_begin,
PasswordFormList all_forms; PasswordFormList all_forms;
if (!GetAllLogins(&all_forms)) if (!GetAllLogins(&all_forms))
return false; return false;
// No need to try migration here: GetAllLogins() does it.
forms->reserve(forms->size() + all_forms.size()); forms->reserve(forms->size() + all_forms.size());
for (size_t i = 0; i < all_forms.size(); ++i) { for (size_t i = 0; i < all_forms.size(); ++i) {
...@@ -741,9 +708,6 @@ bool NativeBackendGnome::GetLoginsList(PasswordFormList* forms, ...@@ -741,9 +708,6 @@ bool NativeBackendGnome::GetLoginsList(PasswordFormList* forms,
<< gnome_keyring_result_to_message(result); << gnome_keyring_result_to_message(result);
return false; return false;
} }
// Successful read of actual data. Try migration if necessary.
if (!migrate_tried_)
MigrateToProfileSpecificLogins();
return true; return true;
} }
...@@ -761,9 +725,6 @@ bool NativeBackendGnome::GetAllLogins(PasswordFormList* forms) { ...@@ -761,9 +725,6 @@ bool NativeBackendGnome::GetAllLogins(PasswordFormList* forms) {
<< gnome_keyring_result_to_message(result); << gnome_keyring_result_to_message(result);
return false; return false;
} }
// Successful read of actual data. Try migration if necessary.
if (!migrate_tried_)
MigrateToProfileSpecificLogins();
return true; return true;
} }
...@@ -773,44 +734,3 @@ std::string NativeBackendGnome::GetProfileSpecificAppString() const { ...@@ -773,44 +734,3 @@ std::string NativeBackendGnome::GetProfileSpecificAppString() const {
// for nothing. Now we use it to distinguish passwords for different profiles. // for nothing. Now we use it to distinguish passwords for different profiles.
return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_); return base::StringPrintf("%s-%d", kGnomeKeyringAppString, profile_id_);
} }
void NativeBackendGnome::MigrateToProfileSpecificLogins() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
DCHECK(!migrate_tried_);
DCHECK_EQ(app_string_, kGnomeKeyringAppString);
// Record the fact that we've attempted migration already right away, so that
// we don't get recursive calls back to MigrateToProfileSpecificLogins().
migrate_tried_ = true;
// First get all the logins, using the old app string.
PasswordFormList forms;
if (!GetAllLogins(&forms))
return;
// Now switch to a profile-specific app string.
app_string_ = GetProfileSpecificAppString();
// Try to add all the logins with the new app string.
bool ok = true;
for (size_t i = 0; i < forms.size(); ++i) {
if (!RawAddLogin(*forms[i]))
ok = false;
delete forms[i];
}
if (ok) {
// All good! Keep the new app string and set a persistent pref.
// NOTE: We explicitly don't delete the old passwords yet. They are
// potentially shared with other profiles and other user data dirs!
// Each other profile must be able to migrate the shared data as well,
// so we must leave it alone. After a few releases, we'll add code to
// delete them, and eventually remove this migration code.
// TODO(mdm): follow through with the plan above.
PasswordStoreX::SetPasswordsUseLocalProfileId(prefs_);
} else {
// We failed to migrate for some reason. Use the old app string.
app_string_ = kGnomeKeyringAppString;
}
}
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
#include "chrome/browser/password_manager/password_store_x.h" #include "chrome/browser/password_manager/password_store_x.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
class PrefService;
namespace autofill { namespace autofill {
struct PasswordForm; struct PasswordForm;
} }
...@@ -76,7 +74,7 @@ class GnomeKeyringLoader { ...@@ -76,7 +74,7 @@ class GnomeKeyringLoader {
class NativeBackendGnome : public PasswordStoreX::NativeBackend, class NativeBackendGnome : public PasswordStoreX::NativeBackend,
public GnomeKeyringLoader { public GnomeKeyringLoader {
public: public:
NativeBackendGnome(LocalProfileId id, PrefService* prefs); explicit NativeBackendGnome(LocalProfileId id);
virtual ~NativeBackendGnome(); virtual ~NativeBackendGnome();
...@@ -109,21 +107,12 @@ class NativeBackendGnome : public PasswordStoreX::NativeBackend, ...@@ -109,21 +107,12 @@ class NativeBackendGnome : public PasswordStoreX::NativeBackend,
// Generates a profile-specific app string based on profile_id_. // Generates a profile-specific app string based on profile_id_.
std::string GetProfileSpecificAppString() const; std::string GetProfileSpecificAppString() const;
// Migrates non-profile-specific logins to be profile-specific.
void MigrateToProfileSpecificLogins();
// The local profile id, used to generate the app string. // The local profile id, used to generate the app string.
const LocalProfileId profile_id_; const LocalProfileId profile_id_;
// The pref service to use for persistent migration settings.
PrefService* prefs_;
// The app string, possibly based on the local profile id. // The app string, possibly based on the local profile id.
std::string app_string_; std::string app_string_;
// True once MigrateToProfileSpecificLogins() has been attempted.
bool migrate_tried_;
DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome); DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome);
}; };
......
...@@ -406,7 +406,7 @@ class NativeBackendGnomeTest : public testing::Test { ...@@ -406,7 +406,7 @@ class NativeBackendGnomeTest : public testing::Test {
ASSERT_TRUE(helper.IsMatchingEnabled()) ASSERT_TRUE(helper.IsMatchingEnabled())
<< "PSL matching needs to be enabled."; << "PSL matching needs to be enabled.";
NativeBackendGnome backend(321, profile_.GetPrefs()); NativeBackendGnome backend(321);
backend.Init(); backend.Init();
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -445,8 +445,6 @@ class NativeBackendGnomeTest : public testing::Test { ...@@ -445,8 +445,6 @@ class NativeBackendGnomeTest : public testing::Test {
content::TestBrowserThread ui_thread_; content::TestBrowserThread ui_thread_;
content::TestBrowserThread db_thread_; content::TestBrowserThread db_thread_;
TestingProfile profile_;
// Provide some test forms to avoid having to set them up in each test. // Provide some test forms to avoid having to set them up in each test.
PasswordForm form_google_; PasswordForm form_google_;
PasswordForm form_facebook_; PasswordForm form_facebook_;
...@@ -454,10 +452,7 @@ class NativeBackendGnomeTest : public testing::Test { ...@@ -454,10 +452,7 @@ class NativeBackendGnomeTest : public testing::Test {
}; };
TEST_F(NativeBackendGnomeTest, BasicAddLogin) { TEST_F(NativeBackendGnomeTest, BasicAddLogin) {
// Pretend that the migration has already taken place. NativeBackendGnome backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init(); backend.Init();
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -473,10 +468,7 @@ TEST_F(NativeBackendGnomeTest, BasicAddLogin) { ...@@ -473,10 +468,7 @@ TEST_F(NativeBackendGnomeTest, BasicAddLogin) {
} }
TEST_F(NativeBackendGnomeTest, BasicListLogins) { TEST_F(NativeBackendGnomeTest, BasicListLogins) {
// Pretend that the migration has already taken place. NativeBackendGnome backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init(); backend.Init();
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -525,10 +517,7 @@ TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledDomains) { ...@@ -525,10 +517,7 @@ TEST_F(NativeBackendGnomeTest, PSLMatchingDisabledDomains) {
} }
TEST_F(NativeBackendGnomeTest, BasicUpdateLogin) { TEST_F(NativeBackendGnomeTest, BasicUpdateLogin) {
// Pretend that the migration has already taken place. NativeBackendGnome backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init(); backend.Init();
// First add google login. // First add google login.
...@@ -561,10 +550,7 @@ TEST_F(NativeBackendGnomeTest, BasicUpdateLogin) { ...@@ -561,10 +550,7 @@ TEST_F(NativeBackendGnomeTest, BasicUpdateLogin) {
} }
TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) { TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) {
// Pretend that the migration has already taken place. NativeBackendGnome backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init(); backend.Init();
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -589,10 +575,7 @@ TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) { ...@@ -589,10 +575,7 @@ TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) {
} }
TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) { TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) {
// Pretend that the migration has already taken place. NativeBackendGnome backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init(); backend.Init();
// First add an unrelated login. // First add an unrelated login.
...@@ -633,10 +616,7 @@ TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) { ...@@ -633,10 +616,7 @@ TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) {
} }
TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) { TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) {
// Pretend that the migration has already taken place. NativeBackendGnome backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init(); backend.Init();
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -656,10 +636,7 @@ TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) { ...@@ -656,10 +636,7 @@ TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) {
} }
TEST_F(NativeBackendGnomeTest, ListLoginsAppends) { TEST_F(NativeBackendGnomeTest, ListLoginsAppends) {
// Pretend that the migration has already taken place. NativeBackendGnome backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init(); backend.Init();
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -691,337 +668,4 @@ TEST_F(NativeBackendGnomeTest, ListLoginsAppends) { ...@@ -691,337 +668,4 @@ TEST_F(NativeBackendGnomeTest, ListLoginsAppends) {
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
} }
// TODO(mdm): add more basic (i.e. non-migration) tests here at some point. // TODO(mdm): add more basic tests here at some point.
TEST_F(NativeBackendGnomeTest, DISABLED_MigrateOneLogin) {
// Reject attempts to migrate so we can populate the store.
mock_keyring_reject_local_ids = true;
{
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init();
BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
base::Unretained(&backend), form_google_));
// Make sure we can get the form back even when migration is failing.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunBothThreads();
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
}
EXPECT_EQ(1u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
// Now allow the migration.
mock_keyring_reject_local_ids = false;
{
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init();
// This should not trigger migration because there will be no results.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(base::IgnoreResult(&NativeBackendGnome::GetBlacklistLogins),
base::Unretained(&backend), &form_list));
RunBothThreads();
// Check that we got nothing back.
EXPECT_EQ(0u, form_list.size());
STLDeleteElements(&form_list);
}
// Check that the keyring is unmodified.
EXPECT_EQ(1u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
// Check that we haven't set the persistent preference.
EXPECT_FALSE(
profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
{
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init();
// Trigger the migration by looking something up.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunBothThreads();
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
}
EXPECT_EQ(2u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
if (mock_keyring_items.size() > 1)
CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42");
// Check that we have set the persistent preference.
EXPECT_TRUE(
profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
}
TEST_F(NativeBackendGnomeTest, DISABLED_MigrateToMultipleProfiles) {
// Reject attempts to migrate so we can populate the store.
mock_keyring_reject_local_ids = true;
{
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init();
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
base::Unretained(&backend), form_google_));
RunBothThreads();
}
EXPECT_EQ(1u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
// Now allow the migration.
mock_keyring_reject_local_ids = false;
{
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init();
// Trigger the migration by looking something up.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunBothThreads();
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
}
EXPECT_EQ(2u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
if (mock_keyring_items.size() > 1)
CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42");
// Check that we have set the persistent preference.
EXPECT_TRUE(
profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
// Normally we'd actually have a different profile. But in the test just reset
// the profile's persistent pref; we pass in the local profile id anyway.
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false);
{
NativeBackendGnome backend(24, profile_.GetPrefs());
backend.Init();
// Trigger the migration by looking something up.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunBothThreads();
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
}
EXPECT_EQ(3u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
if (mock_keyring_items.size() > 1)
CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42");
if (mock_keyring_items.size() > 2)
CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24");
}
TEST_F(NativeBackendGnomeTest, DISABLED_NoMigrationWithPrefSet) {
// Reject attempts to migrate so we can populate the store.
mock_keyring_reject_local_ids = true;
{
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init();
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
base::Unretained(&backend), form_google_));
RunBothThreads();
}
EXPECT_EQ(1u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
// Now allow migration, but also pretend that the it has already taken place.
mock_keyring_reject_local_ids = false;
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
{
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init();
// Trigger the migration by adding a new login.
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
base::Unretained(&backend), form_isc_));
// Look up all logins; we expect only the one we added.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunBothThreads();
// Quick check that we got the right thing back.
EXPECT_EQ(1u, form_list.size());
if (form_list.size() > 0)
EXPECT_EQ(form_isc_.signon_realm, form_list[0]->signon_realm);
STLDeleteElements(&form_list);
}
EXPECT_EQ(2u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
if (mock_keyring_items.size() > 1)
CheckMockKeyringItem(&mock_keyring_items[1], form_isc_, "chrome-42");
}
TEST_F(NativeBackendGnomeTest, DISABLED_DeleteMigratedPasswordIsIsolated) {
// Reject attempts to migrate so we can populate the store.
mock_keyring_reject_local_ids = true;
{
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init();
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin),
base::Unretained(&backend), form_google_));
RunBothThreads();
}
EXPECT_EQ(1u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
// Now allow the migration.
mock_keyring_reject_local_ids = false;
{
NativeBackendGnome backend(42, profile_.GetPrefs());
backend.Init();
// Trigger the migration by looking something up.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunBothThreads();
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
}
EXPECT_EQ(2u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
if (mock_keyring_items.size() > 1)
CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42");
// Check that we have set the persistent preference.
EXPECT_TRUE(
profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
// Normally we'd actually have a different profile. But in the test just reset
// the profile's persistent pref; we pass in the local profile id anyway.
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false);
{
NativeBackendGnome backend(24, profile_.GetPrefs());
backend.Init();
// Trigger the migration by looking something up.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunBothThreads();
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
// There should be three passwords now.
EXPECT_EQ(3u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
if (mock_keyring_items.size() > 1)
CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42");
if (mock_keyring_items.size() > 2)
CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24");
// Now delete the password from this second profile.
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(base::IgnoreResult(&NativeBackendGnome::RemoveLogin),
base::Unretained(&backend), form_google_));
RunBothThreads();
// The other two copies of the password in different profiles should remain.
EXPECT_EQ(2u, mock_keyring_items.size());
if (mock_keyring_items.size() > 0)
CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
if (mock_keyring_items.size() > 1)
CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42");
}
}
...@@ -102,23 +102,11 @@ void LogDeserializationWarning(int version, ...@@ -102,23 +102,11 @@ void LogDeserializationWarning(int version,
} // namespace } // namespace
NativeBackendKWallet::NativeBackendKWallet(LocalProfileId id, NativeBackendKWallet::NativeBackendKWallet(LocalProfileId id)
PrefService* prefs)
: profile_id_(id), : profile_id_(id),
prefs_(prefs),
kwallet_proxy_(NULL), kwallet_proxy_(NULL),
app_name_(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME)) { app_name_(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME)) {
// TODO(mdm): after a few more releases, remove the code which is now dead due folder_name_ = GetProfileSpecificFolderName();
// to the true || here, and simplify this code. We don't do it yet to make it
// easier to revert if necessary.
if (true || PasswordStoreX::PasswordsUseLocalProfileId(prefs)) {
folder_name_ = GetProfileSpecificFolderName();
// We already did the migration previously. Don't try again.
migrate_tried_ = true;
} else {
folder_name_ = kKWalletFolder;
migrate_tried_ = false;
}
} }
NativeBackendKWallet::~NativeBackendKWallet() { NativeBackendKWallet::~NativeBackendKWallet() {
...@@ -926,10 +914,6 @@ int NativeBackendKWallet::WalletHandle() { ...@@ -926,10 +914,6 @@ int NativeBackendKWallet::WalletHandle() {
} }
} }
// Successful initialization. Try migration if necessary.
if (!migrate_tried_)
MigrateToProfileSpecificLogins();
return handle; return handle;
} }
...@@ -938,59 +922,3 @@ std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { ...@@ -938,59 +922,3 @@ std::string NativeBackendKWallet::GetProfileSpecificFolderName() const {
// Now we use it to distinguish passwords for different profiles. // Now we use it to distinguish passwords for different profiles.
return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_);
} }
void NativeBackendKWallet::MigrateToProfileSpecificLogins() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
DCHECK(!migrate_tried_);
DCHECK_EQ(folder_name_, kKWalletFolder);
// Record the fact that we've attempted migration already right away, so that
// we don't get recursive calls back to MigrateToProfileSpecificLogins().
migrate_tried_ = true;
// First get all the logins, using the old folder name.
int wallet_handle = WalletHandle();
if (wallet_handle == kInvalidKWalletHandle)
return;
PasswordFormList forms;
if (!GetAllLogins(&forms, wallet_handle))
return;
// Now switch to a profile-specific folder name.
folder_name_ = GetProfileSpecificFolderName();
// Try to add all the logins with the new folder name.
// This could be done more efficiently by grouping by signon realm and using
// SetLoginsList(), but we do this for simplicity since it is only done once.
// Note, however, that we do need another call to WalletHandle() to create
// this folder if necessary.
bool ok = true;
for (size_t i = 0; i < forms.size(); ++i) {
if (!AddLogin(*forms[i]))
ok = false;
delete forms[i];
}
if (forms.empty()) {
// If there were no logins to migrate, we do an extra call to WalletHandle()
// for its side effect of attempting to create the profile-specific folder.
// This is not strictly necessary, but it's safe and helps in testing.
wallet_handle = WalletHandle();
if (wallet_handle == kInvalidKWalletHandle)
ok = false;
}
if (ok) {
// All good! Keep the new app string and set a persistent pref.
// NOTE: We explicitly don't delete the old passwords yet. They are
// potentially shared with other profiles and other user data dirs!
// Each other profile must be able to migrate the shared data as well,
// so we must leave it alone. After a few releases, we'll add code to
// delete them, and eventually remove this migration code.
// TODO(mdm): follow through with the plan above.
PasswordStoreX::SetPasswordsUseLocalProfileId(prefs_);
} else {
// We failed to migrate for some reason. Use the old folder name.
folder_name_ = kKWalletFolder;
}
}
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
class Pickle; class Pickle;
class PickleIterator; class PickleIterator;
class PrefService;
namespace autofill { namespace autofill {
struct PasswordForm; struct PasswordForm;
...@@ -34,7 +33,7 @@ class ObjectProxy; ...@@ -34,7 +33,7 @@ class ObjectProxy;
// NativeBackend implementation using KWallet. // NativeBackend implementation using KWallet.
class NativeBackendKWallet : public PasswordStoreX::NativeBackend { class NativeBackendKWallet : public PasswordStoreX::NativeBackend {
public: public:
NativeBackendKWallet(LocalProfileId id, PrefService* prefs); explicit NativeBackendKWallet(LocalProfileId id);
virtual ~NativeBackendKWallet(); virtual ~NativeBackendKWallet();
...@@ -131,21 +130,12 @@ class NativeBackendKWallet : public PasswordStoreX::NativeBackend { ...@@ -131,21 +130,12 @@ class NativeBackendKWallet : public PasswordStoreX::NativeBackend {
// Generates a profile-specific folder name based on profile_id_. // Generates a profile-specific folder name based on profile_id_.
std::string GetProfileSpecificFolderName() const; std::string GetProfileSpecificFolderName() const;
// Migrates non-profile-specific logins to be profile-specific.
void MigrateToProfileSpecificLogins();
// The local profile id, used to generate the folder name. // The local profile id, used to generate the folder name.
const LocalProfileId profile_id_; const LocalProfileId profile_id_;
// The pref service to use for persistent migration settings.
PrefService* prefs_;
// The KWallet folder name, possibly based on the local profile id. // The KWallet folder name, possibly based on the local profile id.
std::string folder_name_; std::string folder_name_;
// True once MigrateToProfileSpecificLogins() has been attempted.
bool migrate_tried_;
// DBus handle for communication with klauncher and kwalletd. // DBus handle for communication with klauncher and kwalletd.
scoped_refptr<dbus::Bus> session_bus_; scoped_refptr<dbus::Bus> session_bus_;
// Object proxy for kwalletd. We do not own this. // Object proxy for kwalletd. We do not own this.
......
...@@ -126,8 +126,8 @@ const int NativeBackendKWallet::kInvalidKWalletHandle; ...@@ -126,8 +126,8 @@ const int NativeBackendKWallet::kInvalidKWalletHandle;
// Subclass NativeBackendKWallet to promote some members to public for testing. // Subclass NativeBackendKWallet to promote some members to public for testing.
class NativeBackendKWalletStub : public NativeBackendKWallet { class NativeBackendKWalletStub : public NativeBackendKWallet {
public: public:
NativeBackendKWalletStub(LocalProfileId id, PrefService* pref_service) explicit NativeBackendKWalletStub(LocalProfileId id)
: NativeBackendKWallet(id, pref_service) { : NativeBackendKWallet(id) {
} }
using NativeBackendKWallet::InitWithBus; using NativeBackendKWallet::InitWithBus;
using NativeBackendKWallet::kInvalidKWalletHandle; using NativeBackendKWallet::kInvalidKWalletHandle;
...@@ -226,7 +226,6 @@ class NativeBackendKWalletTest : public NativeBackendKWalletTestBase { ...@@ -226,7 +226,6 @@ class NativeBackendKWalletTest : public NativeBackendKWalletTestBase {
base::MessageLoopForUI message_loop_; base::MessageLoopForUI message_loop_;
content::TestBrowserThread ui_thread_; content::TestBrowserThread ui_thread_;
content::TestBrowserThread db_thread_; content::TestBrowserThread db_thread_;
TestingProfile profile_;
scoped_refptr<dbus::MockBus> mock_session_bus_; scoped_refptr<dbus::MockBus> mock_session_bus_;
scoped_refptr<dbus::MockObjectProxy> mock_klauncher_proxy_; scoped_refptr<dbus::MockObjectProxy> mock_klauncher_proxy_;
...@@ -472,14 +471,14 @@ void NativeBackendKWalletTest::CheckPasswordForms( ...@@ -472,14 +471,14 @@ void NativeBackendKWalletTest::CheckPasswordForms(
} }
TEST_F(NativeBackendKWalletTest, NotEnabled) { TEST_F(NativeBackendKWalletTest, NotEnabled) {
NativeBackendKWalletStub kwallet(42, profile_.GetPrefs()); NativeBackendKWalletStub kwallet(42);
kwallet_enabled_ = false; kwallet_enabled_ = false;
EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_)); EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_));
EXPECT_FALSE(klauncher_contacted_); EXPECT_FALSE(klauncher_contacted_);
} }
TEST_F(NativeBackendKWalletTest, NotRunnable) { TEST_F(NativeBackendKWalletTest, NotRunnable) {
NativeBackendKWalletStub kwallet(42, profile_.GetPrefs()); NativeBackendKWalletStub kwallet(42);
kwallet_runnable_ = false; kwallet_runnable_ = false;
kwallet_running_ = false; kwallet_running_ = false;
EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_)); EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_));
...@@ -487,7 +486,7 @@ TEST_F(NativeBackendKWalletTest, NotRunnable) { ...@@ -487,7 +486,7 @@ TEST_F(NativeBackendKWalletTest, NotRunnable) {
} }
TEST_F(NativeBackendKWalletTest, NotRunningOrEnabled) { TEST_F(NativeBackendKWalletTest, NotRunningOrEnabled) {
NativeBackendKWalletStub kwallet(42, profile_.GetPrefs()); NativeBackendKWalletStub kwallet(42);
kwallet_running_ = false; kwallet_running_ = false;
kwallet_enabled_ = false; kwallet_enabled_ = false;
EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_)); EXPECT_FALSE(kwallet.InitWithBus(mock_session_bus_));
...@@ -495,23 +494,20 @@ TEST_F(NativeBackendKWalletTest, NotRunningOrEnabled) { ...@@ -495,23 +494,20 @@ TEST_F(NativeBackendKWalletTest, NotRunningOrEnabled) {
} }
TEST_F(NativeBackendKWalletTest, NotRunning) { TEST_F(NativeBackendKWalletTest, NotRunning) {
NativeBackendKWalletStub kwallet(42, profile_.GetPrefs()); NativeBackendKWalletStub kwallet(42);
kwallet_running_ = false; kwallet_running_ = false;
EXPECT_TRUE(kwallet.InitWithBus(mock_session_bus_)); EXPECT_TRUE(kwallet.InitWithBus(mock_session_bus_));
EXPECT_TRUE(klauncher_contacted_); EXPECT_TRUE(klauncher_contacted_);
} }
TEST_F(NativeBackendKWalletTest, BasicStartup) { TEST_F(NativeBackendKWalletTest, BasicStartup) {
NativeBackendKWalletStub kwallet(42, profile_.GetPrefs()); NativeBackendKWalletStub kwallet(42);
EXPECT_TRUE(kwallet.InitWithBus(mock_session_bus_)); EXPECT_TRUE(kwallet.InitWithBus(mock_session_bus_));
EXPECT_FALSE(klauncher_contacted_); EXPECT_FALSE(klauncher_contacted_);
} }
TEST_F(NativeBackendKWalletTest, BasicAddLogin) { TEST_F(NativeBackendKWalletTest, BasicAddLogin) {
// Pretend that the migration has already taken place. NativeBackendKWalletStub backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -531,10 +527,7 @@ TEST_F(NativeBackendKWalletTest, BasicAddLogin) { ...@@ -531,10 +527,7 @@ TEST_F(NativeBackendKWalletTest, BasicAddLogin) {
} }
TEST_F(NativeBackendKWalletTest, BasicListLogins) { TEST_F(NativeBackendKWalletTest, BasicListLogins) {
// Pretend that the migration has already taken place. NativeBackendKWalletStub backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -565,10 +558,7 @@ TEST_F(NativeBackendKWalletTest, BasicListLogins) { ...@@ -565,10 +558,7 @@ TEST_F(NativeBackendKWalletTest, BasicListLogins) {
} }
TEST_F(NativeBackendKWalletTest, BasicRemoveLogin) { TEST_F(NativeBackendKWalletTest, BasicRemoveLogin) {
// Pretend that the migration has already taken place. NativeBackendKWalletStub backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -598,10 +588,7 @@ TEST_F(NativeBackendKWalletTest, BasicRemoveLogin) { ...@@ -598,10 +588,7 @@ TEST_F(NativeBackendKWalletTest, BasicRemoveLogin) {
} }
TEST_F(NativeBackendKWalletTest, RemoveNonexistentLogin) { TEST_F(NativeBackendKWalletTest, RemoveNonexistentLogin) {
// Pretend that the migration has already taken place. NativeBackendKWalletStub backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
// First add an unrelated login. // First add an unrelated login.
...@@ -644,10 +631,7 @@ TEST_F(NativeBackendKWalletTest, RemoveNonexistentLogin) { ...@@ -644,10 +631,7 @@ TEST_F(NativeBackendKWalletTest, RemoveNonexistentLogin) {
} }
TEST_F(NativeBackendKWalletTest, AddDuplicateLogin) { TEST_F(NativeBackendKWalletTest, AddDuplicateLogin) {
// Pretend that the migration has already taken place. NativeBackendKWalletStub backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -671,10 +655,7 @@ TEST_F(NativeBackendKWalletTest, AddDuplicateLogin) { ...@@ -671,10 +655,7 @@ TEST_F(NativeBackendKWalletTest, AddDuplicateLogin) {
} }
TEST_F(NativeBackendKWalletTest, ListLoginsAppends) { TEST_F(NativeBackendKWalletTest, ListLoginsAppends) {
// Pretend that the migration has already taken place. NativeBackendKWalletStub backend(42);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_)); EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
BrowserThread::PostTask( BrowserThread::PostTask(
...@@ -710,324 +691,9 @@ TEST_F(NativeBackendKWalletTest, ListLoginsAppends) { ...@@ -710,324 +691,9 @@ TEST_F(NativeBackendKWalletTest, ListLoginsAppends) {
CheckPasswordForms("Chrome Form Data (42)", expected); CheckPasswordForms("Chrome Form Data (42)", expected);
} }
// TODO(mdm): add more basic (i.e. non-migration) tests here at some point. // TODO(mdm): add more basic tests here at some point.
// (For example tests for storing >1 password per realm pickle.) // (For example tests for storing >1 password per realm pickle.)
TEST_F(NativeBackendKWalletTest, DISABLED_MigrateOneLogin) {
// Reject attempts to migrate so we can populate the store.
wallet_.set_reject_local_folders(true);
{
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
base::Unretained(&backend), form_google_));
// Make sure we can get the form back even when migration is failing.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(
&NativeBackendKWalletStub::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunDBThread();
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
}
EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)"));
std::vector<const PasswordForm*> forms;
forms.push_back(&form_google_);
ExpectationArray expected;
expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
CheckPasswordForms("Chrome Form Data", expected);
// Now allow the migration.
wallet_.set_reject_local_folders(false);
{
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
// Trigger the migration by looking something up.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(
&NativeBackendKWalletStub::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunDBThread();
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
}
CheckPasswordForms("Chrome Form Data", expected);
CheckPasswordForms("Chrome Form Data (42)", expected);
// Check that we have set the persistent preference.
EXPECT_TRUE(
profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
}
TEST_F(NativeBackendKWalletTest, DISABLED_MigrateToMultipleProfiles) {
// Reject attempts to migrate so we can populate the store.
wallet_.set_reject_local_folders(true);
{
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
base::Unretained(&backend), form_google_));
RunDBThread();
}
EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)"));
std::vector<const PasswordForm*> forms;
forms.push_back(&form_google_);
ExpectationArray expected;
expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
CheckPasswordForms("Chrome Form Data", expected);
// Now allow the migration.
wallet_.set_reject_local_folders(false);
{
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
// Trigger the migration by looking something up.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(
&NativeBackendKWalletStub::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunDBThread();
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
}
CheckPasswordForms("Chrome Form Data", expected);
CheckPasswordForms("Chrome Form Data (42)", expected);
// Check that we have set the persistent preference.
EXPECT_TRUE(
profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
// Normally we'd actually have a different profile. But in the test just reset
// the profile's persistent pref; we pass in the local profile id anyway.
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false);
{
NativeBackendKWalletStub backend(24, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
// Trigger the migration by looking something up.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(
&NativeBackendKWalletStub::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunDBThread();
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
}
CheckPasswordForms("Chrome Form Data", expected);
CheckPasswordForms("Chrome Form Data (42)", expected);
CheckPasswordForms("Chrome Form Data (24)", expected);
}
TEST_F(NativeBackendKWalletTest, DISABLED_NoMigrationWithPrefSet) {
// Reject attempts to migrate so we can populate the store.
wallet_.set_reject_local_folders(true);
{
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
base::Unretained(&backend), form_google_));
RunDBThread();
}
EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)"));
std::vector<const PasswordForm*> forms;
forms.push_back(&form_google_);
ExpectationArray expected;
expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
CheckPasswordForms("Chrome Form Data", expected);
// Now allow migration, but also pretend that the it has already taken place.
wallet_.set_reject_local_folders(false);
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
{
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
// Trigger the migration by adding a new login.
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
base::Unretained(&backend), form_isc_));
// Look up all logins; we expect only the one we added.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(
&NativeBackendKWalletStub::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunDBThread();
// Quick check that we got the right thing back.
EXPECT_EQ(1u, form_list.size());
if (form_list.size() > 0)
EXPECT_EQ(form_isc_.signon_realm, form_list[0]->signon_realm);
STLDeleteElements(&form_list);
}
CheckPasswordForms("Chrome Form Data", expected);
forms[0] = &form_isc_;
expected.clear();
expected.push_back(make_pair(std::string(form_isc_.signon_realm), forms));
CheckPasswordForms("Chrome Form Data (42)", expected);
}
TEST_F(NativeBackendKWalletTest, DISABLED_DeleteMigratedPasswordIsIsolated) {
// Reject attempts to migrate so we can populate the store.
wallet_.set_reject_local_folders(true);
{
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(&NativeBackendKWalletStub::AddLogin),
base::Unretained(&backend), form_google_));
RunDBThread();
}
EXPECT_FALSE(wallet_.hasFolder("Chrome Form Data (42)"));
std::vector<const PasswordForm*> forms;
forms.push_back(&form_google_);
ExpectationArray expected;
expected.push_back(make_pair(std::string(form_google_.signon_realm), forms));
CheckPasswordForms("Chrome Form Data", expected);
// Now allow the migration.
wallet_.set_reject_local_folders(false);
{
NativeBackendKWalletStub backend(42, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
// Trigger the migration by looking something up.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(
&NativeBackendKWalletStub::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunDBThread();
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
}
CheckPasswordForms("Chrome Form Data", expected);
CheckPasswordForms("Chrome Form Data (42)", expected);
// Check that we have set the persistent preference.
EXPECT_TRUE(
profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
// Normally we'd actually have a different profile. But in the test just reset
// the profile's persistent pref; we pass in the local profile id anyway.
profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false);
{
NativeBackendKWalletStub backend(24, profile_.GetPrefs());
EXPECT_TRUE(backend.InitWithBus(mock_session_bus_));
// Trigger the migration by looking something up.
std::vector<PasswordForm*> form_list;
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(
&NativeBackendKWalletStub::GetAutofillableLogins),
base::Unretained(&backend), &form_list));
RunDBThread();
// Quick check that we got something back.
EXPECT_EQ(1u, form_list.size());
STLDeleteElements(&form_list);
// There should be three passwords now.
CheckPasswordForms("Chrome Form Data", expected);
CheckPasswordForms("Chrome Form Data (42)", expected);
CheckPasswordForms("Chrome Form Data (24)", expected);
// Now delete the password from this second profile.
BrowserThread::PostTask(
BrowserThread::DB, FROM_HERE,
base::Bind(
base::IgnoreResult(&NativeBackendKWalletStub::RemoveLogin),
base::Unretained(&backend), form_google_));
RunDBThread();
// The other two copies of the password in different profiles should remain.
CheckPasswordForms("Chrome Form Data", expected);
CheckPasswordForms("Chrome Form Data (42)", expected);
expected.clear();
CheckPasswordForms("Chrome Form Data (24)", expected);
}
}
class NativeBackendKWalletPickleTest : public NativeBackendKWalletTestBase { class NativeBackendKWalletPickleTest : public NativeBackendKWalletTestBase {
protected: protected:
void CreateVersion1Pickle(const PasswordForm& form, Pickle* pickle); void CreateVersion1Pickle(const PasswordForm& form, Pickle* pickle);
......
...@@ -187,7 +187,7 @@ KeyedService* PasswordStoreFactory::BuildServiceInstanceFor( ...@@ -187,7 +187,7 @@ KeyedService* PasswordStoreFactory::BuildServiceInstanceFor(
if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4) { if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4) {
// KDE3 didn't use DBus, which our KWallet store uses. // KDE3 didn't use DBus, which our KWallet store uses.
VLOG(1) << "Trying KWallet for password storage."; VLOG(1) << "Trying KWallet for password storage.";
backend.reset(new NativeBackendKWallet(id, prefs)); backend.reset(new NativeBackendKWallet(id));
if (backend->Init()) if (backend->Init())
VLOG(1) << "Using KWallet for password storage."; VLOG(1) << "Using KWallet for password storage.";
else else
...@@ -197,7 +197,7 @@ KeyedService* PasswordStoreFactory::BuildServiceInstanceFor( ...@@ -197,7 +197,7 @@ KeyedService* PasswordStoreFactory::BuildServiceInstanceFor(
desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) { desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) {
#if defined(USE_GNOME_KEYRING) #if defined(USE_GNOME_KEYRING)
VLOG(1) << "Trying GNOME keyring for password storage."; VLOG(1) << "Trying GNOME keyring for password storage.";
backend.reset(new NativeBackendGnome(id, prefs)); backend.reset(new NativeBackendGnome(id));
if (backend->Init()) if (backend->Init())
VLOG(1) << "Using GNOME keyring for password storage."; VLOG(1) << "Using GNOME keyring for password storage.";
else else
...@@ -233,14 +233,12 @@ KeyedService* PasswordStoreFactory::BuildServiceInstanceFor( ...@@ -233,14 +233,12 @@ KeyedService* PasswordStoreFactory::BuildServiceInstanceFor(
void PasswordStoreFactory::RegisterProfilePrefs( void PasswordStoreFactory::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) { user_prefs::PrefRegistrySyncable* registry) {
#if !defined(OS_CHROMEOS) && defined(USE_X11) #if !defined(OS_CHROMEOS) && defined(USE_X11)
// Notice that the preprocessor conditions above are exactly those that will
// result in using PasswordStoreX in BuildServiceInstanceFor().
registry->RegisterIntegerPref( registry->RegisterIntegerPref(
prefs::kLocalProfileId, prefs::kLocalProfileId,
kInvalidLocalProfileId, kInvalidLocalProfileId,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
// Notice that the preprocessor conditions above are exactly those that will
// result in using PasswordStoreX in CreatePasswordStore() below.
PasswordStoreX::RegisterProfilePrefs(registry);
#endif #endif
} }
......
...@@ -260,42 +260,3 @@ ssize_t PasswordStoreX::MigrateLogins() { ...@@ -260,42 +260,3 @@ ssize_t PasswordStoreX::MigrateLogins() {
STLDeleteElements(&forms); STLDeleteElements(&forms);
return result; return result;
} }
#if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
// static
void PasswordStoreX::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
// Normally we should be on the UI thread here, but in tests we might not.
registry->RegisterBooleanPref(
prefs::kPasswordsUseLocalProfileId,
// default: passwords don't use local ids
false,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
}
// static
bool PasswordStoreX::PasswordsUseLocalProfileId(PrefService* prefs) {
// Normally we should be on the UI thread here, but in tests we might not.
return prefs->GetBoolean(prefs::kPasswordsUseLocalProfileId);
}
namespace {
// This function is a hack to do something not entirely thread safe: the pref
// service comes from the UI thread, but it's not ref counted. We keep a pointer
// to it on the DB thread, and need to invoke a method on the UI thread. This
// function does that for us without requiring ref counting the pref service.
// TODO(mdm): Fix this if it becomes a problem. Given that this function will
// be called once ever per profile, it probably will not cause a problem...
void UISetPasswordsUseLocalProfileId(PrefService* prefs) {
prefs->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
}
} // anonymous namespace
// static
void PasswordStoreX::SetPasswordsUseLocalProfileId(PrefService* prefs) {
// This method should work on any thread, but we expect the DB thread.
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&UISetPasswordsUseLocalProfileId, prefs));
}
#endif // !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
...@@ -58,19 +58,6 @@ class PasswordStoreX : public PasswordStoreDefault { ...@@ -58,19 +58,6 @@ class PasswordStoreX : public PasswordStoreDefault {
LoginDatabase* login_db, LoginDatabase* login_db,
NativeBackend* backend); NativeBackend* backend);
#if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
// Registers the pref setting used for the methods below.
static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
// Returns true if passwords have been tagged with the local profile id.
static bool PasswordsUseLocalProfileId(PrefService* prefs);
// Sets the persistent bit indicating that passwords have been tagged with the
// local profile id. This cannot be unset; passwords get migrated only once.
// The caller promises that |prefs| will not be deleted any time soon.
static void SetPasswordsUseLocalProfileId(PrefService* prefs);
#endif // !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
private: private:
friend class PasswordStoreXTest; friend class PasswordStoreXTest;
......
...@@ -35,11 +35,6 @@ const char kPasswordManagerGroupsForDomains[] = ...@@ -35,11 +35,6 @@ const char kPasswordManagerGroupsForDomains[] =
#if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
// The local profile id for this profile. // The local profile id for this profile.
const char kLocalProfileId[] = "profile.local_profile_id"; const char kLocalProfileId[] = "profile.local_profile_id";
// Whether passwords in external services (e.g. GNOME Keyring) have been tagged
// with the local profile id yet. (Used for migrating to tagged passwords.)
const char kPasswordsUseLocalProfileId[] =
"profile.passwords_use_local_profile_id";
#endif #endif
} // namespace prefs } // namespace prefs
...@@ -21,7 +21,6 @@ extern const char kPasswordManagerGroupsForDomains[]; ...@@ -21,7 +21,6 @@ extern const char kPasswordManagerGroupsForDomains[];
#if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX) #if !defined(OS_MACOSX) && !defined(OS_CHROMEOS) && defined(OS_POSIX)
extern const char kLocalProfileId[]; extern const char kLocalProfileId[];
extern const char kPasswordsUseLocalProfileId[];
#endif #endif
} // namespace prefs } // namespace prefs
......
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