diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-07 21:08:38 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-07 21:08:38 +0000 |
commit | b78f94325babe6b0e01812ffef36b57aeb45bfa7 (patch) | |
tree | 00bb3eeaf412ae836a3d397e56d37790f87ce500 | |
parent | 37539c7dafc27daba389bee4d0d2e137aae5f91e (diff) | |
download | chromium_src-b78f94325babe6b0e01812ffef36b57aeb45bfa7.zip chromium_src-b78f94325babe6b0e01812ffef36b57aeb45bfa7.tar.gz chromium_src-b78f94325babe6b0e01812ffef36b57aeb45bfa7.tar.bz2 |
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
-rw-r--r-- | chrome/browser/history/history_types.cc | 6 | ||||
-rw-r--r-- | chrome/browser/history/history_types.h | 18 | ||||
-rw-r--r-- | chrome/browser/history/in_memory_history_backend.cc | 11 | ||||
-rw-r--r-- | chrome/browser/history/in_memory_history_backend.h | 4 | ||||
-rw-r--r-- | chrome/browser/history/url_database.cc | 20 | ||||
-rw-r--r-- | chrome/browser/history/url_database.h | 4 | ||||
-rw-r--r-- | chrome/browser/history/url_database_unittest.cc | 20 |
7 files changed, 77 insertions, 6 deletions
diff --git a/chrome/browser/history/history_types.cc b/chrome/browser/history/history_types.cc index 05d9a72..ecc8314 100644 --- a/chrome/browser/history/history_types.cc +++ b/chrome/browser/history/history_types.cc @@ -315,6 +315,12 @@ KeywordSearchTermVisit::KeywordSearchTermVisit() {} KeywordSearchTermVisit::~KeywordSearchTermVisit() {} +// KeywordSearchTermRow -------------------------------------------------------- + +KeywordSearchTermRow::KeywordSearchTermRow() : keyword_id(0), url_id(0) {} + +KeywordSearchTermRow::~KeywordSearchTermRow() {} + // MostVisitedURL -------------------------------------------------------------- MostVisitedURL::MostVisitedURL() {} diff --git a/chrome/browser/history/history_types.h b/chrome/browser/history/history_types.h index bc28dd1..76359fc 100644 --- a/chrome/browser/history/history_types.h +++ b/chrome/browser/history/history_types.h @@ -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. diff --git a/chrome/browser/history/in_memory_history_backend.cc b/chrome/browser/history/in_memory_history_backend.cc index 978c8c4..25219f6 100644 --- a/chrome/browser/history/in_memory_history_backend.cc +++ b/chrome/browser/history/in_memory_history_backend.cc @@ -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 diff --git a/chrome/browser/history/in_memory_history_backend.h b/chrome/browser/history/in_memory_history_backend.h index c775800..6e56636 100644 --- a/chrome/browser/history/in_memory_history_backend.h +++ b/chrome/browser/history/in_memory_history_backend.h @@ -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_; diff --git a/chrome/browser/history/url_database.cc b/chrome/browser/history/url_database.cc index 3f297bd..dd3346b 100644 --- a/chrome/browser/history/url_database.cc +++ b/chrome/browser/history/url_database.cc @@ -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); diff --git a/chrome/browser/history/url_database.h b/chrome/browser/history/url_database.h index 49bf5f0..ae1d7cd 100644 --- a/chrome/browser/history/url_database.h +++ b/chrome/browser/history/url_database.h @@ -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); diff --git a/chrome/browser/history/url_database_unittest.cc b/chrome/browser/history/url_database_unittest.cc index c37323f..b164e48 100644 --- a/chrome/browser/history/url_database_unittest.cc +++ b/chrome/browser/history/url_database_unittest.cc @@ -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. |