summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-11 20:14:13 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-11 20:14:13 +0000
commitafa5a314c7d3698c8065ba824e5700c2af211844 (patch)
tree3be3f505dd3d5609eaaae5c0189892fa30302885 /chrome/browser
parent1ecbf13615d89a0e0369cab2e70692d5b9a46341 (diff)
downloadchromium_src-afa5a314c7d3698c8065ba824e5700c2af211844.zip
chromium_src-afa5a314c7d3698c8065ba824e5700c2af211844.tar.gz
chromium_src-afa5a314c7d3698c8065ba824e5700c2af211844.tar.bz2
Reverting 6815.
Review URL: http://codereview.chromium.org/14006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@6816 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/safe_browsing/database_perftest.cc176
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database.h6
-rw-r--r--chrome/browser/visitedlink_perftest.cc4
3 files changed, 89 insertions, 97 deletions
diff --git a/chrome/browser/safe_browsing/database_perftest.cc b/chrome/browser/safe_browsing/database_perftest.cc
index 0da2ffc..273bda4 100644
--- a/chrome/browser/safe_browsing/database_perftest.cc
+++ b/chrome/browser/safe_browsing/database_perftest.cc
@@ -5,26 +5,25 @@
#include <stdio.h>
#include <stdlib.h>
-#include <limits>
#include <set>
-#include "base/file_path.h"
#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/perftimer.h"
-#include "base/rand_util.h"
-#include "base/scoped_ptr.h"
#include "base/string_util.h"
#include "base/test_file_util.h"
#include "chrome/browser/safe_browsing/safe_browsing_database.h"
-#include "chrome/browser/safe_browsing/safe_browsing_database_impl.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/sqlite_compiled_statement.h"
#include "chrome/common/sqlite_utils.h"
-#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
+// These tests are slow, especially the ones that create databases. So disable
+// them by default.
+//#define SAFE_BROWSING_DATABASE_TESTS_ENABLED
+#ifdef SAFE_BROWSING_DATABASE_TESTS_ENABLED
+
namespace {
// Base class for a safebrowsing database. Derived classes can implement
@@ -36,27 +35,28 @@ class Database {
~Database() {
if (db_) {
+ statement_cache_.Cleanup();
sqlite3_close(db_);
db_ = NULL;
}
}
- bool Init(const FilePath& name, bool create) {
+ bool Init(const std::string& name, bool create) {
// get an empty file for the test DB
- FilePath filename;
+ std::wstring filename;
PathService::Get(base::DIR_TEMP, &filename);
- filename = filename.Append(name);
+ filename.push_back(FilePath::kSeparators[0]);
+ filename.append(ASCIIToWide(name));
if (create) {
- file_util::Delete(filename, false);
+ DeleteFile(filename.c_str());
} else {
- DLOG(INFO) << "evicting " << name.value() << " ...";
- file_util::EvictFileFromSystemCache(filename);
+ DLOG(INFO) << "evicting " << name << " ...";
+ file_util::EvictFileFromSystemCache(filename.c_str());
DLOG(INFO) << "... evicted";
}
- const std::string sqlite_path = WideToUTF8(filename.ToWStringHack());
- if (sqlite3_open(sqlite_path.c_str(), &db_) != SQLITE_OK)
+ if (sqlite3_open(WideToUTF8(filename).c_str(), &db_) != SQLITE_OK)
return false;
statement_cache_.set_db(db_);
@@ -197,7 +197,7 @@ class IndexedWithIDDatabase : public SimpleDatabase {
}
};
-} // namespace
+}
class SafeBrowsing: public testing::Test {
protected:
@@ -253,8 +253,7 @@ class SafeBrowsing: public testing::Test {
db_name_.append(count_start);
db_name_.append(db_->GetDBSuffix());
- FilePath path = FilePath::FromWStringHack(ASCIIToWide(db_name_));
- ASSERT_TRUE(db_->Init(path, type == WRITE));
+ ASSERT_TRUE(db_->Init(db_name_, type == WRITE));
if (type == WRITE) {
WriteEntries(size);
@@ -276,9 +275,10 @@ class SafeBrowsing: public testing::Test {
SQLTransaction transaction(db_->db());
transaction.Begin();
+ int inc = kint32max / count;
for (int i = 0; i < count; i++) {
- int hostkey = base::RandInt(std::numeric_limits<int>::min(),
- std::numeric_limits<int>::max());
+ int hostkey;
+ rand_s((unsigned int*)&hostkey);
ASSERT_TRUE(db_->Add(hostkey, prefixes, 1));
}
@@ -292,8 +292,8 @@ class SafeBrowsing: public testing::Test {
int64 total_ms = 0;
for (int i = 0; i < count; ++i) {
- int key = base::RandInt(std::numeric_limits<int>::min(),
- std::numeric_limits<int>::max());
+ int key;
+ rand_s((unsigned int*)&key);
PerfTimer timer;
@@ -332,75 +332,74 @@ class SafeBrowsing: public testing::Test {
std::string db_name_;
};
-TEST_F(SafeBrowsing, DISABLED_Write_100K) {
+TEST_F(SafeBrowsing, Write_100K) {
}
-TEST_F(SafeBrowsing, DISABLED_Read_100K) {
+TEST_F(SafeBrowsing, Read_100K) {
}
-TEST_F(SafeBrowsing, DISABLED_WriteIndexed_100K) {
+TEST_F(SafeBrowsing, WriteIndexed_100K) {
}
-TEST_F(SafeBrowsing, DISABLED_ReadIndexed_100K) {
+TEST_F(SafeBrowsing, ReadIndexed_100K) {
}
-TEST_F(SafeBrowsing, DISABLED_WriteIndexed_250K) {
+TEST_F(SafeBrowsing, WriteIndexed_250K) {
}
-TEST_F(SafeBrowsing, DISABLED_ReadIndexed_250K) {
+TEST_F(SafeBrowsing, ReadIndexed_250K) {
}
-TEST_F(SafeBrowsing, DISABLED_WriteIndexed_500K) {
+TEST_F(SafeBrowsing, WriteIndexed_500K) {
}
-TEST_F(SafeBrowsing, DISABLED_ReadIndexed_500K) {
+TEST_F(SafeBrowsing, ReadIndexed_500K) {
}
-TEST_F(SafeBrowsing, DISABLED_WriteIndexedWithID_250K) {
+TEST_F(SafeBrowsing, ReadIndexedWithID_250K) {
}
-TEST_F(SafeBrowsing, DISABLED_ReadIndexedWithID_250K) {
+TEST_F(SafeBrowsing, WriteIndexedWithID_250K) {
}
-TEST_F(SafeBrowsing, DISABLED_WriteIndexedWithID_500K) {
+TEST_F(SafeBrowsing, ReadIndexedWithID_500K) {
}
-TEST_F(SafeBrowsing, DISABLED_ReadIndexedWithID_500K) {
+TEST_F(SafeBrowsing, WriteIndexedWithID_500K) {
}
-TEST_F(SafeBrowsing, DISABLED_CountIndexed_250K) {
+TEST_F(SafeBrowsing, CountIndexed_250K) {
}
-TEST_F(SafeBrowsing, DISABLED_CountIndexed_500K) {
+TEST_F(SafeBrowsing, CountIndexed_500K) {
}
-TEST_F(SafeBrowsing, DISABLED_CountIndexedWithID_250K) {
+TEST_F(SafeBrowsing, CountIndexedWithID_250K) {
}
-TEST_F(SafeBrowsing, DISABLED_CountIndexedWithID_500K) {
+TEST_F(SafeBrowsing, CountIndexedWithID_500K) {
}
class SafeBrowsingDatabaseTest {
public:
- SafeBrowsingDatabaseTest(const FilePath& filename) {
+ SafeBrowsingDatabaseTest(const std::wstring& name) {
logging::InitLogging(
NULL, logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
logging::LOCK_LOG_FILE,
logging::DELETE_OLD_LOG_FILE);
- std::wstring tmp_path;
- PathService::Get(base::DIR_TEMP, &tmp_path);
- path_ = FilePath::FromWStringHack(tmp_path);
- path_ = path_.Append(filename);
+ PathService::Get(base::DIR_TEMP, &filename_);
+ filename_.push_back(FilePath::kSeparators[0]);
+ filename_.append(name);
}
void Create(int size) {
- file_util::Delete(path_, false);
+ DeleteFile(filename_.c_str());
- scoped_ptr<SafeBrowsingDatabase> database(SafeBrowsingDatabase::Create());
- database->SetSynchronous();
- EXPECT_TRUE(database->Init(path_.ToWStringHack(), NULL));
+ SafeBrowsingDatabase database;
+ database.set_synchronous();
+ EXPECT_TRUE(database.Init(filename_));
int chunk_id = 0;
int total_host_keys = size;
@@ -414,8 +413,7 @@ class SafeBrowsingDatabaseTest {
for (int j = 0; j < host_keys_per_chunk; ++j) {
SBChunkHost host;
- host.host = base::RandInt(std::numeric_limits<int>::min(),
- std::numeric_limits<int>::max());
+ rand_s((unsigned int*)&host.host);
host.entry = SBEntry::Create(SBEntry::ADD_PREFIX, 2);
host.entry->SetPrefixAt(0, 0x2425525);
host.entry->SetPrefixAt(1, 0x1536366);
@@ -424,37 +422,32 @@ class SafeBrowsingDatabaseTest {
}
}
- database->InsertChunks("goog-malware", chunks);
+ database.InsertChunks("goog-malware", chunks);
}
void Read(bool use_bloom_filter) {
int keys_to_read = 500;
- file_util::EvictFileFromSystemCache(path_);
+ file_util::EvictFileFromSystemCache(filename_.c_str());
- scoped_ptr<SafeBrowsingDatabase> database(SafeBrowsingDatabase::Create());
- database->SetSynchronous();
- EXPECT_TRUE(database->Init(path_.ToWStringHack(), NULL));
+ SafeBrowsingDatabase database;
+ database.set_synchronous();
+ EXPECT_TRUE(database.Init(filename_));
PerfTimer total_timer;
int64 db_ms = 0;
int keys_from_db = 0;
for (int i = 0; i < keys_to_read; ++i) {
- int key = base::RandInt(std::numeric_limits<int>::min(),
- std::numeric_limits<int>::max());
+ int key;
+ rand_s((unsigned int*)&key);
std::string url = StringPrintf("http://www.%d.com/blah.html", key);
std::string matching_list;
std::vector<SBPrefix> prefix_hits;
- std::vector<SBFullHashResult> full_hits;
GURL gurl(url);
- if (!use_bloom_filter || database->NeedToCheckUrl(gurl)) {
+ if (!use_bloom_filter || database.NeedToCheckUrl(gurl)) {
PerfTimer timer;
- database->ContainsUrl(gurl,
- &matching_list,
- &prefix_hits,
- &full_hits,
- base::Time::Now());
+ database.ContainsUrl(gurl, &matching_list, &prefix_hits);
int64 time_ms = timer.Elapsed().InMilliseconds();
@@ -467,80 +460,81 @@ class SafeBrowsingDatabaseTest {
int64 total_ms = total_timer.Elapsed().InMilliseconds();
- DLOG(INFO) << path_.BaseName().value() << " read " << keys_to_read <<
- " entries in " << total_ms << " ms. " << keys_from_db <<
- " keys were read from the db, with average read taking " <<
+ DLOG(INFO) << WideToASCII(file_util::GetFilenameFromPath(filename_)) <<
+ " read " << keys_to_read << " entries in " << total_ms << " ms. " <<
+ keys_from_db << " keys were read from the db, with average read taking " <<
db_ms / keys_from_db << " ms";
}
void BuildBloomFilter() {
- file_util::EvictFileFromSystemCache(path_);
- file_util::Delete(SafeBrowsingDatabase::BloomFilterFilename(
- path_.ToWStringHack()), false);
+ file_util::EvictFileFromSystemCache(filename_.c_str());
+ file_util::Delete(SafeBrowsingDatabase::BloomFilterFilename(filename_), false);
PerfTimer total_timer;
- scoped_ptr<SafeBrowsingDatabase> database(SafeBrowsingDatabase::Create());
- database->SetSynchronous();
- EXPECT_TRUE(database->Init(path_.ToWStringHack(), NULL));
+ SafeBrowsingDatabase database;
+ database.set_synchronous();
+ EXPECT_TRUE(database.Init(filename_));
int64 total_ms = total_timer.Elapsed().InMilliseconds();
- DLOG(INFO) << path_.BaseName().value() <<
+ DLOG(INFO) << WideToASCII(file_util::GetFilenameFromPath(filename_)) <<
" built bloom filter in " << total_ms << " ms.";
}
private:
- FilePath path_;
+ std::wstring filename_;
};
// Adds 100K host records.
-TEST(SafeBrowsingDatabase, DISABLED_FillUp100K) {
- SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing100K")));
+TEST(SafeBrowsingDatabase, FillUp100K) {
+ SafeBrowsingDatabaseTest db(L"SafeBrowsing100K");
db.Create(100000);
}
// Adds 250K host records.
-TEST(SafeBrowsingDatabase, DISABLED_FillUp250K) {
- SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing250K")));
+TEST(SafeBrowsingDatabase, FillUp250K) {
+ SafeBrowsingDatabaseTest db(L"SafeBrowsing250K");
db.Create(250000);
}
// Adds 500K host records.
-TEST(SafeBrowsingDatabase, DISABLED_FillUp500K) {
- SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing500K")));
+TEST(SafeBrowsingDatabase, FillUp500K) {
+ SafeBrowsingDatabaseTest db(L"SafeBrowsing500K");
db.Create(500000);
}
// Reads 500 entries and prints the timing.
-TEST(SafeBrowsingDatabase, DISABLED_ReadFrom250K) {
- SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing250K")));
+TEST(SafeBrowsingDatabase, ReadFrom250K) {
+ SafeBrowsingDatabaseTest db(L"SafeBrowsing250K");
db.Read(false);
}
-TEST(SafeBrowsingDatabase, DISABLED_ReadFrom500K) {
- SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing500K")));
+TEST(SafeBrowsingDatabase, ReadFrom500K) {
+ SafeBrowsingDatabaseTest db(L"SafeBrowsing500K");
db.Read(false);
}
// Read 500 entries with a bloom filter and print the timing.
-TEST(SafeBrowsingDatabase, DISABLED_BloomReadFrom250K) {
- SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing250K")));
+TEST(SafeBrowsingDatabase, BloomReadFrom250K) {
+ SafeBrowsingDatabaseTest db(L"SafeBrowsing250K");
db.Read(true);
}
-TEST(SafeBrowsingDatabase, DISABLED_BloomReadFrom500K) {
- SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing500K")));
+TEST(SafeBrowsingDatabase, BloomReadFrom500K) {
+ SafeBrowsingDatabaseTest db(L"SafeBrowsing500K");
db.Read(true);
}
// Test how long bloom filter creation takes.
-TEST(SafeBrowsingDatabase, DISABLED_BuildBloomFilter250K) {
- SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing250K")));
+TEST(SafeBrowsingDatabase, BuildBloomFilter250K) {
+ SafeBrowsingDatabaseTest db(L"SafeBrowsing250K");
db.BuildBloomFilter();
}
-TEST(SafeBrowsingDatabase, DISABLED_BuildBloomFilter500K) {
- SafeBrowsingDatabaseTest db(FilePath(FILE_PATH_LITERAL("SafeBrowsing500K")));
+TEST(SafeBrowsingDatabase, BuildBloomFilter500K) {
+ SafeBrowsingDatabaseTest db(L"SafeBrowsing500K");
db.BuildBloomFilter();
}
+
+#endif
diff --git a/chrome/browser/safe_browsing/safe_browsing_database.h b/chrome/browser/safe_browsing/safe_browsing_database.h
index 6e6612a..5e38763 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database.h
+++ b/chrome/browser/safe_browsing/safe_browsing_database.h
@@ -89,9 +89,6 @@ class SafeBrowsingDatabase {
virtual std::wstring filename() const { return filename_; }
protected:
- friend class SafeBrowsingDatabaseTest;
- FRIEND_TEST(SafeBrowsingDatabase, HashCaching);
-
static std::wstring BloomFilterFilename(const std::wstring& db_filename);
// Load the bloom filter off disk, or generates one if it doesn't exist.
@@ -109,6 +106,9 @@ class SafeBrowsingDatabase {
// Measuring false positive rate. Call this each time we look in the filter.
virtual void IncrementBloomFilterReadCount() {}
+ // Full hash cache support.
+ FRIEND_TEST(SafeBrowsingDatabase, HashCaching);
+
typedef struct HashCacheEntry {
SBFullHash full_hash;
int list_id;
diff --git a/chrome/browser/visitedlink_perftest.cc b/chrome/browser/visitedlink_perftest.cc
index 3775fab..d589f92 100644
--- a/chrome/browser/visitedlink_perftest.cc
+++ b/chrome/browser/visitedlink_perftest.cc
@@ -6,7 +6,6 @@
#include <string>
#include <vector>
-#include "base/file_path.h"
#include "base/file_util.h"
#include "base/perftimer.h"
#include "base/shared_memory.h"
@@ -144,8 +143,7 @@ TEST_F(VisitedLink, TestLoad) {
for (int i = 0; i < load_count; i++)
{
// make sure the file has to be re-loaded
- file_util::EvictFileFromSystemCache(
- FilePath::FromWStringHack(std::wstring(db_name_)));
+ file_util::EvictFileFromSystemCache(db_name_.c_str());
// cold load (no OS cache, hopefully)
{