Skip to content
Snippets Groups Projects
Commit b78f9432 authored by sky@chromium.org's avatar sky@chromium.org
Browse files

Makes the in memory db update rows that have search terms associated

with them.

BUG=none
TEST=none

Review URL: http://codereview.chromium.org/6135001

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70777 0039d316-1c4b-4281-b951-d872f2087c98
parent 37539c7d
No related branches found
No related tags found
No related merge requests found
......@@ -315,6 +315,12 @@ KeywordSearchTermVisit::KeywordSearchTermVisit() {}
KeywordSearchTermVisit::~KeywordSearchTermVisit() {}
// KeywordSearchTermRow --------------------------------------------------------
KeywordSearchTermRow::KeywordSearchTermRow() : keyword_id(0), url_id(0) {}
KeywordSearchTermRow::~KeywordSearchTermRow() {}
// MostVisitedURL --------------------------------------------------------------
MostVisitedURL::MostVisitedURL() {}
......
......@@ -18,6 +18,7 @@
#include "base/string16.h"
#include "base/time.h"
#include "chrome/browser/history/snippet.h"
#include "chrome/browser/search_engines/template_url_id.h"
#include "chrome/common/page_transition_types.h"
#include "chrome/common/ref_counted_util.h"
#include "chrome/common/thumbnail_score.h"
......@@ -523,6 +524,23 @@ struct KeywordSearchTermVisit {
string16 term;
};
// KeywordSearchTermRow --------------------------------------------------------
// Used for URLs that have a search term associated with them.
struct KeywordSearchTermRow {
KeywordSearchTermRow();
~KeywordSearchTermRow();
// ID of the keyword.
TemplateURLID keyword_id;
// ID of the url.
URLID url_id;
// The search term that was used.
string16 term;
};
// MostVisitedURL --------------------------------------------------------------
// Holds the per-URL information of the most visited query.
......
......@@ -90,7 +90,8 @@ void InMemoryHistoryBackend::Observe(NotificationType type,
PageTransition::Type primary_type =
PageTransition::StripQualifier(visited_details->transition);
if (visited_details->row.typed_count() > 0 ||
primary_type == PageTransition::KEYWORD) {
primary_type == PageTransition::KEYWORD ||
HasKeyword(visited_details->row.url())) {
URLsModifiedDetails modified_details;
modified_details.changed_urls.push_back(visited_details->row);
OnTypedURLsModified(modified_details);
......@@ -186,4 +187,12 @@ void InMemoryHistoryBackend::OnKeywordSearchTermUpdated(
db_->SetKeywordSearchTermsForURL(url_id, details.keyword_id, details.term);
}
bool InMemoryHistoryBackend::HasKeyword(const GURL& url) {
URLID id = db_->GetRowForURL(url, NULL);
if (!id)
return false;
return db_->GetKeywordSearchTermRow(id, NULL);
}
} // namespace history
......@@ -23,6 +23,7 @@
#include "chrome/common/notification_registrar.h"
class FilePath;
class GURL;
class HistoryDatabase;
class Profile;
......@@ -77,6 +78,9 @@ class InMemoryHistoryBackend : public NotificationObserver {
// Handler for HISTORY_KEYWORD_SEARCH_TERM_UPDATED.
void OnKeywordSearchTermUpdated(const KeywordSearchTermDetails& details);
// Returns true if there is a keyword associated with the specified url.
bool HasKeyword(const GURL& url);
NotificationRegistrar registrar_;
scoped_ptr<InMemoryDatabase> db_;
......
......@@ -386,6 +386,26 @@ bool URLDatabase::SetKeywordSearchTermsForURL(URLID url_id,
return statement.Run();
}
bool URLDatabase::GetKeywordSearchTermRow(URLID url_id,
KeywordSearchTermRow* row) {
DCHECK(url_id);
sql::Statement statement(GetDB().GetCachedStatement(SQL_FROM_HERE,
"SELECT keyword_id, term FROM keyword_search_terms WHERE url_id=?"));
if (!statement)
return false;
statement.BindInt64(0, url_id);
if (!statement.Step())
return false;
if (row) {
row->url_id = url_id;
row->keyword_id = statement.ColumnInt64(0);
row->term = statement.ColumnString16(1);
}
return true;
}
void URLDatabase::DeleteAllSearchTermsForKeyword(
TemplateURLID keyword_id) {
DCHECK(keyword_id);
......
......@@ -165,6 +165,10 @@ class URLDatabase {
TemplateURLID keyword_id,
const string16& term);
// Looks up a keyword search term given a url id. Fills row with the data.
// Returns true on success and false otherwise.
bool GetKeywordSearchTermRow(URLID url_id, KeywordSearchTermRow* row);
// Deletes all search terms for the specified keyword that have been added by
// way of SetKeywordSearchTermsForURL.
void DeleteAllSearchTermsForKeyword(TemplateURLID keyword_id);
......
......@@ -136,21 +136,31 @@ TEST_F(URLDatabaseTest, KeywordSearchTermVisit) {
ASSERT_TRUE(url_id != 0);
// Add a keyword visit.
ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, 1, UTF8ToUTF16("visit")));
TemplateURLID keyword_id = 100;
string16 keyword = UTF8ToUTF16("visit");
ASSERT_TRUE(SetKeywordSearchTermsForURL(url_id, keyword_id, keyword));
// Make sure we get it back.
std::vector<KeywordSearchTermVisit> matches;
GetMostRecentKeywordSearchTerms(1, UTF8ToUTF16("visit"), 10, &matches);
GetMostRecentKeywordSearchTerms(keyword_id, keyword, 10, &matches);
ASSERT_EQ(1U, matches.size());
ASSERT_EQ(UTF8ToUTF16("visit"), matches[0].term);
ASSERT_EQ(keyword, matches[0].term);
KeywordSearchTermRow keyword_search_term_row;
ASSERT_TRUE(GetKeywordSearchTermRow(url_id, &keyword_search_term_row));
EXPECT_EQ(keyword_id, keyword_search_term_row.keyword_id);
EXPECT_EQ(url_id, keyword_search_term_row.url_id);
EXPECT_EQ(keyword, keyword_search_term_row.term);
// Delete the keyword visit.
DeleteAllSearchTermsForKeyword(1);
DeleteAllSearchTermsForKeyword(keyword_id);
// Make sure we don't get it back when querying.
matches.clear();
GetMostRecentKeywordSearchTerms(1, UTF8ToUTF16("visit"), 10, &matches);
GetMostRecentKeywordSearchTerms(keyword_id, keyword, 10, &matches);
ASSERT_EQ(0U, matches.size());
ASSERT_FALSE(GetKeywordSearchTermRow(url_id, &keyword_search_term_row));
}
// Make sure deleting a URL also deletes a keyword visit.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment