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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/safe_browsing/browser_feature_extractor.h" 5 #include "chrome/browser/safe_browsing/browser_feature_extractor.h"
6 6
7 #include <map> 7 #include <map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 ClientPhishingRequest* request, 316 ClientPhishingRequest* request,
317 const DoneCallback& callback) { 317 const DoneCallback& callback) {
318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
319 size_t removed = pending_extractions_.erase(request); 319 size_t removed = pending_extractions_.erase(request);
320 DCHECK_EQ(1U, removed); 320 DCHECK_EQ(1U, removed);
321 HistoryService* history; 321 HistoryService* history;
322 if (!request || !request->IsInitialized() || !GetHistoryService(&history)) { 322 if (!request || !request->IsInitialized() || !GetHistoryService(&history)) {
323 callback.Run(false, request); 323 callback.Run(false, request);
324 return; 324 return;
325 } 325 }
326 CancelableRequestProvider::Handle handle = history->QueryURL( 326 // HistoryService::QueryURL migrated from CancelableRequestComsumer to
327 GURL(request->url()), 327 // CancelableRequestTracker and there is no Handle to associate to the
328 true /* wants_visits */, 328 // request. Instead manage the request object lifetime by using a scoped_ptr
329 &request_consumer_, 329 // and using base::Passed(). So if the asynchronous call is canceled, the
330 base::Bind(&BrowserFeatureExtractor::QueryUrlHistoryDone, 330 // request is deleted, otherwise the callback becomes the owner.
331 base::Unretained(this))); 331 scoped_ptr<ClientPhishingRequest> owned_request(request);
332 332 history->QueryURL(GURL(request->url()),
333 StorePendingQuery(handle, request, callback); 333 true /* wants_visits */,
334 base::Bind(&BrowserFeatureExtractor::QueryUrlHistoryDone,
335 base::Unretained(this),
336 base::Passed(&owned_request),
337 callback),
338 &cancelable_task_tracker_);
334 } 339 }
335 340
336 void BrowserFeatureExtractor::QueryUrlHistoryDone( 341 void BrowserFeatureExtractor::QueryUrlHistoryDone(
337 CancelableRequestProvider::Handle handle, 342 scoped_ptr<ClientPhishingRequest> owned_request,
343 const DoneCallback& callback,
338 bool success, 344 bool success,
339 const history::URLRow* row, 345 const history::URLRow& row,
340 history::VisitVector* visits) { 346 const history::VisitVector& visits) {
341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
342 ClientPhishingRequest* request; 348 DCHECK(owned_request);
343 DoneCallback callback;
344 if (!GetPendingQuery(handle, &request, &callback)) {
345 DLOG(FATAL) << "No pending history query found";
346 return;
347 }
348 DCHECK(request);
349 DCHECK(!callback.is_null()); 349 DCHECK(!callback.is_null());
350 ClientPhishingRequest* request = owned_request.release();
350 if (!success) { 351 if (!success) {
351 // URL is not found in the history. In practice this should not 352 // URL is not found in the history. In practice this should not
352 // happen (unless there is a real error) because we just visited 353 // happen (unless there is a real error) because we just visited
353 // that URL. 354 // that URL.
354 callback.Run(false, request); 355 callback.Run(false, request);
355 return; 356 return;
356 } 357 }
357 AddFeature(features::kUrlHistoryVisitCount, 358 AddFeature(features::kUrlHistoryVisitCount,
358 static_cast<double>(row->visit_count()), 359 static_cast<double>(row.visit_count()),
359 request); 360 request);
360 361
361 base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1); 362 base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1);
362 int num_visits_24h_ago = 0; 363 int num_visits_24h_ago = 0;
363 int num_visits_typed = 0; 364 int num_visits_typed = 0;
364 int num_visits_link = 0; 365 int num_visits_link = 0;
365 for (history::VisitVector::const_iterator it = visits->begin(); 366 for (history::VisitVector::const_iterator it = visits.begin();
366 it != visits->end(); ++it) { 367 it != visits.end();
368 ++it) {
367 if (!content::PageTransitionIsMainFrame(it->transition)) { 369 if (!content::PageTransitionIsMainFrame(it->transition)) {
368 continue; 370 continue;
369 } 371 }
370 if (it->visit_time < threshold) { 372 if (it->visit_time < threshold) {
371 ++num_visits_24h_ago; 373 ++num_visits_24h_ago;
372 } 374 }
373 content::PageTransition transition = content::PageTransitionStripQualifier( 375 content::PageTransition transition = content::PageTransitionStripQualifier(
374 it->transition); 376 it->transition);
375 if (transition == content::PAGE_TRANSITION_TYPED) { 377 if (transition == content::PAGE_TRANSITION_TYPED) {
376 ++num_visits_typed; 378 ++num_visits_typed;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 // Limit the number of matched bad IPs in one request to control 534 // Limit the number of matched bad IPs in one request to control
533 // the request's size 535 // the request's size
534 if (matched_bad_ips >= kMaxMalwareIPPerRequest) { 536 if (matched_bad_ips >= kMaxMalwareIPPerRequest) {
535 break; 537 break;
536 } 538 }
537 } 539 }
538 callback.Run(true, request.Pass()); 540 callback.Run(true, request.Pass());
539 } 541 }
540 542
541 } // namespace safe_browsing 543 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698