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

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

Issue 280013002: [safe browsing] Switch to independent cache lifetimes for gethash items. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Bah, just use base::Time and be done. Created 6 years, 7 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 | Annotate | Revision Log
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/database_manager.h" 5 #include "chrome/browser/safe_browsing/database_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 expected_threats, 355 expected_threats,
356 start); 356 start);
357 queued_checks_.push_back(queued_check); 357 queued_checks_.push_back(queued_check);
358 return false; 358 return false;
359 } 359 }
360 360
361 std::vector<SBPrefix> prefix_hits; 361 std::vector<SBPrefix> prefix_hits;
362 std::vector<SBFullHashResult> cached_hits; 362 std::vector<SBFullHashResult> cached_hits;
363 363
364 bool prefix_match = 364 bool prefix_match =
365 database_->ContainsBrowseUrl(url, &prefix_hits, &cached_hits, 365 database_->ContainsBrowseUrl(url, &prefix_hits, &cached_hits);
366 sb_service_->protocol_manager()->last_update());
367 366
368 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", base::TimeTicks::Now() - start); 367 UMA_HISTOGRAM_TIMES("SB2.FilterCheck", base::TimeTicks::Now() - start);
369 368
370 if (!prefix_match) 369 if (!prefix_match)
371 return true; // URL is okay. 370 return true; // URL is okay.
372 371
373 // Needs to be asynchronous, since we could be in the constructor of a 372 // Needs to be asynchronous, since we could be in the constructor of a
374 // ResourceDispatcherHost event handler which can't pause there. 373 // ResourceDispatcherHost event handler which can't pause there.
375 SafeBrowsingCheck* check = new SafeBrowsingCheck(std::vector<GURL>(1, url), 374 SafeBrowsingCheck* check = new SafeBrowsingCheck(std::vector<GURL>(1, url),
376 std::vector<SBFullHash>(), 375 std::vector<SBFullHash>(),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 if (it->client == client) 407 if (it->client == client)
409 it = queued_checks_.erase(it); 408 it = queued_checks_.erase(it);
410 else 409 else
411 ++it; 410 ++it;
412 } 411 }
413 } 412 }
414 413
415 void SafeBrowsingDatabaseManager::HandleGetHashResults( 414 void SafeBrowsingDatabaseManager::HandleGetHashResults(
416 SafeBrowsingCheck* check, 415 SafeBrowsingCheck* check,
417 const std::vector<SBFullHashResult>& full_hashes, 416 const std::vector<SBFullHashResult>& full_hashes,
418 bool can_cache) { 417 const base::TimeDelta& cache_lifetime) {
419 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 418 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
420 419
421 if (!enabled_) 420 if (!enabled_)
422 return; 421 return;
423 422
424 // If the service has been shut down, |check| should have been deleted. 423 // If the service has been shut down, |check| should have been deleted.
425 DCHECK(checks_.find(check) != checks_.end()); 424 DCHECK(checks_.find(check) != checks_.end());
426 425
427 // |start| is set before calling |GetFullHash()|, which should be 426 // |start| is set before calling |GetFullHash()|, which should be
428 // the only path which gets to here. 427 // the only path which gets to here.
429 DCHECK(!check->start.is_null()); 428 DCHECK(!check->start.is_null());
430 UMA_HISTOGRAM_LONG_TIMES("SB2.Network", 429 UMA_HISTOGRAM_LONG_TIMES("SB2.Network",
431 base::TimeTicks::Now() - check->start); 430 base::TimeTicks::Now() - check->start);
432 431
433 std::vector<SBPrefix> prefixes = check->prefix_hits; 432 std::vector<SBPrefix> prefixes = check->prefix_hits;
434 OnHandleGetHashResults(check, full_hashes); // 'check' is deleted here. 433 OnHandleGetHashResults(check, full_hashes); // 'check' is deleted here.
435 434
436 if (can_cache && MakeDatabaseAvailable()) { 435 // Cache the GetHash results.
437 // Cache the GetHash results in memory: 436 if (cache_lifetime != base::TimeDelta() && MakeDatabaseAvailable())
438 database_->CacheHashResults(prefixes, full_hashes); 437 database_->CacheHashResults(prefixes, full_hashes, cache_lifetime);
439 }
440 } 438 }
441 439
442 void SafeBrowsingDatabaseManager::GetChunks(GetChunksCallback callback) { 440 void SafeBrowsingDatabaseManager::GetChunks(GetChunksCallback callback) {
443 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
444 DCHECK(enabled_); 442 DCHECK(enabled_);
445 DCHECK(!callback.is_null()); 443 DCHECK(!callback.is_null());
446 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( 444 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind(
447 &SafeBrowsingDatabaseManager::GetAllChunksFromDatabase, this, callback)); 445 &SafeBrowsingDatabaseManager::GetAllChunksFromDatabase, this, callback));
448 } 446 }
449 447
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 base::AutoLock lock(database_lock_); 833 base::AutoLock lock(database_lock_);
836 closing_database_ = false; 834 closing_database_ = false;
837 } 835 }
838 836
839 void SafeBrowsingDatabaseManager::OnResetDatabase() { 837 void SafeBrowsingDatabaseManager::OnResetDatabase() {
840 DCHECK_EQ(base::MessageLoop::current(), 838 DCHECK_EQ(base::MessageLoop::current(),
841 safe_browsing_thread_->message_loop()); 839 safe_browsing_thread_->message_loop());
842 GetDatabase()->ResetDatabase(); 840 GetDatabase()->ResetDatabase();
843 } 841 }
844 842
845 void SafeBrowsingDatabaseManager::CacheHashResults(
846 const std::vector<SBPrefix>& prefixes,
847 const std::vector<SBFullHashResult>& full_hashes) {
848 DCHECK_EQ(base::MessageLoop::current(),
849 safe_browsing_thread_->message_loop());
850 GetDatabase()->CacheHashResults(prefixes, full_hashes);
851 }
852
853 void SafeBrowsingDatabaseManager::OnHandleGetHashResults( 843 void SafeBrowsingDatabaseManager::OnHandleGetHashResults(
854 SafeBrowsingCheck* check, 844 SafeBrowsingCheck* check,
855 const std::vector<SBFullHashResult>& full_hashes) { 845 const std::vector<SBFullHashResult>& full_hashes) {
856 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 846 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
857 safe_browsing_util::ListType check_type = check->check_type; 847 safe_browsing_util::ListType check_type = check->check_type;
858 SBPrefix prefix = check->prefix_hits[0]; 848 SBPrefix prefix = check->prefix_hits[0];
859 GetHashRequests::iterator it = gethash_requests_.find(prefix); 849 GetHashRequests::iterator it = gethash_requests_.find(prefix);
860 if (check->prefix_hits.size() > 1 || it == gethash_requests_.end()) { 850 if (check->prefix_hits.size() > 1 || it == gethash_requests_.end()) {
861 const bool hit = HandleOneCheck(check, full_hashes); 851 const bool hit = HandleOneCheck(check, full_hashes);
862 RecordGetHashCheckStatus(hit, check_type, full_hashes); 852 RecordGetHashCheckStatus(hit, check_type, full_hashes);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); 1004 new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this));
1015 checks_.insert(check); 1005 checks_.insert(check);
1016 1006
1017 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task); 1007 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task);
1018 1008
1019 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, 1009 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
1020 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, 1010 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback,
1021 check->timeout_factory_->GetWeakPtr(), check), 1011 check->timeout_factory_->GetWeakPtr(), check),
1022 check_timeout_); 1012 check_timeout_);
1023 } 1013 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698