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

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 & fix style errors 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 scoped_ptr<ClientPhishingRequest> owned_request(request);
327 GURL(request->url()), 327 history->QueryURL(GURL(request->url()),
328 true /* wants_visits */, 328 true /* wants_visits */,
329 &request_consumer_, 329 base::Bind(&BrowserFeatureExtractor::QueryUrlHistoryDone,
330 base::Bind(&BrowserFeatureExtractor::QueryUrlHistoryDone, 330 base::Unretained(this),
331 base::Unretained(this))); 331 base::Passed(&owned_request),
blundell 2014/06/11 11:08:40 Is there a reason this can't just be base::Unretai
sdefresne 2014/06/11 16:46:26 The description of ExtractFeatures explain why:
332 332 callback),
333 StorePendingQuery(handle, request, callback); 333 &cancelable_task_tracker_);
blundell 2014/06/11 11:08:40 Can StorePendingQuery() and GetPendingQuery() go a
sdefresne 2014/06/11 16:46:26 No, they are still used by other functions that po
334 } 334 }
335 335
336 void BrowserFeatureExtractor::QueryUrlHistoryDone( 336 void BrowserFeatureExtractor::QueryUrlHistoryDone(
337 CancelableRequestProvider::Handle handle, 337 scoped_ptr<ClientPhishingRequest> owned_request,
338 const DoneCallback& callback,
338 bool success, 339 bool success,
339 const history::URLRow* row, 340 const history::URLRow& row,
340 history::VisitVector* visits) { 341 const history::VisitVector& visits) {
341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 342 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
342 ClientPhishingRequest* request; 343 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()); 344 DCHECK(!callback.is_null());
345 ClientPhishingRequest* request = owned_request.release();
350 if (!success) { 346 if (!success) {
351 // URL is not found in the history. In practice this should not 347 // URL is not found in the history. In practice this should not
352 // happen (unless there is a real error) because we just visited 348 // happen (unless there is a real error) because we just visited
353 // that URL. 349 // that URL.
354 callback.Run(false, request); 350 callback.Run(false, request);
355 return; 351 return;
356 } 352 }
357 AddFeature(features::kUrlHistoryVisitCount, 353 AddFeature(features::kUrlHistoryVisitCount,
358 static_cast<double>(row->visit_count()), 354 static_cast<double>(row.visit_count()),
359 request); 355 request);
360 356
361 base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1); 357 base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1);
362 int num_visits_24h_ago = 0; 358 int num_visits_24h_ago = 0;
363 int num_visits_typed = 0; 359 int num_visits_typed = 0;
364 int num_visits_link = 0; 360 int num_visits_link = 0;
365 for (history::VisitVector::const_iterator it = visits->begin(); 361 for (history::VisitVector::const_iterator it = visits.begin();
366 it != visits->end(); ++it) { 362 it != visits.end();
363 ++it) {
367 if (!content::PageTransitionIsMainFrame(it->transition)) { 364 if (!content::PageTransitionIsMainFrame(it->transition)) {
368 continue; 365 continue;
369 } 366 }
370 if (it->visit_time < threshold) { 367 if (it->visit_time < threshold) {
371 ++num_visits_24h_ago; 368 ++num_visits_24h_ago;
372 } 369 }
373 content::PageTransition transition = content::PageTransitionStripQualifier( 370 content::PageTransition transition = content::PageTransitionStripQualifier(
374 it->transition); 371 it->transition);
375 if (transition == content::PAGE_TRANSITION_TYPED) { 372 if (transition == content::PAGE_TRANSITION_TYPED) {
376 ++num_visits_typed; 373 ++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 529 // Limit the number of matched bad IPs in one request to control
533 // the request's size 530 // the request's size
534 if (matched_bad_ips >= kMaxMalwareIPPerRequest) { 531 if (matched_bad_ips >= kMaxMalwareIPPerRequest) {
535 break; 532 break;
536 } 533 }
537 } 534 }
538 callback.Run(true, request.Pass()); 535 callback.Run(true, request.Pass());
539 } 536 }
540 537
541 } // namespace safe_browsing 538 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698