summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autocomplete/history_url_provider.cc2
-rw-r--r--chrome/browser/history/archived_database.cc1
-rw-r--r--chrome/browser/history/history_database.cc2
-rw-r--r--chrome/browser/history/in_memory_database.cc39
-rw-r--r--chrome/browser/history/url_database.cc28
-rw-r--r--chrome/browser/history/url_database.h9
-rw-r--r--chrome/browser/history/url_database_unittest.cc1
7 files changed, 72 insertions, 10 deletions
diff --git a/chrome/browser/autocomplete/history_url_provider.cc b/chrome/browser/autocomplete/history_url_provider.cc
index 0f75347..fd5b8fb 100644
--- a/chrome/browser/autocomplete/history_url_provider.cc
+++ b/chrome/browser/autocomplete/history_url_provider.cc
@@ -243,7 +243,7 @@ void HistoryURLProvider::DoAutocomplete(history::HistoryBackend* backend,
// give us far more than enough to work with. CullRedirects() will then
// reduce the list to the best kMaxMatches results.
db->AutocompleteForPrefix(WideToUTF16(i->prefix + params->input.text()),
- kMaxMatches * 2, &url_matches);
+ kMaxMatches * 2, (backend == NULL), &url_matches);
for (URLRowVector::const_iterator j(url_matches.begin());
j != url_matches.end(); ++j) {
const Prefix* best_prefix = BestPrefix(j->url(), std::wstring());
diff --git a/chrome/browser/history/archived_database.cc b/chrome/browser/history/archived_database.cc
index 72fa998..08a742f 100644
--- a/chrome/browser/history/archived_database.cc
+++ b/chrome/browser/history/archived_database.cc
@@ -62,6 +62,7 @@ bool ArchivedDatabase::Init(const FilePath& file_name) {
return false;
}
CreateMainURLIndex();
+ CreateKeywordSearchTermsIndices();
if (EnsureCurrentVersion() != sql::INIT_OK) {
db_.Close();
diff --git a/chrome/browser/history/history_database.cc b/chrome/browser/history/history_database.cc
index 3e03504..f0c546c 100644
--- a/chrome/browser/history/history_database.cc
+++ b/chrome/browser/history/history_database.cc
@@ -119,6 +119,7 @@ sql::InitStatus HistoryDatabase::Init(const FilePath& history_name,
!InitSegmentTables())
return sql::INIT_FAILURE;
CreateMainURLIndex();
+ CreateKeywordSearchTermsIndices();
CreateSupplimentaryURLIndices();
// Version check.
@@ -169,6 +170,7 @@ bool HistoryDatabase::RecreateAllTablesButURL() {
// over parts of the URL table that weren't automatically created when the
// temporary URL table was
CreateSupplimentaryURLIndices();
+ CreateKeywordSearchTermsIndices();
return true;
}
diff --git a/chrome/browser/history/in_memory_database.cc b/chrome/browser/history/in_memory_database.cc
index 3227a7a..168a544 100644
--- a/chrome/browser/history/in_memory_database.cc
+++ b/chrome/browser/history/in_memory_database.cc
@@ -41,6 +41,13 @@ bool InMemoryDatabase::InitDB() {
return false;
}
+ // Create the keyword search terms table.
+ if (!InitKeywordSearchTermsTable()) {
+ NOTREACHED() << "Unable to create keyword search terms";
+ db_.Close();
+ return false;
+ }
+
return true;
}
@@ -51,6 +58,7 @@ bool InMemoryDatabase::InitFromScratch() {
// InitDB doesn't create the index so in the disk-loading case, it can be
// added afterwards.
CreateMainURLIndex();
+ CreateKeywordSearchTermsIndices();
return true;
}
@@ -87,6 +95,36 @@ bool InMemoryDatabase::InitFromDisk(const FilePath& history_name) {
end_load - begin_load);
UMA_HISTOGRAM_COUNTS("History.InMemoryDBItemCount", db_.GetLastChangeCount());
+ // Insert keyword search related URLs.
+ begin_load = base::TimeTicks::Now();
+ if (!db_.Execute(
+ "INSERT INTO urls SELECT u.id, u.url, u.title, u.visit_count, "
+ "u.typed_count, u.last_visit_time, u.hidden, u.favicon_id "
+ "FROM history.urls u JOIN history.keyword_search_terms kst "
+ "WHERE u.typed_count = 0 AND u.id = kst.url_id")) {
+ // Unable to get data from the history database. This is OK, the file may
+ // just not exist yet.
+ }
+ end_load = base::TimeTicks::Now();
+ UMA_HISTOGRAM_MEDIUM_TIMES("History.InMemoryDBKeywordURLPopulate",
+ end_load - begin_load);
+ UMA_HISTOGRAM_COUNTS("History.InMemoryDBKeywordURLItemCount",
+ db_.GetLastChangeCount());
+
+ // Copy search terms to memory.
+ begin_load = base::TimeTicks::Now();
+ if (!db_.Execute(
+ "INSERT INTO keyword_search_terms SELECT * FROM "
+ "history.keyword_search_terms")) {
+ // Unable to get data from the history database. This is OK, the file may
+ // just not exist yet.
+ }
+ end_load = base::TimeTicks::Now();
+ UMA_HISTOGRAM_MEDIUM_TIMES("History.InMemoryDBKeywordTermsPopulate",
+ end_load - begin_load);
+ UMA_HISTOGRAM_COUNTS("History.InMemoryDBKeywordTermsCount",
+ db_.GetLastChangeCount());
+
// Detach from the history database on disk.
if (!db_.Execute("DETACH history")) {
NOTREACHED() << "Unable to detach from history database.";
@@ -96,6 +134,7 @@ bool InMemoryDatabase::InitFromDisk(const FilePath& history_name) {
// Index the table, this is faster than creating the index first and then
// inserting into it.
CreateMainURLIndex();
+ CreateKeywordSearchTermsIndices();
return true;
}
diff --git a/chrome/browser/history/url_database.cc b/chrome/browser/history/url_database.cc
index b63d24a..3f297bd 100644
--- a/chrome/browser/history/url_database.cc
+++ b/chrome/browser/history/url_database.cc
@@ -247,16 +247,29 @@ bool URLDatabase::IsFavIconUsed(FavIconID favicon_id) {
void URLDatabase::AutocompleteForPrefix(const string16& prefix,
size_t max_results,
+ bool typed_only,
std::vector<history::URLRow>* results) {
// NOTE: this query originally sorted by starred as the second parameter. But
// as bookmarks is no longer part of the db we no longer include the order
// by clause.
results->clear();
- sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
- "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls "
- "WHERE url >= ? AND url < ? AND hidden = 0 "
- "ORDER BY typed_count DESC, visit_count DESC, last_visit_time DESC "
- "LIMIT ?"));
+ const char* sql;
+ int line;
+ if (typed_only) {
+ sql = "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls "
+ "WHERE url >= ? AND url < ? AND hidden = 0 AND typed_count > 0 "
+ "ORDER BY typed_count DESC, visit_count DESC, last_visit_time DESC "
+ "LIMIT ?";
+ line = __LINE__;
+ } else {
+ sql = "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls "
+ "WHERE url >= ? AND url < ? AND hidden = 0 "
+ "ORDER BY typed_count DESC, visit_count DESC, last_visit_time DESC "
+ "LIMIT ?";
+ line = __LINE__;
+ }
+ sql::Statement statement(
+ GetDB().GetCachedStatement(sql::StatementID(__FILE__, line), sql));
if (!statement)
return;
@@ -327,7 +340,10 @@ bool URLDatabase::InitKeywordSearchTermsTable() {
"term LONGVARCHAR NOT NULL)")) // The actual search term.
return false;
}
+ return true;
+}
+void URLDatabase::CreateKeywordSearchTermsIndices() {
// For searching.
GetDB().Execute("CREATE INDEX keyword_search_terms_index1 ON "
"keyword_search_terms (keyword_id, lower_term)");
@@ -335,8 +351,6 @@ bool URLDatabase::InitKeywordSearchTermsTable() {
// For deletion.
GetDB().Execute("CREATE INDEX keyword_search_terms_index2 ON "
"keyword_search_terms (url_id)");
-
- return true;
}
bool URLDatabase::DropKeywordSearchTermsTable() {
diff --git a/chrome/browser/history/url_database.h b/chrome/browser/history/url_database.h
index 36bfebb..49bf5f0 100644
--- a/chrome/browser/history/url_database.h
+++ b/chrome/browser/history/url_database.h
@@ -138,10 +138,12 @@ class URLDatabase {
// Autocomplete --------------------------------------------------------------
// Fills the given array with URLs matching the given prefix. They will be
- // sorted by typed count, then by visit count, then by visit date (most
- // recent first) up to the given maximum number. Called by HistoryURLProvider.
+ // sorted by typed count, then by visit count, then by visit date (most recent
+ // first) up to the given maximum number. If |typed_only| is true, only urls
+ // that have been typed once are returned. Called by HistoryURLProvider.
void AutocompleteForPrefix(const string16& prefix,
size_t max_results,
+ bool typed_only,
std::vector<URLRow>* results);
// Tries to find the shortest URL beginning with |base| that strictly
@@ -218,6 +220,9 @@ class URLDatabase {
// Ensures the keyword search terms table exists.
bool InitKeywordSearchTermsTable();
+ // Creates the indices used for keyword search terms.
+ void CreateKeywordSearchTermsIndices();
+
// Deletes the keyword search terms table.
bool DropKeywordSearchTermsTable();
diff --git a/chrome/browser/history/url_database_unittest.cc b/chrome/browser/history/url_database_unittest.cc
index f567844..c37323f 100644
--- a/chrome/browser/history/url_database_unittest.cc
+++ b/chrome/browser/history/url_database_unittest.cc
@@ -52,6 +52,7 @@ class URLDatabaseTest : public testing::Test,
CreateMainURLIndex();
CreateSupplimentaryURLIndices();
InitKeywordSearchTermsTable();
+ CreateKeywordSearchTermsIndices();
}
void TearDown() {
db_.Close();