OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/affiliation_database.h" | 5 #include "components/password_manager/core/browser/affiliation_database.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
7 #include "base/bind.h" | 9 #include "base/bind.h" |
8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
9 #include "sql/connection.h" | 11 #include "sql/connection.h" |
10 #include "sql/error_delegate_util.h" | 12 #include "sql/error_delegate_util.h" |
11 #include "sql/meta_table.h" | 13 #include "sql/meta_table.h" |
12 #include "sql/statement.h" | 14 #include "sql/statement.h" |
13 #include "sql/transaction.h" | 15 #include "sql/transaction.h" |
14 | 16 |
15 namespace password_manager { | 17 namespace password_manager { |
16 | 18 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 DCHECK(results); | 89 DCHECK(results); |
88 results->clear(); | 90 results->clear(); |
89 | 91 |
90 sql::Statement statement(sql_connection_->GetCachedStatement( | 92 sql::Statement statement(sql_connection_->GetCachedStatement( |
91 SQL_FROM_HERE, | 93 SQL_FROM_HERE, |
92 "SELECT m.facet_uri, c.last_update_time, c.id " | 94 "SELECT m.facet_uri, c.last_update_time, c.id " |
93 "FROM eq_class_members m, eq_classes c " | 95 "FROM eq_class_members m, eq_classes c " |
94 "WHERE m.set_id = c.id " | 96 "WHERE m.set_id = c.id " |
95 "ORDER BY c.id")); | 97 "ORDER BY c.id")); |
96 | 98 |
97 int64 last_eq_class_id = 0; | 99 int64_t last_eq_class_id = 0; |
98 while (statement.Step()) { | 100 while (statement.Step()) { |
99 int64 eq_class_id = statement.ColumnInt64(2); | 101 int64_t eq_class_id = statement.ColumnInt64(2); |
100 if (results->empty() || eq_class_id != last_eq_class_id) { | 102 if (results->empty() || eq_class_id != last_eq_class_id) { |
101 results->push_back(AffiliatedFacetsWithUpdateTime()); | 103 results->push_back(AffiliatedFacetsWithUpdateTime()); |
102 last_eq_class_id = eq_class_id; | 104 last_eq_class_id = eq_class_id; |
103 } | 105 } |
104 results->back().facets.push_back( | 106 results->back().facets.push_back( |
105 FacetURI::FromCanonicalSpec(statement.ColumnString(0))); | 107 FacetURI::FromCanonicalSpec(statement.ColumnString(0))); |
106 results->back().last_update_time = | 108 results->back().last_update_time = |
107 base::Time::FromInternalValue(statement.ColumnInt64(1)); | 109 base::Time::FromInternalValue(statement.ColumnInt64(1)); |
108 } | 110 } |
109 } | 111 } |
110 | 112 |
111 void AffiliationDatabase::DeleteAffiliationsForFacet( | 113 void AffiliationDatabase::DeleteAffiliationsForFacet( |
112 const FacetURI& facet_uri) { | 114 const FacetURI& facet_uri) { |
113 sql::Transaction transaction(sql_connection_.get()); | 115 sql::Transaction transaction(sql_connection_.get()); |
114 if (!transaction.Begin()) | 116 if (!transaction.Begin()) |
115 return; | 117 return; |
116 | 118 |
117 sql::Statement statement_lookup(sql_connection_->GetCachedStatement( | 119 sql::Statement statement_lookup(sql_connection_->GetCachedStatement( |
118 SQL_FROM_HERE, | 120 SQL_FROM_HERE, |
119 "SELECT m.set_id FROM eq_class_members m " | 121 "SELECT m.set_id FROM eq_class_members m " |
120 "WHERE m.facet_uri = ?")); | 122 "WHERE m.facet_uri = ?")); |
121 statement_lookup.BindString(0, facet_uri.canonical_spec()); | 123 statement_lookup.BindString(0, facet_uri.canonical_spec()); |
122 | 124 |
123 // No such |facet_uri|, nothing to do. | 125 // No such |facet_uri|, nothing to do. |
124 if (!statement_lookup.Step()) | 126 if (!statement_lookup.Step()) |
125 return; | 127 return; |
126 | 128 |
127 int64 eq_class_id = statement_lookup.ColumnInt64(0); | 129 int64_t eq_class_id = statement_lookup.ColumnInt64(0); |
128 | 130 |
129 // Children will get deleted due to 'ON DELETE CASCADE'. | 131 // Children will get deleted due to 'ON DELETE CASCADE'. |
130 sql::Statement statement_parent(sql_connection_->GetCachedStatement( | 132 sql::Statement statement_parent(sql_connection_->GetCachedStatement( |
131 SQL_FROM_HERE, "DELETE FROM eq_classes WHERE eq_classes.id = ?")); | 133 SQL_FROM_HERE, "DELETE FROM eq_classes WHERE eq_classes.id = ?")); |
132 statement_parent.BindInt64(0, eq_class_id); | 134 statement_parent.BindInt64(0, eq_class_id); |
133 if (!statement_parent.Run()) | 135 if (!statement_parent.Run()) |
134 return; | 136 return; |
135 | 137 |
136 transaction.Commit(); | 138 transaction.Commit(); |
137 } | 139 } |
(...skipping 29 matching lines...) Expand all Loading... |
167 | 169 |
168 sql::Transaction transaction(sql_connection_.get()); | 170 sql::Transaction transaction(sql_connection_.get()); |
169 if (!transaction.Begin()) | 171 if (!transaction.Begin()) |
170 return false; | 172 return false; |
171 | 173 |
172 statement_parent.BindInt64( | 174 statement_parent.BindInt64( |
173 0, affiliated_facets.last_update_time.ToInternalValue()); | 175 0, affiliated_facets.last_update_time.ToInternalValue()); |
174 if (!statement_parent.Run()) | 176 if (!statement_parent.Run()) |
175 return false; | 177 return false; |
176 | 178 |
177 int64 eq_class_id = sql_connection_->GetLastInsertRowId(); | 179 int64_t eq_class_id = sql_connection_->GetLastInsertRowId(); |
178 for (const FacetURI& uri : affiliated_facets.facets) { | 180 for (const FacetURI& uri : affiliated_facets.facets) { |
179 statement_child.Reset(true); | 181 statement_child.Reset(true); |
180 statement_child.BindString(0, uri.canonical_spec()); | 182 statement_child.BindString(0, uri.canonical_spec()); |
181 statement_child.BindInt64(1, eq_class_id); | 183 statement_child.BindInt64(1, eq_class_id); |
182 if (!statement_child.Run()) | 184 if (!statement_child.Run()) |
183 return false; | 185 return false; |
184 } | 186 } |
185 | 187 |
186 return transaction.Commit(); | 188 return transaction.Commit(); |
187 } | 189 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 sql_connection_->RazeAndClose(); | 257 sql_connection_->RazeAndClose(); |
256 return; | 258 return; |
257 } | 259 } |
258 | 260 |
259 // The default handling is to assert on debug and to ignore on release. | 261 // The default handling is to assert on debug and to ignore on release. |
260 if (!sql::Connection::ShouldIgnoreSqliteError(error)) | 262 if (!sql::Connection::ShouldIgnoreSqliteError(error)) |
261 DLOG(FATAL) << sql_connection_->GetErrorMessage(); | 263 DLOG(FATAL) << sql_connection_->GetErrorMessage(); |
262 } | 264 } |
263 | 265 |
264 } // namespace password_manager | 266 } // namespace password_manager |
OLD | NEW |