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/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
14 #include "content/public/common/password_form.h" | 14 #include "components/autofill/core/common/password_form.h" |
15 #include "sql/connection.h" | 15 #include "sql/connection.h" |
16 #include "sql/meta_table.h" | 16 #include "sql/meta_table.h" |
17 | 17 |
18 // Interface to the database storage of login information, intended as a helper | 18 // Interface to the database storage of login information, intended as a helper |
19 // for PasswordStore on platforms that need internal storage of some or all of | 19 // for PasswordStore on platforms that need internal storage of some or all of |
20 // the login information. | 20 // the login information. |
21 class LoginDatabase { | 21 class LoginDatabase { |
22 public: | 22 public: |
23 LoginDatabase(); | 23 LoginDatabase(); |
24 virtual ~LoginDatabase(); | 24 virtual ~LoginDatabase(); |
25 | 25 |
26 // Initialize the database with an sqlite file at the given path. | 26 // Initialize the database with an sqlite file at the given path. |
27 // If false is returned, no other method should be called. | 27 // If false is returned, no other method should be called. |
28 bool Init(const base::FilePath& db_path); | 28 bool Init(const base::FilePath& db_path); |
29 | 29 |
30 // Reports usage metrics to UMA. | 30 // Reports usage metrics to UMA. |
31 void ReportMetrics(); | 31 void ReportMetrics(); |
32 | 32 |
33 // Adds |form| to the list of remembered password forms. | 33 // Adds |form| to the list of remembered password forms. |
34 bool AddLogin(const content::PasswordForm& form); | 34 bool AddLogin(const autofill::PasswordForm& form); |
35 | 35 |
36 // Updates remembered password form. Returns true on success and sets | 36 // Updates remembered password form. Returns true on success and sets |
37 // items_changed (if non-NULL) to the number of logins updated. | 37 // items_changed (if non-NULL) to the number of logins updated. |
38 bool UpdateLogin(const content::PasswordForm& form, int* items_changed); | 38 bool UpdateLogin(const autofill::PasswordForm& form, int* items_changed); |
39 | 39 |
40 // Removes |form| from the list of remembered password forms. | 40 // Removes |form| from the list of remembered password forms. |
41 bool RemoveLogin(const content::PasswordForm& form); | 41 bool RemoveLogin(const autofill::PasswordForm& form); |
42 | 42 |
43 // Removes all logins created from |delete_begin| onwards (inclusive) and | 43 // Removes all logins created from |delete_begin| onwards (inclusive) and |
44 // before |delete_end|. You may use a null Time value to do an unbounded | 44 // before |delete_end|. You may use a null Time value to do an unbounded |
45 // delete in either direction. | 45 // delete in either direction. |
46 bool RemoveLoginsCreatedBetween(const base::Time delete_begin, | 46 bool RemoveLoginsCreatedBetween(const base::Time delete_begin, |
47 const base::Time delete_end); | 47 const base::Time delete_end); |
48 | 48 |
49 // Loads a list of matching password forms into the specified vector |forms|. | 49 // Loads a list of matching password forms into the specified vector |forms|. |
50 // The list will contain all possibly relevant entries to the observed |form|, | 50 // The list will contain all possibly relevant entries to the observed |form|, |
51 // including blacklisted matches. | 51 // including blacklisted matches. |
52 bool GetLogins(const content::PasswordForm& form, | 52 bool GetLogins(const autofill::PasswordForm& form, |
53 std::vector<content::PasswordForm*>* forms) const; | 53 std::vector<autofill::PasswordForm*>* forms) const; |
54 | 54 |
55 // Loads all logins created from |begin| onwards (inclusive) and before |end|. | 55 // Loads all logins created from |begin| onwards (inclusive) and before |end|. |
56 // You may use a null Time value to do an unbounded search in either | 56 // You may use a null Time value to do an unbounded search in either |
57 // direction. | 57 // direction. |
58 bool GetLoginsCreatedBetween( | 58 bool GetLoginsCreatedBetween( |
59 const base::Time begin, | 59 const base::Time begin, |
60 const base::Time end, | 60 const base::Time end, |
61 std::vector<content::PasswordForm*>* forms) const; | 61 std::vector<autofill::PasswordForm*>* forms) const; |
62 | 62 |
63 // Loads the complete list of autofillable password forms (i.e., not blacklist | 63 // Loads the complete list of autofillable password forms (i.e., not blacklist |
64 // entries) into |forms|. | 64 // entries) into |forms|. |
65 bool GetAutofillableLogins( | 65 bool GetAutofillableLogins( |
66 std::vector<content::PasswordForm*>* forms) const; | 66 std::vector<autofill::PasswordForm*>* forms) const; |
67 | 67 |
68 // Loads the complete list of blacklist forms into |forms|. | 68 // Loads the complete list of blacklist forms into |forms|. |
69 bool GetBlacklistLogins( | 69 bool GetBlacklistLogins( |
70 std::vector<content::PasswordForm*>* forms) const; | 70 std::vector<autofill::PasswordForm*>* forms) const; |
71 | 71 |
72 // Deletes the login database file on disk, and creates a new, empty database. | 72 // Deletes the login database file on disk, and creates a new, empty database. |
73 // This can be used after migrating passwords to some other store, to ensure | 73 // This can be used after migrating passwords to some other store, to ensure |
74 // that SQLite doesn't leave fragments of passwords in the database file. | 74 // that SQLite doesn't leave fragments of passwords in the database file. |
75 // Returns true on success; otherwise, whether the file was deleted and | 75 // Returns true on success; otherwise, whether the file was deleted and |
76 // whether further use of this login database will succeed is unspecified. | 76 // whether further use of this login database will succeed is unspecified. |
77 bool DeleteAndRecreateDatabaseFile(); | 77 bool DeleteAndRecreateDatabaseFile(); |
78 | 78 |
79 private: | 79 private: |
80 friend class LoginDatabaseTest; | 80 friend class LoginDatabaseTest; |
(...skipping 11 matching lines...) Expand all Loading... |
92 // temporarily unavailable). | 92 // temporarily unavailable). |
93 bool DecryptedString(const std::string& cipher_text, | 93 bool DecryptedString(const std::string& cipher_text, |
94 string16* plain_text) const; | 94 string16* plain_text) const; |
95 | 95 |
96 bool InitLoginsTable(); | 96 bool InitLoginsTable(); |
97 bool MigrateOldVersionsAsNeeded(); | 97 bool MigrateOldVersionsAsNeeded(); |
98 | 98 |
99 // Fills |form| from the values in the given statement (which is assumed to | 99 // Fills |form| from the values in the given statement (which is assumed to |
100 // be of the form used by the Get*Logins methods). | 100 // be of the form used by the Get*Logins methods). |
101 // Returns true if |form| was successfully filled. | 101 // Returns true if |form| was successfully filled. |
102 bool InitPasswordFormFromStatement(content::PasswordForm* form, | 102 bool InitPasswordFormFromStatement(autofill::PasswordForm* form, |
103 sql::Statement& s) const; | 103 sql::Statement& s) const; |
104 | 104 |
105 // Loads all logins whose blacklist setting matches |blacklisted| into | 105 // Loads all logins whose blacklist setting matches |blacklisted| into |
106 // |forms|. | 106 // |forms|. |
107 bool GetAllLoginsWithBlacklistSetting( | 107 bool GetAllLoginsWithBlacklistSetting( |
108 bool blacklisted, std::vector<content::PasswordForm*>* forms) const; | 108 bool blacklisted, std::vector<autofill::PasswordForm*>* forms) const; |
109 | 109 |
110 // Serialization routines for vectors. | 110 // Serialization routines for vectors. |
111 Pickle SerializeVector(const std::vector<string16>& vec) const; | 111 Pickle SerializeVector(const std::vector<string16>& vec) const; |
112 std::vector<string16> DeserializeVector(const Pickle& pickle) const; | 112 std::vector<string16> DeserializeVector(const Pickle& pickle) const; |
113 | 113 |
114 base::FilePath db_path_; | 114 base::FilePath db_path_; |
115 mutable sql::Connection db_; | 115 mutable sql::Connection db_; |
116 sql::MetaTable meta_table_; | 116 sql::MetaTable meta_table_; |
117 | 117 |
118 // Set to true if the public suffix based domain matching is enabled. | 118 // Set to true if the public suffix based domain matching is enabled. |
119 bool public_suffix_domain_matching_; | 119 bool public_suffix_domain_matching_; |
120 | 120 |
121 DISALLOW_COPY_AND_ASSIGN(LoginDatabase); | 121 DISALLOW_COPY_AND_ASSIGN(LoginDatabase); |
122 }; | 122 }; |
123 | 123 |
124 #endif // CHROME_BROWSER_PASSWORD_MANAGER_LOGIN_DATABASE_H_ | 124 #endif // CHROME_BROWSER_PASSWORD_MANAGER_LOGIN_DATABASE_H_ |
OLD | NEW |