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

Side by Side Diff: components/history/core/browser/url_database.cc

Issue 1143183002: Proof of concept implementation of context based history filtering. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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
OLDNEW
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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 // Convenience to fill a URLRow. Must be in sync with the fields in 61 // Convenience to fill a URLRow. Must be in sync with the fields in
62 // kURLRowFields. 62 // kURLRowFields.
63 void URLDatabase::FillURLRow(sql::Statement& s, URLRow* i) { 63 void URLDatabase::FillURLRow(sql::Statement& s, URLRow* i) {
64 DCHECK(i); 64 DCHECK(i);
65 i->id_ = s.ColumnInt64(0); 65 i->id_ = s.ColumnInt64(0);
66 i->url_ = GURL(s.ColumnString(1)); 66 i->url_ = GURL(s.ColumnString(1));
67 i->title_ = s.ColumnString16(2); 67 i->title_ = s.ColumnString16(2);
68 i->visit_count_ = s.ColumnInt(3); 68 i->visit_count_ = s.ColumnInt(3);
69 i->typed_count_ = s.ColumnInt(4); 69 i->typed_count_ = s.ColumnInt(4);
70 i->last_visit_ = base::Time::FromInternalValue(s.ColumnInt64(5)); 70 i->last_visit_ = base::Time::FromInternalValue(s.ColumnInt64(5));
71 i->hidden_ = s.ColumnInt(6) != 0; 71 i->context_ = static_cast<history::HistoryContext>(s.ColumnInt(6));
72 i->hidden_ = s.ColumnInt(7) != 0;
72 } 73 }
73 74
74 bool URLDatabase::GetURLRow(URLID url_id, URLRow* info) { 75 bool URLDatabase::GetURLRow(URLID url_id, URLRow* info) {
75 // TODO(brettw) We need check for empty URLs to handle the case where 76 // TODO(brettw) We need check for empty URLs to handle the case where
76 // there are old URLs in the database that are empty that got in before 77 // there are old URLs in the database that are empty that got in before
77 // we added any checks. We should eventually be able to remove it 78 // we added any checks. We should eventually be able to remove it
78 // when all inputs are using GURL (which prohibit empty input). 79 // when all inputs are using GURL (which prohibit empty input).
79 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, 80 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
80 "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls WHERE id=?")); 81 "SELECT" HISTORY_URL_ROW_FIELDS "FROM urls WHERE id=?"));
81 statement.BindInt64(0, url_id); 82 statement.BindInt64(0, url_id);
(...skipping 26 matching lines...) Expand all
108 if (!statement.Step()) 109 if (!statement.Step())
109 return 0; // no data 110 return 0; // no data
110 111
111 if (info) 112 if (info)
112 FillURLRow(statement, info); 113 FillURLRow(statement, info);
113 return statement.ColumnInt64(0); 114 return statement.ColumnInt64(0);
114 } 115 }
115 116
116 bool URLDatabase::UpdateURLRow(URLID url_id, const URLRow& info) { 117 bool URLDatabase::UpdateURLRow(URLID url_id, const URLRow& info) {
117 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE, 118 sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
118 "UPDATE urls SET title=?,visit_count=?,typed_count=?,last_visit_time=?," 119 "UPDATE urls SET title=?,visit_count=?,typed_count=?,last_visit_time=?,con text=?,"
119 "hidden=?" 120 "hidden=?"
120 "WHERE id=?")); 121 "WHERE id=?"));
121 statement.BindString16(0, info.title()); 122 statement.BindString16(0, info.title());
122 statement.BindInt(1, info.visit_count()); 123 statement.BindInt(1, info.visit_count());
123 statement.BindInt(2, info.typed_count()); 124 statement.BindInt(2, info.typed_count());
124 statement.BindInt64(3, info.last_visit().ToInternalValue()); 125 statement.BindInt64(3, info.last_visit().ToInternalValue());
125 statement.BindInt(4, info.hidden() ? 1 : 0); 126 statement.BindInt(4, info.context());
126 statement.BindInt64(5, url_id); 127 statement.BindInt(5, info.hidden() ? 1 : 0);
128 statement.BindInt64(6, url_id);
127 129
128 return statement.Run() && GetDB().GetLastChangeCount() > 0; 130 return statement.Run() && GetDB().GetLastChangeCount() > 0;
129 } 131 }
130 132
131 URLID URLDatabase::AddURLInternal(const URLRow& info, bool is_temporary) { 133 URLID URLDatabase::AddURLInternal(const URLRow& info, bool is_temporary) {
132 // This function is used to insert into two different tables, so we have to 134 // This function is used to insert into two different tables, so we have to
133 // do some shuffling. Unfortinately, we can't use the macro 135 // do some shuffling. Unfortinately, we can't use the macro
134 // HISTORY_URL_ROW_FIELDS because that specifies the table name which is 136 // HISTORY_URL_ROW_FIELDS because that specifies the table name which is
135 // invalid in the insert syntax. 137 // invalid in the insert syntax.
136 #define ADDURL_COMMON_SUFFIX \ 138 #define ADDURL_COMMON_SUFFIX \
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 std::string sql; 598 std::string sql;
597 sql.append("CREATE TABLE "); 599 sql.append("CREATE TABLE ");
598 sql.append(name); 600 sql.append(name);
599 sql.append("(" 601 sql.append("("
600 "id INTEGER PRIMARY KEY," 602 "id INTEGER PRIMARY KEY,"
601 "url LONGVARCHAR," 603 "url LONGVARCHAR,"
602 "title LONGVARCHAR," 604 "title LONGVARCHAR,"
603 "visit_count INTEGER DEFAULT 0 NOT NULL," 605 "visit_count INTEGER DEFAULT 0 NOT NULL,"
604 "typed_count INTEGER DEFAULT 0 NOT NULL," 606 "typed_count INTEGER DEFAULT 0 NOT NULL,"
605 "last_visit_time INTEGER NOT NULL," 607 "last_visit_time INTEGER NOT NULL,"
608 "context INTEGER DEFAULT 0 NOT NULL,"
606 "hidden INTEGER DEFAULT 0 NOT NULL," 609 "hidden INTEGER DEFAULT 0 NOT NULL,"
607 "favicon_id INTEGER DEFAULT 0 NOT NULL)"); // favicon_id is not used now. 610 "favicon_id INTEGER DEFAULT 0 NOT NULL)"); // favicon_id is not used now.
608 611
609 return GetDB().Execute(sql.c_str()); 612 return GetDB().Execute(sql.c_str());
610 } 613 }
611 614
612 bool URLDatabase::CreateMainURLIndex() { 615 bool URLDatabase::CreateMainURLIndex() {
613 return GetDB().Execute( 616 return GetDB().Execute(
614 "CREATE INDEX IF NOT EXISTS urls_url_index ON urls (url)"); 617 "CREATE INDEX IF NOT EXISTS urls_url_index ON urls (url)");
615 } 618 }
(...skipping 10 matching lines...) Expand all
626 bool RowQualifiesAsSignificant(const URLRow& row, 629 bool RowQualifiesAsSignificant(const URLRow& row,
627 const base::Time& threshold) { 630 const base::Time& threshold) {
628 const base::Time& real_threshold = 631 const base::Time& real_threshold =
629 threshold.is_null() ? AutocompleteAgeThreshold() : threshold; 632 threshold.is_null() ? AutocompleteAgeThreshold() : threshold;
630 return (row.typed_count() >= kLowQualityMatchTypedLimit) || 633 return (row.typed_count() >= kLowQualityMatchTypedLimit) ||
631 (row.visit_count() >= kLowQualityMatchVisitLimit) || 634 (row.visit_count() >= kLowQualityMatchVisitLimit) ||
632 (row.last_visit() >= real_threshold); 635 (row.last_visit() >= real_threshold);
633 } 636 }
634 637
635 } // namespace history 638 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/url_database.h ('k') | components/history/core/browser/url_row.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698