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

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

Issue 573553004: Eliminate NOTIFICATION_HISTORY_LOADED notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add ScopedObserver to InMemoryHistoryBackend,PrerenderLocalPredictor,ChromeTemplateURLServiceClient Created 6 years, 1 month 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/in_memory_url_index.cc
diff --git a/chrome/browser/history/in_memory_url_index.cc b/chrome/browser/history/in_memory_url_index.cc
index 545501c23cd50861534d11a8f3ffd8a72f4efad5..74ad2a07063e068a6fc88a59cdd1585f2e5f943d 100644
--- a/chrome/browser/history/in_memory_url_index.cc
+++ b/chrome/browser/history/in_memory_url_index.cc
@@ -103,7 +103,8 @@ InMemoryURLIndex::InMemoryURLIndex(Profile* profile,
save_cache_observer_(NULL),
shutdown_(false),
restored_(false),
- needs_to_be_cached_(false) {
+ needs_to_be_cached_(false),
+ history_service_observer_(this) {
InitializeSchemeWhitelist(&scheme_whitelist_);
if (profile) {
// TODO(mrossetti): Register for language change notifications.
@@ -111,7 +112,7 @@ InMemoryURLIndex::InMemoryURLIndex(Profile* profile,
registrar_.Add(this, chrome::NOTIFICATION_HISTORY_URLS_DELETED, source);
}
if (history_service_)
- history_service_->AddObserver(this);
+ history_service_observer_.Add(history_service_);
}
// Called only by unit tests.
@@ -124,7 +125,8 @@ InMemoryURLIndex::InMemoryURLIndex()
save_cache_observer_(NULL),
shutdown_(false),
restored_(false),
- needs_to_be_cached_(false) {
+ needs_to_be_cached_(false),
+ history_service_observer_(this) {
InitializeSchemeWhitelist(&scheme_whitelist_);
}
@@ -139,8 +141,7 @@ void InMemoryURLIndex::Init() {
}
void InMemoryURLIndex::ShutDown() {
- if (history_service_)
- history_service_->RemoveObserver(this);
+ history_service_observer_.RemoveAll();
registrar_.RemoveAll();
cache_reader_tracker_.TryCancelAll();
shutdown_ = true;
@@ -191,11 +192,6 @@ void InMemoryURLIndex::Observe(int notification_type,
OnURLsDeleted(
content::Details<history::URLsDeletedDetails>(details).ptr());
break;
- case chrome::NOTIFICATION_HISTORY_LOADED:
- registrar_.Remove(this, chrome::NOTIFICATION_HISTORY_LOADED,
- content::Source<Profile>(profile_));
- ScheduleRebuildFromHistory();
- break;
default:
// For simplicity, the unit tests send us all notifications, even when
// we haven't registered for them, so don't assert here.
@@ -228,6 +224,10 @@ void InMemoryURLIndex::OnURLsModified(HistoryService* history_service,
}
}
+void InMemoryURLIndex::OnHistoryServiceLoaded(HistoryService* history_service) {
+ ScheduleRebuildFromHistory();
+}
+
void InMemoryURLIndex::OnURLsDeleted(const URLsDeletedDetails* details) {
if (details->all_history) {
ClearPrivateData();
@@ -298,11 +298,13 @@ void InMemoryURLIndex::OnCacheLoadDone(
FROM_HERE, base::Bind(DeleteCacheFile, path));
HistoryService* service =
HistoryServiceFactory::GetForProfileWithoutCreating(profile_);
- if (service && service->backend_loaded()) {
- ScheduleRebuildFromHistory();
- } else {
- registrar_.Add(this, chrome::NOTIFICATION_HISTORY_LOADED,
- content::Source<Profile>(profile_));
+ if (service) {
+ if (!service->backend_loaded()) {
+ if (!history_service_observer_.IsObserving(service))
+ history_service_observer_.Add(service);
+ } else {
+ ScheduleRebuildFromHistory();
+ }
}
}
}

Powered by Google App Engine
This is Rietveld 408576698