OLD | NEW |
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/login_database.h" | 5 #include "components/password_manager/core/browser/login_database.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/metrics/histogram.h" | 13 #include "base/metrics/histogram.h" |
14 #include "base/pickle.h" | 14 #include "base/pickle.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
17 #include "components/autofill/core/common/password_form.h" | 17 #include "components/autofill/core/common/password_form.h" |
18 #include "google_apis/gaia/gaia_auth_util.h" | 18 #include "google_apis/gaia/gaia_auth_util.h" |
19 #include "google_apis/gaia/gaia_urls.h" | 19 #include "google_apis/gaia/gaia_urls.h" |
20 #include "sql/connection.h" | 20 #include "sql/connection.h" |
21 #include "sql/statement.h" | 21 #include "sql/statement.h" |
22 #include "sql/transaction.h" | 22 #include "sql/transaction.h" |
23 | 23 |
24 using autofill::PasswordForm; | 24 using autofill::PasswordForm; |
25 | 25 |
26 namespace password_manager { | 26 namespace password_manager { |
27 | 27 |
28 static const int kCurrentVersionNumber = 8; | 28 static const int kCurrentVersionNumber = 7; |
29 static const int kCompatibleVersionNumber = 1; | 29 static const int kCompatibleVersionNumber = 1; |
30 | 30 |
31 Pickle SerializeVector(const std::vector<base::string16>& vec) { | 31 Pickle SerializeVector(const std::vector<base::string16>& vec) { |
32 Pickle p; | 32 Pickle p; |
33 for (size_t i = 0; i < vec.size(); ++i) { | 33 for (size_t i = 0; i < vec.size(); ++i) { |
34 p.WriteString16(vec[i]); | 34 p.WriteString16(vec[i]); |
35 } | 35 } |
36 return p; | 36 return p; |
37 } | 37 } |
38 | 38 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 case 6: | 217 case 6: |
218 if (!db_.Execute("ALTER TABLE logins ADD COLUMN display_name VARCHAR") || | 218 if (!db_.Execute("ALTER TABLE logins ADD COLUMN display_name VARCHAR") || |
219 !db_.Execute("ALTER TABLE logins ADD COLUMN avatar_url VARCHAR") || | 219 !db_.Execute("ALTER TABLE logins ADD COLUMN avatar_url VARCHAR") || |
220 !db_.Execute("ALTER TABLE logins " | 220 !db_.Execute("ALTER TABLE logins " |
221 "ADD COLUMN federation_url VARCHAR") || | 221 "ADD COLUMN federation_url VARCHAR") || |
222 !db_.Execute("ALTER TABLE logins ADD COLUMN is_zero_click INTEGER")) { | 222 !db_.Execute("ALTER TABLE logins ADD COLUMN is_zero_click INTEGER")) { |
223 return false; | 223 return false; |
224 } | 224 } |
225 meta_table_.SetVersionNumber(7); | 225 meta_table_.SetVersionNumber(7); |
226 // Fall through. | 226 // Fall through. |
227 case 7: | 227 // TODO(gcasto): Remove use_additional_auth by copying table. |
228 if (!db_.Execute( | 228 // https://www.sqlite.org/lang_altertable.html |
229 "ALTER TABLE logins DROP COLUMN use_additional_auth")) { | |
230 return false; | |
231 } | |
232 meta_table_.SetVersionNumber(8); | |
233 // Fall through. | |
234 case kCurrentVersionNumber: | 229 case kCurrentVersionNumber: |
235 // Already up to date | 230 // Already up to date |
236 return true; | 231 return true; |
237 default: | 232 default: |
238 NOTREACHED(); | 233 NOTREACHED(); |
239 return false; | 234 return false; |
240 } | 235 } |
241 } | 236 } |
242 | 237 |
243 bool LoginDatabase::InitLoginsTable() { | 238 bool LoginDatabase::InitLoginsTable() { |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 | 759 |
765 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { | 760 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { |
766 DCHECK(db_.is_open()); | 761 DCHECK(db_.is_open()); |
767 meta_table_.Reset(); | 762 meta_table_.Reset(); |
768 db_.Close(); | 763 db_.Close(); |
769 sql::Connection::Delete(db_path_); | 764 sql::Connection::Delete(db_path_); |
770 return Init(db_path_); | 765 return Init(db_path_); |
771 } | 766 } |
772 | 767 |
773 } // namespace password_manager | 768 } // namespace password_manager |
OLD | NEW |