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

Unified Diff: chrome/browser/safe_browsing/threat_details_history.cc

Issue 2796123003: Componentize safe_browsing: factor out chrome/ deps in ThreatDetailsRedirectsCollector. (Closed)
Patch Set: fix crashes Created 3 years, 8 months 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/threat_details_history.cc
diff --git a/chrome/browser/safe_browsing/threat_details_history.cc b/chrome/browser/safe_browsing/threat_details_history.cc
index ce25110e43c673baed9e9e7e4a42bafaf5da2830..4c0c6ec15e1cfef4b55f05aeaed14f0c1951da27 100644
--- a/chrome/browser/safe_browsing/threat_details_history.cc
+++ b/chrome/browser/safe_browsing/threat_details_history.cc
@@ -10,10 +10,8 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
-#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/history/history_service_factory.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/safe_browsing/threat_details.h"
+#include "components/history/core/browser/history_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
@@ -23,12 +21,14 @@ using content::BrowserThread;
namespace safe_browsing {
ThreatDetailsRedirectsCollector::ThreatDetailsRedirectsCollector(
- Profile* profile)
- : profile_(profile), has_started_(false) {
+ const base::WeakPtr<history::HistoryService>& history_service)
+ : has_started_(false),
+ history_service_(history_service),
+ history_service_observer_(this) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- if (profile) {
- registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
- content::Source<Profile>(profile));
+
+ if (history_service) {
+ history_service_observer_.Add(history_service.get());
}
}
@@ -59,16 +59,6 @@ ThreatDetailsRedirectsCollector::GetCollectedUrls() const {
return redirects_urls_;
}
-void ThreatDetailsRedirectsCollector::Observe(
- int type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) {
- DCHECK_CURRENTLY_ON(BrowserThread::UI);
- DCHECK_EQ(type, chrome::NOTIFICATION_PROFILE_DESTROYED);
- DVLOG(1) << "Profile gone.";
- profile_ = NULL;
-}
-
ThreatDetailsRedirectsCollector::~ThreatDetailsRedirectsCollector() {}
void ThreatDetailsRedirectsCollector::StartGetRedirects(
@@ -84,21 +74,16 @@ void ThreatDetailsRedirectsCollector::StartGetRedirects(
void ThreatDetailsRedirectsCollector::GetRedirects(const GURL& url) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
- if (!profile_) {
- AllDone();
- return;
- }
- history::HistoryService* history = HistoryServiceFactory::GetForProfile(
- profile_, ServiceAccessType::EXPLICIT_ACCESS);
- if (!history) {
+ if (!history_service_) {
AllDone();
return;
}
- history->QueryRedirectsTo(
- url, base::Bind(&ThreatDetailsRedirectsCollector::OnGotQueryRedirectsTo,
- base::Unretained(this), url),
+ history_service_->QueryRedirectsTo(
+ url,
+ base::Bind(&ThreatDetailsRedirectsCollector::OnGotQueryRedirectsTo,
+ base::Unretained(this), url),
&request_tracker_);
}
@@ -129,4 +114,10 @@ void ThreatDetailsRedirectsCollector::AllDone() {
callback_.Reset();
}
+void ThreatDetailsRedirectsCollector::HistoryServiceBeingDeleted(
+ history::HistoryService* history_service) {
+ history_service_observer_.Remove(history_service);
+ history_service_.reset();
+}
+
} // namespace safe_browsing

Powered by Google App Engine
This is Rietveld 408576698