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