OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_DATABASE_H_ |
| 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_DATABASE_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/time/time.h" |
| 12 #include "components/password_manager/core/browser/affiliation_utils.h" |
| 13 |
| 14 namespace base { |
| 15 class FilePath; |
| 16 } // namespace base |
| 17 |
| 18 namespace sql { |
| 19 class Connection; |
| 20 class Statement; |
| 21 } // namespace sql |
| 22 |
| 23 namespace password_manager { |
| 24 |
| 25 // Stores equivalence classes of facets, i.e., facets that are affiliated with |
| 26 // each other, in an SQLite database. See affiliation_utils.h for a more |
| 27 // detailed definition of what this means. |
| 28 // |
| 29 // Under the assumption that there is most likely not much the caller can do in |
| 30 // case of database errors, most methods silently ignore them. Nevertheless, the |
| 31 // caller must plan ahead for this rare but non-negligible scenario, and expect |
| 32 // that in odd cases basic database invariants will not hold. |
| 33 class AffiliationDatabase { |
| 34 public: |
| 35 AffiliationDatabase(); |
| 36 ~AffiliationDatabase(); |
| 37 |
| 38 // Opens an existing database at |path|, or creates a new one if none exists, |
| 39 // and returns true on success. |
| 40 bool Init(const base::FilePath& path); |
| 41 |
| 42 // Looks up the equivalence class containing |facet_uri|, and returns true if |
| 43 // such a class is found, in which case it is also stored into |result|. |
| 44 bool GetAffiliationsForFacet(const FacetURI& facet_uri, |
| 45 AffiliatedFacetsWithUpdateTime* result) const; |
| 46 |
| 47 // Retrieves all stored equivalence classes. |
| 48 void GetAllAffiliations( |
| 49 std::vector<AffiliatedFacetsWithUpdateTime>* results) const; |
| 50 |
| 51 // Removes the stored equivalence class, if any, containing |facet_uri|. |
| 52 void DeleteAffiliationsForFacet(const FacetURI& facet_uri); |
| 53 |
| 54 // Removes stored equivalence classes that were last updated before the |
| 55 // |cutoff_threshold|. |
| 56 void DeleteAffiliationsOlderThan(const base::Time& cutoff_threshold); |
| 57 |
| 58 // Removes all records from all tables of the database. |
| 59 void DeleteAllAffiliations(); |
| 60 |
| 61 // Stores the equivalence class defined by |affiliated_facets| to the DB and |
| 62 // returns true unless it has a non-empty subset with a preexisting class, in |
| 63 // which case no changes are made and the function returns false. |
| 64 bool Store(const AffiliatedFacetsWithUpdateTime& affiliated_facets); |
| 65 |
| 66 // Stores the equivalence class defined by |affiliated_facets| to the DB, |
| 67 // database, and removes any other equivalence classes that are in conflict |
| 68 // with |affiliated_facets|, i.e. those that are neither equal nor disjoint to |
| 69 // it. Removed equivalence classes are stored into |removed_affiliations|. |
| 70 void StoreAndRemoveConflicting( |
| 71 const AffiliatedFacetsWithUpdateTime& affiliated_facets, |
| 72 std::vector<AffiliatedFacetsWithUpdateTime>* removed_affiliations); |
| 73 |
| 74 // Deletes the database file at |path| along with all its auxiliary files. The |
| 75 // database must be closed before calling this. |
| 76 static void Delete(const base::FilePath& path); |
| 77 |
| 78 private: |
| 79 // Creates any tables and indices that do not already exist in the database. |
| 80 bool CreateTablesAndIndicesIfNeeded(); |
| 81 |
| 82 // Called when SQLite encounters an error. |
| 83 void SQLErrorCallback(int error_number, sql::Statement* statement); |
| 84 |
| 85 // The SQL connection to the database. |
| 86 std::unique_ptr<sql::Connection> sql_connection_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(AffiliationDatabase); |
| 89 }; |
| 90 |
| 91 } // namespace password_manager |
| 92 |
| 93 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_DATABASE_H_ |
OLD | NEW |