| 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/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> |
| 11 | 11 |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/time/time.h" |
| 14 #include "components/history/core/browser/url_database.h" | 15 #include "components/history/core/browser/url_database.h" |
| 15 #include "components/history/core/browser/visit_filter.h" | 16 #include "components/history/core/browser/visit_filter.h" |
| 16 #include "sql/statement.h" | 17 #include "sql/statement.h" |
| 17 #include "ui/base/page_transition_types.h" | 18 #include "ui/base/page_transition_types.h" |
| 18 #include "url/url_constants.h" | 19 #include "url/url_constants.h" |
| 19 | 20 |
| 20 namespace history { | 21 namespace history { |
| 21 | 22 |
| 22 VisitDatabase::VisitDatabase() { | 23 VisitDatabase::VisitDatabase() { |
| 23 } | 24 } |
| (...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 } | 530 } |
| 530 | 531 |
| 531 if (!statement.Succeeded()) | 532 if (!statement.Succeeded()) |
| 532 return false; | 533 return false; |
| 533 | 534 |
| 534 *first_visit = base::Time::FromInternalValue(statement.ColumnInt64(0)); | 535 *first_visit = base::Time::FromInternalValue(statement.ColumnInt64(0)); |
| 535 *count = statement.ColumnInt(1); | 536 *count = statement.ColumnInt(1); |
| 536 return true; | 537 return true; |
| 537 } | 538 } |
| 538 | 539 |
| 540 bool VisitDatabase::GetHistoryCount(int* count) { |
| 541 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 542 "SELECT COUNT(*) FROM (" |
| 543 "SELECT DISTINCT url, " |
| 544 // Convert unit of timestamp from the numbers of microseconds since |
| 545 // 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 |
| 547 // valid here. |
| 548 "DATE((visit_time - ?) / ?, 'unixepoch', 'localtime') " |
| 549 "FROM visits " |
| 550 "WHERE (transition & ?) != 0 " // CHAIN_END |
| 551 "AND (transition & ?) NOT IN (?, ?, ?)" // NO SUBFRAME or |
| 552 // KEYWORD_GENERATED |
| 553 ")")); |
| 554 |
| 555 statement.BindInt64(0, base::Time::kTimeTToMicrosecondsOffset); |
| 556 statement.BindInt64(1, base::Time::kMicrosecondsPerSecond); |
| 557 statement.BindInt(2, ui::PAGE_TRANSITION_CHAIN_END); |
| 558 statement.BindInt(3, ui::PAGE_TRANSITION_CORE_MASK); |
| 559 statement.BindInt(4, ui::PAGE_TRANSITION_AUTO_SUBFRAME); |
| 560 statement.BindInt(5, ui::PAGE_TRANSITION_MANUAL_SUBFRAME); |
| 561 statement.BindInt(6, ui::PAGE_TRANSITION_KEYWORD_GENERATED); |
| 562 |
| 563 if (!statement.Step()) |
| 564 return false; |
| 565 |
| 566 *count = statement.ColumnInt(0); |
| 567 return true; |
| 568 } |
| 569 |
| 539 bool VisitDatabase::GetStartDate(base::Time* first_visit) { | 570 bool VisitDatabase::GetStartDate(base::Time* first_visit) { |
| 540 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, | 571 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, |
| 541 "SELECT MIN(visit_time) FROM visits WHERE visit_time != 0")); | 572 "SELECT MIN(visit_time) FROM visits WHERE visit_time != 0")); |
| 542 if (!statement.Step() || statement.ColumnInt64(0) == 0) { | 573 if (!statement.Step() || statement.ColumnInt64(0) == 0) { |
| 543 *first_visit = base::Time::Now(); | 574 *first_visit = base::Time::Now(); |
| 544 return false; | 575 return false; |
| 545 } | 576 } |
| 546 *first_visit = base::Time::FromInternalValue(statement.ColumnInt64(0)); | 577 *first_visit = base::Time::FromInternalValue(statement.ColumnInt64(0)); |
| 547 return true; | 578 return true; |
| 548 } | 579 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 593 // Old versions don't have the visit_duration column, we modify the table | 624 // Old versions don't have the visit_duration column, we modify the table |
| 594 // to add that field. | 625 // to add that field. |
| 595 if (!GetDB().Execute("ALTER TABLE visits " | 626 if (!GetDB().Execute("ALTER TABLE visits " |
| 596 "ADD COLUMN visit_duration INTEGER DEFAULT 0 NOT NULL")) | 627 "ADD COLUMN visit_duration INTEGER DEFAULT 0 NOT NULL")) |
| 597 return false; | 628 return false; |
| 598 } | 629 } |
| 599 return true; | 630 return true; |
| 600 } | 631 } |
| 601 | 632 |
| 602 } // namespace history | 633 } // namespace history |
| OLD | NEW |