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

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

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

Powered by Google App Engine
This is Rietveld 408576698