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 #include "components/password_manager/core/browser/statistics_table.h" | 5 #include "components/password_manager/core/browser/statistics_table.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <limits> | 10 #include <limits> |
11 #include <set> | |
11 | 12 |
12 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
13 #include "sql/connection.h" | 14 #include "sql/connection.h" |
14 #include "sql/statement.h" | 15 #include "sql/statement.h" |
15 | 16 |
16 namespace password_manager { | 17 namespace password_manager { |
17 namespace { | 18 namespace { |
18 | 19 |
19 // Convenience enum for interacting with SQL queries that use all the columns. | 20 // Convenience enum for interacting with SQL queries that use all the columns. |
20 enum LoginTableColumns { | 21 enum LoginTableColumns { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 result.push_back(base::WrapUnique(new InteractionsStats)); | 120 result.push_back(base::WrapUnique(new InteractionsStats)); |
120 result.back()->origin_domain = GURL(s.ColumnString(COLUMN_ORIGIN_DOMAIN)); | 121 result.back()->origin_domain = GURL(s.ColumnString(COLUMN_ORIGIN_DOMAIN)); |
121 result.back()->username_value = s.ColumnString16(COLUMN_USERNAME); | 122 result.back()->username_value = s.ColumnString16(COLUMN_USERNAME); |
122 result.back()->dismissal_count = s.ColumnInt(COLUMN_DISMISSALS); | 123 result.back()->dismissal_count = s.ColumnInt(COLUMN_DISMISSALS); |
123 result.back()->update_time = | 124 result.back()->update_time = |
124 base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE)); | 125 base::Time::FromInternalValue(s.ColumnInt64(COLUMN_DATE)); |
125 } | 126 } |
126 return result; | 127 return result; |
127 } | 128 } |
128 | 129 |
129 bool StatisticsTable::RemoveStatsBetween(base::Time delete_begin, | 130 bool StatisticsTable::RemoveStatsByOriginAndTime( |
130 base::Time delete_end) { | 131 const base::Callback<bool(const GURL&)>& origin_filter, |
131 sql::Statement s(db_->GetCachedStatement( | 132 base::Time delete_begin, |
132 SQL_FROM_HERE, | 133 base::Time delete_end) { |
133 "DELETE FROM stats WHERE update_time >= ? AND update_time < ?")); | 134 if (delete_end.is_null()) |
134 s.BindInt64(0, delete_begin.ToInternalValue()); | 135 delete_end = base::Time::Max(); |
135 s.BindInt64(1, delete_end.is_null() ? std::numeric_limits<int64_t>::max() | 136 |
136 : delete_end.ToInternalValue()); | 137 // All origins. |
137 return s.Run(); | 138 if (origin_filter.is_null()) { |
139 sql::Statement delete_statement(db_->GetCachedStatement( | |
140 SQL_FROM_HERE, | |
141 "DELETE FROM stats WHERE update_time >= ? AND update_time < ?")); | |
142 delete_statement.BindInt64(0, delete_begin.ToInternalValue()); | |
143 delete_statement.BindInt64(1, delete_end.ToInternalValue()); | |
144 | |
145 return delete_statement.Run(); | |
146 } | |
147 | |
148 // Origin filtering. | |
149 sql::Statement select_statement( | |
150 db_->GetCachedStatement(SQL_FROM_HERE, | |
151 "SELECT origin_domain FROM stats " | |
152 "WHERE update_time >= ? AND update_time < ?")); | |
153 select_statement.BindInt64(0, delete_begin.ToInternalValue()); | |
154 select_statement.BindInt64(1, delete_end.ToInternalValue()); | |
155 | |
156 std::set<std::string> origins; | |
157 while (select_statement.Step()) { | |
158 if (!origin_filter.Run(GURL(select_statement.ColumnString(0)))) | |
159 continue; | |
160 | |
161 origins.insert(select_statement.ColumnString(0)); | |
162 } | |
163 | |
164 bool success = true; | |
165 | |
166 for (const std::string& origin : origins) { | |
167 sql::Statement origin_delete_statement(db_->GetCachedStatement( | |
168 SQL_FROM_HERE, | |
169 "DELETE FROM stats " | |
170 "WHERE origin_domain = ? AND update_time >= ? AND update_time < ?")); | |
171 origin_delete_statement.BindString(0, origin); | |
172 origin_delete_statement.BindInt64(1, delete_begin.ToInternalValue()); | |
173 origin_delete_statement.BindInt64(2, delete_end.ToInternalValue()); | |
174 success &= origin_delete_statement.Run(); | |
vabr (Chromium)
2016/09/08 09:04:36
I'm feeling uncomfortable about mixing bit-wise &
msramek
2016/09/08 10:45:29
Done. Makes sense.
| |
175 } | |
176 | |
177 return success; | |
138 } | 178 } |
139 | 179 |
140 } // namespace password_manager | 180 } // namespace password_manager |
OLD | NEW |