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 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
175 static bool disable_sb = | |
176 !variations::GetVariationParamValue("LightSpeed", "DisableSB").empty(); | |
gab
2015/02/13 22:58:21
Hmmm actually, isn't this boolean logic backwards?
gab
2015/02/13 23:00:09
Oh nvm, it's !empty(), i.e. disabled == not not di
gab
2015/02/13 23:01:36
Would be nice to have a boolean method on that API
| |
177 return disable_sb; | |
178 } | |
179 | |
170 } // namespace | 180 } // namespace |
171 | 181 |
172 // static | 182 // static |
173 SBThreatType SafeBrowsingDatabaseManager::GetHashSeverestThreatType( | 183 SBThreatType SafeBrowsingDatabaseManager::GetHashSeverestThreatType( |
174 const SBFullHash& hash, | 184 const SBFullHash& hash, |
175 const std::vector<SBFullHashResult>& full_hashes) { | 185 const std::vector<SBFullHashResult>& full_hashes) { |
176 return GetThreatTypeFromListType( | 186 return GetThreatTypeFromListType( |
177 GetHashSeverestThreatListType(hash, full_hashes, NULL)); | 187 GetHashSeverestThreatListType(hash, full_hashes, NULL)); |
178 } | 188 } |
179 | 189 |
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
586 std::vector<SBPrefix> prefixes = check->prefix_hits; | 596 std::vector<SBPrefix> prefixes = check->prefix_hits; |
587 OnHandleGetHashResults(check, full_hashes); // 'check' is deleted here. | 597 OnHandleGetHashResults(check, full_hashes); // 'check' is deleted here. |
588 | 598 |
589 // Cache the GetHash results. | 599 // Cache the GetHash results. |
590 if (cache_lifetime != base::TimeDelta() && MakeDatabaseAvailable()) | 600 if (cache_lifetime != base::TimeDelta() && MakeDatabaseAvailable()) |
591 database_->CacheHashResults(prefixes, full_hashes, cache_lifetime); | 601 database_->CacheHashResults(prefixes, full_hashes, cache_lifetime); |
592 } | 602 } |
593 | 603 |
594 void SafeBrowsingDatabaseManager::GetChunks(GetChunksCallback callback) { | 604 void SafeBrowsingDatabaseManager::GetChunks(GetChunksCallback callback) { |
595 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 605 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
606 | |
607 if (ShouldDisableSafeBrowsing()) | |
608 return; | |
609 | |
596 DCHECK(enabled_); | 610 DCHECK(enabled_); |
597 DCHECK(!callback.is_null()); | 611 DCHECK(!callback.is_null()); |
598 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 612 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |
599 &SafeBrowsingDatabaseManager::GetAllChunksFromDatabase, this, callback)); | 613 &SafeBrowsingDatabaseManager::GetAllChunksFromDatabase, this, callback)); |
600 } | 614 } |
601 | 615 |
602 void SafeBrowsingDatabaseManager::AddChunks( | 616 void SafeBrowsingDatabaseManager::AddChunks( |
603 const std::string& list, | 617 const std::string& list, |
604 scoped_ptr<ScopedVector<SBChunkData> > chunks, | 618 scoped_ptr<ScopedVector<SBChunkData> > chunks, |
605 AddChunksCallback callback) { | 619 AddChunksCallback callback) { |
606 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 620 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
621 | |
622 if (ShouldDisableSafeBrowsing()) | |
623 return; | |
624 | |
607 DCHECK(enabled_); | 625 DCHECK(enabled_); |
608 DCHECK(!callback.is_null()); | 626 DCHECK(!callback.is_null()); |
609 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 627 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |
610 &SafeBrowsingDatabaseManager::AddDatabaseChunks, this, list, | 628 &SafeBrowsingDatabaseManager::AddDatabaseChunks, this, list, |
611 base::Passed(&chunks), callback)); | 629 base::Passed(&chunks), callback)); |
612 } | 630 } |
613 | 631 |
614 void SafeBrowsingDatabaseManager::DeleteChunks( | 632 void SafeBrowsingDatabaseManager::DeleteChunks( |
615 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { | 633 scoped_ptr<std::vector<SBChunkDelete> > chunk_deletes) { |
616 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 634 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
635 | |
636 if (ShouldDisableSafeBrowsing()) | |
637 return; | |
638 | |
617 DCHECK(enabled_); | 639 DCHECK(enabled_); |
618 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 640 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |
619 &SafeBrowsingDatabaseManager::DeleteDatabaseChunks, this, | 641 &SafeBrowsingDatabaseManager::DeleteDatabaseChunks, this, |
620 base::Passed(&chunk_deletes))); | 642 base::Passed(&chunk_deletes))); |
621 } | 643 } |
622 | 644 |
623 void SafeBrowsingDatabaseManager::UpdateStarted() { | 645 void SafeBrowsingDatabaseManager::UpdateStarted() { |
624 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 646 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
647 | |
648 if (ShouldDisableSafeBrowsing()) | |
649 return; | |
650 | |
625 DCHECK(enabled_); | 651 DCHECK(enabled_); |
626 DCHECK(!update_in_progress_); | 652 DCHECK(!update_in_progress_); |
627 update_in_progress_ = true; | 653 update_in_progress_ = true; |
628 } | 654 } |
629 | 655 |
630 void SafeBrowsingDatabaseManager::UpdateFinished(bool update_succeeded) { | 656 void SafeBrowsingDatabaseManager::UpdateFinished(bool update_succeeded) { |
631 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 657 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
632 DCHECK(enabled_); | 658 DCHECK(enabled_); |
633 if (update_in_progress_) { | 659 if (update_in_progress_) { |
634 update_in_progress_ = false; | 660 update_in_progress_ = false; |
635 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, | 661 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, |
636 base::Bind(&SafeBrowsingDatabaseManager::DatabaseUpdateFinished, | 662 base::Bind(&SafeBrowsingDatabaseManager::DatabaseUpdateFinished, |
637 this, update_succeeded)); | 663 this, update_succeeded)); |
638 } | 664 } |
639 } | 665 } |
640 | 666 |
641 void SafeBrowsingDatabaseManager::ResetDatabase() { | 667 void SafeBrowsingDatabaseManager::ResetDatabase() { |
642 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 668 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
643 DCHECK(enabled_); | 669 DCHECK(enabled_); |
644 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( | 670 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, base::Bind( |
645 &SafeBrowsingDatabaseManager::OnResetDatabase, this)); | 671 &SafeBrowsingDatabaseManager::OnResetDatabase, this)); |
646 } | 672 } |
647 | 673 |
648 void SafeBrowsingDatabaseManager::StartOnIOThread() { | 674 void SafeBrowsingDatabaseManager::StartOnIOThread() { |
649 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 675 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
650 if (enabled_) | 676 if (enabled_) |
651 return; | 677 return; |
652 | 678 |
679 if (ShouldDisableSafeBrowsing()) | |
680 return; | |
681 | |
653 DCHECK(!safe_browsing_thread_.get()); | 682 DCHECK(!safe_browsing_thread_.get()); |
654 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); | 683 safe_browsing_thread_.reset(new base::Thread("Chrome_SafeBrowsingThread")); |
655 if (!safe_browsing_thread_->Start()) | 684 if (!safe_browsing_thread_->Start()) |
656 return; | 685 return; |
657 enabled_ = true; | 686 enabled_ = true; |
658 | 687 |
659 MakeDatabaseAvailable(); | 688 MakeDatabaseAvailable(); |
660 } | 689 } |
661 | 690 |
662 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { | 691 void SafeBrowsingDatabaseManager::StopOnIOThread(bool shutdown) { |
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1169 new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); | 1198 new base::WeakPtrFactory<SafeBrowsingDatabaseManager>(this)); |
1170 checks_.insert(check); | 1199 checks_.insert(check); |
1171 | 1200 |
1172 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task); | 1201 safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, task); |
1173 | 1202 |
1174 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, | 1203 base::MessageLoop::current()->PostDelayedTask(FROM_HERE, |
1175 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, | 1204 base::Bind(&SafeBrowsingDatabaseManager::TimeoutCallback, |
1176 check->timeout_factory_->GetWeakPtr(), check), | 1205 check->timeout_factory_->GetWeakPtr(), check), |
1177 check_timeout_); | 1206 check_timeout_); |
1178 } | 1207 } |
OLD | NEW |