summaryrefslogtreecommitdiffstats
path: root/chrome/browser/safe_browsing
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-02 21:44:37 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-02 21:44:37 +0000
commitd83d03aa8eea8f6173e161f134816746f8384e47 (patch)
tree10208e844592117a7d65fc3557a49e9126997a27 /chrome/browser/safe_browsing
parentb3f541017baf3eaaf4fc52d392630f9f040bae5e (diff)
downloadchromium_src-d83d03aa8eea8f6173e161f134816746f8384e47.zip
chromium_src-d83d03aa8eea8f6173e161f134816746f8384e47.tar.gz
chromium_src-d83d03aa8eea8f6173e161f134816746f8384e47.tar.bz2
Fourth patch in getting rid of caching MessageLoop pointers.
BUG=25354 Review URL: http://codereview.chromium.org/348037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30751 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing')
-rw-r--r--chrome/browser/safe_browsing/protocol_manager.cc12
-rw-r--r--chrome/browser/safe_browsing/protocol_manager.h6
-rw-r--r--chrome/browser/safe_browsing/protocol_manager_unittest.cc6
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_service.cc86
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_service.h12
5 files changed, 57 insertions, 65 deletions
diff --git a/chrome/browser/safe_browsing/protocol_manager.cc b/chrome/browser/safe_browsing/protocol_manager.cc
index 99249e1..aeef7b2 100644
--- a/chrome/browser/safe_browsing/protocol_manager.cc
+++ b/chrome/browser/safe_browsing/protocol_manager.cc
@@ -7,13 +7,13 @@
#include "base/file_version_info.h"
#include "base/histogram.h"
#include "base/logging.h"
-#include "base/message_loop.h"
#include "base/rand_util.h"
#include "base/stl_util-inl.h"
#include "base/string_util.h"
#include "base/sys_info.h"
#include "base/task.h"
#include "base/timer.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/safe_browsing/protocol_parser.h"
#include "chrome/browser/safe_browsing/safe_browsing_service.h"
@@ -67,7 +67,6 @@ static const int kSbMaxBackOff = 8;
SafeBrowsingProtocolManager::SafeBrowsingProtocolManager(
SafeBrowsingService* sb_service,
- MessageLoop* notify_loop,
const std::string& client_key,
const std::string& wrapped_key)
: sb_service_(sb_service),
@@ -80,7 +79,6 @@ SafeBrowsingProtocolManager::SafeBrowsingProtocolManager(
update_state_(FIRST_REQUEST),
initial_request_(true),
chunk_pending_to_write_(false),
- notify_loop_(notify_loop),
client_key_(client_key),
wrapped_key_(wrapped_key),
update_size_(0) {
@@ -423,9 +421,11 @@ bool SafeBrowsingProtocolManager::HandleServiceResponse(const GURL& url,
client_key_ = client_key;
wrapped_key_ = wrapped_key;
- notify_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- sb_service_, &SafeBrowsingService::OnNewMacKeys, client_key_,
- wrapped_key_));
+ ChromeThread::PostTask(
+ ChromeThread::UI, FROM_HERE,
+ NewRunnableMethod(
+ sb_service_, &SafeBrowsingService::OnNewMacKeys, client_key_,
+ wrapped_key_));
break;
}
diff --git a/chrome/browser/safe_browsing/protocol_manager.h b/chrome/browser/safe_browsing/protocol_manager.h
index e9d0408..e267bcb 100644
--- a/chrome/browser/safe_browsing/protocol_manager.h
+++ b/chrome/browser/safe_browsing/protocol_manager.h
@@ -24,7 +24,6 @@
#include "chrome/browser/safe_browsing/safe_browsing_util.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
-class MessageLoop;
class Task;
class Timer;
class URLRequestStatus;
@@ -50,7 +49,6 @@ class SafeBrowsingProtocolManager : public URLFetcher::Delegate {
public:
SafeBrowsingProtocolManager(SafeBrowsingService* sb_service,
- MessageLoop* notify_loop,
const std::string& client_key,
const std::string& wrapped_key);
~SafeBrowsingProtocolManager();
@@ -212,10 +210,6 @@ class SafeBrowsingProtocolManager : public URLFetcher::Delegate {
// added to the database yet.
bool chunk_pending_to_write_;
- // Message loop for forwarding MAC keys to the SafeBrowsingService for
- // storage.
- MessageLoop* notify_loop_;
-
// The keys used for MAC. Empty keys mean we aren't using MAC.
std::string client_key_;
std::string wrapped_key_;
diff --git a/chrome/browser/safe_browsing/protocol_manager_unittest.cc b/chrome/browser/safe_browsing/protocol_manager_unittest.cc
index 8af7a1b..40b8b77 100644
--- a/chrome/browser/safe_browsing/protocol_manager_unittest.cc
+++ b/chrome/browser/safe_browsing/protocol_manager_unittest.cc
@@ -16,7 +16,7 @@ class SafeBrowsingProtocolManagerTest : public testing::Test {
// Ensure that we respect section 5 of the SafeBrowsing protocol specification.
TEST_F(SafeBrowsingProtocolManagerTest, TestBackOffTimes) {
- SafeBrowsingProtocolManager pm(NULL, NULL, "", "");
+ SafeBrowsingProtocolManager pm(NULL, "", "");
pm.next_update_sec_ = 1800;
DCHECK(pm.back_off_fuzz_ >= 0.0 && pm.back_off_fuzz_ <= 1.0);
@@ -54,7 +54,7 @@ TEST_F(SafeBrowsingProtocolManagerTest, TestBackOffTimes) {
// Test string combinations with and without MAC.
TEST_F(SafeBrowsingProtocolManagerTest, TestChunkStrings) {
- SafeBrowsingProtocolManager pm(NULL, NULL, "", "");
+ SafeBrowsingProtocolManager pm(NULL, "", "");
// Add and Sub chunks.
SBListChunkRanges phish("goog-phish-shavar");
@@ -87,7 +87,7 @@ TEST_F(SafeBrowsingProtocolManagerTest, TestChunkStrings) {
}
TEST_F(SafeBrowsingProtocolManagerTest, TestGetHashBackOffTimes) {
- SafeBrowsingProtocolManager pm(NULL, NULL, "", "");
+ SafeBrowsingProtocolManager pm(NULL, "", "");
// No errors or back off time yet.
EXPECT_EQ(pm.gethash_error_count_, 0);
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc
index 260c592..2dddb60 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc
@@ -31,8 +31,7 @@ using base::Time;
using base::TimeDelta;
SafeBrowsingService::SafeBrowsingService()
- : io_loop_(NULL),
- database_(NULL),
+ : database_(NULL),
protocol_manager_(NULL),
enabled_(false),
resetting_(false),
@@ -44,9 +43,7 @@ SafeBrowsingService::~SafeBrowsingService() {
}
// Only called on the UI thread.
-void SafeBrowsingService::Initialize(MessageLoop* io_loop) {
- io_loop_ = io_loop;
-
+void SafeBrowsingService::Initialize() {
// Get the profile's preference for SafeBrowsing.
FilePath user_data_dir;
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
@@ -75,26 +72,26 @@ void SafeBrowsingService::Start() {
WideToASCII(local_state->GetString(prefs::kSafeBrowsingWrappedKey));
}
- io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SafeBrowsingService::OnIOInitialize, MessageLoop::current(),
- client_key, wrapped_key));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this, &SafeBrowsingService::OnIOInitialize, client_key, wrapped_key));
safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
this, &SafeBrowsingService::OnDBInitialize));
}
void SafeBrowsingService::ShutDown() {
- io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SafeBrowsingService::OnIOShutdown));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &SafeBrowsingService::OnIOShutdown));
}
-void SafeBrowsingService::OnIOInitialize(MessageLoop* notify_loop,
- const std::string& client_key,
+void SafeBrowsingService::OnIOInitialize(const std::string& client_key,
const std::string& wrapped_key) {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
enabled_ = true;
protocol_manager_ = new SafeBrowsingProtocolManager(this,
- notify_loop,
client_key,
wrapped_key);
// We want to initialize the protocol manager only after the database has
@@ -111,7 +108,7 @@ void SafeBrowsingService::OnDBInitialize() {
}
void SafeBrowsingService::OnIOShutdown() {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (!enabled_)
return;
@@ -166,7 +163,7 @@ bool SafeBrowsingService::CanCheckUrl(const GURL& url) const {
}
bool SafeBrowsingService::CheckUrl(const GURL& url, Client* client) {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (!enabled_ || !database_)
return true;
@@ -202,8 +199,9 @@ bool SafeBrowsingService::CheckUrl(const GURL& url, Client* client) {
check->full_hits.swap(full_hits);
checks_.insert(check);
- io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SafeBrowsingService::OnCheckDone, check));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &SafeBrowsingService::OnCheckDone, check));
return false;
}
@@ -278,7 +276,8 @@ void SafeBrowsingService::DoDisplayBlockingPage(
NavigationEntry* entry = wc->controller().GetActiveEntry();
if (entry)
referrer_url = entry->referrer();
- io_loop_->PostTask(FROM_HERE,
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
NewRunnableMethod(this,
&SafeBrowsingService::ReportMalware,
resource.url,
@@ -290,7 +289,7 @@ void SafeBrowsingService::DoDisplayBlockingPage(
}
void SafeBrowsingService::CancelCheck(Client* client) {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
for (CurrentChecks::iterator i = checks_.begin(); i != checks_.end(); ++i) {
if ((*i)->client == client)
@@ -309,7 +308,7 @@ void SafeBrowsingService::CancelCheck(Client* client) {
}
void SafeBrowsingService::OnCheckDone(SafeBrowsingCheck* check) {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
// If we've been shutdown during the database lookup, this check will already
// have been deleted (in OnIOShutdown).
@@ -367,8 +366,9 @@ SafeBrowsingDatabase* SafeBrowsingService::GetDatabase() {
database->Init(path, chunk_callback);
database_ = database;
- io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SafeBrowsingService::DatabaseLoadComplete));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &SafeBrowsingService::DatabaseLoadComplete));
TimeDelta open_time = Time::Now() - before;
SB_DLOG(INFO) << "SafeBrowsing database open took " <<
@@ -445,7 +445,7 @@ void SafeBrowsingService::HandleOneCheck(
}
void SafeBrowsingService::UpdateStarted() {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DCHECK(enabled_);
DCHECK(!update_in_progress_);
update_in_progress_ = true;
@@ -454,7 +454,7 @@ void SafeBrowsingService::UpdateStarted() {
}
void SafeBrowsingService::UpdateFinished(bool update_succeeded) {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DCHECK(enabled_);
if (update_in_progress_) {
update_in_progress_ = false;
@@ -509,18 +509,19 @@ void SafeBrowsingService::OnNewMacKeys(const std::string& client_key,
void SafeBrowsingService::ChunkInserted() {
DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop());
- io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SafeBrowsingService::OnChunkInserted));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &SafeBrowsingService::OnChunkInserted));
}
void SafeBrowsingService::OnChunkInserted() {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (enabled_)
protocol_manager_->OnChunkInserted();
}
void SafeBrowsingService::DatabaseLoadComplete() {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (!enabled_)
return;
@@ -541,7 +542,7 @@ void SafeBrowsingService::RegisterPrefs(PrefService* prefs) {
}
void SafeBrowsingService::ResetDatabase() {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
resetting_ = true;
safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
this, &SafeBrowsingService::OnResetDatabase));
@@ -550,12 +551,13 @@ void SafeBrowsingService::ResetDatabase() {
void SafeBrowsingService::OnResetDatabase() {
DCHECK(MessageLoop::current() == safe_browsing_thread_->message_loop());
GetDatabase()->ResetDatabase();
- io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SafeBrowsingService::OnResetComplete));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(this, &SafeBrowsingService::OnResetComplete));
}
void SafeBrowsingService::OnResetComplete() {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (enabled_) {
resetting_ = false;
database_loaded_ = true;
@@ -565,7 +567,7 @@ void SafeBrowsingService::OnResetComplete() {
void SafeBrowsingService::HandleChunk(const std::string& list,
std::deque<SBChunk>* chunks) {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DCHECK(enabled_);
safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
this, &SafeBrowsingService::HandleChunkForDatabase, list, chunks));
@@ -581,7 +583,7 @@ void SafeBrowsingService::HandleChunkForDatabase(
void SafeBrowsingService::HandleChunkDelete(
std::vector<SBChunkDelete>* chunk_deletes) {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
DCHECK(enabled_);
safe_browsing_thread_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
this, &SafeBrowsingService::DeleteChunks, chunk_deletes));
@@ -608,15 +610,17 @@ void SafeBrowsingService::GetAllChunksFromDatabase() {
}
}
- io_loop_->PostTask(FROM_HERE, NewRunnableMethod(
- this, &SafeBrowsingService::OnGetAllChunksFromDatabase, lists,
- database_error));
+ ChromeThread::PostTask(
+ ChromeThread::IO, FROM_HERE,
+ NewRunnableMethod(
+ this, &SafeBrowsingService::OnGetAllChunksFromDatabase, lists,
+ database_error));
}
// Called on the io thread with the results of all chunks.
void SafeBrowsingService::OnGetAllChunksFromDatabase(
const std::vector<SBListChunkRanges>& lists, bool database_error) {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (enabled_)
protocol_manager_->OnGetChunksComplete(lists, database_error);
}
@@ -647,7 +651,7 @@ void SafeBrowsingService::CacheHashResults(
}
void SafeBrowsingService::RunQueuedClients() {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
HISTOGRAM_COUNTS("SB.QueueDepth", queued_checks_.size());
while (!queued_checks_.empty()) {
QueuedCheck check = queued_checks_.front();
@@ -660,7 +664,7 @@ void SafeBrowsingService::RunQueuedClients() {
void SafeBrowsingService::ReportMalware(const GURL& malware_url,
const GURL& page_url,
const GURL& referrer_url) {
- DCHECK(MessageLoop::current() == io_loop_);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
if (!enabled_ || !database_)
return;
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.h b/chrome/browser/safe_browsing/safe_browsing_service.h
index 95417b7..d5cca6b 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.h
+++ b/chrome/browser/safe_browsing/safe_browsing_service.h
@@ -23,7 +23,6 @@
#include "webkit/glue/resource_type.h"
class BloomFilter;
-class MessageLoop;
class PrefService;
class SafeBrowsingBlockingPage;
class SafeBrowsingDatabase;
@@ -68,14 +67,11 @@ class SafeBrowsingService
SafeBrowsingService();
~SafeBrowsingService();
- // Initializes the service. io_loop is the message loop that the
- // caller of this service (ResourceDispatcherHost) wants to be notified on
- // for check results.
- void Initialize(MessageLoop* io_loop);
+ // Initializes the service.
+ void Initialize();
// Called to initialize objects that are used on the io_thread.
- void OnIOInitialize(MessageLoop* notify_loop,
- const std::string& client_key,
+ void OnIOInitialize(const std::string& client_key,
const std::string& wrapped_key);
// Called to initialize objects that are used on the db_thread.
@@ -234,8 +230,6 @@ class SafeBrowsingService
void OnUpdateComplete(bool update_succeeded);
- MessageLoop* io_loop_;
-
typedef std::set<SafeBrowsingCheck*> CurrentChecks;
CurrentChecks checks_;