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

Unified Diff: chrome/browser/safe_browsing/incident_reporting/last_download_finder.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/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 fbfbcc3614075b56b1d536a50e78cae822615a49..b3e4f3ff7634f9080b1a1eb6a4ea3c21b6cdd62b 100644
--- a/chrome/browser/safe_browsing/incident_reporting/last_download_finder.cc
+++ b/chrome/browser/safe_browsing/incident_reporting/last_download_finder.cc
@@ -159,7 +159,8 @@ scoped_ptr<LastDownloadFinder> LastDownloadFinder::Create(
return finder.Pass();
}
-LastDownloadFinder::LastDownloadFinder() : weak_ptr_factory_(this) {
+LastDownloadFinder::LastDownloadFinder()
+ : history_service_observer_(this), weak_ptr_factory_(this) {
}
LastDownloadFinder::LastDownloadFinder(
@@ -168,6 +169,7 @@ LastDownloadFinder::LastDownloadFinder(
const LastDownloadCallback& callback)
: download_details_getter_(download_details_getter),
callback_(callback),
+ history_service_observer_(this),
weak_ptr_factory_(this) {
// Observe profile lifecycle events so that the finder can begin or abandon
// the search in profiles while it is running.
@@ -175,9 +177,6 @@ LastDownloadFinder::LastDownloadFinder(
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());
@@ -198,7 +197,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 (profile_states_.count(profile))
return;
@@ -240,7 +239,10 @@ void LastDownloadFinder::OnMetadataQuery(
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);
+ }
}
}
@@ -327,10 +329,6 @@ 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:
AbandonSearchInProfile(content::Source<Profile>(source).ptr());
break;
@@ -339,4 +337,14 @@ void LastDownloadFinder::Observe(int type,
}
}
+void LastDownloadFinder::OnHistoryServiceLoaded(
+ HistoryService* history_service) {
+ OnProfileHistoryLoaded(history_service->profile(), history_service);
+}
+
+void LastDownloadFinder::HistoryServiceBeingDeleted(
+ HistoryService* history_service) {
+ history_service_observer_.Remove(history_service);
+}
+
} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698