Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: components/password_manager/core/browser/affiliation_database.h

Issue 797983003: Implement AffiliationDatabase to cache affiliation information in a SQLite DB. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@aff_fetcher
Patch Set: Fix nits. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "base/macros.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "components/password_manager/core/browser/affiliation_utils.h"
12
13 namespace base {
14 class FilePath;
15 } // namespace base
16
17 namespace sql {
18 class Connection;
19 class Statement;
20 } // namespace sql
21
22 namespace password_manager {
23
24 // Stores equivalence classes of facets, i.e., facets that are affiliated with
25 // each other, in an SQLite database. See affiliation_utils.h for a more
26 // detailed definition of what this means.
27 //
28 // Under the assumption that there is most likely not much the caller can do in
29 // case of database errors, most methods silently ignore them. Nevertheless, the
30 // caller must plan ahead for this rare but non-negligible scenario, and expect
31 // that in odd cases basic database invariants will not hold.
32 class AffiliationDatabase {
33 public:
34 AffiliationDatabase();
35 ~AffiliationDatabase();
36
37 // Opens an existing database at |path|, or creates a new one if none exists,
38 // and returns true on success.
39 bool Init(const base::FilePath& path);
40
41 // Looks up the equivalence class containing |facet_uri|, and returns true if
42 // such a class is found, in which case it is also stored into |result|.
43 bool GetAffiliationsForFacet(const FacetURI& facet_uri,
44 AffiliatedFacetsWithUpdateTime* result) const;
45
46 // Retrieves all stored equivalence classes.
47 void GetAllAffiliations(
48 std::vector<AffiliatedFacetsWithUpdateTime>* results) const;
49
50 // Removes the stored equivalence class, if any, containing |facet_uri|.
51 void DeleteAffiliationsForFacet(const FacetURI& facet_uri);
52
53 // Removes stored equivalence classes that were last updated before the
54 // |cutoff_threshold|.
55 void DeleteAffiliationsOlderThan(const base::Time& cutoff_threshold);
56
57 // Removes all records from all tables of the database.
58 void DeleteAllAffiliations();
59
60 // Stores the equivalence class defined by |affiliated_facets| to the DB and
61 // returns true unless it has a non-empty subset with a preexisting class, in
62 // which case no changes are made and the function returns false.
63 bool Store(const AffiliatedFacetsWithUpdateTime& affiliated_facets);
64
65 // Stores the equivalence class defined by |affiliated_facets| to the DB,
66 // database, and removes any other equivalence classes that are in conflict
67 // with |affiliated_facets|, i.e. those that are neither equal nor disjoint to
68 // it. Removed equivalence classes are stored into |removed_affiliations|.
69 void StoreAndRemoveConflicting(
70 const AffiliatedFacetsWithUpdateTime& affiliated_facets,
71 std::vector<AffiliatedFacetsWithUpdateTime>* removed_affiliations);
72
73 private:
74 // Creates any tables and indices that do not already exist in the database.
75 bool CreateTablesAndIndicesIfNeeded();
76
77 // Called when SQLite encounters an error.
78 void SQLErrorCallback(int error_number, sql::Statement* statement);
79
80 // The SQL connection to the database.
81 scoped_ptr<sql::Connection> sql_connection_;
82
83 DISALLOW_COPY_AND_ASSIGN(AffiliationDatabase);
84 };
85
86 } // namespace password_manager
87
88 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_AFFILIATION_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698