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

Side by Side Diff: components/password_manager/core/browser/password_store_default.cc

Issue 838453003: Open the LoginDatabase on the DB thread, not the UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix nits from vabr@. Created 5 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/password_manager/core/browser/password_store_default.h" 5 #include "components/password_manager/core/browser/password_store_default.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/stl_util.h" 11 #include "base/stl_util.h"
12 #include "components/password_manager/core/browser/password_store_change.h" 12 #include "components/password_manager/core/browser/password_store_change.h"
13 13
14 using autofill::PasswordForm; 14 using autofill::PasswordForm;
15 15
16 namespace password_manager { 16 namespace password_manager {
17 17
18 PasswordStoreDefault::PasswordStoreDefault( 18 PasswordStoreDefault::PasswordStoreDefault(
19 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner, 19 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner,
20 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner, 20 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner,
21 LoginDatabase* login_db) 21 scoped_ptr<LoginDatabase> login_db)
22 : PasswordStore(main_thread_runner, db_thread_runner), login_db_(login_db) { 22 : PasswordStore(main_thread_runner, db_thread_runner),
23 DCHECK(login_db); 23 login_db_(login_db.Pass()) {
24 } 24 }
25 25
26 PasswordStoreDefault::~PasswordStoreDefault() { 26 PasswordStoreDefault::~PasswordStoreDefault() {
27 } 27 }
28 28
29 bool PasswordStoreDefault::Init(
30 const syncer::SyncableService::StartSyncFlare& flare) {
31 ScheduleTask(base::Bind(&PasswordStoreDefault::InitOnDBThread, this));
32 return PasswordStore::Init(flare);
33 }
34
35 void PasswordStoreDefault::InitOnDBThread() {
36 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
37 DCHECK(login_db_);
38 if (!login_db_->Init()) {
39 login_db_.reset();
40 LOG(ERROR) << "Could not create/open login database.";
41 }
42 }
43
29 void PasswordStoreDefault::ReportMetricsImpl( 44 void PasswordStoreDefault::ReportMetricsImpl(
30 const std::string& sync_username, 45 const std::string& sync_username,
31 bool custom_passphrase_sync_enabled) { 46 bool custom_passphrase_sync_enabled) {
47 if (!login_db_)
48 return;
32 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 49 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
33 login_db_->ReportMetrics(sync_username, custom_passphrase_sync_enabled); 50 login_db_->ReportMetrics(sync_username, custom_passphrase_sync_enabled);
34 } 51 }
35 52
36 PasswordStoreChangeList PasswordStoreDefault::AddLoginImpl( 53 PasswordStoreChangeList PasswordStoreDefault::AddLoginImpl(
37 const PasswordForm& form) { 54 const PasswordForm& form) {
38 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 55 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
56 if (!login_db_)
57 return PasswordStoreChangeList();
39 return login_db_->AddLogin(form); 58 return login_db_->AddLogin(form);
40 } 59 }
41 60
42 PasswordStoreChangeList PasswordStoreDefault::UpdateLoginImpl( 61 PasswordStoreChangeList PasswordStoreDefault::UpdateLoginImpl(
43 const PasswordForm& form) { 62 const PasswordForm& form) {
44 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 63 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
64 if (!login_db_)
65 return PasswordStoreChangeList();
45 return login_db_->UpdateLogin(form); 66 return login_db_->UpdateLogin(form);
46 } 67 }
47 68
48 PasswordStoreChangeList PasswordStoreDefault::RemoveLoginImpl( 69 PasswordStoreChangeList PasswordStoreDefault::RemoveLoginImpl(
49 const PasswordForm& form) { 70 const PasswordForm& form) {
50 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 71 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
51 PasswordStoreChangeList changes; 72 PasswordStoreChangeList changes;
52 if (login_db_->RemoveLogin(form)) 73 if (login_db_ && login_db_->RemoveLogin(form))
53 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); 74 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form));
54 return changes; 75 return changes;
55 } 76 }
56 77
57 PasswordStoreChangeList PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl( 78 PasswordStoreChangeList PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl(
58 base::Time delete_begin, 79 base::Time delete_begin,
59 base::Time delete_end) { 80 base::Time delete_end) {
60 std::vector<PasswordForm*> forms; 81 std::vector<PasswordForm*> forms;
61 PasswordStoreChangeList changes; 82 PasswordStoreChangeList changes;
62 if (login_db_->GetLoginsCreatedBetween(delete_begin, delete_end, &forms)) { 83 if (login_db_ &&
84 login_db_->GetLoginsCreatedBetween(delete_begin, delete_end, &forms)) {
63 if (login_db_->RemoveLoginsCreatedBetween(delete_begin, delete_end)) { 85 if (login_db_->RemoveLoginsCreatedBetween(delete_begin, delete_end)) {
64 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); 86 for (std::vector<PasswordForm*>::const_iterator it = forms.begin();
65 it != forms.end(); ++it) { 87 it != forms.end(); ++it) {
66 changes.push_back( 88 changes.push_back(
67 PasswordStoreChange(PasswordStoreChange::REMOVE, **it)); 89 PasswordStoreChange(PasswordStoreChange::REMOVE, **it));
68 } 90 }
69 LogStatsForBulkDeletion(changes.size()); 91 LogStatsForBulkDeletion(changes.size());
70 } 92 }
71 } 93 }
72 STLDeleteElements(&forms); 94 STLDeleteElements(&forms);
73 return changes; 95 return changes;
74 } 96 }
75 97
76 PasswordStoreChangeList PasswordStoreDefault::RemoveLoginsSyncedBetweenImpl( 98 PasswordStoreChangeList PasswordStoreDefault::RemoveLoginsSyncedBetweenImpl(
77 base::Time delete_begin, 99 base::Time delete_begin,
78 base::Time delete_end) { 100 base::Time delete_end) {
79 std::vector<PasswordForm*> forms; 101 std::vector<PasswordForm*> forms;
80 PasswordStoreChangeList changes; 102 PasswordStoreChangeList changes;
81 if (login_db_->GetLoginsSyncedBetween(delete_begin, delete_end, &forms)) { 103 if (login_db_ &&
104 login_db_->GetLoginsSyncedBetween(delete_begin, delete_end, &forms)) {
82 if (login_db_->RemoveLoginsSyncedBetween(delete_begin, delete_end)) { 105 if (login_db_->RemoveLoginsSyncedBetween(delete_begin, delete_end)) {
83 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); 106 for (std::vector<PasswordForm*>::const_iterator it = forms.begin();
84 it != forms.end(); ++it) { 107 it != forms.end(); ++it) {
85 changes.push_back( 108 changes.push_back(
86 PasswordStoreChange(PasswordStoreChange::REMOVE, **it)); 109 PasswordStoreChange(PasswordStoreChange::REMOVE, **it));
87 } 110 }
88 LogStatsForBulkDeletionDuringRollback(changes.size()); 111 LogStatsForBulkDeletionDuringRollback(changes.size());
89 } 112 }
90 } 113 }
91 STLDeleteElements(&forms); 114 STLDeleteElements(&forms);
92 return changes; 115 return changes;
93 } 116 }
94 117
95 void PasswordStoreDefault::GetLoginsImpl( 118 void PasswordStoreDefault::GetLoginsImpl(
96 const autofill::PasswordForm& form, 119 const autofill::PasswordForm& form,
97 AuthorizationPromptPolicy prompt_policy, 120 AuthorizationPromptPolicy prompt_policy,
98 const ConsumerCallbackRunner& callback_runner) { 121 const ConsumerCallbackRunner& callback_runner) {
99 std::vector<PasswordForm*> matched_forms; 122 std::vector<PasswordForm*> matched_forms;
100 login_db_->GetLogins(form, &matched_forms); 123 if (login_db_)
124 login_db_->GetLogins(form, &matched_forms);
101 callback_runner.Run(matched_forms); 125 callback_runner.Run(matched_forms);
102 } 126 }
103 127
104 void PasswordStoreDefault::GetAutofillableLoginsImpl( 128 void PasswordStoreDefault::GetAutofillableLoginsImpl(
105 GetLoginsRequest* request) { 129 GetLoginsRequest* request) {
106 FillAutofillableLogins(request->result()); 130 FillAutofillableLogins(request->result());
107 ForwardLoginsResult(request); 131 ForwardLoginsResult(request);
108 } 132 }
109 133
110 void PasswordStoreDefault::GetBlacklistLoginsImpl(GetLoginsRequest* request) { 134 void PasswordStoreDefault::GetBlacklistLoginsImpl(GetLoginsRequest* request) {
111 FillBlacklistLogins(request->result()); 135 FillBlacklistLogins(request->result());
112 ForwardLoginsResult(request); 136 ForwardLoginsResult(request);
113 } 137 }
114 138
115 bool PasswordStoreDefault::FillAutofillableLogins( 139 bool PasswordStoreDefault::FillAutofillableLogins(
116 std::vector<PasswordForm*>* forms) { 140 std::vector<PasswordForm*>* forms) {
117 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 141 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
118 return login_db_->GetAutofillableLogins(forms); 142 return login_db_ && login_db_->GetAutofillableLogins(forms);
119 } 143 }
120 144
121 bool PasswordStoreDefault::FillBlacklistLogins( 145 bool PasswordStoreDefault::FillBlacklistLogins(
122 std::vector<PasswordForm*>* forms) { 146 std::vector<PasswordForm*>* forms) {
123 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 147 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
124 return login_db_->GetBlacklistLogins(forms); 148 return login_db_ && login_db_->GetBlacklistLogins(forms);
125 } 149 }
126 150
127 } // namespace password_manager 151 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698