summaryrefslogtreecommitdiffstats
path: root/chrome/browser/history/history.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/history/history.cc')
-rw-r--r--chrome/browser/history/history.cc87
1 files changed, 55 insertions, 32 deletions
diff --git a/chrome/browser/history/history.cc b/chrome/browser/history/history.cc
index bc5db7d..53a5420 100644
--- a/chrome/browser/history/history.cc
+++ b/chrome/browser/history/history.cc
@@ -127,12 +127,8 @@ HistoryService::HistoryService()
profile_(NULL),
backend_loaded_(false),
bookmark_service_(NULL),
- no_db_(false) {
- // Is NULL when running generate_profile.
- if (NotificationService::current()) {
- registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED,
- Source<Profile>(profile_));
- }
+ no_db_(false),
+ needs_top_sites_migration_(false) {
}
HistoryService::HistoryService(Profile* profile)
@@ -140,9 +136,13 @@ HistoryService::HistoryService(Profile* profile)
profile_(profile),
backend_loaded_(false),
bookmark_service_(NULL),
- no_db_(false) {
+ no_db_(false),
+ needs_top_sites_migration_(false) {
+ DCHECK(profile_);
registrar_.Add(this, NotificationType::HISTORY_URLS_DELETED,
Source<Profile>(profile_));
+ registrar_.Add(this, NotificationType::TEMPLATE_URL_REMOVED,
+ Source<Profile>(profile_));
}
HistoryService::~HistoryService() {
@@ -609,30 +609,40 @@ HistoryService::Handle HistoryService::QueryMostVisitedURLs(
void HistoryService::Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
- if (type != NotificationType::HISTORY_URLS_DELETED) {
- NOTREACHED();
+ if (!thread_)
return;
- }
- // 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);
+ 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;
+ }
+
+ case NotificationType::TEMPLATE_URL_REMOVED:
+ DeleteAllSearchTermsForKeyword(*(Details<TemplateURLID>(details).ptr()));
+ break;
+
+ default:
+ NOTREACHED();
+ }
}
bool HistoryService::Init(const FilePath& history_dir,
@@ -673,6 +683,7 @@ bool HistoryService::CanAddURL(const GURL& url) {
// typed. Right now, however, these are marked as typed even when triggered
// by a shortcut or menu action.
if (url.SchemeIs(chrome::kJavaScriptScheme) ||
+ url.SchemeIs(chrome::kChromeDevToolsScheme) ||
url.SchemeIs(chrome::kChromeUIScheme) ||
url.SchemeIs(chrome::kViewSourceScheme) ||
url.SchemeIs(chrome::kChromeInternalScheme))
@@ -733,6 +744,9 @@ void HistoryService::BroadcastNotifications(
if (!g_browser_process)
return;
+ if (!thread_)
+ return;
+
// The source of all of our notifications is the profile. Note that this
// pointer is NULL in unit tests.
Source<Profile> source(profile_);
@@ -769,12 +783,21 @@ void HistoryService::OnDBLoaded() {
NotificationService::current()->Notify(NotificationType::HISTORY_LOADED,
Source<Profile>(profile_),
Details<HistoryService>(this));
+ if (thread_ && profile_ && history::TopSites::IsEnabled()) {
+ // We don't want to force creation of TopSites.
+ history::TopSites* ts = profile_->GetTopSitesWithoutCreating();
+ if (ts)
+ ts->HistoryLoaded();
+ }
}
void HistoryService::StartTopSitesMigration() {
- if (history::TopSites::IsEnabled()) {
- history::TopSites* ts = profile_->GetTopSites();
- ts->StartMigration();
+ needs_top_sites_migration_ = true;
+ if (thread_ && profile_ && history::TopSites::IsEnabled()) {
+ // We don't want to force creation of TopSites.
+ history::TopSites* ts = profile_->GetTopSitesWithoutCreating();
+ if (ts)
+ ts->MigrateFromHistory();
}
}