Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Side by Side Diff: chrome/browser/password_manager/native_backend_kwallet_x.cc

Issue 196173023: [Password Manager] Remove dead profile migration code for GNOME/KWallet (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/password_manager/native_backend_kwallet_x.h" 5 #include "chrome/browser/password_manager/native_backend_kwallet_x.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 << ") with native architecture size; will try alternate " 95 << ") with native architecture size; will try alternate "
96 << "size."; 96 << "size.";
97 } else { 97 } else {
98 LOG(ERROR) << "Failed to deserialize version " << version 98 LOG(ERROR) << "Failed to deserialize version " << version
99 << " KWallet entry (realm: " << signon_realm << ")"; 99 << " KWallet entry (realm: " << signon_realm << ")";
100 } 100 }
101 } 101 }
102 102
103 } // namespace 103 } // namespace
104 104
105 NativeBackendKWallet::NativeBackendKWallet(LocalProfileId id, 105 NativeBackendKWallet::NativeBackendKWallet(LocalProfileId id)
106 PrefService* prefs)
107 : profile_id_(id), 106 : profile_id_(id),
108 prefs_(prefs),
109 kwallet_proxy_(NULL), 107 kwallet_proxy_(NULL),
110 app_name_(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME)) { 108 app_name_(l10n_util::GetStringUTF8(IDS_PRODUCT_NAME)) {
111 // TODO(mdm): after a few more releases, remove the code which is now dead due 109 folder_name_ = GetProfileSpecificFolderName();
112 // to the true || here, and simplify this code. We don't do it yet to make it
113 // easier to revert if necessary.
114 if (true || PasswordStoreX::PasswordsUseLocalProfileId(prefs)) {
115 folder_name_ = GetProfileSpecificFolderName();
116 // We already did the migration previously. Don't try again.
117 migrate_tried_ = true;
118 } else {
119 folder_name_ = kKWalletFolder;
120 migrate_tried_ = false;
121 }
122 } 110 }
123 111
124 NativeBackendKWallet::~NativeBackendKWallet() { 112 NativeBackendKWallet::~NativeBackendKWallet() {
125 // This destructor is called on the thread that is destroying the Profile 113 // This destructor is called on the thread that is destroying the Profile
126 // containing the PasswordStore that owns this NativeBackend. Generally that 114 // containing the PasswordStore that owns this NativeBackend. Generally that
127 // won't be the DB thread; it will be the UI thread. So we post a message to 115 // won't be the DB thread; it will be the UI thread. So we post a message to
128 // shut it down on the DB thread, and it will be destructed afterward when the 116 // shut it down on the DB thread, and it will be destructed afterward when the
129 // scoped_refptr<dbus::Bus> goes out of scope. The NativeBackend will be 117 // scoped_refptr<dbus::Bus> goes out of scope. The NativeBackend will be
130 // destroyed before that occurs, but that's OK. 118 // destroyed before that occurs, but that's OK.
131 if (session_bus_.get()) { 119 if (session_bus_.get()) {
(...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after
919 LOG(ERROR) << "Error reading response from kwalletd (createFolder): " 907 LOG(ERROR) << "Error reading response from kwalletd (createFolder): "
920 << response->ToString(); 908 << response->ToString();
921 return kInvalidKWalletHandle; 909 return kInvalidKWalletHandle;
922 } 910 }
923 if (!success) { 911 if (!success) {
924 LOG(ERROR) << "Error creating KWallet folder"; 912 LOG(ERROR) << "Error creating KWallet folder";
925 return kInvalidKWalletHandle; 913 return kInvalidKWalletHandle;
926 } 914 }
927 } 915 }
928 916
929 // Successful initialization. Try migration if necessary.
930 if (!migrate_tried_)
931 MigrateToProfileSpecificLogins();
932
933 return handle; 917 return handle;
934 } 918 }
935 919
936 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const { 920 std::string NativeBackendKWallet::GetProfileSpecificFolderName() const {
937 // Originally, the folder name was always just "Chrome Form Data". 921 // Originally, the folder name was always just "Chrome Form Data".
938 // Now we use it to distinguish passwords for different profiles. 922 // Now we use it to distinguish passwords for different profiles.
939 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_); 923 return base::StringPrintf("%s (%d)", kKWalletFolder, profile_id_);
940 } 924 }
941
942 void NativeBackendKWallet::MigrateToProfileSpecificLogins() {
943 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
944
945 DCHECK(!migrate_tried_);
946 DCHECK_EQ(folder_name_, kKWalletFolder);
947
948 // Record the fact that we've attempted migration already right away, so that
949 // we don't get recursive calls back to MigrateToProfileSpecificLogins().
950 migrate_tried_ = true;
951
952 // First get all the logins, using the old folder name.
953 int wallet_handle = WalletHandle();
954 if (wallet_handle == kInvalidKWalletHandle)
955 return;
956 PasswordFormList forms;
957 if (!GetAllLogins(&forms, wallet_handle))
958 return;
959
960 // Now switch to a profile-specific folder name.
961 folder_name_ = GetProfileSpecificFolderName();
962
963 // Try to add all the logins with the new folder name.
964 // This could be done more efficiently by grouping by signon realm and using
965 // SetLoginsList(), but we do this for simplicity since it is only done once.
966 // Note, however, that we do need another call to WalletHandle() to create
967 // this folder if necessary.
968 bool ok = true;
969 for (size_t i = 0; i < forms.size(); ++i) {
970 if (!AddLogin(*forms[i]))
971 ok = false;
972 delete forms[i];
973 }
974 if (forms.empty()) {
975 // If there were no logins to migrate, we do an extra call to WalletHandle()
976 // for its side effect of attempting to create the profile-specific folder.
977 // This is not strictly necessary, but it's safe and helps in testing.
978 wallet_handle = WalletHandle();
979 if (wallet_handle == kInvalidKWalletHandle)
980 ok = false;
981 }
982
983 if (ok) {
984 // All good! Keep the new app string and set a persistent pref.
985 // NOTE: We explicitly don't delete the old passwords yet. They are
986 // potentially shared with other profiles and other user data dirs!
987 // Each other profile must be able to migrate the shared data as well,
988 // so we must leave it alone. After a few releases, we'll add code to
989 // delete them, and eventually remove this migration code.
990 // TODO(mdm): follow through with the plan above.
991 PasswordStoreX::SetPasswordsUseLocalProfileId(prefs_);
992 } else {
993 // We failed to migrate for some reason. Use the old folder name.
994 folder_name_ = kKWalletFolder;
995 }
996 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698