OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/login_database.h" | 5 #include "chrome/browser/password_manager/login_database.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "app/sql/statement.h" | 10 #include "app/sql/statement.h" |
11 #include "app/sql/transaction.h" | 11 #include "app/sql/transaction.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/histogram.h" | 14 #include "base/histogram.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/time.h" | 16 #include "base/time.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/common/sqlite_utils.h" | |
19 | 18 |
20 using webkit_glue::PasswordForm; | 19 using webkit_glue::PasswordForm; |
21 | 20 |
22 static const int kCurrentVersionNumber = 1; | 21 static const int kCurrentVersionNumber = 1; |
23 static const int kCompatibleVersionNumber = 1; | 22 static const int kCompatibleVersionNumber = 1; |
24 | 23 |
| 24 namespace { |
| 25 |
25 // Convenience enum for interacting with SQL queries that use all the columns. | 26 // Convenience enum for interacting with SQL queries that use all the columns. |
26 typedef enum { | 27 enum LoginTableColumns { |
27 COLUMN_ORIGIN_URL = 0, | 28 COLUMN_ORIGIN_URL = 0, |
28 COLUMN_ACTION_URL, | 29 COLUMN_ACTION_URL, |
29 COLUMN_USERNAME_ELEMENT, | 30 COLUMN_USERNAME_ELEMENT, |
30 COLUMN_USERNAME_VALUE, | 31 COLUMN_USERNAME_VALUE, |
31 COLUMN_PASSWORD_ELEMENT, | 32 COLUMN_PASSWORD_ELEMENT, |
32 COLUMN_PASSWORD_VALUE, | 33 COLUMN_PASSWORD_VALUE, |
33 COLUMN_SUBMIT_ELEMENT, | 34 COLUMN_SUBMIT_ELEMENT, |
34 COLUMN_SIGNON_REALM, | 35 COLUMN_SIGNON_REALM, |
35 COLUMN_SSL_VALID, | 36 COLUMN_SSL_VALID, |
36 COLUMN_PREFERRED, | 37 COLUMN_PREFERRED, |
37 COLUMN_DATE_CREATED, | 38 COLUMN_DATE_CREATED, |
38 COLUMN_BLACKLISTED_BY_USER, | 39 COLUMN_BLACKLISTED_BY_USER, |
39 COLUMN_SCHEME | 40 COLUMN_SCHEME |
40 } LoginTableColumns; | 41 }; |
| 42 |
| 43 } // namespace |
41 | 44 |
42 LoginDatabase::LoginDatabase() { | 45 LoginDatabase::LoginDatabase() { |
43 } | 46 } |
44 | 47 |
45 LoginDatabase::~LoginDatabase() { | 48 LoginDatabase::~LoginDatabase() { |
46 } | 49 } |
47 | 50 |
48 bool LoginDatabase::Init(const FilePath& db_path) { | 51 bool LoginDatabase::Init(const FilePath& db_path) { |
49 // Set pragmas for a small, private database (based on WebDatabase). | 52 // Set pragmas for a small, private database (based on WebDatabase). |
50 db_.set_page_size(2048); | 53 db_.set_page_size(2048); |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 return s.Succeeded(); | 398 return s.Succeeded(); |
396 } | 399 } |
397 | 400 |
398 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { | 401 bool LoginDatabase::DeleteAndRecreateDatabaseFile() { |
399 DCHECK(db_.is_open()); | 402 DCHECK(db_.is_open()); |
400 meta_table_.Reset(); | 403 meta_table_.Reset(); |
401 db_.Close(); | 404 db_.Close(); |
402 file_util::Delete(db_path_, false); | 405 file_util::Delete(db_path_, false); |
403 return Init(db_path_); | 406 return Init(db_path_); |
404 } | 407 } |
OLD | NEW |