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..e76a4661487a4c82952bab14cd5cf6af194d7a78 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()); |
@@ -147,7 +147,7 @@ void LastDownloadFinder::SearchInProfile(Profile* profile) { |
// Exit early if already processing this profile. This could happen if, for |
// example, NOTIFICATION_PROFILE_ADDED arrives after construction while |
- // waiting for NOTIFICATION_HISTORY_LOADED. |
+ // waiting for OnHistoryServiceLoaded. |
if (std::find(profiles_.begin(), profiles_.end(), profile) != |
profiles_.end()) { |
return; |
@@ -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,24 @@ 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: { |
brettw
2014/11/14 21:13:06
I think this change is unnecessary.
nshaik
2014/11/15 07:04:15
Done.
|
AbandonSearchInProfile(content::Source<Profile>(source).ptr()); |
break; |
+ } |
default: |
break; |
} |
} |
+void LastDownloadFinder::OnHistoryServiceLoaded( |
brettw
2014/11/14 21:13:07
Order should match.
nshaik
2014/11/15 07:04:15
Done.
|
+ HistoryService* history_service) { |
+ OnProfileHistoryLoaded(history_service->profile(), history_service); |
+ history_service_observer_.Remove(history_service); |
+} |
+ |
+void LastDownloadFinder::HistoryServiceBeingDeleted( |
+ HistoryService* history_service) { |
+ history_service_observer_.Remove(history_service); |
+} |
+ |
} // namespace safe_browsing |