Index: components/history/core/browser/visit_database.cc |
diff --git a/components/history/core/browser/visit_database.cc b/components/history/core/browser/visit_database.cc |
index 6d5819c36621ae11058b478811aaca64af2736e8..3d4e7159197c182e6c4b32485aa41a05a07b7720 100644 |
--- a/components/history/core/browser/visit_database.cc |
+++ b/components/history/core/browser/visit_database.cc |
@@ -11,6 +11,7 @@ |
#include "base/logging.h" |
#include "base/strings/string_number_conversions.h" |
+#include "base/time/time.h" |
#include "components/history/core/browser/url_database.h" |
#include "components/history/core/browser/visit_filter.h" |
#include "sql/statement.h" |
@@ -536,6 +537,36 @@ bool VisitDatabase::GetVisibleVisitCountToHost(const GURL& url, |
return true; |
} |
+bool VisitDatabase::GetHistoryCount(int* count) { |
+ sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
+ "SELECT COUNT(*) FROM (" |
+ "SELECT DISTINCT url, " |
+ // Convert unit of timestamp from the numbers of microseconds since |
+ // Windows Epoch to the number of seconds from Unix Epoch. Leap seconds |
+ // are not handled in both timestamp units, so a linear conversion is |
+ // valid here. |
+ "DATE((visit_time - ?) / ?, 'unixepoch', 'localtime') " |
+ "FROM visits " |
+ "WHERE (transition & ?) != 0 " // CHAIN_END |
+ "AND (transition & ?) NOT IN (?, ?, ?)" // NO SUBFRAME or |
+ // KEYWORD_GENERATED |
+ ")")); |
+ |
+ statement.BindInt64(0, base::Time::kTimeTToMicrosecondsOffset); |
+ statement.BindInt64(1, base::Time::kMicrosecondsPerSecond); |
+ statement.BindInt(2, ui::PAGE_TRANSITION_CHAIN_END); |
+ statement.BindInt(3, ui::PAGE_TRANSITION_CORE_MASK); |
+ statement.BindInt(4, ui::PAGE_TRANSITION_AUTO_SUBFRAME); |
+ statement.BindInt(5, ui::PAGE_TRANSITION_MANUAL_SUBFRAME); |
+ statement.BindInt(6, ui::PAGE_TRANSITION_KEYWORD_GENERATED); |
+ |
+ if (!statement.Step()) |
+ return false; |
+ |
+ *count = statement.ColumnInt(0); |
+ return true; |
+} |
+ |
bool VisitDatabase::GetStartDate(base::Time* first_visit) { |
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
"SELECT MIN(visit_time) FROM visits WHERE visit_time != 0")); |