Chromium Code Reviews| 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/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 12 matching lines...) Expand all Loading... | |
| 23 #include "chrome/browser/safe_browsing/malware_details.h" | 23 #include "chrome/browser/safe_browsing/malware_details.h" |
| 24 #include "chrome/browser/safe_browsing/protocol_manager.h" | 24 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 25 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 25 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
| 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 27 #include "chrome/browser/safe_browsing/ui_manager.h" | 27 #include "chrome/browser/safe_browsing/ui_manager.h" |
| 28 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
| 29 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
| 30 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 31 #include "components/metrics/metrics_service.h" | 31 #include "components/metrics/metrics_service.h" |
| 32 #include "components/startup_metric_utils/startup_metric_utils.h" | 32 #include "components/startup_metric_utils/startup_metric_utils.h" |
| 33 #include "components/variations/variations_associated_data.h" | |
| 33 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/notification_service.h" | 35 #include "content/public/browser/notification_service.h" |
| 35 #include "url/url_constants.h" | 36 #include "url/url_constants.h" |
| 36 | 37 |
| 37 using content::BrowserThread; | 38 using content::BrowserThread; |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 // Timeout for match checks, e.g. download URLs, hashes. | 42 // Timeout for match checks, e.g. download URLs, hashes. |
| 42 const int kCheckTimeoutMs = 10000; | 43 const int kCheckTimeoutMs = 10000; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 case safe_browsing_util::BINURL: | 161 case safe_browsing_util::BINURL: |
| 161 return SB_THREAT_TYPE_BINARY_MALWARE_URL; | 162 return SB_THREAT_TYPE_BINARY_MALWARE_URL; |
| 162 case safe_browsing_util::EXTENSIONBLACKLIST: | 163 case safe_browsing_util::EXTENSIONBLACKLIST: |
| 163 return SB_THREAT_TYPE_EXTENSION; | 164 return SB_THREAT_TYPE_EXTENSION; |
| 164 default: | 165 default: |
| 165 DVLOG(1) << "Unknown safe browsing list id " << list_type; | 166 DVLOG(1) << "Unknown safe browsing list id " << list_type; |
| 166 return SB_THREAT_TYPE_SAFE; | 167 return SB_THREAT_TYPE_SAFE; |
| 167 } | 168 } |
| 168 } | 169 } |
| 169 | 170 |
| 171 // TODO(asvitkine): Experimental code for measuring start up impact of SB. | |
| 172 // Remove when experimentation is complete. http://crbug.com/450037 | |
| 173 bool ShouldDisableSafeBrowsing() { | |
| 174 static bool disable_sb = | |
|
gab
2015/02/13 18:09:35
DCHECK_CURRENTLY_ON(BrowserThread::IO);
since a s
Alexei Svitkine (slow)
2015/02/13 19:00:08
Done.
| |
| 175 !variations::GetVariationParamValue("LightSpeed", "DisableSB").empty(); | |
| 176 return disable_sb; | |
| 177 } | |
| 178 | |
| 170 } // namespace | 179 } // namespace |
| 171 | 180 |
| 172 // static | 181 // static |
| 173 SBThreatType SafeBrowsingDatabaseManager::GetHashSeverestThreatType( | 182 SBThreatType SafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
| 174 const SBFullHash& hash, | 183 const SBFullHash& hash, |
| 175 const std::vector<SBFullHashResult>& full_hashes) { | 184 const std::vector<SBFullHashResult>& full_hashes) { |
| 176 return GetThreatTypeFromListType( | 185 return GetThreatTypeFromListType( |
| 177 GetHashSeverestThreatListType(hash, full_hashes, NULL)); | 186 GetHashSeverestThreatListType(hash, full_hashes, NULL)); |
| 178 } | 187 } |
| 179 | 188 |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 586 std::vector<SBPrefix> prefixes = check->prefix_hits; | 595 std::vector<SBPrefix> prefixes = check->prefix_hits; |
| 587 OnHandleGetHashResults(check, full_hashes); // 'check' is deleted here. | 596 OnHandleGetHashResults(check, full_hashes); // 'check' is deleted here. |
| 588 | 597 |
| 589 // Cache the GetHash results. | 598 // Cache the GetHash results. |
| 590 if (cache_lifetime != base::TimeDelta() && MakeDatabaseAvailable()) | 599 if (cache_lifetime != base::TimeDelta() && MakeDatabaseAvailable()) |
| 591 database_->CacheHashResults(prefixes, full_hashes, cache_lifetime); | 600 database_->CacheHashResults(prefixes, full_hashes, cache_lifetime); |
| 592 } | 601 } |
| 593 | 602 |
| 594 void SafeBrowsingDatabaseManager::GetChunks(GetChunksCallback callback) { | 603 void SafeBrowsingDatabaseManager::GetChunks(GetChunksCallback callback) { |
| 595 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 604 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 605 | |
| 606 if (ShouldDisableSafeBrowsing()) | |
| 607 return; | |
| 608 | |
| 596 DCHECK(enabled_); | 609 DCHECK(enabled_); |
| 597 DCHECK(!callback.is_null()); | 610 DCHECK(!callback.is_null()); |
| 598 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 611 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 599 &SafeBrowsingDatabaseManager::GetAllChunksFromDatabase, this, callback)); | 612 &SafeBrowsingDatabaseManager::GetAllChunksFromDatabase, this, callback)); |
| 600 } | 613 } |
| 601 | 614 |
| 602 void SafeBrowsingDatabaseManager::AddChunks( | 615 void SafeBrowsingDatabaseManager::AddChunks( |
| 603 const std::string& list, | 616 const std::string& list, |
| 604 scoped_ptr<ScopedVector<SBChunkData> > chunks, | 617 scoped_ptr<ScopedVector<SBChunkData> > chunks, |
| 605 AddChunksCallback callback) { | 618 AddChunksCallback callback) { |
| 606 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 619 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 620 | |
| 621 if (ShouldDisableSafeBrowsing()) | |
| 622 return; | |
| 623 | |
| 607 DCHECK(enabled_); | 624 DCHECK(enabled_); |
| 608 DCHECK(!callback.is_null()); | 625 DCHECK(!callback.is_null()); |
| 609 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 626 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 610 &SafeBrowsingDatabaseManager::AddDatabaseChunks, this, list, | 627 &SafeBrowsingDatabaseManager::AddDatabaseChunks, this, list, |
| 611 base::Passed(&chunks), callback)); | 628 base::Passed(&chunks), callback)); |
| 612 } | 629 } |
| 613 | 630 |
| 614 void SafeBrowsingDatabaseManager::DeleteChunks( | 631 void SafeBrowsingDatabaseManager::DeleteChunks( |
| 615 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { | 632 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { |
| 616 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 633 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 634 | |
| 635 if (ShouldDisableSafeBrowsing()) | |
| 636 return; | |
| 637 | |
| 617 DCHECK(enabled_); | 638 DCHECK(enabled_); |
| 618 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 639 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 619 &SafeBrowsingDatabaseManager::DeleteDatabaseChunks, this, | 640 &SafeBrowsingDatabaseManager::DeleteDatabaseChunks, this, |
| 620 base::Passed(&chunk_deletes))); | 641 base::Passed(&chunk_deletes))); |
| 621 } | 642 } |
| 622 | 643 |
| 623 void SafeBrowsingDatabaseManager::UpdateStarted() { | 644 void SafeBrowsingDatabaseManager::UpdateStarted() { |
| 624 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 645 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 646 | |
| 647 if (ShouldDisableSafeBrowsing()) | |
| 648 return; | |
| 649 | |
| 625 DCHECK(enabled_); | 650 DCHECK(enabled_); |
| 626 DCHECK(!update_in_progress_); | 651 DCHECK(!update_in_progress_); |
| 627 update_in_progress_ = true; | 652 update_in_progress_ = true; |
| 628 } | 653 } |
| 629 | 654 |
| 630 void SafeBrowsingDatabaseManager::UpdateFinished(bool update_succeeded) { | 655 void SafeBrowsingDatabaseManager::UpdateFinished(bool update_succeeded) { |
| 631 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 656 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 632 DCHECK(enabled_); | 657 DCHECK(enabled_); |
| 633 if (update_in_progress_) { | 658 if (update_in_progress_) { |
| 634 update_in_progress_ = false; | 659 update_in_progress_ = false; |
| 635 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, | 660 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, |
| 636 base::Bind(&SafeBrowsingDatabaseManager::DatabaseUpdateFinished, | 661 base::Bind(&SafeBrowsingDatabaseManager::DatabaseUpdateFinished, |
| 637 this, update_succeeded)); | 662 this, update_succeeded)); |
| 638 } | 663 } |
| 639 } | 664 } |
| 640 | 665 |
| 641 void SafeBrowsingDatabaseManager::ResetDatabase() { | 666 void SafeBrowsingDatabaseManager::ResetDatabase() { |
| 642 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 667 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 643 DCHECK(enabled_); | 668 DCHECK(enabled_); |
| 644 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 669 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |
| 645 &SafeBrowsingDatabaseManager::OnResetDatabase, this)); | 670 &SafeBrowsingDatabaseManager::OnResetDatabase, this)); |
| 646 } | 671 } |
| 647 | 672 |
| 648 void SafeBrowsingDatabaseManager::StartOnIOThread() { | 673 void SafeBrowsingDatabaseManager::StartOnIOThread() { |
| 649 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 674 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 650 if (enabled_) | 675 if (enabled_) |
| 651 return; | 676 return; |
| 652 | 677 |
| 678 if (ShouldDisableSafeBrowsing()) | |
| 679 return; | |
| 680 | |
| 653 DCHECK(!safe_browsing_thread_.get()); | 681 DCHECK(!safe_browsing_thread_.get()); |
| 654 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); | 682 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); |
| 655 if (!safe_browsing_thread_->Start()) | 683 if (!safe_browsing_thread_->Start()) |
| 656 return; | 684 return; |
| 657 enabled_ = true; | 685 enabled_ = true; |
| 658 | 686 |
| 659 MakeDatabaseAvailable(); | 687 MakeDatabaseAvailable(); |
| 660 } | 688 } |
| 661 | 689 |
| 662 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { | 690 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { |
| (...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1169 new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); | 1197 new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); |
| 1170 checks_.insert(check); | 1198 checks_.insert(check); |
| 1171 | 1199 |
| 1172 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task); | 1200 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task); |
| 1173 | 1201 |
| 1174 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 1202 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 1175 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, | 1203 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, |
| 1176 check->timeout_factory_->GetWeakPtr(), check), | 1204 check->timeout_factory_->GetWeakPtr(), check), |
| 1177 check_timeout_); | 1205 check_timeout_); |
| 1178 } | 1206 } |
| OLD | NEW |