OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_STATISTICS_TABLE_H_ | 5 #ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_STATISTICS_TABLE_H_ |
6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_STATISTICS_TABLE_H_ | 6 #define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_STATISTICS_TABLE_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 23 matching lines...) Expand all Loading... |
34 int dismissal_count = 0; | 34 int dismissal_count = 0; |
35 | 35 |
36 // The date when the row was updated. | 36 // The date when the row was updated. |
37 base::Time update_time; | 37 base::Time update_time; |
38 }; | 38 }; |
39 | 39 |
40 bool operator==(const InteractionsStats& lhs, const InteractionsStats& rhs); | 40 bool operator==(const InteractionsStats& lhs, const InteractionsStats& rhs); |
41 | 41 |
42 // Returns an element from |stats| with |username| or nullptr if not found. | 42 // Returns an element from |stats| with |username| or nullptr if not found. |
43 const InteractionsStats* FindStatsByUsername( | 43 const InteractionsStats* FindStatsByUsername( |
44 const std::vector<const InteractionsStats*>& stats, | 44 const std::vector<InteractionsStats>& stats, |
45 const base::string16& username); | 45 const base::string16& username); |
46 | 46 |
47 // Represents the 'stats' table in the Login Database. | 47 // Represents the 'stats' table in the Login Database. |
48 class StatisticsTable { | 48 class StatisticsTable { |
49 public: | 49 public: |
50 StatisticsTable(); | 50 StatisticsTable(); |
51 ~StatisticsTable(); | 51 ~StatisticsTable(); |
52 | 52 |
53 // Initializes |db_|. | 53 // Initializes |db_|. |
54 void Init(sql::Connection* db); | 54 void Init(sql::Connection* db); |
55 | 55 |
56 // Creates the statistics table if it doesn't exist. | 56 // Creates the statistics table if it doesn't exist. |
57 bool CreateTableIfNecessary(); | 57 bool CreateTableIfNecessary(); |
58 | 58 |
59 // Migrates this table to |version|. The current version should be less than | 59 // Migrates this table to |version|. The current version should be less than |
60 // |version|. Returns false if there was migration work to do and it failed, | 60 // |version|. Returns false if there was migration work to do and it failed, |
61 // true otherwise. | 61 // true otherwise. |
62 bool MigrateToVersion(int version); | 62 bool MigrateToVersion(int version); |
63 | 63 |
64 // Adds or replaces the statistics about |stats.origin_domain| and | 64 // Adds or replaces the statistics about |stats.origin_domain| and |
65 // |stats.username_value|. | 65 // |stats.username_value|. |
66 bool AddRow(const InteractionsStats& stats); | 66 bool AddRow(const InteractionsStats& stats); |
67 | 67 |
68 // Removes the statistics for |domain|. Returns true if the SQL completed | 68 // Removes the statistics for |domain|. Returns true if the SQL completed |
69 // successfully. | 69 // successfully. |
70 bool RemoveRow(const GURL& domain); | 70 bool RemoveRow(const GURL& domain); |
71 | 71 |
72 // Returns the statistics for |domain| if it exists. | 72 // Returns the statistics for |domain| if it exists. |
73 std::vector<std::unique_ptr<InteractionsStats>> GetRows(const GURL& domain); | 73 std::vector<InteractionsStats> GetRows(const GURL& domain); |
74 | 74 |
75 // Removes the statistics between the dates. If |origin_filter| is not null, | 75 // Removes the statistics between the dates. If |origin_filter| is not null, |
76 // only statistics for matching origins are removed. Returns true if the SQL | 76 // only statistics for matching origins are removed. Returns true if the SQL |
77 // completed successfully. | 77 // completed successfully. |
78 bool RemoveStatsByOriginAndTime( | 78 bool RemoveStatsByOriginAndTime( |
79 const base::Callback<bool(const GURL&)>& origin_filter, | 79 const base::Callback<bool(const GURL&)>& origin_filter, |
80 base::Time delete_begin, | 80 base::Time delete_begin, |
81 base::Time delete_end); | 81 base::Time delete_end); |
82 | 82 |
83 private: | 83 private: |
84 sql::Connection* db_; | 84 sql::Connection* db_; |
85 | 85 |
86 DISALLOW_COPY_AND_ASSIGN(StatisticsTable); | 86 DISALLOW_COPY_AND_ASSIGN(StatisticsTable); |
87 }; | 87 }; |
88 | 88 |
89 } // namespace password_manager | 89 } // namespace password_manager |
90 | 90 |
91 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_STATISTICS_TABLE_H_ | 91 #endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_STATISTICS_TABLE_H_ |
OLD | NEW |