Index: chrome/browser/safe_browsing/incident_reporting/last_download_finder.cc |
diff --git a/chrome/browser/safe_browsing/incident_reporting/last_download_finder.cc b/chrome/browser/safe_browsing/incident_reporting/last_download_finder.cc |
index b829960180fad95137d5d39a9559e24f17d4a9b3..2043b01e3261beaea92a67a05925844c12dfa897 100644 |
--- a/chrome/browser/safe_browsing/incident_reporting/last_download_finder.cc |
+++ b/chrome/browser/safe_browsing/incident_reporting/last_download_finder.cc |
@@ -112,21 +112,21 @@ scoped_ptr<LastDownloadFinder> LastDownloadFinder::Create( |
return finder.Pass(); |
} |
-LastDownloadFinder::LastDownloadFinder() : weak_ptr_factory_(this) { |
+LastDownloadFinder::LastDownloadFinder() |
+ : weak_ptr_factory_(this), history_service_observer_(this) { |
} |
LastDownloadFinder::LastDownloadFinder(const std::vector<Profile*>& profiles, |
const LastDownloadCallback& callback) |
- : callback_(callback), weak_ptr_factory_(this) { |
+ : callback_(callback), |
+ weak_ptr_factory_(this), |
+ history_service_observer_(this) { |
// Observe profile lifecycle events so that the finder can begin or abandon |
// the search in profiles while it is running. |
notification_registrar_.Add(this, |
chrome::NOTIFICATION_PROFILE_ADDED, |
content::NotificationService::AllSources()); |
notification_registrar_.Add(this, |
- chrome::NOTIFICATION_HISTORY_LOADED, |
- content::NotificationService::AllSources()); |
- notification_registrar_.Add(this, |
chrome::NOTIFICATION_PROFILE_DESTROYED, |
content::NotificationService::AllSources()); |
@@ -165,7 +165,10 @@ void LastDownloadFinder::SearchInProfile(Profile* profile) { |
base::Bind(&LastDownloadFinder::OnDownloadQuery, |
weak_ptr_factory_.GetWeakPtr(), |
profile)); |
- } // else wait until history is loaded. |
+ } else { |
+ // else wait until history is loaded. |
+ history_service_observer_.Add(history_service); |
+ } |
} |
void LastDownloadFinder::OnProfileHistoryLoaded( |
@@ -242,16 +245,23 @@ void LastDownloadFinder::Observe(int type, |
case chrome::NOTIFICATION_PROFILE_ADDED: |
SearchInProfile(content::Source<Profile>(source).ptr()); |
break; |
- case chrome::NOTIFICATION_HISTORY_LOADED: |
- OnProfileHistoryLoaded(content::Source<Profile>(source).ptr(), |
- content::Details<HistoryService>(details).ptr()); |
- break; |
- case chrome::NOTIFICATION_PROFILE_DESTROYED: |
+ case chrome::NOTIFICATION_PROFILE_DESTROYED: { |
AbandonSearchInProfile(content::Source<Profile>(source).ptr()); |
+ HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
+ content::Source<Profile>(source).ptr(), Profile::IMPLICIT_ACCESS); |
+ if (history_service) |
+ history_service_observer_.Remove(history_service); |
break; |
+ } |
default: |
break; |
} |
} |
+void LastDownloadFinder::OnHistoryServiceLoaded( |
+ HistoryService* history_service) { |
+ OnProfileHistoryLoaded(history_service->profile(), history_service); |
+ history_service_observer_.Remove(history_service); |
+} |
+ |
} // namespace safe_browsing |