OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/history/core/browser/visitsegment_database.h" | 5 #include "components/history/core/browser/visitsegment_database.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
8 | 10 |
9 #include <algorithm> | 11 #include <algorithm> |
10 #include <string> | 12 #include <string> |
11 #include <vector> | 13 #include <vector> |
12 | 14 |
13 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" |
14 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
15 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
17 #include "components/history/core/browser/page_usage_data.h" | 20 #include "components/history/core/browser/page_usage_data.h" |
18 #include "sql/statement.h" | 21 #include "sql/statement.h" |
19 #include "sql/transaction.h" | 22 #include "sql/transaction.h" |
20 | 23 |
21 // The following tables are used to store url segment information. | 24 // The following tables are used to store url segment information. |
22 // | 25 // |
23 // segments | 26 // segments |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 "WHERE time_slot = ? AND segment_id = ?")); | 178 "WHERE time_slot = ? AND segment_id = ?")); |
176 select.BindInt64(0, t.ToInternalValue()); | 179 select.BindInt64(0, t.ToInternalValue()); |
177 select.BindInt64(1, segment_id); | 180 select.BindInt64(1, segment_id); |
178 | 181 |
179 if (!select.is_valid()) | 182 if (!select.is_valid()) |
180 return false; | 183 return false; |
181 | 184 |
182 if (select.Step()) { | 185 if (select.Step()) { |
183 sql::Statement update(GetDB().GetCachedStatement(SQL_FROM_HERE, | 186 sql::Statement update(GetDB().GetCachedStatement(SQL_FROM_HERE, |
184 "UPDATE segment_usage SET visit_count = ? WHERE id = ?")); | 187 "UPDATE segment_usage SET visit_count = ? WHERE id = ?")); |
185 update.BindInt64(0, select.ColumnInt64(1) + static_cast<int64>(amount)); | 188 update.BindInt64(0, select.ColumnInt64(1) + static_cast<int64_t>(amount)); |
186 update.BindInt64(1, select.ColumnInt64(0)); | 189 update.BindInt64(1, select.ColumnInt64(0)); |
187 | 190 |
188 return update.Run(); | 191 return update.Run(); |
189 } else { | 192 } else { |
190 sql::Statement insert(GetDB().GetCachedStatement(SQL_FROM_HERE, | 193 sql::Statement insert(GetDB().GetCachedStatement(SQL_FROM_HERE, |
191 "INSERT INTO segment_usage " | 194 "INSERT INTO segment_usage " |
192 "(segment_id, time_slot, visit_count) VALUES (?, ?, ?)")); | 195 "(segment_id, time_slot, visit_count) VALUES (?, ?, ?)")); |
193 insert.BindInt64(0, segment_id); | 196 insert.BindInt64(0, segment_id); |
194 insert.BindInt64(1, t.ToInternalValue()); | 197 insert.BindInt64(1, t.ToInternalValue()); |
195 insert.BindInt64(2, static_cast<int64>(amount)); | 198 insert.BindInt64(2, static_cast<int64_t>(amount)); |
196 | 199 |
197 return insert.Run(); | 200 return insert.Run(); |
198 } | 201 } |
199 } | 202 } |
200 | 203 |
201 void VisitSegmentDatabase::QuerySegmentUsage( | 204 void VisitSegmentDatabase::QuerySegmentUsage( |
202 base::Time from_time, | 205 base::Time from_time, |
203 int max_result_count, | 206 int max_result_count, |
204 std::vector<PageUsageData*>* results) { | 207 std::vector<PageUsageData*>* results) { |
205 // This function gathers the highest-ranked segments in two queries. | 208 // This function gathers the highest-ranked segments in two queries. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 "name VARCHAR," | 321 "name VARCHAR," |
319 "url_id INTEGER NON NULL)") && | 322 "url_id INTEGER NON NULL)") && |
320 GetDB().Execute("INSERT INTO segments_tmp SELECT " | 323 GetDB().Execute("INSERT INTO segments_tmp SELECT " |
321 "id, name, url_id FROM segments") && | 324 "id, name, url_id FROM segments") && |
322 GetDB().Execute("DROP TABLE segments") && | 325 GetDB().Execute("DROP TABLE segments") && |
323 GetDB().Execute("ALTER TABLE segments_tmp RENAME TO segments") && | 326 GetDB().Execute("ALTER TABLE segments_tmp RENAME TO segments") && |
324 transaction.Commit(); | 327 transaction.Commit(); |
325 } | 328 } |
326 | 329 |
327 } // namespace history | 330 } // namespace history |
OLD | NEW |