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

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: 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 const base::FilePath& login_db_file_path)
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_file_path_(login_db_file_path) {
24 } 24 }
25 25
26 PasswordStoreDefault::~PasswordStoreDefault() { 26 PasswordStoreDefault::~PasswordStoreDefault() {
27 } 27 }
28 28
29 void PasswordStoreDefault::InitOnDBThread() {
30 login_db_.reset(new LoginDatabase());
31 if (!login_db_->Init(login_db_file_path_)) {
32 login_db_.reset();
33 LOG(ERROR) << "Could not initialize login database.";
34 }
35 }
36
37 bool PasswordStoreDefault::Init(
38 const syncer::SyncableService::StartSyncFlare& flare) {
39 ScheduleTask(base::Bind(&PasswordStoreDefault::InitOnDBThread, this));
40 return PasswordStore::Init(flare);
41 }
42
29 void PasswordStoreDefault::ReportMetricsImpl( 43 void PasswordStoreDefault::ReportMetricsImpl(
30 const std::string& sync_username, 44 const std::string& sync_username,
31 bool custom_passphrase_sync_enabled) { 45 bool custom_passphrase_sync_enabled) {
46 if (!login_db_)
47 return;
32 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 48 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
33 login_db_->ReportMetrics(sync_username, custom_passphrase_sync_enabled); 49 login_db_->ReportMetrics(sync_username, custom_passphrase_sync_enabled);
34 } 50 }
35 51
36 PasswordStoreChangeList PasswordStoreDefault::AddLoginImpl( 52 PasswordStoreChangeList PasswordStoreDefault::AddLoginImpl(
37 const PasswordForm& form) { 53 const PasswordForm& form) {
38 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 54 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
55 if (!login_db_)
56 return PasswordStoreChangeList();
39 return login_db_->AddLogin(form); 57 return login_db_->AddLogin(form);
40 } 58 }
41 59
42 PasswordStoreChangeList PasswordStoreDefault::UpdateLoginImpl( 60 PasswordStoreChangeList PasswordStoreDefault::UpdateLoginImpl(
43 const PasswordForm& form) { 61 const PasswordForm& form) {
44 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 62 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
63 if (!login_db_)
64 return PasswordStoreChangeList();
45 return login_db_->UpdateLogin(form); 65 return login_db_->UpdateLogin(form);
46 } 66 }
47 67
48 PasswordStoreChangeList PasswordStoreDefault::RemoveLoginImpl( 68 PasswordStoreChangeList PasswordStoreDefault::RemoveLoginImpl(
49 const PasswordForm& form) { 69 const PasswordForm& form) {
50 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 70 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
51 PasswordStoreChangeList changes; 71 PasswordStoreChangeList changes;
52 if (login_db_->RemoveLogin(form)) 72 if (login_db_ && login_db_->RemoveLogin(form))
53 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form)); 73 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, form));
54 return changes; 74 return changes;
55 } 75 }
56 76
57 PasswordStoreChangeList PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl( 77 PasswordStoreChangeList PasswordStoreDefault::RemoveLoginsCreatedBetweenImpl(
58 base::Time delete_begin, 78 base::Time delete_begin,
59 base::Time delete_end) { 79 base::Time delete_end) {
60 std::vector<PasswordForm*> forms; 80 std::vector<PasswordForm*> forms;
61 PasswordStoreChangeList changes; 81 PasswordStoreChangeList changes;
62 if (login_db_->GetLoginsCreatedBetween(delete_begin, delete_end, &forms)) { 82 if (login_db_ &&
83 login_db_->GetLoginsCreatedBetween(delete_begin, delete_end, &forms)) {
63 if (login_db_->RemoveLoginsCreatedBetween(delete_begin, delete_end)) { 84 if (login_db_->RemoveLoginsCreatedBetween(delete_begin, delete_end)) {
64 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); 85 for (std::vector<PasswordForm*>::const_iterator it = forms.begin();
65 it != forms.end(); ++it) { 86 it != forms.end(); ++it) {
66 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE, 87 changes.push_back(PasswordStoreChange(PasswordStoreChange::REMOVE,
67 **it)); 88 **it));
68 } 89 }
69 LogStatsForBulkDeletion(changes.size()); 90 LogStatsForBulkDeletion(changes.size());
70 } 91 }
71 } 92 }
72 STLDeleteElements(&forms); 93 STLDeleteElements(&forms);
73 return changes; 94 return changes;
74 } 95 }
75 96
76 PasswordStoreChangeList PasswordStoreDefault::RemoveLoginsSyncedBetweenImpl( 97 PasswordStoreChangeList PasswordStoreDefault::RemoveLoginsSyncedBetweenImpl(
77 base::Time delete_begin, 98 base::Time delete_begin,
78 base::Time delete_end) { 99 base::Time delete_end) {
79 std::vector<PasswordForm*> forms; 100 std::vector<PasswordForm*> forms;
80 PasswordStoreChangeList changes; 101 PasswordStoreChangeList changes;
81 if (login_db_->GetLoginsSyncedBetween(delete_begin, delete_end, &forms)) { 102 if (login_db_ &&
103 login_db_->GetLoginsSyncedBetween(delete_begin, delete_end, &forms)) {
82 if (login_db_->RemoveLoginsSyncedBetween(delete_begin, delete_end)) { 104 if (login_db_->RemoveLoginsSyncedBetween(delete_begin, delete_end)) {
83 for (std::vector<PasswordForm*>::const_iterator it = forms.begin(); 105 for (std::vector<PasswordForm*>::const_iterator it = forms.begin();
84 it != forms.end(); 106 it != forms.end();
85 ++it) { 107 ++it) {
86 changes.push_back( 108 changes.push_back(
87 PasswordStoreChange(PasswordStoreChange::REMOVE, **it)); 109 PasswordStoreChange(PasswordStoreChange::REMOVE, **it));
88 } 110 }
89 LogStatsForBulkDeletionDuringRollback(changes.size()); 111 LogStatsForBulkDeletionDuringRollback(changes.size());
90 } 112 }
91 } 113 }
92 STLDeleteElements(&forms); 114 STLDeleteElements(&forms);
93 return changes; 115 return changes;
94 } 116 }
95 117
96 void PasswordStoreDefault::GetLoginsImpl( 118 void PasswordStoreDefault::GetLoginsImpl(
97 const autofill::PasswordForm& form, 119 const autofill::PasswordForm& form,
98 AuthorizationPromptPolicy prompt_policy, 120 AuthorizationPromptPolicy prompt_policy,
99 const ConsumerCallbackRunner& callback_runner) { 121 const ConsumerCallbackRunner& callback_runner) {
100 std::vector<PasswordForm*> matched_forms; 122 std::vector<PasswordForm*> matched_forms;
101 login_db_->GetLogins(form, &matched_forms); 123 if (login_db_)
124 login_db_->GetLogins(form, &matched_forms);
102 callback_runner.Run(matched_forms); 125 callback_runner.Run(matched_forms);
103 } 126 }
104 127
105 void PasswordStoreDefault::GetAutofillableLoginsImpl( 128 void PasswordStoreDefault::GetAutofillableLoginsImpl(
106 GetLoginsRequest* request) { 129 GetLoginsRequest* request) {
107 FillAutofillableLogins(request->result()); 130 FillAutofillableLogins(request->result());
108 ForwardLoginsResult(request); 131 ForwardLoginsResult(request);
109 } 132 }
110 133
111 void PasswordStoreDefault::GetBlacklistLoginsImpl( 134 void PasswordStoreDefault::GetBlacklistLoginsImpl(
112 GetLoginsRequest* request) { 135 GetLoginsRequest* request) {
113 FillBlacklistLogins(request->result()); 136 FillBlacklistLogins(request->result());
114 ForwardLoginsResult(request); 137 ForwardLoginsResult(request);
115 } 138 }
116 139
117 bool PasswordStoreDefault::FillAutofillableLogins( 140 bool PasswordStoreDefault::FillAutofillableLogins(
118 std::vector<PasswordForm*>* forms) { 141 std::vector<PasswordForm*>* forms) {
119 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 142 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
120 return login_db_->GetAutofillableLogins(forms); 143 return login_db_ && login_db_->GetAutofillableLogins(forms);
121 } 144 }
122 145
123 bool PasswordStoreDefault::FillBlacklistLogins( 146 bool PasswordStoreDefault::FillBlacklistLogins(
124 std::vector<PasswordForm*>* forms) { 147 std::vector<PasswordForm*>* forms) {
125 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread()); 148 DCHECK(GetBackgroundTaskRunner()->BelongsToCurrentThread());
126 return login_db_->GetBlacklistLogins(forms); 149 return login_db_ && login_db_->GetBlacklistLogins(forms);
127 } 150 }
128 151
129 } // namespace password_manager 152 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698