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 b761164f125274e753e17ade94c8998fa45416f6..5d6a3b0501dd67041df09a1945e9599c9ec4afd7 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. |
@@ -113,7 +114,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. |
@@ -126,7 +127,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_); |
} |
@@ -141,8 +143,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; |
@@ -197,11 +198,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. |
@@ -304,11 +300,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() && |
+ !history_service_observer_.IsObserving(service)) { |
brettw
2014/11/14 21:13:06
Are you sure you want to change this condition lik
nshaik
2014/11/15 07:04:15
Fixed it.
|
+ history_service_observer_.Add(service); |
+ } else { |
+ ScheduleRebuildFromHistory(); |
+ } |
} |
} |
} |
@@ -382,4 +380,8 @@ void InMemoryURLIndex::OnCacheSaveDone(bool succeeded) { |
save_cache_observer_->OnCacheSaveFinished(succeeded); |
} |
+void InMemoryURLIndex::OnHistoryServiceLoaded(HistoryService* history_service) { |
+ ScheduleRebuildFromHistory(); |
+} |
+ |
} // namespace history |