Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(323)

Side by Side Diff: chrome/browser/history/url_database.cc

Issue 7314018: Don't autocomplete searches of >1 word if they've only been visited once and the user has not yet... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/history/url_database.h" 5 #include "chrome/browser/history/url_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 int max_count, 470 int max_count,
471 std::vector<KeywordSearchTermVisit>* matches) { 471 std::vector<KeywordSearchTermVisit>* matches) {
472 // NOTE: the keyword_id can be zero if on first run the user does a query 472 // NOTE: the keyword_id can be zero if on first run the user does a query
473 // before the TemplateURLService has finished loading. As the chances of this 473 // before the TemplateURLService has finished loading. As the chances of this
474 // occurring are small, we ignore it. 474 // occurring are small, we ignore it.
475 if (!keyword_id) 475 if (!keyword_id)
476 return; 476 return;
477 477
478 DCHECK(!prefix.empty()); 478 DCHECK(!prefix.empty());
479 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, 479 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
480 "SELECT DISTINCT kv.term, u.last_visit_time " 480 "SELECT DISTINCT kv.term, u.visit_count, u.last_visit_time "
481 "FROM keyword_search_terms kv " 481 "FROM keyword_search_terms kv "
482 "JOIN urls u ON kv.url_id = u.id " 482 "JOIN urls u ON kv.url_id = u.id "
483 "WHERE kv.keyword_id = ? AND kv.lower_term >= ? AND kv.lower_term < ? " 483 "WHERE kv.keyword_id = ? AND kv.lower_term >= ? AND kv.lower_term < ? "
484 "ORDER BY u.last_visit_time DESC LIMIT ?")); 484 "ORDER BY u.last_visit_time DESC LIMIT ?"));
485 if (!statement) 485 if (!statement)
486 return; 486 return;
487 487
488 // NOTE: Keep this ToLower() call in sync with search_provider.cc. 488 // NOTE: Keep this ToLower() call in sync with search_provider.cc.
489 string16 lower_prefix = base::i18n::ToLower(prefix); 489 string16 lower_prefix = base::i18n::ToLower(prefix);
490 // This magic gives us a prefix search. 490 // This magic gives us a prefix search.
491 string16 next_prefix = lower_prefix; 491 string16 next_prefix = lower_prefix;
492 next_prefix[next_prefix.size() - 1] = 492 next_prefix[next_prefix.size() - 1] =
493 next_prefix[next_prefix.size() - 1] + 1; 493 next_prefix[next_prefix.size() - 1] + 1;
494 statement.BindInt64(0, keyword_id); 494 statement.BindInt64(0, keyword_id);
495 statement.BindString16(1, lower_prefix); 495 statement.BindString16(1, lower_prefix);
496 statement.BindString16(2, next_prefix); 496 statement.BindString16(2, next_prefix);
497 statement.BindInt(3, max_count); 497 statement.BindInt(3, max_count);
498 498
499 KeywordSearchTermVisit visit; 499 KeywordSearchTermVisit visit;
500 while (statement.Step()) { 500 while (statement.Step()) {
501 visit.term = statement.ColumnString16(0); 501 visit.term = statement.ColumnString16(0);
502 visit.time = base::Time::FromInternalValue(statement.ColumnInt64(1)); 502 visit.visits = statement.ColumnInt(1);
503 visit.time = base::Time::FromInternalValue(statement.ColumnInt64(2));
503 matches->push_back(visit); 504 matches->push_back(visit);
504 } 505 }
505 } 506 }
506 507
507 bool URLDatabase::DropStarredIDFromURLs() { 508 bool URLDatabase::DropStarredIDFromURLs() {
508 if (!GetDB().DoesColumnExist("urls", "starred_id")) 509 if (!GetDB().DoesColumnExist("urls", "starred_id"))
509 return true; // urls is already updated, no need to continue. 510 return true; // urls is already updated, no need to continue.
510 511
511 // Create a temporary table to contain the new URLs table. 512 // Create a temporary table to contain the new URLs table.
512 if (!CreateTemporaryURLTable()) { 513 if (!CreateTemporaryURLTable()) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 return GetDB().Execute(sql.c_str()); 552 return GetDB().Execute(sql.c_str());
552 } 553 }
553 554
554 void URLDatabase::CreateMainURLIndex() { 555 void URLDatabase::CreateMainURLIndex() {
555 // Index over URLs so we can quickly look up based on URL. Ignore errors as 556 // Index over URLs so we can quickly look up based on URL. Ignore errors as
556 // this likely already exists (and the same below). 557 // this likely already exists (and the same below).
557 GetDB().Execute("CREATE INDEX urls_url_index ON urls (url)"); 558 GetDB().Execute("CREATE INDEX urls_url_index ON urls (url)");
558 } 559 }
559 560
560 } // namespace history 561 } // namespace history
OLDNEW
« chrome/browser/autocomplete/shortcuts_provider.cc ('K') | « chrome/browser/history/history_types.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698