| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/url_database.h" | 5 #include "components/history/core/browser/url_database.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 if (GetDB().DoesTableExist(name)) | 576 if (GetDB().DoesTableExist(name)) |
| 577 return true; | 577 return true; |
| 578 | 578 |
| 579 // Note: revise implementation for InsertOrUpdateURLRowByID() if you add any | 579 // Note: revise implementation for InsertOrUpdateURLRowByID() if you add any |
| 580 // new constraints to the schema. | 580 // new constraints to the schema. |
| 581 std::string sql; | 581 std::string sql; |
| 582 sql.append("CREATE TABLE "); | 582 sql.append("CREATE TABLE "); |
| 583 sql.append(name); | 583 sql.append(name); |
| 584 sql.append( | 584 sql.append( |
| 585 "(" | 585 "(" |
| 586 "id INTEGER PRIMARY KEY AUTOINCREMENT," | 586 // The id uses AUTOINCREMENT is for sync propose. Sync uses this |id| as |
| 587 // Using AUTOINCREMENT is for sync propose. Sync uses this |id| as an | 587 // an unique key to identify the URLs. If here did not use AUTOINCREMENT, |
| 588 // unique key to identify the URLs. If here did not use AUTOINCREMENT, and | 588 // and Sync was not working somehow, a ROWID could be deleted and re-used |
| 589 // Sync was not working somehow, a ROWID could be deleted and re-used | |
| 590 // during this period. Once Sync come back, Sync would use ROWIDs and | 589 // during this period. Once Sync come back, Sync would use ROWIDs and |
| 591 // timestamps to see if there are any updates need to be synced. And sync | 590 // timestamps to see if there are any updates need to be synced. And sync |
| 592 // will only see the new URL, but missed the deleted URL. | 591 // will only see the new URL, but missed the deleted URL. |
| 592 // |
| 593 // IMPORTANT NOTE: Currently new tables are created with AUTOINCREMENT |
| 594 // but the migration code is disabled. This means that you will not |
| 595 // be able to count on AUTOINCREMENT behavior without adding |
| 596 // additional migration steps. |
| 597 // |
| 598 // Along with this, an unused favicon_id column will exist for tables |
| 599 // without AUTOINCREMENT. This should be removed everywhere. |
| 600 // |
| 601 // TODO(https://crbug.com/736136) figure out how to update users to use |
| 602 // AUTOINCREMENT and remove the favicon_id column consistently. |
| 603 "id INTEGER PRIMARY KEY AUTOINCREMENT," |
| 593 "url LONGVARCHAR," | 604 "url LONGVARCHAR," |
| 594 "title LONGVARCHAR," | 605 "title LONGVARCHAR," |
| 595 "visit_count INTEGER DEFAULT 0 NOT NULL," | 606 "visit_count INTEGER DEFAULT 0 NOT NULL," |
| 596 "typed_count INTEGER DEFAULT 0 NOT NULL," | 607 "typed_count INTEGER DEFAULT 0 NOT NULL," |
| 597 "last_visit_time INTEGER NOT NULL," | 608 "last_visit_time INTEGER NOT NULL," |
| 598 "hidden INTEGER DEFAULT 0 NOT NULL)"); | 609 "hidden INTEGER DEFAULT 0 NOT NULL)"); |
| 610 // IMPORTANT: If you change the colums, also update in_memory_database.cc |
| 611 // where the values are copied (InitFromDisk). |
| 599 | 612 |
| 600 return GetDB().Execute(sql.c_str()); | 613 return GetDB().Execute(sql.c_str()); |
| 601 } | 614 } |
| 602 | 615 |
| 603 bool URLDatabase::CreateMainURLIndex() { | 616 bool URLDatabase::CreateMainURLIndex() { |
| 604 return GetDB().Execute( | 617 return GetDB().Execute( |
| 605 "CREATE INDEX IF NOT EXISTS urls_url_index ON urls (url)"); | 618 "CREATE INDEX IF NOT EXISTS urls_url_index ON urls (url)"); |
| 606 } | 619 } |
| 607 | 620 |
| 608 bool URLDatabase::RecreateURLTableWithAllContents() { | 621 bool URLDatabase::RecreateURLTableWithAllContents() { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 bool RowQualifiesAsSignificant(const URLRow& row, | 653 bool RowQualifiesAsSignificant(const URLRow& row, |
| 641 const base::Time& threshold) { | 654 const base::Time& threshold) { |
| 642 const base::Time& real_threshold = | 655 const base::Time& real_threshold = |
| 643 threshold.is_null() ? AutocompleteAgeThreshold() : threshold; | 656 threshold.is_null() ? AutocompleteAgeThreshold() : threshold; |
| 644 return (row.typed_count() >= kLowQualityMatchTypedLimit) || | 657 return (row.typed_count() >= kLowQualityMatchTypedLimit) || |
| 645 (row.visit_count() >= kLowQualityMatchVisitLimit) || | 658 (row.visit_count() >= kLowQualityMatchVisitLimit) || |
| 646 (row.last_visit() >= real_threshold); | 659 (row.last_visit() >= real_threshold); |
| 647 } | 660 } |
| 648 | 661 |
| 649 } // namespace history | 662 } // namespace history |
| OLD | NEW |