OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_LOGIN_DATABASE_H_ | 5 #ifndef CHROME_BROWSER_PASSWORD_MANAGER_LOGIN_DATABASE_H_ |
6 #define CHROME_BROWSER_PASSWORD_MANAGER_LOGIN_DATABASE_H_ | 6 #define CHROME_BROWSER_PASSWORD_MANAGER_LOGIN_DATABASE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/string16.h" | 12 #include "base/string16.h" |
| 13 #include "content/public/common/password_form.h" |
13 #include "sql/connection.h" | 14 #include "sql/connection.h" |
14 #include "sql/meta_table.h" | 15 #include "sql/meta_table.h" |
15 #include "webkit/forms/password_form.h" | |
16 | 16 |
17 // Interface to the database storage of login information, intended as a helper | 17 // Interface to the database storage of login information, intended as a helper |
18 // for PasswordStore on platforms that need internal storage of some or all of | 18 // for PasswordStore on platforms that need internal storage of some or all of |
19 // the login information. | 19 // the login information. |
20 class LoginDatabase { | 20 class LoginDatabase { |
21 public: | 21 public: |
22 LoginDatabase(); | 22 LoginDatabase(); |
23 virtual ~LoginDatabase(); | 23 virtual ~LoginDatabase(); |
24 | 24 |
25 // Initialize the database with an sqlite file at the given path. | 25 // Initialize the database with an sqlite file at the given path. |
26 // If false is returned, no other method should be called. | 26 // If false is returned, no other method should be called. |
27 bool Init(const FilePath& db_path); | 27 bool Init(const FilePath& db_path); |
28 | 28 |
29 // Reports usage metrics to UMA. | 29 // Reports usage metrics to UMA. |
30 void ReportMetrics(); | 30 void ReportMetrics(); |
31 | 31 |
32 // Adds |form| to the list of remembered password forms. | 32 // Adds |form| to the list of remembered password forms. |
33 bool AddLogin(const webkit::forms::PasswordForm& form); | 33 bool AddLogin(const content::PasswordForm& form); |
34 | 34 |
35 // Updates remembered password form. Returns true on success and sets | 35 // Updates remembered password form. Returns true on success and sets |
36 // items_changed (if non-NULL) to the number of logins updated. | 36 // items_changed (if non-NULL) to the number of logins updated. |
37 bool UpdateLogin(const webkit::forms::PasswordForm& form, int* items_changed); | 37 bool UpdateLogin(const content::PasswordForm& form, int* items_changed); |
38 | 38 |
39 // Removes |form| from the list of remembered password forms. | 39 // Removes |form| from the list of remembered password forms. |
40 bool RemoveLogin(const webkit::forms::PasswordForm& form); | 40 bool RemoveLogin(const content::PasswordForm& form); |
41 | 41 |
42 // Removes all logins created from |delete_begin| onwards (inclusive) and | 42 // Removes all logins created from |delete_begin| onwards (inclusive) and |
43 // before |delete_end|. You may use a null Time value to do an unbounded | 43 // before |delete_end|. You may use a null Time value to do an unbounded |
44 // delete in either direction. | 44 // delete in either direction. |
45 bool RemoveLoginsCreatedBetween(const base::Time delete_begin, | 45 bool RemoveLoginsCreatedBetween(const base::Time delete_begin, |
46 const base::Time delete_end); | 46 const base::Time delete_end); |
47 | 47 |
48 // Loads a list of matching password forms into the specified vector |forms|. | 48 // Loads a list of matching password forms into the specified vector |forms|. |
49 // The list will contain all possibly relevant entries to the observed |form|, | 49 // The list will contain all possibly relevant entries to the observed |form|, |
50 // including blacklisted matches. | 50 // including blacklisted matches. |
51 bool GetLogins(const webkit::forms::PasswordForm& form, | 51 bool GetLogins(const content::PasswordForm& form, |
52 std::vector<webkit::forms::PasswordForm*>* forms) const; | 52 std::vector<content::PasswordForm*>* forms) const; |
53 | 53 |
54 // Loads all logins created from |begin| onwards (inclusive) and before |end|. | 54 // Loads all logins created from |begin| onwards (inclusive) and before |end|. |
55 // You may use a null Time value to do an unbounded search in either | 55 // You may use a null Time value to do an unbounded search in either |
56 // direction. | 56 // direction. |
57 bool GetLoginsCreatedBetween( | 57 bool GetLoginsCreatedBetween( |
58 const base::Time begin, | 58 const base::Time begin, |
59 const base::Time end, | 59 const base::Time end, |
60 std::vector<webkit::forms::PasswordForm*>* forms) const; | 60 std::vector<content::PasswordForm*>* forms) const; |
61 | 61 |
62 // Loads the complete list of autofillable password forms (i.e., not blacklist | 62 // Loads the complete list of autofillable password forms (i.e., not blacklist |
63 // entries) into |forms|. | 63 // entries) into |forms|. |
64 bool GetAutofillableLogins( | 64 bool GetAutofillableLogins( |
65 std::vector<webkit::forms::PasswordForm*>* forms) const; | 65 std::vector<content::PasswordForm*>* forms) const; |
66 | 66 |
67 // Loads the complete list of blacklist forms into |forms|. | 67 // Loads the complete list of blacklist forms into |forms|. |
68 bool GetBlacklistLogins( | 68 bool GetBlacklistLogins( |
69 std::vector<webkit::forms::PasswordForm*>* forms) const; | 69 std::vector<content::PasswordForm*>* forms) const; |
70 | 70 |
71 // Deletes the login database file on disk, and creates a new, empty database. | 71 // Deletes the login database file on disk, and creates a new, empty database. |
72 // This can be used after migrating passwords to some other store, to ensure | 72 // This can be used after migrating passwords to some other store, to ensure |
73 // that SQLite doesn't leave fragments of passwords in the database file. | 73 // that SQLite doesn't leave fragments of passwords in the database file. |
74 // Returns true on success; otherwise, whether the file was deleted and | 74 // Returns true on success; otherwise, whether the file was deleted and |
75 // whether further use of this login database will succeed is unspecified. | 75 // whether further use of this login database will succeed is unspecified. |
76 bool DeleteAndRecreateDatabaseFile(); | 76 bool DeleteAndRecreateDatabaseFile(); |
77 | 77 |
78 private: | 78 private: |
79 // Returns an encrypted version of plain_text. | 79 // Returns an encrypted version of plain_text. |
80 std::string EncryptedString(const string16& plain_text) const; | 80 std::string EncryptedString(const string16& plain_text) const; |
81 | 81 |
82 // Returns a decrypted version of cipher_text. | 82 // Returns a decrypted version of cipher_text. |
83 string16 DecryptedString(const std::string& cipher_text) const; | 83 string16 DecryptedString(const std::string& cipher_text) const; |
84 | 84 |
85 bool InitLoginsTable(); | 85 bool InitLoginsTable(); |
86 void MigrateOldVersionsAsNeeded(); | 86 void MigrateOldVersionsAsNeeded(); |
87 | 87 |
88 // Fills |form| from the values in the given statement (which is assumed to | 88 // Fills |form| from the values in the given statement (which is assumed to |
89 // be of the form used by the Get*Logins methods). | 89 // be of the form used by the Get*Logins methods). |
90 void InitPasswordFormFromStatement(webkit::forms::PasswordForm* form, | 90 void InitPasswordFormFromStatement(content::PasswordForm* form, |
91 sql::Statement& s) const; | 91 sql::Statement& s) const; |
92 | 92 |
93 // Loads all logins whose blacklist setting matches |blacklisted| into | 93 // Loads all logins whose blacklist setting matches |blacklisted| into |
94 // |forms|. | 94 // |forms|. |
95 bool GetAllLoginsWithBlacklistSetting( | 95 bool GetAllLoginsWithBlacklistSetting( |
96 bool blacklisted, std::vector<webkit::forms::PasswordForm*>* forms) const; | 96 bool blacklisted, std::vector<content::PasswordForm*>* forms) const; |
97 | 97 |
98 FilePath db_path_; | 98 FilePath db_path_; |
99 mutable sql::Connection db_; | 99 mutable sql::Connection db_; |
100 sql::MetaTable meta_table_; | 100 sql::MetaTable meta_table_; |
101 | 101 |
102 DISALLOW_COPY_AND_ASSIGN(LoginDatabase); | 102 DISALLOW_COPY_AND_ASSIGN(LoginDatabase); |
103 }; | 103 }; |
104 | 104 |
105 #endif // CHROME_BROWSER_PASSWORD_MANAGER_LOGIN_DATABASE_H_ | 105 #endif // CHROME_BROWSER_PASSWORD_MANAGER_LOGIN_DATABASE_H_ |
OLD | NEW |