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

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

Issue 314293005: Change HistoryService::QueryURL to use CancelableTaskTracker (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and add comment for scoped_ptr usage Created 6 years, 6 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/browser_feature_extractor.cc
diff --git a/chrome/browser/safe_browsing/browser_feature_extractor.cc b/chrome/browser/safe_browsing/browser_feature_extractor.cc
index 8d0bd73577bf5b4cf6d8b1f6e26d56e607fae5fa..2ef679b14c575d0cfbf2cf43b8937e5a3d8ac894 100644
--- a/chrome/browser/safe_browsing/browser_feature_extractor.cc
+++ b/chrome/browser/safe_browsing/browser_feature_extractor.cc
@@ -323,30 +323,31 @@ void BrowserFeatureExtractor::StartExtractFeatures(
callback.Run(false, request);
return;
}
- CancelableRequestProvider::Handle handle = history->QueryURL(
- GURL(request->url()),
- true /* wants_visits */,
- &request_consumer_,
- base::Bind(&BrowserFeatureExtractor::QueryUrlHistoryDone,
- base::Unretained(this)));
-
- StorePendingQuery(handle, request, callback);
+ // HistoryService::QueryURL migrated from CancelableRequestComsumer to
+ // CancelableRequestTracker and there is no Handle to associate to the
+ // request. Instead manage the request object lifetime by using a scoped_ptr
+ // and using base::Passed(). So if the asynchronous call is canceled, the
+ // request is deleted, otherwise the callback becomes the owner.
+ scoped_ptr<ClientPhishingRequest> owned_request(request);
+ history->QueryURL(GURL(request->url()),
+ true /* wants_visits */,
+ base::Bind(&BrowserFeatureExtractor::QueryUrlHistoryDone,
+ base::Unretained(this),
+ base::Passed(&owned_request),
+ callback),
+ &cancelable_task_tracker_);
}
void BrowserFeatureExtractor::QueryUrlHistoryDone(
- CancelableRequestProvider::Handle handle,
+ scoped_ptr<ClientPhishingRequest> owned_request,
+ const DoneCallback& callback,
bool success,
- const history::URLRow* row,
- history::VisitVector* visits) {
+ const history::URLRow& row,
+ const history::VisitVector& visits) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- ClientPhishingRequest* request;
- DoneCallback callback;
- if (!GetPendingQuery(handle, &request, &callback)) {
- DLOG(FATAL) << "No pending history query found";
- return;
- }
- DCHECK(request);
+ DCHECK(owned_request);
DCHECK(!callback.is_null());
+ ClientPhishingRequest* request = owned_request.release();
if (!success) {
// URL is not found in the history. In practice this should not
// happen (unless there is a real error) because we just visited
@@ -355,15 +356,16 @@ void BrowserFeatureExtractor::QueryUrlHistoryDone(
return;
}
AddFeature(features::kUrlHistoryVisitCount,
- static_cast<double>(row->visit_count()),
+ static_cast<double>(row.visit_count()),
request);
base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1);
int num_visits_24h_ago = 0;
int num_visits_typed = 0;
int num_visits_link = 0;
- for (history::VisitVector::const_iterator it = visits->begin();
- it != visits->end(); ++it) {
+ for (history::VisitVector::const_iterator it = visits.begin();
+ it != visits.end();
+ ++it) {
if (!content::PageTransitionIsMainFrame(it->transition)) {
continue;
}

Powered by Google App Engine
This is Rietveld 408576698