summaryrefslogtreecommitdiffstats
path: root/chrome/browser/safe_browsing
diff options
context:
space:
mode:
authorevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-23 21:15:42 +0000
committerevanm@google.com <evanm@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-23 21:15:42 +0000
commitd2d89baed092e57c107dc801b2a9ce3e0f6d4327 (patch)
treed5ea2ac2cabfe24eb351c3d8ad3b92746f9dc130 /chrome/browser/safe_browsing
parent03393da161328db98bdaf32e65c2877a259df916 (diff)
downloadchromium_src-d2d89baed092e57c107dc801b2a9ce3e0f6d4327.zip
chromium_src-d2d89baed092e57c107dc801b2a9ce3e0f6d4327.tar.gz
chromium_src-d2d89baed092e57c107dc801b2a9ce3e0f6d4327.tar.bz2
Port some more parts of browser/
This first needs http://codereview.chromium.org/6492 (porting base/process_util). BUG=2333 Review URL: http://codereview.chromium.org/6268 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@3858 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/safe_browsing')
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_bloom.cc14
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_impl.cc25
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_impl_unittest.cc28
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_unittest.cc100
4 files changed, 104 insertions, 63 deletions
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc b/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
index 3da1d25..01d0b99 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
@@ -4,9 +4,11 @@
#include "chrome/browser/safe_browsing/safe_browsing_database_bloom.h"
+#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/platform_thread.h"
#include "base/sha2.h"
#include "base/string_util.h"
#include "chrome/browser/safe_browsing/bloom_filter.h"
@@ -38,13 +40,11 @@ static const int kMaxStalenessMinutes = 45;
SafeBrowsingDatabaseBloom::SafeBrowsingDatabaseBloom()
: db_(NULL),
- init_(false),
transaction_count_(0),
+ init_(false),
chunk_inserted_callback_(NULL),
-#pragma warning(suppress: 4355) // can use this
- reset_factory_(this),
-#pragma warning(suppress: 4355) // can use this
- resume_factory_(this),
+ ALLOW_THIS_IN_INITIALIZER_LIST(reset_factory_(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(resume_factory_(this)),
did_resume_(false) {
}
@@ -1017,7 +1017,7 @@ void SafeBrowsingDatabaseBloom::ClearCachedHashesForChunk(int list_id,
++eit;
}
if (entries.empty())
- it = hash_cache_.erase(it);
+ hash_cache_.erase(it++);
else
++it;
}
@@ -1049,7 +1049,7 @@ void SafeBrowsingDatabaseBloom::OnResumeDone() {
void SafeBrowsingDatabaseBloom::WaitAfterResume() {
if (did_resume_) {
- Sleep(kOnResumeHoldupMs);
+ PlatformThread::Sleep(kOnResumeHoldupMs);
did_resume_ = false;
}
}
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_impl.cc b/chrome/browser/safe_browsing/safe_browsing_database_impl.cc
index 498ebb3..02c2d04 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_impl.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_impl.cc
@@ -4,9 +4,11 @@
#include "chrome/browser/safe_browsing/safe_browsing_database_impl.h"
+#include "base/compiler_specific.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "base/platform_thread.h"
#include "base/sha2.h"
#include "base/string_util.h"
#include "chrome/browser/safe_browsing/bloom_filter.h"
@@ -56,20 +58,15 @@ static const int kMaxStalenessMinutes = 45;
SafeBrowsingDatabaseImpl::SafeBrowsingDatabaseImpl()
: db_(NULL),
- init_(false),
transaction_count_(0),
+ init_(false),
asynchronous_(true),
chunk_inserted_callback_(NULL),
-#pragma warning(suppress: 4355) // can use this
- bloom_read_factory_(this),
-#pragma warning(suppress: 4355) // can use this
- bloom_write_factory_(this),
-#pragma warning(suppress: 4355) // can use this
- process_factory_(this),
-#pragma warning(suppress: 4355) // can use this
- reset_factory_(this),
-#pragma warning(suppress: 4355) // can use this
- resume_factory_(this),
+ ALLOW_THIS_IN_INITIALIZER_LIST(process_factory_(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(bloom_read_factory_(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(bloom_write_factory_(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(reset_factory_(this)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(resume_factory_(this)),
disk_delay_(kMaxThreadHoldupMs) {
}
@@ -473,7 +470,7 @@ void SafeBrowsingDatabaseImpl::RunThrottledWork() {
&SafeBrowsingDatabaseImpl::RunThrottledWork), disk_delay_);
break;
} else {
- Sleep(kMaxThreadHoldupMs);
+ PlatformThread::Sleep(kMaxThreadHoldupMs);
}
}
}
@@ -1014,7 +1011,7 @@ void SafeBrowsingDatabaseImpl::OnReadHostKeys(int start_id) {
if (asynchronous_) {
break;
} else {
- Sleep(kMaxThreadHoldupMs);
+ PlatformThread::Sleep(kMaxThreadHoldupMs);
}
}
}
@@ -1180,7 +1177,7 @@ void SafeBrowsingDatabaseImpl::ClearCachedHashesForChunk(int list_id,
++eit;
}
if (entries.empty())
- it = hash_cache_.erase(it);
+ hash_cache_.erase(it++);
else
++it;
}
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_impl_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_database_impl_unittest.cc
index 5e67054..3afcedc 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_impl_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_impl_unittest.cc
@@ -89,7 +89,7 @@ TEST(SafeBrowsingDatabaseImpl, HashCaching) {
PathService::Get(base::DIR_TEMP, &filename);
filename.push_back(file_util::kPathSeparator);
filename.append(L"SafeBrowsingTestDatabase");
- DeleteFile(filename.c_str()); // In case it existed from a previous run.
+ file_util::Delete(filename, false); // In case it existed from a previous run.
SafeBrowsingDatabaseImpl database;
database.SetSynchronous();
@@ -98,7 +98,7 @@ TEST(SafeBrowsingDatabaseImpl, HashCaching) {
PopulateDatabaseForCacheTest(&database);
// We should have both full hashes in the cache.
- EXPECT_EQ(database.hash_cache_.size(), 2);
+ EXPECT_EQ(database.hash_cache_.size(), 2U);
// Test the cache lookup for the first prefix.
std::string list;
@@ -106,7 +106,7 @@ TEST(SafeBrowsingDatabaseImpl, HashCaching) {
std::vector<SBFullHashResult> full_hashes;
database.ContainsUrl(GURL("http://www.evil.com/phishing.html"),
&list, &prefixes, &full_hashes, Time::Now());
- EXPECT_EQ(full_hashes.size(), 1);
+ EXPECT_EQ(full_hashes.size(), 1U);
SBFullHashResult full_hash;
base::SHA256HashString("www.evil.com/phishing.html",
@@ -120,7 +120,7 @@ TEST(SafeBrowsingDatabaseImpl, HashCaching) {
// Test the cache lookup for the second prefix.
database.ContainsUrl(GURL("http://www.evil.com/malware.html"),
&list, &prefixes, &full_hashes, Time::Now());
- EXPECT_EQ(full_hashes.size(), 1);
+ EXPECT_EQ(full_hashes.size(), 1U);
base::SHA256HashString("www.evil.com/malware.html",
&full_hash.hash, sizeof(SBFullHash));
EXPECT_EQ(memcmp(&full_hashes[0].hash,
@@ -149,7 +149,7 @@ TEST(SafeBrowsingDatabaseImpl, HashCaching) {
// This prefix should still be there.
database.ContainsUrl(GURL("http://www.evil.com/malware.html"),
&list, &prefixes, &full_hashes, Time::Now());
- EXPECT_EQ(full_hashes.size(), 1);
+ EXPECT_EQ(full_hashes.size(), 1U);
base::SHA256HashString("www.evil.com/malware.html",
&full_hash.hash, sizeof(SBFullHash));
EXPECT_EQ(memcmp(&full_hashes[0].hash,
@@ -161,7 +161,7 @@ TEST(SafeBrowsingDatabaseImpl, HashCaching) {
// This prefix should be gone.
database.ContainsUrl(GURL("http://www.evil.com/phishing.html"),
&list, &prefixes, &full_hashes, Time::Now());
- EXPECT_EQ(full_hashes.size(), 0);
+ EXPECT_EQ(full_hashes.size(), 0U);
prefixes.clear();
full_hashes.clear();
@@ -170,8 +170,8 @@ TEST(SafeBrowsingDatabaseImpl, HashCaching) {
AddDelChunk(&database, "goog-malware-shavar", 1);
database.ContainsUrl(GURL("http://www.evil.com/malware.html"),
&list, &prefixes, &full_hashes, Time::Now());
- EXPECT_EQ(full_hashes.size(), 0);
- EXPECT_EQ(database.hash_cache_.size(), 0);
+ EXPECT_EQ(full_hashes.size(), 0U);
+ EXPECT_EQ(database.hash_cache_.size(), 0U);
prefixes.clear();
full_hashes.clear();
@@ -180,7 +180,7 @@ TEST(SafeBrowsingDatabaseImpl, HashCaching) {
// the cached entries' received time to make them older, since the database
// cache insert uses Time::Now(). First, store some entries.
PopulateDatabaseForCacheTest(&database);
- EXPECT_EQ(database.hash_cache_.size(), 2);
+ EXPECT_EQ(database.hash_cache_.size(), 2U);
// Now adjust one of the entries times to be in the past.
Time expired = Time::Now() - TimeDelta::FromMinutes(60);
@@ -194,15 +194,15 @@ TEST(SafeBrowsingDatabaseImpl, HashCaching) {
database.ContainsUrl(GURL("http://www.evil.com/malware.html"),
&list, &prefixes, &full_hashes, expired);
- EXPECT_EQ(full_hashes.size(), 0);
+ EXPECT_EQ(full_hashes.size(), 0U);
// Expired entry was dumped.
- EXPECT_EQ(database.hash_cache_.size(), 1);
+ EXPECT_EQ(database.hash_cache_.size(), 1U);
// This entry should still exist.
database.ContainsUrl(GURL("http://www.evil.com/phishing.html"),
&list, &prefixes, &full_hashes, expired);
- EXPECT_EQ(full_hashes.size(), 1);
+ EXPECT_EQ(full_hashes.size(), 1U);
// Testing prefix miss caching. First, we clear out the existing database,
@@ -217,11 +217,11 @@ TEST(SafeBrowsingDatabaseImpl, HashCaching) {
database.CacheHashResults(prefix_misses, empty_full_hash);
// Prefixes with no full results are misses.
- EXPECT_EQ(database.prefix_miss_cache_.size(), 2);
+ EXPECT_EQ(database.prefix_miss_cache_.size(), 2U);
// Update the database.
PopulateDatabaseForCacheTest(&database);
// Prefix miss cache should be cleared.
- EXPECT_EQ(database.prefix_miss_cache_.size(), 0);
+ EXPECT_EQ(database.prefix_miss_cache_.size(), 0U);
}
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
index 21de75a..803b0ef 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
@@ -63,7 +63,8 @@ namespace {
SafeBrowsingDatabase* SetupTestDatabase() {
std::wstring filename = GetTestDatabaseName();
- DeleteFile(filename.c_str()); // In case it existed from a previous run.
+ // In case it existed from a previous run.
+ file_util::Delete(filename, false);
SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create();
database->SetSynchronous();
@@ -73,7 +74,7 @@ namespace {
}
void TearDownTestDatabase(SafeBrowsingDatabase* database) {
- DeleteFile(GetTestDatabaseName().c_str());
+ file_util::Delete(GetTestDatabaseName(), false);
delete database;
}
@@ -141,7 +142,7 @@ TEST(SafeBrowsingDatabase, Database) {
// Make sure they were added correctly.
std::vector<SBListChunkRanges> lists;
database->GetListsInfo(&lists);
- EXPECT_EQ(lists.size(), 1);
+ EXPECT_EQ(lists.size(), 1U);
EXPECT_EQ(lists[0].name, "goog-malware");
EXPECT_EQ(lists[0].adds, "1-3");
EXPECT_TRUE(lists[0].subs.empty());
@@ -154,7 +155,7 @@ TEST(SafeBrowsingDatabase, Database) {
&matching_list, &prefix_hits,
&full_hashes, now));
EXPECT_EQ(prefix_hits[0], Sha256Prefix("www.evil.com/phishing.html"));
- EXPECT_EQ(prefix_hits.size(), 1);
+ EXPECT_EQ(prefix_hits.size(), 1U);
EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/malware.html"),
&matching_list, &prefix_hits,
@@ -183,7 +184,7 @@ TEST(SafeBrowsingDatabase, Database) {
EXPECT_FALSE(database->ContainsUrl(GURL("http://www.evil.com/"),
&matching_list, &prefix_hits,
&full_hashes, now));
- EXPECT_EQ(prefix_hits.size(), 0);
+ EXPECT_EQ(prefix_hits.size(), 0U);
EXPECT_FALSE(database->ContainsUrl(GURL("http://www.evil.com/robots.txt"),
&matching_list, &prefix_hits,
@@ -211,12 +212,12 @@ TEST(SafeBrowsingDatabase, Database) {
&matching_list, &prefix_hits,
&full_hashes, now));
EXPECT_EQ(prefix_hits[0], Sha256Prefix("www.evil.com/phishing.html"));
- EXPECT_EQ(prefix_hits.size(), 1);
+ EXPECT_EQ(prefix_hits.size(), 1U);
EXPECT_FALSE(database->ContainsUrl(GURL("http://www.evil.com/notevil1.html"),
&matching_list, &prefix_hits,
&full_hashes, now));
- EXPECT_EQ(prefix_hits.size(), 0);
+ EXPECT_EQ(prefix_hits.size(), 0U);
EXPECT_TRUE(database->ContainsUrl(GURL("http://www.evil.com/notevil2.html"),
&matching_list, &prefix_hits,
@@ -231,7 +232,7 @@ TEST(SafeBrowsingDatabase, Database) {
&full_hashes, now));
database->GetListsInfo(&lists);
- EXPECT_EQ(lists.size(), 1);
+ EXPECT_EQ(lists.size(), 1U);
EXPECT_EQ(lists[0].name, "goog-malware");
EXPECT_EQ(lists[0].subs, "4");
@@ -252,7 +253,7 @@ TEST(SafeBrowsingDatabase, Database) {
&full_hashes, now));
database->GetListsInfo(&lists);
- EXPECT_EQ(lists.size(), 1);
+ EXPECT_EQ(lists.size(), 1U);
EXPECT_EQ(lists[0].name, "goog-malware");
EXPECT_EQ(lists[0].adds, "1,3");
EXPECT_EQ(lists[0].subs, "4");
@@ -283,7 +284,7 @@ TEST(SafeBrowsingDatabase, Database) {
database->UpdateFinished();
database->GetListsInfo(&lists);
- EXPECT_EQ(lists.size(), 1);
+ EXPECT_EQ(lists.size(), 1U);
EXPECT_EQ(lists[0].name, "goog-malware");
EXPECT_EQ(lists[0].adds, "1,3");
EXPECT_EQ(lists[0].subs, "");
@@ -461,15 +462,22 @@ TEST(SafeBrowsingDatabase, ZeroSizeChunk) {
}
void PrintStat(const wchar_t* name) {
+#if defined(OS_WIN)
int value = StatsTable::current()->GetCounterValue(name);
- std::wstring out = StringPrintf(L"%ls %d\r\n", name, value);
- OutputDebugStringW(out.c_str());
+ LOG(INFO) << StringPrintf(L"%ls %d", name, value);
+#else
+ // TODO(port): Enable when StatsTable is ported.
+ NOTIMPLEMENTED();
+#endif
}
std::wstring GetFullSBDataPath(const std::wstring& path) {
std::wstring full_path;
CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &full_path));
- file_util::AppendToPath(&full_path, L"chrome\\test\\data\\safe_browsing");
+ file_util::AppendToPath(&full_path, L"chrome");
+ file_util::AppendToPath(&full_path, L"test");
+ file_util::AppendToPath(&full_path, L"data");
+ file_util::AppendToPath(&full_path, L"safe_browsing");
file_util::AppendToPath(&full_path, path);
CHECK(file_util::PathExists(full_path));
return full_path;
@@ -489,7 +497,8 @@ void PeformUpdate(const std::wstring& initial_db,
PathService::Get(base::DIR_TEMP, &filename);
filename.push_back(file_util::kPathSeparator);
filename.append(L"SafeBrowsingTestDatabase");
- DeleteFile(filename.c_str()); // In case it existed from a previous run.
+ // In case it existed from a previous run.
+ file_util::Delete(filename, false);
if (!initial_db.empty()) {
std::wstring full_initial_db = GetFullSBDataPath(initial_db);
@@ -515,16 +524,16 @@ void PeformUpdate(const std::wstring& initial_db,
CHECK(metric->GetIOCounters(&after));
- OutputDebugStringA(StringPrintf("I/O Read Bytes: %d\r\n",
- after.ReadTransferCount - before.ReadTransferCount).c_str());
- OutputDebugStringA(StringPrintf("I/O Write Bytes: %d\r\n",
- after.WriteTransferCount - before.WriteTransferCount).c_str());
- OutputDebugStringA(StringPrintf("I/O Reads: %d\r\n",
- after.ReadOperationCount - before.ReadOperationCount).c_str());
- OutputDebugStringA(StringPrintf("I/O Writes: %d\r\n",
- after.WriteOperationCount - before.WriteOperationCount).c_str());
- OutputDebugStringA(StringPrintf("Finished in %d ms\r\n",
- (Time::Now() - before_time).InMilliseconds()).c_str());
+ LOG(INFO) << StringPrintf("I/O Read Bytes: %d",
+ after.ReadTransferCount - before.ReadTransferCount);
+ LOG(INFO) << StringPrintf("I/O Write Bytes: %d",
+ after.WriteTransferCount - before.WriteTransferCount);
+ LOG(INFO) << StringPrintf("I/O Reads: %d",
+ after.ReadOperationCount - before.ReadOperationCount);
+ LOG(INFO) << StringPrintf("I/O Writes: %d",
+ after.WriteOperationCount - before.WriteOperationCount);
+ LOG(INFO) << StringPrintf("Finished in %d ms",
+ (Time::Now() - before_time).InMilliseconds());
PrintStat(L"c:SB.HostSelect");
PrintStat(L"c:SB.HostSelectForBloomFilter");
@@ -605,6 +614,28 @@ void UpdateDatabase(const std::wstring& initial_db,
PeformUpdate(initial_db, chunks, deletes);
}
+namespace {
+
+const wchar_t* GetOldSafeBrowsingPath() {
+ std::wstring path = L"old";
+ file_util::AppendToPath(&path, L"SafeBrowsing");
+ return path.c_str();
+}
+
+const wchar_t* GetOldResponsePath() {
+ std::wstring path = L"old";
+ file_util::AppendToPath(&path, L"response");
+ return path.c_str();
+}
+
+const wchar_t* GetOldUpdatesPath() {
+ std::wstring path = L"old";
+ file_util::AppendToPath(&path, L"updates");
+ return path.c_str();
+}
+
+} // namespace
+
// Counts the IO needed for the initial update of a database.
// test\data\safe_browsing\download_update.py was used to fetch the add/sub
// chunks that are read, in order to get repeatable runs.
@@ -612,23 +643,36 @@ TEST(SafeBrowsingDatabase, DISABLED_DatabaseInitialIO) {
UpdateDatabase(L"", L"", L"initial");
}
+// TODO(port): For now on Linux the test below would fail with error below:
+// [1004/201323:FATAL:browser/safe_browsing/safe_browsing_database_impl.cc(712)]
+// Check failed: false.
+//
// Counts the IO needed to update a month old database.
// The data files were generated by running "..\download_update.py postdata"
// in the "safe_browsing\old" directory.
TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldIO) {
- UpdateDatabase(L"old\\SafeBrowsing", L"old\\response", L"old\\updates");
+ UpdateDatabase(GetOldSafeBrowsingPath(), GetOldResponsePath(),
+ GetOldUpdatesPath());
}
+// TODO(port): For now on Linux the test below would fail with error below:
+// [1004/201323:FATAL:browser/safe_browsing/safe_browsing_database_impl.cc(712)]
+// Check failed: false.
+//
// Like DatabaseOldIO but only the deletes.
TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldDeletesIO) {
- UpdateDatabase(L"old\\SafeBrowsing", L"old\\response", L"");
+ UpdateDatabase(GetOldSafeBrowsingPath(), GetOldResponsePath(), L"");
}
// Like DatabaseOldIO but only the updates.
TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldUpdatesIO) {
- UpdateDatabase(L"old\\SafeBrowsing", L"", L"old\\updates");
+ UpdateDatabase(GetOldSafeBrowsingPath(), L"", GetOldUpdatesPath());
}
+// TODO(port): For now on Linux the test below would fail with error below:
+// [1004/201323:FATAL:browser/safe_browsing/safe_browsing_database_impl.cc(712)]
+// Check failed: false.
+//
// Does a a lot of addel's on very large chunks.
TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldLotsofDeletesIO) {
std::vector<ChunksInfo> chunks;
@@ -638,5 +682,5 @@ TEST(SafeBrowsingDatabase, DISABLED_DatabaseOldLotsofDeletesIO) {
del.list_name = "goog-malware-shavar";
del.chunk_del.push_back(ChunkRange(3539, 3579));
deletes->push_back(del);
- PeformUpdate(L"old\\SafeBrowsing", chunks, deletes);
+ PeformUpdate(GetOldSafeBrowsingPath(), chunks, deletes);
}