Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7171)

Unified Diff: chrome/browser/history/top_sites_impl.cc

Issue 773103004: Remove NOTIFICATION_HISTORY_URLS_DELETED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove NotificationObserver from InMemoryURLIndex Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698