Index: chrome/browser/history/top_sites_impl.cc |
diff --git a/chrome/browser/history/top_sites_impl.cc b/chrome/browser/history/top_sites_impl.cc |
index ba422eeef1502295ed52669de5e4224b25502e9a..f260454cd22bfc01731c62d1f71cb077e5b5ad09 100644 |
--- a/chrome/browser/history/top_sites_impl.cc |
+++ b/chrome/browser/history/top_sites_impl.cc |
@@ -101,13 +101,12 @@ TopSitesImpl::TopSitesImpl(Profile* profile) |
thread_safe_cache_(new TopSitesCache()), |
profile_(profile), |
last_num_urls_changed_(0), |
- loaded_(false) { |
+ loaded_(false), |
+ history_service_observer_(this) { |
if (!profile_) |
return; |
if (content::NotificationService::current()) { |
- registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, |
- content::Source<Profile>(profile_)); |
// Listen for any nav commits. We'll ignore those not related to this |
// profile when we get the notification. |
registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
@@ -742,31 +741,7 @@ void TopSitesImpl::Observe(int type, |
if (!loaded_) |
return; |
- if (type == chrome::NOTIFICATION_HISTORY_URLS_DELETED) { |
- content::Details<history::URLsDeletedDetails> deleted_details(details); |
- if (deleted_details->all_history) { |
- SetTopSites(MostVisitedURLList()); |
- backend_->ResetDatabase(); |
- } else { |
- std::set<size_t> indices_to_delete; // Indices into top_sites_. |
- for (URLRows::const_iterator i = deleted_details->rows.begin(); |
- i != deleted_details->rows.end(); ++i) { |
- if (cache_->IsKnownURL(i->url())) |
- indices_to_delete.insert(cache_->GetURLIndex(i->url())); |
- } |
- |
- if (indices_to_delete.empty()) |
- return; |
- |
- MostVisitedURLList new_top_sites(cache_->top_sites()); |
- for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin(); |
- i != indices_to_delete.rend(); i++) { |
- new_top_sites.erase(new_top_sites.begin() + *i); |
- } |
- SetTopSites(new_top_sites); |
- } |
- StartQueryForMostVisited(); |
- } else if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
+ if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
sdefresne
2014/12/04 17:21:13
This is the only notification listened for, so DCH
nshaik
2014/12/07 09:34:50
Done.
|
NavigationController* controller = |
content::Source<NavigationController>(source).ptr(); |
Profile* profile = Profile::FromBrowserContext( |
@@ -874,6 +849,12 @@ void TopSitesImpl::MoveStateToLoaded() { |
for (size_t i = 0; i < pending_callbacks.size(); i++) |
pending_callbacks[i].Run(filtered_urls_all, filtered_urls_nonforced); |
+ HistoryService* hs = |
+ HistoryServiceFactory::GetForProfile(profile_, Profile::EXPLICIT_ACCESS); |
+ // |hs| may be null during unit tests. |
+ if (hs) |
+ history_service_observer_.Add(hs); |
+ |
NotifyTopSitesLoaded(); |
} |
@@ -925,4 +906,35 @@ void TopSitesImpl::OnTopSitesAvailableFromHistory( |
SetTopSites(*pages); |
} |
+void TopSitesImpl::OnURLsDeleted( |
+ HistoryService* history_service, |
+ const history::URLsDeletedDetails& deleted_details) { |
+ if (deleted_details.all_history) { |
+ SetTopSites(MostVisitedURLList()); |
+ backend_->ResetDatabase(); |
+ } else { |
+ std::set<size_t> indices_to_delete; // Indices into top_sites_. |
+ for (URLRows::const_iterator i = deleted_details.rows.begin(); |
+ i != deleted_details.rows.end(); ++i) { |
+ if (cache_->IsKnownURL(i->url())) |
+ indices_to_delete.insert(cache_->GetURLIndex(i->url())); |
+ } |
+ |
+ if (indices_to_delete.empty()) |
+ return; |
+ |
+ MostVisitedURLList new_top_sites(cache_->top_sites()); |
+ for (std::set<size_t>::reverse_iterator i = indices_to_delete.rbegin(); |
+ i != indices_to_delete.rend(); i++) { |
+ new_top_sites.erase(new_top_sites.begin() + *i); |
+ } |
+ SetTopSites(new_top_sites); |
+ } |
+ StartQueryForMostVisited(); |
+} |
+ |
+void TopSitesImpl::HistoryServiceBeingDeleted(HistoryService* history_service) { |
+ history_service_observer_.Remove(history_service); |
+} |
+ |
} // namespace history |