Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(484)

Side by Side Diff: components/history/core/browser/visit_database.cc

Issue 1370493002: Enable history counting for time ranges. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/visit_database.h" 5 #include "components/history/core/browser/visit_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 } 530 }
531 531
532 if (!statement.Succeeded()) 532 if (!statement.Succeeded())
533 return false; 533 return false;
534 534
535 *first_visit = base::Time::FromInternalValue(statement.ColumnInt64(0)); 535 *first_visit = base::Time::FromInternalValue(statement.ColumnInt64(0));
536 *count = statement.ColumnInt(1); 536 *count = statement.ColumnInt(1);
537 return true; 537 return true;
538 } 538 }
539 539
540 bool VisitDatabase::GetHistoryCount(int* count) { 540 bool VisitDatabase::GetHistoryCount(const base::Time& begin_time,
541 const base::Time& end_time,
542 int* count) {
541 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, 543 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
542 "SELECT COUNT(*) FROM (" 544 "SELECT COUNT(*) FROM ("
543 "SELECT DISTINCT url, " 545 "SELECT DISTINCT url, "
544 // Convert unit of timestamp from the numbers of microseconds since 546 // Convert unit of timestamp from the numbers of microseconds since
545 // Windows Epoch to the number of seconds from Unix Epoch. Leap seconds 547 // Windows Epoch to the number of seconds from Unix Epoch. Leap seconds
546 // are not handled in both timestamp units, so a linear conversion is 548 // are not handled in both timestamp units, so a linear conversion is
547 // valid here. 549 // valid here.
548 "DATE((visit_time - ?) / ?, 'unixepoch', 'localtime') " 550 "DATE((visit_time - ?) / ?, 'unixepoch', 'localtime')"
549 "FROM visits " 551 "FROM visits "
550 "WHERE (transition & ?) != 0 " // CHAIN_END 552 "WHERE (transition & ?) != 0 " // CHAIN_END
551 "AND (transition & ?) NOT IN (?, ?, ?)" // NO SUBFRAME or 553 "AND (transition & ?) NOT IN (?, ?, ?) " // NO SUBFRAME or
552 // KEYWORD_GENERATED 554 // KEYWORD_GENERATED
555 "AND visit_time >= ? AND visit_time < ?"
553 ")")); 556 ")"));
554 557
555 statement.BindInt64(0, base::Time::kTimeTToMicrosecondsOffset); 558 statement.BindInt64(0, base::Time::kTimeTToMicrosecondsOffset);
lwchkg 2015/09/25 04:15:02 Just to remind that you have proposed to change th
msramek 2015/09/25 10:44:35 I keep it in mind, but I'll fix this in a separate
556 statement.BindInt64(1, base::Time::kMicrosecondsPerSecond); 559 statement.BindInt64(1, base::Time::kMicrosecondsPerSecond);
557 statement.BindInt(2, ui::PAGE_TRANSITION_CHAIN_END); 560 statement.BindInt(2, ui::PAGE_TRANSITION_CHAIN_END);
558 statement.BindInt(3, ui::PAGE_TRANSITION_CORE_MASK); 561 statement.BindInt(3, ui::PAGE_TRANSITION_CORE_MASK);
559 statement.BindInt(4, ui::PAGE_TRANSITION_AUTO_SUBFRAME); 562 statement.BindInt(4, ui::PAGE_TRANSITION_AUTO_SUBFRAME);
560 statement.BindInt(5, ui::PAGE_TRANSITION_MANUAL_SUBFRAME); 563 statement.BindInt(5, ui::PAGE_TRANSITION_MANUAL_SUBFRAME);
561 statement.BindInt(6, ui::PAGE_TRANSITION_KEYWORD_GENERATED); 564 statement.BindInt(6, ui::PAGE_TRANSITION_KEYWORD_GENERATED);
565 statement.BindInt64(7, begin_time.ToInternalValue());
566 statement.BindInt64(8, end_time.ToInternalValue());
562 567
563 if (!statement.Step()) 568 if (!statement.Step())
564 return false; 569 return false;
565 570
566 *count = statement.ColumnInt(0); 571 *count = statement.ColumnInt(0);
567 return true; 572 return true;
568 } 573 }
569 574
570 bool VisitDatabase::GetStartDate(base::Time* first_visit) { 575 bool VisitDatabase::GetStartDate(base::Time* first_visit) {
571 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, 576 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 // Old versions don't have the visit_duration column, we modify the table 629 // Old versions don't have the visit_duration column, we modify the table
625 // to add that field. 630 // to add that field.
626 if (!GetDB().Execute("ALTER TABLE visits " 631 if (!GetDB().Execute("ALTER TABLE visits "
627 "ADD COLUMN visit_duration INTEGER DEFAULT 0 NOT NULL")) 632 "ADD COLUMN visit_duration INTEGER DEFAULT 0 NOT NULL"))
628 return false; 633 return false;
629 } 634 }
630 return true; 635 return true;
631 } 636 }
632 637
633 } // namespace history 638 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698