OLD | NEW |
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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 AddFeature(features::kHttpStatusCode, info.http_status_code, request); | 301 AddFeature(features::kHttpStatusCode, info.http_status_code, request); |
302 } | 302 } |
303 } | 303 } |
304 | 304 |
305 void BrowserFeatureExtractor::StartExtractFeatures( | 305 void BrowserFeatureExtractor::StartExtractFeatures( |
306 scoped_ptr<ClientPhishingRequest> request, | 306 scoped_ptr<ClientPhishingRequest> request, |
307 const DoneCallback& callback) { | 307 const DoneCallback& callback) { |
308 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 308 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
309 history::HistoryService* history; | 309 history::HistoryService* history; |
310 if (!request || !request->IsInitialized() || !GetHistoryService(&history)) { | 310 if (!request || !request->IsInitialized() || !GetHistoryService(&history)) { |
311 callback.Run(false, request.Pass()); | 311 callback.Run(false, std::move(request)); |
312 return; | 312 return; |
313 } | 313 } |
314 GURL request_url(request->url()); | 314 GURL request_url(request->url()); |
315 history->QueryURL(request_url, | 315 history->QueryURL(request_url, |
316 true /* wants_visits */, | 316 true /* wants_visits */, |
317 base::Bind(&BrowserFeatureExtractor::QueryUrlHistoryDone, | 317 base::Bind(&BrowserFeatureExtractor::QueryUrlHistoryDone, |
318 base::Unretained(this), | 318 base::Unretained(this), |
319 base::Passed(&request), | 319 base::Passed(&request), |
320 callback), | 320 callback), |
321 &cancelable_task_tracker_); | 321 &cancelable_task_tracker_); |
322 } | 322 } |
323 | 323 |
324 void BrowserFeatureExtractor::QueryUrlHistoryDone( | 324 void BrowserFeatureExtractor::QueryUrlHistoryDone( |
325 scoped_ptr<ClientPhishingRequest> request, | 325 scoped_ptr<ClientPhishingRequest> request, |
326 const DoneCallback& callback, | 326 const DoneCallback& callback, |
327 bool success, | 327 bool success, |
328 const history::URLRow& row, | 328 const history::URLRow& row, |
329 const history::VisitVector& visits) { | 329 const history::VisitVector& visits) { |
330 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 330 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
331 DCHECK(request); | 331 DCHECK(request); |
332 DCHECK(!callback.is_null()); | 332 DCHECK(!callback.is_null()); |
333 if (!success) { | 333 if (!success) { |
334 // URL is not found in the history. In practice this should not | 334 // URL is not found in the history. In practice this should not |
335 // happen (unless there is a real error) because we just visited | 335 // happen (unless there is a real error) because we just visited |
336 // that URL. | 336 // that URL. |
337 callback.Run(false, request.Pass()); | 337 callback.Run(false, std::move(request)); |
338 return; | 338 return; |
339 } | 339 } |
340 AddFeature(features::kUrlHistoryVisitCount, | 340 AddFeature(features::kUrlHistoryVisitCount, |
341 static_cast<double>(row.visit_count()), | 341 static_cast<double>(row.visit_count()), |
342 request.get()); | 342 request.get()); |
343 | 343 |
344 base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1); | 344 base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1); |
345 int num_visits_24h_ago = 0; | 345 int num_visits_24h_ago = 0; |
346 int num_visits_typed = 0; | 346 int num_visits_typed = 0; |
347 int num_visits_link = 0; | 347 int num_visits_link = 0; |
(...skipping 20 matching lines...) Expand all Loading... |
368 AddFeature(features::kUrlHistoryTypedCount, | 368 AddFeature(features::kUrlHistoryTypedCount, |
369 static_cast<double>(num_visits_typed), | 369 static_cast<double>(num_visits_typed), |
370 request.get()); | 370 request.get()); |
371 AddFeature(features::kUrlHistoryLinkCount, | 371 AddFeature(features::kUrlHistoryLinkCount, |
372 static_cast<double>(num_visits_link), | 372 static_cast<double>(num_visits_link), |
373 request.get()); | 373 request.get()); |
374 | 374 |
375 // Issue next history lookup for host visits. | 375 // Issue next history lookup for host visits. |
376 history::HistoryService* history; | 376 history::HistoryService* history; |
377 if (!GetHistoryService(&history)) { | 377 if (!GetHistoryService(&history)) { |
378 callback.Run(false, request.Pass()); | 378 callback.Run(false, std::move(request)); |
379 return; | 379 return; |
380 } | 380 } |
381 GURL request_url(request->url()); | 381 GURL request_url(request->url()); |
382 history->GetVisibleVisitCountToHost( | 382 history->GetVisibleVisitCountToHost( |
383 request_url, | 383 request_url, |
384 base::Bind(&BrowserFeatureExtractor::QueryHttpHostVisitsDone, | 384 base::Bind(&BrowserFeatureExtractor::QueryHttpHostVisitsDone, |
385 base::Unretained(this), | 385 base::Unretained(this), |
386 base::Passed(&request), | 386 base::Passed(&request), |
387 callback), | 387 callback), |
388 &cancelable_task_tracker_); | 388 &cancelable_task_tracker_); |
389 } | 389 } |
390 | 390 |
391 void BrowserFeatureExtractor::QueryHttpHostVisitsDone( | 391 void BrowserFeatureExtractor::QueryHttpHostVisitsDone( |
392 scoped_ptr<ClientPhishingRequest> request, | 392 scoped_ptr<ClientPhishingRequest> request, |
393 const DoneCallback& callback, | 393 const DoneCallback& callback, |
394 bool success, | 394 bool success, |
395 int num_visits, | 395 int num_visits, |
396 base::Time first_visit) { | 396 base::Time first_visit) { |
397 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 397 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
398 DCHECK(request); | 398 DCHECK(request); |
399 DCHECK(!callback.is_null()); | 399 DCHECK(!callback.is_null()); |
400 if (!success) { | 400 if (!success) { |
401 callback.Run(false, request.Pass()); | 401 callback.Run(false, std::move(request)); |
402 return; | 402 return; |
403 } | 403 } |
404 SetHostVisitsFeatures(num_visits, first_visit, true, request.get()); | 404 SetHostVisitsFeatures(num_visits, first_visit, true, request.get()); |
405 | 405 |
406 // Same lookup but for the HTTPS URL. | 406 // Same lookup but for the HTTPS URL. |
407 history::HistoryService* history; | 407 history::HistoryService* history; |
408 if (!GetHistoryService(&history)) { | 408 if (!GetHistoryService(&history)) { |
409 callback.Run(false, request.Pass()); | 409 callback.Run(false, std::move(request)); |
410 return; | 410 return; |
411 } | 411 } |
412 std::string https_url = request->url(); | 412 std::string https_url = request->url(); |
413 history->GetVisibleVisitCountToHost( | 413 history->GetVisibleVisitCountToHost( |
414 GURL(https_url.replace(0, 5, "https:")), | 414 GURL(https_url.replace(0, 5, "https:")), |
415 base::Bind(&BrowserFeatureExtractor::QueryHttpsHostVisitsDone, | 415 base::Bind(&BrowserFeatureExtractor::QueryHttpsHostVisitsDone, |
416 base::Unretained(this), | 416 base::Unretained(this), |
417 base::Passed(&request), | 417 base::Passed(&request), |
418 callback), | 418 callback), |
419 &cancelable_task_tracker_); | 419 &cancelable_task_tracker_); |
420 } | 420 } |
421 | 421 |
422 void BrowserFeatureExtractor::QueryHttpsHostVisitsDone( | 422 void BrowserFeatureExtractor::QueryHttpsHostVisitsDone( |
423 scoped_ptr<ClientPhishingRequest> request, | 423 scoped_ptr<ClientPhishingRequest> request, |
424 const DoneCallback& callback, | 424 const DoneCallback& callback, |
425 bool success, | 425 bool success, |
426 int num_visits, | 426 int num_visits, |
427 base::Time first_visit) { | 427 base::Time first_visit) { |
428 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 428 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
429 DCHECK(request); | 429 DCHECK(request); |
430 DCHECK(!callback.is_null()); | 430 DCHECK(!callback.is_null()); |
431 if (!success) { | 431 if (!success) { |
432 callback.Run(false, request.Pass()); | 432 callback.Run(false, std::move(request)); |
433 return; | 433 return; |
434 } | 434 } |
435 SetHostVisitsFeatures(num_visits, first_visit, false, request.get()); | 435 SetHostVisitsFeatures(num_visits, first_visit, false, request.get()); |
436 callback.Run(true, request.Pass()); | 436 callback.Run(true, std::move(request)); |
437 } | 437 } |
438 | 438 |
439 void BrowserFeatureExtractor::SetHostVisitsFeatures( | 439 void BrowserFeatureExtractor::SetHostVisitsFeatures( |
440 int num_visits, | 440 int num_visits, |
441 base::Time first_visit, | 441 base::Time first_visit, |
442 bool is_http_query, | 442 bool is_http_query, |
443 ClientPhishingRequest* request) { | 443 ClientPhishingRequest* request) { |
444 DCHECK(request); | 444 DCHECK(request); |
445 AddFeature(is_http_query ? | 445 AddFeature(is_http_query ? |
446 features::kHttpHostVisitCount : features::kHttpsHostVisitCount, | 446 features::kHttpHostVisitCount : features::kHttpsHostVisitCount, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 for (IPUrlMap::const_iterator it = bad_ips->begin(); | 481 for (IPUrlMap::const_iterator it = bad_ips->begin(); |
482 it != bad_ips->end(); ++it) { | 482 it != bad_ips->end(); ++it) { |
483 AddMalwareIpUrlInfo(it->first, it->second, request.get()); | 483 AddMalwareIpUrlInfo(it->first, it->second, request.get()); |
484 ++matched_bad_ips; | 484 ++matched_bad_ips; |
485 // Limit the number of matched bad IPs in one request to control | 485 // Limit the number of matched bad IPs in one request to control |
486 // the request's size | 486 // the request's size |
487 if (matched_bad_ips >= kMaxMalwareIPPerRequest) { | 487 if (matched_bad_ips >= kMaxMalwareIPPerRequest) { |
488 break; | 488 break; |
489 } | 489 } |
490 } | 490 } |
491 callback.Run(true, request.Pass()); | 491 callback.Run(true, std::move(request)); |
492 } | 492 } |
493 | 493 |
494 } // namespace safe_browsing | 494 } // namespace safe_browsing |
OLD | NEW |