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

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

Issue 283563002: Password Login Database: report correct changes from AddLogin(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: the nit addressed Created 6 years, 7 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/password_store_x.h" 5 #include "chrome/browser/password_manager/password_store_x.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "components/password_manager/core/browser/password_store_change.h" 16 #include "components/password_manager/core/browser/password_store_change.h"
17 #include "components/password_manager/core/common/password_manager_pref_names.h" 17 #include "components/password_manager/core/common/password_manager_pref_names.h"
18 #include "components/user_prefs/pref_registry_syncable.h" 18 #include "components/user_prefs/pref_registry_syncable.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/notification_service.h" 20 #include "content/public/browser/notification_service.h"
21 21
22 using autofill::PasswordForm; 22 using autofill::PasswordForm;
23 using content::BrowserThread; 23 using content::BrowserThread;
24 using password_manager::PasswordStoreChange; 24 using password_manager::PasswordStoreChange;
25 using password_manager::PasswordStoreChangeList; 25 using password_manager::PasswordStoreChangeList;
26 using password_manager::PasswordStoreDefault; 26 using password_manager::PasswordStoreDefault;
27 using std::vector; 27 using std::vector;
28 28
29 namespace {
30
31 bool AddLoginToBackend(const scoped_ptr<PasswordStoreX::NativeBackend>& backend,
32 const PasswordForm& form,
33 PasswordStoreChangeList* changes) {
34 *changes = backend->AddLogin(form);
35 return (!changes->empty() &&
36 changes->back().type() == PasswordStoreChange::ADD);
37 }
38
39 } // namespace
40
29 PasswordStoreX::PasswordStoreX( 41 PasswordStoreX::PasswordStoreX(
30 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, 42 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner,
31 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, 43 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner,
32 password_manager::LoginDatabase* login_db, 44 password_manager::LoginDatabase* login_db,
33 NativeBackend* backend) 45 NativeBackend* backend)
34 : PasswordStoreDefault(main_thread_runner, db_thread_runner, login_db), 46 : PasswordStoreDefault(main_thread_runner, db_thread_runner, login_db),
35 backend_(backend), 47 backend_(backend),
36 migration_checked_(!backend), 48 migration_checked_(!backend),
37 allow_fallback_(false) {} 49 allow_fallback_(false) {}
38 50
39 PasswordStoreX::~PasswordStoreX() {} 51 PasswordStoreX::~PasswordStoreX() {}
40 52
41 PasswordStoreChangeList PasswordStoreX::AddLoginImpl(const PasswordForm& form) { 53 PasswordStoreChangeList PasswordStoreX::AddLoginImpl(const PasswordForm& form) {
42 CheckMigration(); 54 CheckMigration();
43 PasswordStoreChangeList changes; 55 PasswordStoreChangeList changes;
44 if (use_native_backend() && backend_->AddLogin(form)) { 56 if (use_native_backend() && AddLoginToBackend(backend_, form, &changes)) {
45 changes.push_back(PasswordStoreChange(PasswordStoreChange::ADD, form));
46 allow_fallback_ = false; 57 allow_fallback_ = false;
47 } else if (allow_default_store()) { 58 } else if (allow_default_store()) {
48 changes = PasswordStoreDefault::AddLoginImpl(form); 59 changes = PasswordStoreDefault::AddLoginImpl(form);
49 } 60 }
50 return changes; 61 return changes;
51 } 62 }
52 63
53 PasswordStoreChangeList PasswordStoreX::UpdateLoginImpl( 64 PasswordStoreChangeList PasswordStoreX::UpdateLoginImpl(
54 const PasswordForm& form) { 65 const PasswordForm& form) {
55 CheckMigration(); 66 CheckMigration();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 DCHECK(backend_.get()); 241 DCHECK(backend_.get());
231 vector<PasswordForm*> forms; 242 vector<PasswordForm*> forms;
232 bool ok = PasswordStoreDefault::FillAutofillableLogins(&forms) && 243 bool ok = PasswordStoreDefault::FillAutofillableLogins(&forms) &&
233 PasswordStoreDefault::FillBlacklistLogins(&forms); 244 PasswordStoreDefault::FillBlacklistLogins(&forms);
234 if (ok) { 245 if (ok) {
235 // We add all the passwords (and blacklist entries) to the native backend 246 // We add all the passwords (and blacklist entries) to the native backend
236 // before attempting to remove any from the login database, to make sure we 247 // before attempting to remove any from the login database, to make sure we
237 // don't somehow end up with some of the passwords in one store and some in 248 // don't somehow end up with some of the passwords in one store and some in
238 // another. We'll always have at least one intact store this way. 249 // another. We'll always have at least one intact store this way.
239 for (size_t i = 0; i < forms.size(); ++i) { 250 for (size_t i = 0; i < forms.size(); ++i) {
240 if (!backend_->AddLogin(*forms[i])) { 251 PasswordStoreChangeList changes;
252 if (!AddLoginToBackend(backend_, *forms[i], &changes)) {
241 ok = false; 253 ok = false;
242 break; 254 break;
243 } 255 }
244 } 256 }
245 if (ok) { 257 if (ok) {
246 for (size_t i = 0; i < forms.size(); ++i) { 258 for (size_t i = 0; i < forms.size(); ++i) {
247 // If even one of these calls to RemoveLoginImpl() succeeds, then we 259 // If even one of these calls to RemoveLoginImpl() succeeds, then we
248 // should prefer the native backend to the now-incomplete login 260 // should prefer the native backend to the now-incomplete login
249 // database. Thus we want to return a success status even in the case 261 // database. Thus we want to return a success status even in the case
250 // where some fail. The only real problem with this is that we might 262 // where some fail. The only real problem with this is that we might
251 // leave passwords in the login database and never come back to clean 263 // leave passwords in the login database and never come back to clean
252 // them out if any of these calls do fail. 264 // them out if any of these calls do fail.
253 PasswordStoreDefault::RemoveLoginImpl(*forms[i]); 265 PasswordStoreDefault::RemoveLoginImpl(*forms[i]);
254 } 266 }
255 // Finally, delete the database file itself. We remove the passwords from 267 // Finally, delete the database file itself. We remove the passwords from
256 // it before deleting the file just in case there is some problem deleting 268 // it before deleting the file just in case there is some problem deleting
257 // the file (e.g. directory is not writable, but file is), which would 269 // the file (e.g. directory is not writable, but file is), which would
258 // otherwise cause passwords to re-migrate next (or maybe every) time. 270 // otherwise cause passwords to re-migrate next (or maybe every) time.
259 DeleteAndRecreateDatabaseFile(); 271 DeleteAndRecreateDatabaseFile();
260 } 272 }
261 } 273 }
262 ssize_t result = ok ? forms.size() : -1; 274 ssize_t result = ok ? forms.size() : -1;
263 STLDeleteElements(&forms); 275 STLDeleteElements(&forms);
264 return result; 276 return result;
265 } 277 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_store_x.h ('k') | chrome/browser/password_manager/password_store_x_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698