diff options
-rw-r--r-- | chrome/browser/history/history.cc | 55 | ||||
-rw-r--r-- | chrome/browser/history/history_backend.cc | 8 | ||||
-rw-r--r-- | chrome/browser/history/history_notifications.cc | 4 | ||||
-rw-r--r-- | chrome/browser/history/history_notifications.h | 11 | ||||
-rw-r--r-- | chrome/browser/history/in_memory_history_backend.cc | 39 | ||||
-rw-r--r-- | chrome/browser/history/in_memory_history_backend.h | 4 | ||||
-rw-r--r-- | chrome/browser/search_engines/template_url_model.cc | 13 | ||||
-rw-r--r-- | chrome/common/notification_type.h | 8 |
8 files changed, 112 insertions, 30 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_; diff --git a/chrome/browser/search_engines/template_url_model.cc b/chrome/browser/search_engines/template_url_model.cc index 5b5b02e..6c72f5f 100644 --- a/chrome/browser/search_engines/template_url_model.cc +++ b/chrome/browser/search_engines/template_url_model.cc @@ -606,8 +606,7 @@ void TemplateURLModel::SetKeywordSearchTermsForURL(const TemplateURL* t_url, profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : NULL; if (!history) return; - history->SetKeywordSearchTermsForURL(url, t_url->id(), - WideToUTF16Hack(term)); + history->SetKeywordSearchTermsForURL(url, t_url->id(), WideToUTF16Hack(term)); } void TemplateURLModel::Init(const Initializer* initializers, @@ -1239,10 +1238,12 @@ void TemplateURLModel::RemoveNoNotify(const TemplateURL* template_url) { service_->RemoveKeyword(*template_url); if (profile_) { - HistoryService* history = - profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); - if (history) - history->DeleteAllSearchTermsForKeyword(template_url->id()); + Source<Profile> source(profile_); + TemplateURLID id = template_url->id(); + NotificationService::current()->Notify( + NotificationType::TEMPLATE_URL_REMOVED, + source, + Details<TemplateURLID>(&id)); } // We own the TemplateURL and need to delete it. diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h index 9fdc50b..b8ffb76 100644 --- a/chrome/common/notification_type.h +++ b/chrome/common/notification_type.h @@ -637,6 +637,10 @@ class NotificationType { // the details is history::URLsDeletedDetails that lists the deleted URLs. HISTORY_URLS_DELETED, + // Sent when a keyword search term is updated. The source is the Profile and + // the details are history::KeywordSearchTermDetails + HISTORY_KEYWORD_SEARCH_TERM_UPDATED, + // Sent by history when the favicon of a URL changes. The source is the // profile, and the details is history::FavIconChangeDetails (see // history_notifications.h). @@ -707,6 +711,10 @@ class NotificationType { // NoDetails. TEMPLATE_URL_MODEL_LOADED, + // Sent when a TemplateURL is removed from the model. The source is the + // Profile, and the details the id of the TemplateURL being removed. + TEMPLATE_URL_REMOVED, + // Notification triggered when a web application has been installed or // uninstalled. Any application view should reload its data. The source is // the profile. No details are provided. |