summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-04 16:23:17 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-04 16:23:17 +0000
commite14e05c948c2ff602fcc6a1137c5c61d112cb38f (patch)
tree80e11edbf6becb56143a2696005bc6d6bc9cde49 /chrome/browser/history
parent4a842345af02ac3ae84015683383539a84f66d8c (diff)
downloadchromium_src-e14e05c948c2ff602fcc6a1137c5c61d112cb38f.zip
chromium_src-e14e05c948c2ff602fcc6a1137c5c61d112cb38f.tar.gz
chromium_src-e14e05c948c2ff602fcc6a1137c5c61d112cb38f.tar.bz2
Makes the in memory db update keyword search terms.
BUG=61518 TEST=none Review URL: http://codereview.chromium.org/4449002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65065 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/history')
-rw-r--r--chrome/browser/history/history.cc55
-rw-r--r--chrome/browser/history/history_backend.cc8
-rw-r--r--chrome/browser/history/history_notifications.cc4
-rw-r--r--chrome/browser/history/history_notifications.h11
-rw-r--r--chrome/browser/history/in_memory_history_backend.cc39
-rw-r--r--chrome/browser/history/in_memory_history_backend.h4
6 files changed, 97 insertions, 24 deletions
diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc
index 278df31..3a5ae85 100644
--- a/chrome/browser/history/history.cc
+++ b/chrome/browser/history/history.cc
@@ -145,6 +145,8 @@ HistoryService::HistoryService(Profile* profile)
needs_top_sites_migration_(false) {
registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED,
Source<Profile>(profile_));
+ registrar_.Add(this, NotificationType::TEMPLATE_URL_REMOVED,
+ Source<Profile>(profile_));
}
HistoryService::~HistoryService() {
@@ -611,30 +613,37 @@ HistoryService::Handle HistoryService::QueryMostVisitedURLs(
void HistoryService::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- if (type != NotificationType::HISTORY_URLS_DELETED) {
- NOTREACHED();
- return;
- }
+ switch (type.value) {
+ case NotificationType::HISTORY_URLS_DELETED: {
+ // Update the visited link system for deleted URLs. We will update the
+ // visited link system for added URLs as soon as we get the add
+ // notification (we don't have to wait for the backend, which allows us to
+ // be faster to update the state).
+ //
+ // For deleted URLs, we don't typically know what will be deleted since
+ // delete notifications are by time. We would also like to be more
+ // respectful of privacy and never tell the user something is gone when it
+ // isn't. Therefore, we update the delete URLs after the fact.
+ if (!profile_)
+ return; // No profile, probably unit testing.
+ Details<history::URLsDeletedDetails> deleted_details(details);
+ VisitedLinkMaster* visited_links = profile_->GetVisitedLinkMaster();
+ if (!visited_links)
+ return; // Nobody to update.
+ if (deleted_details->all_history)
+ visited_links->DeleteAllURLs();
+ else // Delete individual ones.
+ visited_links->DeleteURLs(deleted_details->urls);
+ break;
+ }
- // Update the visited link system for deleted URLs. We will update the
- // visited link system for added URLs as soon as we get the add
- // notification (we don't have to wait for the backend, which allows us to
- // be faster to update the state).
- //
- // For deleted URLs, we don't typically know what will be deleted since
- // delete notifications are by time. We would also like to be more
- // respectful of privacy and never tell the user something is gone when it
- // isn't. Therefore, we update the delete URLs after the fact.
- if (!profile_)
- return; // No profile, probably unit testing.
- Details<history::URLsDeletedDetails> deleted_details(details);
- VisitedLinkMaster* visited_links = profile_->GetVisitedLinkMaster();
- if (!visited_links)
- return; // Nobody to update.
- if (deleted_details->all_history)
- visited_links->DeleteAllURLs();
- else // Delete individual ones.
- visited_links->DeleteURLs(deleted_details->urls);
+ case NotificationType::TEMPLATE_URL_REMOVED:
+ DeleteAllSearchTermsForKeyword(*(Details<TemplateURLID>(details).ptr()));
+ break;
+
+ default:
+ NOTREACHED();
+ }
}
bool HistoryService::Init(const FilePath& history_dir,
diff --git a/chrome/browser/history/history_backend.cc b/chrome/browser/history/history_backend.cc
index 00577bb..0bf6045 100644
--- a/chrome/browser/history/history_backend.cc
+++ b/chrome/browser/history/history_backend.cc
@@ -1035,6 +1035,14 @@ void HistoryBackend::SetKeywordSearchTermsForURL(const GURL& url,
}
db_->SetKeywordSearchTermsForURL(url_row.id(), keyword_id, term);
+
+ // details is deleted by BroadcastNotifications.
+ KeywordSearchTermDetails* details = new KeywordSearchTermDetails;
+ details->url = url;
+ details->keyword_id = keyword_id;
+ details->term = term;
+ BroadcastNotifications(NotificationType::HISTORY_KEYWORD_SEARCH_TERM_UPDATED,
+ details);
ScheduleCommit();
}
diff --git a/chrome/browser/history/history_notifications.cc b/chrome/browser/history/history_notifications.cc
index c846eaf..0fdfa94 100644
--- a/chrome/browser/history/history_notifications.cc
+++ b/chrome/browser/history/history_notifications.cc
@@ -28,4 +28,8 @@ FavIconChangeDetails::FavIconChangeDetails() {}
FavIconChangeDetails::~FavIconChangeDetails() {}
+KeywordSearchTermDetails::KeywordSearchTermDetails() : keyword_id(0) {}
+
+KeywordSearchTermDetails::~KeywordSearchTermDetails() {}
+
} // namespace history
diff --git a/chrome/browser/history/history_notifications.h b/chrome/browser/history/history_notifications.h
index a39a1b9..0d82135 100644
--- a/chrome/browser/history/history_notifications.h
+++ b/chrome/browser/history/history_notifications.h
@@ -13,6 +13,7 @@
#include "googleurl/src/gurl.h"
#include "chrome/browser/history/history_types.h"
+#include "chrome/browser/search_engines/template_url_id.h"
namespace history {
@@ -83,6 +84,16 @@ struct FavIconChangeDetails : public HistoryDetails {
std::set<GURL> urls;
};
+// Details for HISTORY_KEYWORD_SEARCH_TERM_UPDATED.
+struct KeywordSearchTermDetails : public HistoryDetails {
+ KeywordSearchTermDetails();
+ ~KeywordSearchTermDetails();
+
+ GURL url;
+ TemplateURLID keyword_id;
+ string16 term;
+};
+
} // namespace history
#endif // CHROME_BROWSER_HISTORY_HISTORY_NOTIFICATIONS_H__
diff --git a/chrome/browser/history/in_memory_history_backend.cc b/chrome/browser/history/in_memory_history_backend.cc
index 6827a78..be82f58 100644
--- a/chrome/browser/history/in_memory_history_backend.cc
+++ b/chrome/browser/history/in_memory_history_backend.cc
@@ -72,6 +72,9 @@ void InMemoryHistoryBackend::AttachToHistoryService(Profile* profile) {
registrar_.Add(this, NotificationType::HISTORY_URL_VISITED, source);
registrar_.Add(this, NotificationType::HISTORY_TYPED_URLS_MODIFIED, source);
registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED, source);
+ registrar_.Add(this, NotificationType::HISTORY_KEYWORD_SEARCH_TERM_UPDATED,
+ source);
+ registrar_.Add(this, NotificationType::TEMPLATE_URL_REMOVED, source);
}
void InMemoryHistoryBackend::Observe(NotificationType type,
@@ -80,13 +83,20 @@ void InMemoryHistoryBackend::Observe(NotificationType type,
switch (type.value) {
case NotificationType::HISTORY_URL_VISITED: {
Details<history::URLVisitedDetails> visited_details(details);
- if (visited_details->row.typed_count() > 0) {
+ PageTransition::Type primary_type =
+ PageTransition::StripQualifier(visited_details->transition);
+ if (visited_details->row.typed_count() > 0 ||
+ primary_type == PageTransition::KEYWORD) {
URLsModifiedDetails modified_details;
modified_details.changed_urls.push_back(visited_details->row);
OnTypedURLsModified(modified_details);
}
break;
}
+ case NotificationType::HISTORY_KEYWORD_SEARCH_TERM_UPDATED:
+ OnKeywordSearchTermUpdated(
+ *Details<history::KeywordSearchTermDetails>(details).ptr());
+ break;
case NotificationType::HISTORY_TYPED_URLS_MODIFIED:
OnTypedURLsModified(
*Details<history::URLsModifiedDetails>(details).ptr());
@@ -94,6 +104,10 @@ void InMemoryHistoryBackend::Observe(NotificationType type,
case NotificationType::HISTORY_URLS_DELETED:
OnURLsDeleted(*Details<history::URLsDeletedDetails>(details).ptr());
break;
+ case NotificationType::TEMPLATE_URL_REMOVED:
+ db_->DeleteAllSearchTermsForKeyword(
+ *(Details<TemplateURLID>(details).ptr()));
+ break;
default:
// For simplicity, the unit tests send us all notifications, even when
// we haven't registered for them, so don't assert here.
@@ -145,4 +159,27 @@ void InMemoryHistoryBackend::OnURLsDeleted(const URLsDeletedDetails& details) {
}
}
+void InMemoryHistoryBackend::OnKeywordSearchTermUpdated(
+ const KeywordSearchTermDetails& details) {
+ // The url won't exist for new search terms (as the user hasn't typed it), so
+ // we force it to be added. If we end up adding a URL it won't be
+ // autocompleted as the typed count is 0.
+ URLRow url_row;
+ URLID url_id;
+ if (!db_->GetRowForURL(details.url, &url_row)) {
+ // Because this row won't have a typed count the title and other stuff
+ // doesn't matter. If the user ends up typing the url we'll update the title
+ // in OnTypedURLsModified.
+ URLRow new_row(details.url);
+ new_row.set_last_visit(base::Time::Now());
+ url_id = db_->AddURL(new_row);
+ if (!url_id)
+ return; // Error adding.
+ } else {
+ url_id = url_row.id();
+ }
+
+ db_->SetKeywordSearchTermsForURL(url_id, details.keyword_id, details.term);
+}
+
} // namespace history
diff --git a/chrome/browser/history/in_memory_history_backend.h b/chrome/browser/history/in_memory_history_backend.h
index 4fdc3a5..c775800 100644
--- a/chrome/browser/history/in_memory_history_backend.h
+++ b/chrome/browser/history/in_memory_history_backend.h
@@ -30,6 +30,7 @@ namespace history {
class InMemoryDatabase;
class InMemoryURLIndex;
+struct KeywordSearchTermDetails;
class URLDatabase;
struct URLsDeletedDetails;
struct URLsModifiedDetails;
@@ -73,6 +74,9 @@ class InMemoryHistoryBackend : public NotificationObserver {
// Handler for NOTIFY_HISTORY_URLS_DELETED.
void OnURLsDeleted(const URLsDeletedDetails& details);
+ // Handler for HISTORY_KEYWORD_SEARCH_TERM_UPDATED.
+ void OnKeywordSearchTermUpdated(const KeywordSearchTermDetails& details);
+
NotificationRegistrar registrar_;
scoped_ptr<InMemoryDatabase> db_;