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 "chrome/browser/history/visitsegment_database.h" | 5 #include "chrome/browser/history/visitsegment_database.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <string> | 10 #include <string> |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 insert.BindInt64(2, static_cast<int64>(amount)); | 210 insert.BindInt64(2, static_cast<int64>(amount)); |
211 | 211 |
212 return insert.Run(); | 212 return insert.Run(); |
213 } | 213 } |
214 } | 214 } |
215 | 215 |
216 void VisitSegmentDatabase::QuerySegmentUsage( | 216 void VisitSegmentDatabase::QuerySegmentUsage( |
217 base::Time from_time, | 217 base::Time from_time, |
218 int max_result_count, | 218 int max_result_count, |
219 std::vector<PageUsageData*>* results) { | 219 std::vector<PageUsageData*>* results) { |
| 220 QuerySegmentUsageTimeInterval(from_time, base::Time(), max_result_count, |
| 221 results); |
| 222 } |
| 223 void VisitSegmentDatabase::QuerySegmentUsageTimeInterval( |
| 224 base::Time from_time, |
| 225 base::Time to_time, |
| 226 int max_result_count, |
| 227 std::vector<PageUsageData*>* results) { |
220 // This function gathers the highest-ranked segments in two queries. | 228 // This function gathers the highest-ranked segments in two queries. |
221 // The first gathers scores for all segments. | 229 // The first gathers scores for all segments. |
222 // The second gathers segment data (url, title, etc.) for the highest-ranked | 230 // The second gathers segment data (url, title, etc.) for the highest-ranked |
223 // segments. | 231 // segments. |
224 // TODO(evanm): this disregards the "presentation index", which was what was | 232 // TODO(evanm): this disregards the "presentation index", which was what was |
225 // used to lock results into position. But the rest of our code currently | 233 // used to lock results into position. But the rest of our code currently |
226 // does as well. | 234 // does as well. |
227 | 235 |
228 // Gather all the segment scores. | 236 // Gather all the segment scores. |
229 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 237 sql::Statement statement; |
230 "SELECT segment_id, time_slot, visit_count " | 238 if (to_time.is_null()) { |
231 "FROM segment_usage WHERE time_slot >= ? " | 239 statement.Assign(GetDB().GetCachedStatement(SQL_FROM_HERE, |
232 "ORDER BY segment_id")); | 240 "SELECT segment_id, time_slot, visit_count " |
| 241 "FROM segment_usage WHERE time_slot >= ? " |
| 242 "ORDER BY segment_id")); |
| 243 } else { |
| 244 statement.Assign(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 245 "SELECT segment_id, time_slot, visit_count " |
| 246 "FROM segment_usage WHERE time_slot >= ? AND time_slot <= ?" |
| 247 "ORDER BY segment_id")); |
| 248 } |
233 if (!statement.is_valid()) | 249 if (!statement.is_valid()) |
234 return; | 250 return; |
235 | 251 |
236 base::Time ts = from_time.LocalMidnight(); | 252 base::Time ts = (to_time.is_null()) ? from_time.LocalMidnight() : from_time; |
237 statement.BindInt64(0, ts.ToInternalValue()); | 253 statement.BindInt64(0, ts.ToInternalValue()); |
| 254 if (!to_time.is_null()) |
| 255 statement.BindInt64(1, to_time.ToInternalValue()); |
238 | 256 |
239 base::Time now = base::Time::Now(); | 257 base::Time now = base::Time::Now(); |
240 SegmentID last_segment_id = 0; | 258 SegmentID last_segment_id = 0; |
241 PageUsageData* pud = NULL; | 259 PageUsageData* pud = NULL; |
242 float score = 0; | 260 float score = 0; |
243 while (statement.Step()) { | 261 while (statement.Step()) { |
244 SegmentID segment_id = statement.ColumnInt64(0); | 262 SegmentID segment_id = statement.ColumnInt64(0); |
245 if (segment_id != last_segment_id) { | 263 if (segment_id != last_segment_id) { |
246 if (pud) { | 264 if (pud) { |
247 pud->SetScore(score); | 265 pud->SetScore(score); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 return false; | 350 return false; |
333 | 351 |
334 sql::Statement delete_seg(GetDB().GetCachedStatement(SQL_FROM_HERE, | 352 sql::Statement delete_seg(GetDB().GetCachedStatement(SQL_FROM_HERE, |
335 "DELETE FROM segments WHERE url_id = ?")); | 353 "DELETE FROM segments WHERE url_id = ?")); |
336 delete_seg.BindInt64(0, url_id); | 354 delete_seg.BindInt64(0, url_id); |
337 | 355 |
338 return delete_seg.Run(); | 356 return delete_seg.Run(); |
339 } | 357 } |
340 | 358 |
341 } // namespace history | 359 } // namespace history |
OLD | NEW |