| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 | 5 |
| 6 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 6 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/histogram.h" | 9 #include "base/histogram.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/chrome_thread.h" | |
| 16 #include "chrome/browser/profile_manager.h" | 15 #include "chrome/browser/profile_manager.h" |
| 17 #include "chrome/browser/safe_browsing/protocol_manager.h" | 16 #include "chrome/browser/safe_browsing/protocol_manager.h" |
| 18 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" | 17 #include "chrome/browser/safe_browsing/safe_browsing_blocking_page.h" |
| 19 #include "chrome/browser/safe_browsing/safe_browsing_database.h" | 18 #include "chrome/browser/safe_browsing/safe_browsing_database.h" |
| 20 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
| 21 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 23 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 24 #include "chrome/common/pref_service.h" | 23 #include "chrome/common/pref_service.h" |
| 25 #include "net/base/registry_controlled_domain.h" | 24 #include "net/base/registry_controlled_domain.h" |
| 26 | 25 |
| 27 using base::Time; | 26 using base::Time; |
| 28 using base::TimeDelta; | 27 using base::TimeDelta; |
| 29 | 28 |
| 30 SafeBrowsingService::SafeBrowsingService() | 29 SafeBrowsingService::SafeBrowsingService() |
| 31 : io_loop_(NULL), | 30 : io_loop_(NULL), |
| 32 database_(NULL), | 31 database_(NULL), |
| 33 protocol_manager_(NULL), | 32 protocol_manager_(NULL), |
| 34 enabled_(false), | 33 enabled_(false), |
| 35 resetting_(false), | 34 resetting_(false), |
| 36 database_loaded_(false) { | 35 database_loaded_(false) { |
| 37 new_safe_browsing_ = !CommandLine().HasSwitch(switches::kUseOldSafeBrowsing); | 36 new_safe_browsing_ = !CommandLine().HasSwitch(switches::kUseOldSafeBrowsing); |
| 38 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | |
| 39 DCHECK(monitor); | |
| 40 if (monitor) | |
| 41 monitor->AddObserver(this); | |
| 42 } | 37 } |
| 43 | 38 |
| 44 SafeBrowsingService::~SafeBrowsingService() { | 39 SafeBrowsingService::~SafeBrowsingService() { |
| 45 base::SystemMonitor* monitor = base::SystemMonitor::Get(); | |
| 46 if (monitor) | |
| 47 monitor->RemoveObserver(this); | |
| 48 } | 40 } |
| 49 | 41 |
| 50 // Only called on the UI thread. | 42 // Only called on the UI thread. |
| 51 void SafeBrowsingService::Initialize(MessageLoop* io_loop) { | 43 void SafeBrowsingService::Initialize(MessageLoop* io_loop) { |
| 52 io_loop_ = io_loop; | 44 io_loop_ = io_loop; |
| 53 | 45 |
| 54 // Get the profile's preference for SafeBrowsing. | 46 // Get the profile's preference for SafeBrowsing. |
| 55 std::wstring user_data_dir; | 47 std::wstring user_data_dir; |
| 56 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 48 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 57 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 49 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| (...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 UMA_HISTOGRAM_LONG_TIMES(L"SB.Delay", time); | 655 UMA_HISTOGRAM_LONG_TIMES(L"SB.Delay", time); |
| 664 } | 656 } |
| 665 | 657 |
| 666 void SafeBrowsingService::CacheHashResults( | 658 void SafeBrowsingService::CacheHashResults( |
| 667 const std::vector<SBPrefix>& prefixes, | 659 const std::vector<SBPrefix>& prefixes, |
| 668 const std::vector<SBFullHashResult>& full_hashes) { | 660 const std::vector<SBFullHashResult>& full_hashes) { |
| 669 DCHECK(MessageLoop::current() == db_thread_->message_loop()); | 661 DCHECK(MessageLoop::current() == db_thread_->message_loop()); |
| 670 GetDatabase()->CacheHashResults(prefixes, full_hashes); | 662 GetDatabase()->CacheHashResults(prefixes, full_hashes); |
| 671 } | 663 } |
| 672 | 664 |
| 673 void SafeBrowsingService::OnSuspend(base::SystemMonitor*) { | 665 void SafeBrowsingService::OnSuspend() { |
| 674 } | 666 } |
| 675 | 667 |
| 676 // Tell the SafeBrowsing database not to do expensive disk operations for a few | 668 // Tell the SafeBrowsing database not to do expensive disk operations for a few |
| 677 // minutes after waking up. It's quite likely that the act of resuming from a | 669 // minutes after waking up. It's quite likely that the act of resuming from a |
| 678 // low power state will involve much disk activity, which we don't want to | 670 // low power state will involve much disk activity, which we don't want to |
| 679 // exacerbate. | 671 // exacerbate. |
| 680 void SafeBrowsingService::OnResume(base::SystemMonitor*) { | 672 void SafeBrowsingService::OnResume() { |
| 673 DCHECK(MessageLoop::current() == io_loop_); |
| 681 if (enabled_) { | 674 if (enabled_) { |
| 682 ChromeThread::GetMessageLoop(ChromeThread::DB)->PostTask(FROM_HERE, | 675 db_thread_->message_loop()->PostTask(FROM_HERE, |
| 683 NewRunnableMethod(this, &SafeBrowsingService::HandleResume)); | 676 NewRunnableMethod(this, &SafeBrowsingService::HandleResume)); |
| 684 } | 677 } |
| 685 } | 678 } |
| 686 | 679 |
| 687 void SafeBrowsingService::HandleResume() { | 680 void SafeBrowsingService::HandleResume() { |
| 688 DCHECK(MessageLoop::current() == db_thread_->message_loop()); | 681 DCHECK(MessageLoop::current() == db_thread_->message_loop()); |
| 689 // We don't call GetDatabase() here, since we want to avoid unnecessary calls | 682 // We don't call GetDatabase() here, since we want to avoid unnecessary calls |
| 690 // to Open, Reset, etc, or reload the bloom filter while we're coming out of | 683 // to Open, Reset, etc, or reload the bloom filter while we're coming out of |
| 691 // a suspended state. | 684 // a suspended state. |
| 692 if (database_) | 685 if (database_) |
| 693 database_->HandleResume(); | 686 database_->HandleResume(); |
| 694 } | 687 } |
| 695 | 688 |
| 696 void SafeBrowsingService::RunQueuedClients() { | 689 void SafeBrowsingService::RunQueuedClients() { |
| 697 DCHECK(MessageLoop::current() == io_loop_); | 690 DCHECK(MessageLoop::current() == io_loop_); |
| 698 HISTOGRAM_COUNTS(L"SB.QueueDepth", queued_checks_.size()); | 691 HISTOGRAM_COUNTS(L"SB.QueueDepth", queued_checks_.size()); |
| 699 while (!queued_checks_.empty()) { | 692 while (!queued_checks_.empty()) { |
| 700 QueuedCheck check = queued_checks_.front(); | 693 QueuedCheck check = queued_checks_.front(); |
| 701 HISTOGRAM_TIMES(L"SB.QueueDelay", Time::Now() - check.start); | 694 HISTOGRAM_TIMES(L"SB.QueueDelay", Time::Now() - check.start); |
| 702 CheckUrl(check.url, check.client); | 695 CheckUrl(check.url, check.client); |
| 703 queued_checks_.pop_front(); | 696 queued_checks_.pop_front(); |
| 704 } | 697 } |
| 705 } | 698 } |
| 706 | 699 |
| OLD | NEW |