Chromium Code Reviews| 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..69a5bce853b4b00b398c3df7d61dbfe19c934f9c 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: { |
| AbandonSearchInProfile(content::Source<Profile>(source).ptr()); |
| + HistoryService* history_service = |
| + HistoryServiceFactory::GetForProfileIfExists( |
| + content::Source<Profile>(source).ptr(), Profile::IMPLICIT_ACCESS); |
| + if (history_service) |
|
sdefresne
2014/11/08 15:16:42
nit: you could now instead implement HistoryServic
nshaik
2014/11/09 09:21:15
Done.
|
| + 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 |