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 <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 Loading... |
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 // HistoryService::QueryURL migrated from CancelableRequestComsumer to | 326 CancelableRequestProvider::Handle handle = history->QueryURL( |
327 // CancelableRequestTracker and there is no Handle to associate to the | 327 GURL(request->url()), |
328 // request. Instead manage the request object lifetime by using a scoped_ptr | 328 true /* wants_visits */, |
329 // and using base::Passed(). So if the asynchronous call is canceled, the | 329 &request_consumer_, |
330 // request is deleted, otherwise the callback becomes the owner. | 330 base::Bind(&BrowserFeatureExtractor::QueryUrlHistoryDone, |
331 scoped_ptr<ClientPhishingRequest> owned_request(request); | 331 base::Unretained(this))); |
332 history->QueryURL(GURL(request->url()), | 332 |
333 true /* wants_visits */, | 333 StorePendingQuery(handle, request, callback); |
334 base::Bind(&BrowserFeatureExtractor::QueryUrlHistoryDone, | |
335 base::Unretained(this), | |
336 base::Passed(&owned_request), | |
337 callback), | |
338 &cancelable_task_tracker_); | |
339 } | 334 } |
340 | 335 |
341 void BrowserFeatureExtractor::QueryUrlHistoryDone( | 336 void BrowserFeatureExtractor::QueryUrlHistoryDone( |
342 scoped_ptr<ClientPhishingRequest> owned_request, | 337 CancelableRequestProvider::Handle handle, |
343 const DoneCallback& callback, | |
344 bool success, | 338 bool success, |
345 const history::URLRow& row, | 339 const history::URLRow* row, |
346 const history::VisitVector& visits) { | 340 history::VisitVector* visits) { |
347 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
348 DCHECK(owned_request); | 342 ClientPhishingRequest* 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(); | |
351 if (!success) { | 350 if (!success) { |
352 // URL is not found in the history. In practice this should not | 351 // URL is not found in the history. In practice this should not |
353 // happen (unless there is a real error) because we just visited | 352 // happen (unless there is a real error) because we just visited |
354 // that URL. | 353 // that URL. |
355 callback.Run(false, request); | 354 callback.Run(false, request); |
356 return; | 355 return; |
357 } | 356 } |
358 AddFeature(features::kUrlHistoryVisitCount, | 357 AddFeature(features::kUrlHistoryVisitCount, |
359 static_cast<double>(row.visit_count()), | 358 static_cast<double>(row->visit_count()), |
360 request); | 359 request); |
361 | 360 |
362 base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1); | 361 base::Time threshold = base::Time::Now() - base::TimeDelta::FromDays(1); |
363 int num_visits_24h_ago = 0; | 362 int num_visits_24h_ago = 0; |
364 int num_visits_typed = 0; | 363 int num_visits_typed = 0; |
365 int num_visits_link = 0; | 364 int num_visits_link = 0; |
366 for (history::VisitVector::const_iterator it = visits.begin(); | 365 for (history::VisitVector::const_iterator it = visits->begin(); |
367 it != visits.end(); | 366 it != visits->end(); ++it) { |
368 ++it) { | |
369 if (!content::PageTransitionIsMainFrame(it->transition)) { | 367 if (!content::PageTransitionIsMainFrame(it->transition)) { |
370 continue; | 368 continue; |
371 } | 369 } |
372 if (it->visit_time < threshold) { | 370 if (it->visit_time < threshold) { |
373 ++num_visits_24h_ago; | 371 ++num_visits_24h_ago; |
374 } | 372 } |
375 content::PageTransition transition = content::PageTransitionStripQualifier( | 373 content::PageTransition transition = content::PageTransitionStripQualifier( |
376 it->transition); | 374 it->transition); |
377 if (transition == content::PAGE_TRANSITION_TYPED) { | 375 if (transition == content::PAGE_TRANSITION_TYPED) { |
378 ++num_visits_typed; | 376 ++num_visits_typed; |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 // Limit the number of matched bad IPs in one request to control | 532 // Limit the number of matched bad IPs in one request to control |
535 // the request's size | 533 // the request's size |
536 if (matched_bad_ips >= kMaxMalwareIPPerRequest) { | 534 if (matched_bad_ips >= kMaxMalwareIPPerRequest) { |
537 break; | 535 break; |
538 } | 536 } |
539 } | 537 } |
540 callback.Run(true, request.Pass()); | 538 callback.Run(true, request.Pass()); |
541 } | 539 } |
542 | 540 |
543 } // namespace safe_browsing | 541 } // namespace safe_browsing |
OLD | NEW |