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

Side by Side Diff: chrome/browser/safe_browsing/browser_feature_extractor.cc

Issue 1060033003: [chrome/browser/safe_browsing] favor DCHECK_CURRENTLY_ON for better logs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed unit test break now Created 5 years, 8 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
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/client_side_detection_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 25 matching lines...) Expand all
36 36
37 namespace safe_browsing { 37 namespace safe_browsing {
38 38
39 namespace { 39 namespace {
40 40
41 const int kMaxMalwareIPPerRequest = 5; 41 const int kMaxMalwareIPPerRequest = 5;
42 42
43 void FilterBenignIpsOnIOThread( 43 void FilterBenignIpsOnIOThread(
44 scoped_refptr<SafeBrowsingDatabaseManager> database_manager, 44 scoped_refptr<SafeBrowsingDatabaseManager> database_manager,
45 IPUrlMap* ips) { 45 IPUrlMap* ips) {
46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 46 DCHECK_CURRENTLY_ON(BrowserThread::IO);
47 for (IPUrlMap::iterator it = ips->begin(); it != ips->end();) { 47 for (IPUrlMap::iterator it = ips->begin(); it != ips->end();) {
48 if (!database_manager.get() || 48 if (!database_manager.get() ||
49 !database_manager->MatchMalwareIP(it->first)) { 49 !database_manager->MatchMalwareIP(it->first)) {
50 // it++ here returns a copy of the old iterator and passes it to erase. 50 // it++ here returns a copy of the old iterator and passes it to erase.
51 ips->erase(it++); 51 ips->erase(it++);
52 } else { 52 } else {
53 ++it; 53 ++it;
54 } 54 }
55 } 55 }
56 } 56 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 DCHECK(tab); 172 DCHECK(tab);
173 } 173 }
174 174
175 BrowserFeatureExtractor::~BrowserFeatureExtractor() { 175 BrowserFeatureExtractor::~BrowserFeatureExtractor() {
176 weak_factory_.InvalidateWeakPtrs(); 176 weak_factory_.InvalidateWeakPtrs();
177 } 177 }
178 178
179 void BrowserFeatureExtractor::ExtractFeatures(const BrowseInfo* info, 179 void BrowserFeatureExtractor::ExtractFeatures(const BrowseInfo* info,
180 ClientPhishingRequest* request, 180 ClientPhishingRequest* request,
181 const DoneCallback& callback) { 181 const DoneCallback& callback) {
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 182 DCHECK_CURRENTLY_ON(BrowserThread::UI);
183 DCHECK(request); 183 DCHECK(request);
184 DCHECK(info); 184 DCHECK(info);
185 DCHECK_EQ(0U, request->url().find("http:")); 185 DCHECK_EQ(0U, request->url().find("http:"));
186 DCHECK(!callback.is_null()); 186 DCHECK(!callback.is_null());
187 // Extract features pertaining to this navigation. 187 // Extract features pertaining to this navigation.
188 const NavigationController& controller = tab_->GetController(); 188 const NavigationController& controller = tab_->GetController();
189 int url_index = -1; 189 int url_index = -1;
190 int first_host_index = -1; 190 int first_host_index = -1;
191 191
192 GURL request_url(request->url()); 192 GURL request_url(request->url());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 base::Bind(&BrowserFeatureExtractor::StartExtractFeatures, 241 base::Bind(&BrowserFeatureExtractor::StartExtractFeatures,
242 weak_factory_.GetWeakPtr(), 242 weak_factory_.GetWeakPtr(),
243 base::Passed(&req), 243 base::Passed(&req),
244 callback)); 244 callback));
245 } 245 }
246 246
247 void BrowserFeatureExtractor::ExtractMalwareFeatures( 247 void BrowserFeatureExtractor::ExtractMalwareFeatures(
248 BrowseInfo* info, 248 BrowseInfo* info,
249 ClientMalwareRequest* request, 249 ClientMalwareRequest* request,
250 const MalwareDoneCallback& callback) { 250 const MalwareDoneCallback& callback) {
251 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 251 DCHECK_CURRENTLY_ON(BrowserThread::UI);
252 DCHECK(!callback.is_null()); 252 DCHECK(!callback.is_null());
253 253
254 // Grab the IPs because they might go away before we're done 254 // Grab the IPs because they might go away before we're done
255 // checking them against the IP blacklist on the IO thread. 255 // checking them against the IP blacklist on the IO thread.
256 scoped_ptr<IPUrlMap> ips(new IPUrlMap); 256 scoped_ptr<IPUrlMap> ips(new IPUrlMap);
257 ips->swap(info->ips); 257 ips->swap(info->ips);
258 258
259 IPUrlMap* ips_ptr = ips.get(); 259 IPUrlMap* ips_ptr = ips.get();
260 260
261 // The API doesn't take a scoped_ptr because the API gets mocked and we 261 // The API doesn't take a scoped_ptr because the API gets mocked and we
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 request); 295 request);
296 } 296 }
297 if (info.http_status_code != 0) { 297 if (info.http_status_code != 0) {
298 AddFeature(features::kHttpStatusCode, info.http_status_code, request); 298 AddFeature(features::kHttpStatusCode, info.http_status_code, request);
299 } 299 }
300 } 300 }
301 301
302 void BrowserFeatureExtractor::StartExtractFeatures( 302 void BrowserFeatureExtractor::StartExtractFeatures(
303 scoped_ptr<ClientPhishingRequest> request, 303 scoped_ptr<ClientPhishingRequest> request,
304 const DoneCallback& callback) { 304 const DoneCallback& callback) {
305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 305 DCHECK_CURRENTLY_ON(BrowserThread::UI);
306 history::HistoryService* history; 306 history::HistoryService* history;
307 if (!request || !request->IsInitialized() || !GetHistoryService(&history)) { 307 if (!request || !request->IsInitialized() || !GetHistoryService(&history)) {
308 callback.Run(false, request.Pass()); 308 callback.Run(false, request.Pass());
309 return; 309 return;
310 } 310 }
311 GURL request_url(request->url()); 311 GURL request_url(request->url());
312 history->QueryURL(request_url, 312 history->QueryURL(request_url,
313 true /* wants_visits */, 313 true /* wants_visits */,
314 base::Bind(&BrowserFeatureExtractor::QueryUrlHistoryDone, 314 base::Bind(&BrowserFeatureExtractor::QueryUrlHistoryDone,
315 base::Unretained(this), 315 base::Unretained(this),
316 base::Passed(&request), 316 base::Passed(&request),
317 callback), 317 callback),
318 &cancelable_task_tracker_); 318 &cancelable_task_tracker_);
319 } 319 }
320 320
321 void BrowserFeatureExtractor::QueryUrlHistoryDone( 321 void BrowserFeatureExtractor::QueryUrlHistoryDone(
322 scoped_ptr<ClientPhishingRequest> request, 322 scoped_ptr<ClientPhishingRequest> request,
323 const DoneCallback& callback, 323 const DoneCallback& callback,
324 bool success, 324 bool success,
325 const history::URLRow& row, 325 const history::URLRow& row,
326 const history::VisitVector& visits) { 326 const history::VisitVector& visits) {
327 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 327 DCHECK_CURRENTLY_ON(BrowserThread::UI);
328 DCHECK(request); 328 DCHECK(request);
329 DCHECK(!callback.is_null()); 329 DCHECK(!callback.is_null());
330 if (!success) { 330 if (!success) {
331 // URL is not found in the history. In practice this should not 331 // URL is not found in the history. In practice this should not
332 // happen (unless there is a real error) because we just visited 332 // happen (unless there is a real error) because we just visited
333 // that URL. 333 // that URL.
334 callback.Run(false, request.Pass()); 334 callback.Run(false, request.Pass());
335 return; 335 return;
336 } 336 }
337 AddFeature(features::kUrlHistoryVisitCount, 337 AddFeature(features::kUrlHistoryVisitCount,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 callback), 384 callback),
385 &cancelable_task_tracker_); 385 &cancelable_task_tracker_);
386 } 386 }
387 387
388 void BrowserFeatureExtractor::QueryHttpHostVisitsDone( 388 void BrowserFeatureExtractor::QueryHttpHostVisitsDone(
389 scoped_ptr<ClientPhishingRequest> request, 389 scoped_ptr<ClientPhishingRequest> request,
390 const DoneCallback& callback, 390 const DoneCallback& callback,
391 bool success, 391 bool success,
392 int num_visits, 392 int num_visits,
393 base::Time first_visit) { 393 base::Time first_visit) {
394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 394 DCHECK_CURRENTLY_ON(BrowserThread::UI);
395 DCHECK(request); 395 DCHECK(request);
396 DCHECK(!callback.is_null()); 396 DCHECK(!callback.is_null());
397 if (!success) { 397 if (!success) {
398 callback.Run(false, request.Pass()); 398 callback.Run(false, request.Pass());
399 return; 399 return;
400 } 400 }
401 SetHostVisitsFeatures(num_visits, first_visit, true, request.get()); 401 SetHostVisitsFeatures(num_visits, first_visit, true, request.get());
402 402
403 // Same lookup but for the HTTPS URL. 403 // Same lookup but for the HTTPS URL.
404 history::HistoryService* history; 404 history::HistoryService* history;
(...skipping 10 matching lines...) Expand all
415 callback), 415 callback),
416 &cancelable_task_tracker_); 416 &cancelable_task_tracker_);
417 } 417 }
418 418
419 void BrowserFeatureExtractor::QueryHttpsHostVisitsDone( 419 void BrowserFeatureExtractor::QueryHttpsHostVisitsDone(
420 scoped_ptr<ClientPhishingRequest> request, 420 scoped_ptr<ClientPhishingRequest> request,
421 const DoneCallback& callback, 421 const DoneCallback& callback,
422 bool success, 422 bool success,
423 int num_visits, 423 int num_visits,
424 base::Time first_visit) { 424 base::Time first_visit) {
425 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 425 DCHECK_CURRENTLY_ON(BrowserThread::UI);
426 DCHECK(request); 426 DCHECK(request);
427 DCHECK(!callback.is_null()); 427 DCHECK(!callback.is_null());
428 if (!success) { 428 if (!success) {
429 callback.Run(false, request.Pass()); 429 callback.Run(false, request.Pass());
430 return; 430 return;
431 } 431 }
432 SetHostVisitsFeatures(num_visits, first_visit, false, request.get()); 432 SetHostVisitsFeatures(num_visits, first_visit, false, request.get());
433 callback.Run(true, request.Pass()); 433 callback.Run(true, request.Pass());
434 } 434 }
435 435
(...skipping 30 matching lines...) Expand all
466 } 466 }
467 } 467 }
468 DVLOG(2) << "Unable to query history. No history service available."; 468 DVLOG(2) << "Unable to query history. No history service available.";
469 return false; 469 return false;
470 } 470 }
471 471
472 void BrowserFeatureExtractor::FinishExtractMalwareFeatures( 472 void BrowserFeatureExtractor::FinishExtractMalwareFeatures(
473 scoped_ptr<IPUrlMap> bad_ips, 473 scoped_ptr<IPUrlMap> bad_ips,
474 MalwareDoneCallback callback, 474 MalwareDoneCallback callback,
475 scoped_ptr<ClientMalwareRequest> request) { 475 scoped_ptr<ClientMalwareRequest> request) {
476 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 476 DCHECK_CURRENTLY_ON(BrowserThread::UI);
477 int matched_bad_ips = 0; 477 int matched_bad_ips = 0;
478 for (IPUrlMap::const_iterator it = bad_ips->begin(); 478 for (IPUrlMap::const_iterator it = bad_ips->begin();
479 it != bad_ips->end(); ++it) { 479 it != bad_ips->end(); ++it) {
480 AddMalwareIpUrlInfo(it->first, it->second, request.get()); 480 AddMalwareIpUrlInfo(it->first, it->second, request.get());
481 ++matched_bad_ips; 481 ++matched_bad_ips;
482 // Limit the number of matched bad IPs in one request to control 482 // Limit the number of matched bad IPs in one request to control
483 // the request's size 483 // the request's size
484 if (matched_bad_ips >= kMaxMalwareIPPerRequest) { 484 if (matched_bad_ips >= kMaxMalwareIPPerRequest) {
485 break; 485 break;
486 } 486 }
487 } 487 }
488 callback.Run(true, request.Pass()); 488 callback.Run(true, request.Pass());
489 } 489 }
490 490
491 } // namespace safe_browsing 491 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/safe_browsing/client_side_detection_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698