summaryrefslogtreecommitdiffstats
path: root/chrome/browser/password_manager
diff options
context:
space:
mode:
authormdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-14 22:59:17 +0000
committermdm@chromium.org <mdm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-14 22:59:17 +0000
commit9c587a0112d239f5d9fd6979e7b3be4a970068ad (patch)
tree77c2730342c13eb475bd74ef376378fe9731a672 /chrome/browser/password_manager
parentdbb9a148bc9c67581cb861d38d750127031157da (diff)
downloadchromium_src-9c587a0112d239f5d9fd6979e7b3be4a970068ad.zip
chromium_src-9c587a0112d239f5d9fd6979e7b3be4a970068ad.tar.gz
chromium_src-9c587a0112d239f5d9fd6979e7b3be4a970068ad.tar.bz2
Revert 92615 - Linux: make externally-stored passwords (e.g. GNOME Keyring) profile-specific.
This is accomplished by associating a randomly generated id with each profile, and storing the profile id with the passwords. The ids are chosen such that they are obviously not unique ids (there are more users than ids), yet within one machine they should be unique with high probability. Although profiles have names, it turns out that using these names as the identifiers is not preferable for two reasons. First, the names are actually the account email addresses, and not user-provided strings. The default profile, if not using sync, has the empty string for its name. This means that we still have to worry about migration in this case, and can't cleanly assume that existing passwords "belong" to the default profile, because we can't always tell which profile is the default. Second, the sync code seems to be rather non-robust and fails frequently when passwords change underneath it. Using the profile name would mean that the same account synced within different user data dirs would share passwords, which the sync code won't really like. (Of course, this is the current situation as well, with different user data dirs.) Speaking of migration: this change leaves the original, shared passwords alone, and they will be migrated (copied, really) into each profile the first time it is used. After a while, we can add code to delete these shared passwords so they don't persist forever without being visible in the UI. Eventually, we can remove the migration and deletion code. BUG=77022 Review URL: http://codereview.chromium.org/7212031 TBR=mdm@chromium.org Review URL: http://codereview.chromium.org/7373014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92618 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/password_manager')
-rw-r--r--chrome/browser/password_manager/native_backend_gnome_x.cc191
-rw-r--r--chrome/browser/password_manager/native_backend_gnome_x.h27
-rw-r--r--chrome/browser/password_manager/native_backend_kwallet_x.cc149
-rw-r--r--chrome/browser/password_manager/native_backend_kwallet_x.h45
-rw-r--r--chrome/browser/password_manager/password_store_x.cc37
-rw-r--r--chrome/browser/password_manager/password_store_x.h12
6 files changed, 108 insertions, 353 deletions
diff --git a/chrome/browser/password_manager/native_backend_gnome_x.cc b/chrome/browser/password_manager/native_backend_gnome_x.cc
index 80c9c80..6141a9e 100644
--- a/chrome/browser/password_manager/native_backend_gnome_x.cc
+++ b/chrome/browser/password_manager/native_backend_gnome_x.cc
@@ -13,9 +13,7 @@
#include "base/logging.h"
#include "base/string_number_conversions.h"
-#include "base/string_piece.h"
#include "base/string_util.h"
-#include "base/stringprintf.h"
#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "base/synchronization/waitable_event.h"
@@ -46,7 +44,12 @@ namespace {
F(store_password) \
F(delete_password) \
F(find_itemsv) \
- F(result_to_message)
+ F(result_to_message) \
+ F(list_keyring_names) \
+ F(list_item_ids) \
+ F(item_get_attributes) \
+ F(item_get_info) \
+ F(item_info_get_secret)
// Define the actual function pointers that we'll use in application code.
#define GNOME_KEYRING_DEFINE_WRAPPER(name) \
@@ -80,6 +83,16 @@ const struct {
wrap_gnome_keyring_find_itemsv
#define gnome_keyring_result_to_message \
wrap_gnome_keyring_result_to_message
+#define gnome_keyring_list_keyring_names \
+ wrap_gnome_keyring_list_keyring_names
+#define gnome_keyring_list_item_ids \
+ wrap_gnome_keyring_list_item_ids
+#define gnome_keyring_item_get_attributes \
+ wrap_gnome_keyring_item_get_attributes
+#define gnome_keyring_item_get_info \
+ wrap_gnome_keyring_item_get_info
+#define gnome_keyring_item_info_get_secret \
+ wrap_gnome_keyring_item_info_get_secret
/* Load the library and initialize the function pointers. */
bool LoadGnomeKeyring() {
@@ -110,13 +123,14 @@ bool LoadGnomeKeyring() {
#else // !defined(DLOPEN_GNOME_KEYRING)
bool LoadGnomeKeyring() {
- // We don't need to do anything here.
+ // We don't need to do anything here. When linking directly, we also assume
+ // that whoever is compiling this code has checked that the version is OK.
return true;
}
#endif // !defined(DLOPEN_GNOME_KEYRING)
-const char kGnomeKeyringAppString[] = "chrome";
+#define GNOME_KEYRING_APPLICATION_CHROME "chrome"
// Convert the attributes of a given keyring entry into a new PasswordForm.
// Note: does *not* get the actual password, as that is not a key attribute!
@@ -133,8 +147,7 @@ PasswordForm* FormFromAttributes(GnomeKeyringAttributeList* attrs) {
uint_attr_map[attr.name] = attr.value.integer;
}
// Check to make sure this is a password we care about.
- const std::string& app_value = string_attr_map["application"];
- if (!base::StringPiece(app_value).starts_with(kGnomeKeyringAppString))
+ if (string_attr_map["application"] != GNOME_KEYRING_APPLICATION_CHROME)
return NULL;
PasswordForm* form = new PasswordForm();
@@ -228,14 +241,13 @@ class GKRMethod {
GKRMethod() : event_(false, false), result_(GNOME_KEYRING_RESULT_CANCELLED) {}
// Action methods. These call gnome_keyring_* functions. Call from UI thread.
- // See GetProfileSpecificAppString() for more information on the app string.
- void AddLogin(const PasswordForm& form, const char* app_string);
- void AddLoginSearch(const PasswordForm& form, const char* app_string);
- void UpdateLoginSearch(const PasswordForm& form, const char* app_string);
- void RemoveLogin(const PasswordForm& form, const char* app_string);
- void GetLogins(const PasswordForm& form, const char* app_string);
- void GetLoginsList(uint32_t blacklisted_by_user, const char* app_string);
- void GetAllLogins(const char* app_string);
+ void AddLogin(const PasswordForm& form);
+ void AddLoginSearch(const PasswordForm& form);
+ void UpdateLoginSearch(const PasswordForm& form);
+ void RemoveLogin(const PasswordForm& form);
+ void GetLogins(const PasswordForm& form);
+ void GetLoginsList(uint32_t blacklisted_by_user);
+ void GetAllLogins();
// Use after AddLogin, RemoveLogin.
GnomeKeyringResult WaitResult();
@@ -256,7 +268,7 @@ class GKRMethod {
NativeBackendGnome::PasswordFormList forms_;
};
-void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) {
+void GKRMethod::AddLogin(const PasswordForm& form) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
time_t date_created = form.date_created.ToTimeT();
// If we are asked to save a password with 0 date, use the current time.
@@ -283,12 +295,11 @@ void GKRMethod::AddLogin(const PasswordForm& form, const char* app_string) {
"date_created", base::Int64ToString(date_created).c_str(),
"blacklisted_by_user", form.blacklisted_by_user,
"scheme", form.scheme,
- "application", app_string,
+ "application", GNOME_KEYRING_APPLICATION_CHROME,
NULL);
}
-void GKRMethod::AddLoginSearch(const PasswordForm& form,
- const char* app_string) {
+void GKRMethod::AddLoginSearch(const PasswordForm& form) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Search GNOME Keyring for matching passwords to update.
gnome_keyring_find_itemsv(
@@ -309,12 +320,11 @@ void GKRMethod::AddLoginSearch(const PasswordForm& form,
"signon_realm", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
form.signon_realm.c_str(),
"application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
- app_string,
+ GNOME_KEYRING_APPLICATION_CHROME,
NULL);
}
-void GKRMethod::UpdateLoginSearch(const PasswordForm& form,
- const char* app_string) {
+void GKRMethod::UpdateLoginSearch(const PasswordForm& form) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Search GNOME Keyring for matching passwords to update.
gnome_keyring_find_itemsv(
@@ -333,11 +343,11 @@ void GKRMethod::UpdateLoginSearch(const PasswordForm& form,
"signon_realm", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
form.signon_realm.c_str(),
"application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
- app_string,
+ GNOME_KEYRING_APPLICATION_CHROME,
NULL);
}
-void GKRMethod::RemoveLogin(const PasswordForm& form, const char* app_string) {
+void GKRMethod::RemoveLogin(const PasswordForm& form) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// We find forms using the same fields as LoginDatabase::RemoveLogin().
gnome_keyring_delete_password(
@@ -355,7 +365,7 @@ void GKRMethod::RemoveLogin(const PasswordForm& form, const char* app_string) {
NULL);
}
-void GKRMethod::GetLogins(const PasswordForm& form, const char* app_string) {
+void GKRMethod::GetLogins(const PasswordForm& form) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Search GNOME Keyring for matching passwords.
gnome_keyring_find_itemsv(
@@ -366,12 +376,11 @@ void GKRMethod::GetLogins(const PasswordForm& form, const char* app_string) {
"signon_realm", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
form.signon_realm.c_str(),
"application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
- app_string,
+ GNOME_KEYRING_APPLICATION_CHROME,
NULL);
}
-void GKRMethod::GetLoginsList(uint32_t blacklisted_by_user,
- const char* app_string) {
+void GKRMethod::GetLoginsList(uint32_t blacklisted_by_user) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// Search GNOME Keyring for matching passwords.
gnome_keyring_find_itemsv(
@@ -382,11 +391,11 @@ void GKRMethod::GetLoginsList(uint32_t blacklisted_by_user,
"blacklisted_by_user", GNOME_KEYRING_ATTRIBUTE_TYPE_UINT32,
blacklisted_by_user,
"application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
- app_string,
+ GNOME_KEYRING_APPLICATION_CHROME,
NULL);
}
-void GKRMethod::GetAllLogins(const char* app_string) {
+void GKRMethod::GetAllLogins() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// We need to search for something, otherwise we get no results - so
// we search for the fixed application string.
@@ -396,7 +405,7 @@ void GKRMethod::GetAllLogins(const char* app_string) {
this, // data
NULL, // destroy_data
"application", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
- app_string,
+ GNOME_KEYRING_APPLICATION_CHROME,
NULL);
}
@@ -441,16 +450,7 @@ struct RunnableMethodTraits<GKRMethod> {
void ReleaseCallee(GKRMethod*) {}
};
-NativeBackendGnome::NativeBackendGnome(LocalProfileId id, PrefService* prefs)
- : profile_id_(id), prefs_(prefs) {
- if (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() {
@@ -466,16 +466,13 @@ bool NativeBackendGnome::RawAddLogin(const PasswordForm& form) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
NewRunnableMethod(&method,
&GKRMethod::AddLogin,
- form, app_string_.c_str()));
+ form));
GnomeKeyringResult result = method.WaitResult();
if (result != GNOME_KEYRING_RESULT_OK) {
LOG(ERROR) << "Keyring save failed: "
<< gnome_keyring_result_to_message(result);
return false;
}
- // Successful write. Try migration if necessary.
- if (!migrate_tried_)
- MigrateToProfileSpecificLogins();
return true;
}
@@ -488,9 +485,9 @@ bool NativeBackendGnome::AddLogin(const PasswordForm& form) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
GKRMethod method;
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(&method,
- &GKRMethod::AddLoginSearch,
- form, app_string_.c_str()));
+ NewRunnableMethod(&method,
+ &GKRMethod::AddLoginSearch,
+ form));
PasswordFormList forms;
GnomeKeyringResult result = method.WaitResult(&forms);
if (result != GNOME_KEYRING_RESULT_OK &&
@@ -501,15 +498,9 @@ bool NativeBackendGnome::AddLogin(const PasswordForm& form) {
}
if (forms.size() > 0) {
if (forms.size() > 1) {
- LOG(WARNING) << "Adding login when there are " << forms.size()
- << " matching logins already! Will replace only the first.";
+ LOG(WARNING) << "Adding login when there are " << forms.size() <<
+ " 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]);
for (size_t i = 0; i < forms.size(); ++i)
delete forms[i];
@@ -530,7 +521,7 @@ bool NativeBackendGnome::UpdateLogin(const PasswordForm& form) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
NewRunnableMethod(&method,
&GKRMethod::UpdateLoginSearch,
- form, app_string_.c_str()));
+ form));
PasswordFormList forms;
GnomeKeyringResult result = method.WaitResult(&forms);
if (result != GNOME_KEYRING_RESULT_OK) {
@@ -538,12 +529,6 @@ bool NativeBackendGnome::UpdateLogin(const PasswordForm& form) {
<< gnome_keyring_result_to_message(result);
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;
for (size_t i = 0; i < forms.size(); ++i) {
if (forms[i]->action != form.action ||
@@ -576,18 +561,13 @@ bool NativeBackendGnome::RemoveLogin(const PasswordForm& form) {
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
NewRunnableMethod(&method,
&GKRMethod::RemoveLogin,
- form, app_string_.c_str()));
+ form));
GnomeKeyringResult result = method.WaitResult();
if (result != GNOME_KEYRING_RESULT_OK) {
LOG(ERROR) << "Keyring delete failed: "
<< gnome_keyring_result_to_message(result);
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;
}
@@ -601,7 +581,6 @@ bool NativeBackendGnome::RemoveLoginsCreatedBetween(
PasswordFormList forms;
if (!GetAllLogins(&forms))
return false;
- // No need to try migration here: GetAllLogins() does it.
for (size_t i = 0; i < forms.size(); ++i) {
if (delete_begin <= forms[i]->date_created &&
@@ -618,10 +597,10 @@ bool NativeBackendGnome::GetLogins(const PasswordForm& form,
PasswordFormList* forms) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
GKRMethod method;
- BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
- NewRunnableMethod(&method,
- &GKRMethod::GetLogins,
- form, app_string_.c_str()));
+ BrowserThread::PostTask(
+ BrowserThread::UI,
+ FROM_HERE,
+ NewRunnableMethod(&method, &GKRMethod::GetLogins, form));
GnomeKeyringResult result = method.WaitResult(forms);
if (result == GNOME_KEYRING_RESULT_NO_MATCH)
return true;
@@ -630,9 +609,6 @@ bool NativeBackendGnome::GetLogins(const PasswordForm& form,
<< gnome_keyring_result_to_message(result);
return false;
}
- // Successful read of actual data. Try migration if necessary.
- if (!migrate_tried_)
- MigrateToProfileSpecificLogins();
return true;
}
@@ -645,7 +621,6 @@ bool NativeBackendGnome::GetLoginsCreatedBetween(const base::Time& get_begin,
PasswordFormList all_forms;
if (!GetAllLogins(&all_forms))
return false;
- // No need to try migration here: GetAllLogins() does it.
forms->reserve(forms->size() + all_forms.size());
for (size_t i = 0; i < all_forms.size(); ++i) {
@@ -678,8 +653,7 @@ bool NativeBackendGnome::GetLoginsList(PasswordFormList* forms,
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
NewRunnableMethod(&method,
&GKRMethod::GetLoginsList,
- blacklisted_by_user,
- app_string_.c_str()));
+ blacklisted_by_user));
GnomeKeyringResult result = method.WaitResult(forms);
if (result == GNOME_KEYRING_RESULT_NO_MATCH)
return true;
@@ -688,9 +662,6 @@ bool NativeBackendGnome::GetLoginsList(PasswordFormList* forms,
<< gnome_keyring_result_to_message(result);
return false;
}
- // Successful read of actual data. Try migration if necessary.
- if (!migrate_tried_)
- MigrateToProfileSpecificLogins();
return true;
}
@@ -698,8 +669,7 @@ bool NativeBackendGnome::GetAllLogins(PasswordFormList* forms) {
GKRMethod method;
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
NewRunnableMethod(&method,
- &GKRMethod::GetAllLogins,
- app_string_.c_str()));
+ &GKRMethod::GetAllLogins));
GnomeKeyringResult result = method.WaitResult(forms);
if (result == GNOME_KEYRING_RESULT_NO_MATCH)
return true;
@@ -708,56 +678,5 @@ bool NativeBackendGnome::GetAllLogins(PasswordFormList* forms) {
<< gnome_keyring_result_to_message(result);
return false;
}
- // Successful read of actual data. Try migration if necessary.
- if (!migrate_tried_)
- MigrateToProfileSpecificLogins();
return true;
}
-
-std::string NativeBackendGnome::GetProfileSpecificAppString() const {
- // Originally, the application string was always just "chrome" and used only
- // so that we had *something* to search for since GNOME Keyring won't search
- // for nothing. Now we use it to distinguish passwords for different profiles.
- return 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;
- }
-}
diff --git a/chrome/browser/password_manager/native_backend_gnome_x.h b/chrome/browser/password_manager/native_backend_gnome_x.h
index 1740c42..3eebcfa 100644
--- a/chrome/browser/password_manager/native_backend_gnome_x.h
+++ b/chrome/browser/password_manager/native_backend_gnome_x.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -6,14 +6,9 @@
#define CHROME_BROWSER_PASSWORD_MANAGER_NATIVE_BACKEND_GNOME_X_H_
#pragma once
-#include <string>
-
#include "base/basictypes.h"
#include "base/time.h"
#include "chrome/browser/password_manager/password_store_x.h"
-#include "chrome/browser/profiles/profile.h"
-
-class PrefService;
namespace webkit_glue {
struct PasswordForm;
@@ -22,7 +17,7 @@ struct PasswordForm;
// NativeBackend implementation using GNOME Keyring.
class NativeBackendGnome : public PasswordStoreX::NativeBackend {
public:
- NativeBackendGnome(LocalProfileId id, PrefService* prefs);
+ NativeBackendGnome();
virtual ~NativeBackendGnome();
@@ -52,24 +47,6 @@ class NativeBackendGnome : public PasswordStoreX::NativeBackend {
// Helper for GetLoginsCreatedBetween().
bool GetAllLogins(PasswordFormList* forms);
- // Generates a profile-specific app string based on profile_id_.
- 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.
- 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.
- std::string app_string_;
-
- // True once MigrateToProfileSpecificLogins() has been attempted.
- bool migrate_tried_;
-
DISALLOW_COPY_AND_ASSIGN(NativeBackendGnome);
};
diff --git a/chrome/browser/password_manager/native_backend_kwallet_x.cc b/chrome/browser/password_manager/native_backend_kwallet_x.cc
index 9e7c172..2417a07 100644
--- a/chrome/browser/password_manager/native_backend_kwallet_x.cc
+++ b/chrome/browser/password_manager/native_backend_kwallet_x.cc
@@ -11,37 +11,27 @@
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "content/browser/browser_thread.h"
-#include "grit/chromium_strings.h"
-#include "ui/base/l10n/l10n_util.h"
using std::string;
using std::vector;
using webkit_glue::PasswordForm;
-// We could localize this string, but then changing your locale would cause
+// We could localize these strings, but then changing your locale would cause
// you to lose access to all your stored passwords. Maybe best not to do that.
-const char NativeBackendKWallet::kKWalletFolder[] = "Chrome Form Data";
-
-const char NativeBackendKWallet::kKWalletServiceName[] = "org.kde.kwalletd";
-const char NativeBackendKWallet::kKWalletPath[] = "/modules/kwalletd";
-const char NativeBackendKWallet::kKWalletInterface[] = "org.kde.KWallet";
-const char NativeBackendKWallet::kKLauncherServiceName[] = "org.kde.klauncher";
-const char NativeBackendKWallet::kKLauncherPath[] = "/KLauncher";
-const char NativeBackendKWallet::kKLauncherInterface[] = "org.kde.KLauncher";
-
-NativeBackendKWallet::NativeBackendKWallet(LocalProfileId id,
- PrefService* prefs)
- : profile_id_(id), prefs_(prefs),
- error_(NULL), connection_(NULL), proxy_(NULL),
- app_name_(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME)) {
- if (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;
- }
+const char* NativeBackendKWallet::kAppId = "Chrome";
+const char* NativeBackendKWallet::kKWalletFolder = "Chrome Form Data";
+
+const char* NativeBackendKWallet::kKWalletServiceName = "org.kde.kwalletd";
+const char* NativeBackendKWallet::kKWalletPath = "/modules/kwalletd";
+const char* NativeBackendKWallet::kKWalletInterface = "org.kde.KWallet";
+const char* NativeBackendKWallet::kKLauncherServiceName = "org.kde.klauncher";
+const char* NativeBackendKWallet::kKLauncherPath = "/KLauncher";
+const char* NativeBackendKWallet::kKLauncherInterface = "org.kde.KLauncher";
+
+NativeBackendKWallet::NativeBackendKWallet()
+ : error_(NULL),
+ connection_(NULL),
+ proxy_(NULL) {
}
NativeBackendKWallet::~NativeBackendKWallet() {
@@ -212,8 +202,8 @@ bool NativeBackendKWallet::RemoveLoginsCreatedBetween(
char** realm_list = NULL;
dbus_g_proxy_call(proxy_, "entryList", &error_,
G_TYPE_INT, wallet_handle, // handle
- G_TYPE_STRING, folder_name_.c_str(), // folder
- G_TYPE_STRING, app_name_.c_str(), // appid
+ G_TYPE_STRING, kKWalletFolder, // folder
+ G_TYPE_STRING, kAppId, // appid
G_TYPE_INVALID,
G_TYPE_STRV, &realm_list,
G_TYPE_INVALID);
@@ -225,9 +215,9 @@ bool NativeBackendKWallet::RemoveLoginsCreatedBetween(
GArray* byte_array = NULL;
dbus_g_proxy_call(proxy_, "readEntry", &error_,
G_TYPE_INT, wallet_handle, // handle
- G_TYPE_STRING, folder_name_.c_str(), // folder
+ G_TYPE_STRING, kKWalletFolder, // folder
G_TYPE_STRING, *realm, // key
- G_TYPE_STRING, app_name_.c_str(), // appid
+ G_TYPE_STRING, kAppId, // appid
G_TYPE_INVALID,
DBUS_TYPE_G_UCHAR_ARRAY, &byte_array,
G_TYPE_INVALID);
@@ -300,9 +290,9 @@ bool NativeBackendKWallet::GetLoginsList(PasswordFormList* forms,
gboolean has_entry = false;
dbus_g_proxy_call(proxy_, "hasEntry", &error_,
G_TYPE_INT, wallet_handle, // handle
- G_TYPE_STRING, folder_name_.c_str(), // folder
+ G_TYPE_STRING, kKWalletFolder, // folder
G_TYPE_STRING, signon_realm.c_str(), // key
- G_TYPE_STRING, app_name_.c_str(), // appid
+ G_TYPE_STRING, kAppId, // appid
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &has_entry,
G_TYPE_INVALID);
@@ -317,9 +307,9 @@ bool NativeBackendKWallet::GetLoginsList(PasswordFormList* forms,
GArray* byte_array = NULL;
dbus_g_proxy_call(proxy_, "readEntry", &error_,
G_TYPE_INT, wallet_handle, // handle
- G_TYPE_STRING, folder_name_.c_str(), // folder
+ G_TYPE_STRING, kKWalletFolder, // folder
G_TYPE_STRING, signon_realm.c_str(), // key
- G_TYPE_STRING, app_name_.c_str(), // appid
+ G_TYPE_STRING, kAppId, // appid
G_TYPE_INVALID,
DBUS_TYPE_G_UCHAR_ARRAY, &byte_array,
G_TYPE_INVALID);
@@ -389,8 +379,8 @@ bool NativeBackendKWallet::GetAllLogins(PasswordFormList* forms,
char** realm_list = NULL;
dbus_g_proxy_call(proxy_, "entryList", &error_,
G_TYPE_INT, wallet_handle, // handle
- G_TYPE_STRING, folder_name_.c_str(), // folder
- G_TYPE_STRING, app_name_.c_str(), // appid
+ G_TYPE_STRING, kKWalletFolder, // folder
+ G_TYPE_STRING, kAppId, // appid
G_TYPE_INVALID,
G_TYPE_STRV, &realm_list,
G_TYPE_INVALID);
@@ -401,9 +391,9 @@ bool NativeBackendKWallet::GetAllLogins(PasswordFormList* forms,
GArray* byte_array = NULL;
dbus_g_proxy_call(proxy_, "readEntry", &error_,
G_TYPE_INT, wallet_handle, // handle
- G_TYPE_STRING, folder_name_.c_str(), // folder
+ G_TYPE_STRING, kKWalletFolder, // folder
G_TYPE_STRING, *realm, // key
- G_TYPE_STRING, app_name_.c_str(), // appid
+ G_TYPE_STRING, kAppId, // appid
G_TYPE_INVALID,
DBUS_TYPE_G_UCHAR_ARRAY, &byte_array,
G_TYPE_INVALID);
@@ -429,9 +419,9 @@ bool NativeBackendKWallet::SetLoginsList(const PasswordFormList& forms,
int ret = 0;
dbus_g_proxy_call(proxy_, "removeEntry", &error_,
G_TYPE_INT, wallet_handle, // handle
- G_TYPE_STRING, folder_name_.c_str(), // folder
+ G_TYPE_STRING, kKWalletFolder, // folder
G_TYPE_STRING, signon_realm.c_str(), // key
- G_TYPE_STRING, app_name_.c_str(), // appid
+ G_TYPE_STRING, kAppId, // appid
G_TYPE_INVALID,
G_TYPE_INT, &ret,
G_TYPE_INVALID);
@@ -454,10 +444,10 @@ bool NativeBackendKWallet::SetLoginsList(const PasswordFormList& forms,
int ret = 0;
dbus_g_proxy_call(proxy_, "writeEntry", &error_,
G_TYPE_INT, wallet_handle, // handle
- G_TYPE_STRING, folder_name_.c_str(), // folder
+ G_TYPE_STRING, kKWalletFolder, // folder
G_TYPE_STRING, signon_realm.c_str(), // key
DBUS_TYPE_G_UCHAR_ARRAY, byte_array, // value
- G_TYPE_STRING, app_name_.c_str(), // appid
+ G_TYPE_STRING, kAppId, // appid
G_TYPE_INVALID,
G_TYPE_INT, &ret,
G_TYPE_INVALID);
@@ -602,12 +592,11 @@ bool NativeBackendKWallet::CheckError() {
int NativeBackendKWallet::WalletHandle() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
// Open the wallet.
- // TODO(mdm): Are we leaking these handles? Find out.
int handle = kInvalidKWalletHandle;
dbus_g_proxy_call(proxy_, "open", &error_,
- G_TYPE_STRING, wallet_name_.c_str(), // wallet
- G_TYPE_INT64, 0LL, // wid
- G_TYPE_STRING, app_name_.c_str(), // appid
+ G_TYPE_STRING, wallet_name_.c_str(), // wallet
+ G_TYPE_INT64, 0LL, // wid
+ G_TYPE_STRING, kAppId, // appid
G_TYPE_INVALID,
G_TYPE_INT, &handle,
G_TYPE_INVALID);
@@ -617,9 +606,9 @@ int NativeBackendKWallet::WalletHandle() {
// Check if our folder exists.
gboolean has_folder = false;
dbus_g_proxy_call(proxy_, "hasFolder", &error_,
- G_TYPE_INT, handle, // handle
- G_TYPE_STRING, folder_name_.c_str(), // folder
- G_TYPE_STRING, app_name_.c_str(), // appid
+ G_TYPE_INT, handle, // handle
+ G_TYPE_STRING, kKWalletFolder, // folder
+ G_TYPE_STRING, kAppId, // appid
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &has_folder,
G_TYPE_INVALID);
@@ -630,9 +619,9 @@ int NativeBackendKWallet::WalletHandle() {
if (!has_folder) {
gboolean success = false;
dbus_g_proxy_call(proxy_, "createFolder", &error_,
- G_TYPE_INT, handle, // handle
- G_TYPE_STRING, folder_name_.c_str(), // folder
- G_TYPE_STRING, app_name_.c_str(), // appid
+ G_TYPE_INT, handle, // handle
+ G_TYPE_STRING, kKWalletFolder, // folder
+ G_TYPE_STRING, kAppId, // appid
G_TYPE_INVALID,
G_TYPE_BOOLEAN, &success,
G_TYPE_INVALID);
@@ -640,63 +629,5 @@ int NativeBackendKWallet::WalletHandle() {
return kInvalidKWalletHandle;
}
- // Successful initialization. Try migration if necessary.
- if (!migrate_tried_)
- MigrateToProfileSpecificLogins();
-
return handle;
}
-
-std::string NativeBackendKWallet::GetProfileSpecificFolderName() const {
- // Originally, the folder name was always just "Chrome Form Data".
- // Now we use it to distinguish passwords for different profiles.
- return 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 (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;
- }
-}
diff --git a/chrome/browser/password_manager/native_backend_kwallet_x.h b/chrome/browser/password_manager/native_backend_kwallet_x.h
index 7481f28..b12d8ed 100644
--- a/chrome/browser/password_manager/native_backend_kwallet_x.h
+++ b/chrome/browser/password_manager/native_backend_kwallet_x.h
@@ -14,19 +14,14 @@
#include "base/basictypes.h"
#include "base/time.h"
#include "chrome/browser/password_manager/password_store_x.h"
-#include "chrome/browser/profiles/profile.h"
+#include "webkit/glue/password_form.h"
class Pickle;
-class PrefService;
-
-namespace webkit_glue {
-struct PasswordForm;
-}
// NativeBackend implementation using KWallet.
class NativeBackendKWallet : public PasswordStoreX::NativeBackend {
public:
- NativeBackendKWallet(LocalProfileId id, PrefService* prefs);
+ NativeBackendKWallet();
virtual ~NativeBackendKWallet();
@@ -114,38 +109,22 @@ class NativeBackendKWallet : public PasswordStoreX::NativeBackend {
// read old pickles. (Note: do not eat old pickles past the expiration date.)
static const int kPickleVersion = 0;
+ // Name of the application - will appear in kwallet's dialogs.
+ static const char* kAppId;
// Name of the folder to store passwords in.
- static const char kKWalletFolder[];
+ static const char* kKWalletFolder;
// DBus stuff.
- static const char kKWalletServiceName[];
- static const char kKWalletPath[];
- static const char kKWalletInterface[];
- static const char kKLauncherServiceName[];
- static const char kKLauncherPath[];
- static const char kKLauncherInterface[];
+ static const char* kKWalletServiceName;
+ static const char* kKWalletPath;
+ static const char* kKWalletInterface;
+ static const char* kKLauncherServiceName;
+ static const char* kKLauncherPath;
+ static const char* kKLauncherInterface;
// Invalid handle returned by WalletHandle().
static const int kInvalidKWalletHandle = -1;
- // Generates a profile-specific folder name based on profile_id_.
- 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.
- 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.
- std::string folder_name_;
-
- // True once MigrateToProfileSpecificLogins() has been attempted.
- bool migrate_tried_;
-
// Error from the last DBus call. NULL when there's no error. Freed and
// cleared by CheckError().
GError* error_;
@@ -156,8 +135,6 @@ class NativeBackendKWallet : public PasswordStoreX::NativeBackend {
// The name of the wallet we've opened. Set during Init().
std::string wallet_name_;
- // The application name (e.g. "Chromium"), shown in KWallet auth dialogs.
- const std::string app_name_;
DISALLOW_COPY_AND_ASSIGN(NativeBackendKWallet);
};
diff --git a/chrome/browser/password_manager/password_store_x.cc b/chrome/browser/password_manager/password_store_x.cc
index 87a9e25..9ffd31c 100644
--- a/chrome/browser/password_manager/password_store_x.cc
+++ b/chrome/browser/password_manager/password_store_x.cc
@@ -11,8 +11,6 @@
#include "base/logging.h"
#include "base/stl_util-inl.h"
#include "chrome/browser/password_manager/password_store_change.h"
-#include "chrome/browser/prefs/pref_service.h"
-#include "chrome/common/pref_names.h"
#include "content/browser/browser_thread.h"
#include "chrome/common/chrome_notification_types.h"
#include "content/common/notification_service.h"
@@ -264,38 +262,3 @@ ssize_t PasswordStoreX::MigrateLogins() {
STLDeleteElements(&forms);
return result;
}
-
-// static
-void PasswordStoreX::RegisterUserPrefs(PrefService* prefs) {
- // Normally we should be on the UI thread here, but in tests we might not.
- prefs->RegisterBooleanPref(prefs::kPasswordsUseLocalProfileId,
- false, // default: passwords don't use local ids
- PrefService::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,
- NewRunnableFunction(UISetPasswordsUseLocalProfileId,
- prefs));
-}
diff --git a/chrome/browser/password_manager/password_store_x.h b/chrome/browser/password_manager/password_store_x.h
index 100e09e..ee9ad30 100644
--- a/chrome/browser/password_manager/password_store_x.h
+++ b/chrome/browser/password_manager/password_store_x.h
@@ -13,7 +13,6 @@
#include "chrome/browser/password_manager/password_store_default.h"
class LoginDatabase;
-class PrefService;
class Profile;
class WebDataService;
@@ -57,17 +56,6 @@ class PasswordStoreX : public PasswordStoreDefault {
WebDataService* web_data_service,
NativeBackend* backend);
- // Registers the pref setting used for the methods below.
- static void RegisterUserPrefs(PrefService* prefs);
-
- // 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);
-
private:
friend class PasswordStoreXTest;