| Index: chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
|
| diff --git a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
|
| index 6407e534eec1d7a421cca0e974014b9db92c4bdb..0095efb04e3ec3f2179823db10655596408d80f1 100644
|
| --- a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
|
| +++ b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
|
| @@ -7,17 +7,11 @@
|
| #include "app/sql/connection.h"
|
| #include "app/sql/statement.h"
|
| #include "base/file_util.h"
|
| -#include "base/format_macros.h"
|
| #include "base/logging.h"
|
| #include "base/message_loop.h"
|
| -#include "base/metrics/stats_counters.h"
|
| -#include "base/path_service.h"
|
| -#include "base/process_util.h"
|
| #include "base/scoped_temp_dir.h"
|
| #include "base/sha2.h"
|
| -#include "base/string_util.h"
|
| #include "base/time.h"
|
| -#include "chrome/browser/safe_browsing/protocol_parser.h"
|
| #include "chrome/browser/safe_browsing/safe_browsing_database.h"
|
| #include "chrome/browser/safe_browsing/safe_browsing_store_file.h"
|
| #include "chrome/browser/safe_browsing/safe_browsing_store_sqlite.h"
|
| @@ -1164,234 +1158,3 @@ TEST_F(SafeBrowsingDatabaseTest, DISABLED_FileCorruptionHandling) {
|
|
|
| database_.reset();
|
| }
|
| -
|
| -namespace {
|
| -
|
| -void PrintStat(const char* name) {
|
| - int value = base::StatsTable::current()->GetCounterValue(name);
|
| - SB_DLOG(INFO) << StringPrintf("%s %d", name, value);
|
| -}
|
| -
|
| -FilePath GetFullSBDataPath(const FilePath& path) {
|
| - FilePath full_path;
|
| - if (!PathService::Get(base::DIR_SOURCE_ROOT, &full_path)) {
|
| - ADD_FAILURE() << "Unable to find test DIR_SOURCE_ROOT for test data.";
|
| - return FilePath();
|
| - }
|
| - full_path = full_path.AppendASCII("chrome");
|
| - full_path = full_path.AppendASCII("test");
|
| - full_path = full_path.AppendASCII("data");
|
| - full_path = full_path.AppendASCII("safe_browsing");
|
| - full_path = full_path.Append(path);
|
| - return full_path;
|
| -}
|
| -
|
| -// TODO(shess): The clients of this structure manually manage
|
| -// |chunks|. Improve this code to apply the RAII idiom to manage
|
| -// |chunks|.
|
| -struct ChunksInfo {
|
| - SBChunkList* chunks; // weak
|
| - std::string listname;
|
| -};
|
| -
|
| -// TODO(shess): Move this into SafeBrowsingDatabaseTest.
|
| -void PerformUpdate(SafeBrowsingDatabaseNew* database,
|
| - const FilePath& database_filename,
|
| - const FilePath& initial_db,
|
| - const std::vector<ChunksInfo>& chunks,
|
| - const std::vector<SBChunkDelete>& deletes) {
|
| - base::IoCounters before, after;
|
| -
|
| - if (!initial_db.empty()) {
|
| - FilePath full_initial_db = GetFullSBDataPath(initial_db);
|
| - ASSERT_FALSE(full_initial_db.empty());
|
| - ASSERT_TRUE(file_util::PathExists(full_initial_db));
|
| - ASSERT_TRUE(file_util::CopyFile(full_initial_db, database_filename));
|
| - }
|
| -
|
| - Time before_time = Time::Now();
|
| - base::ProcessHandle handle = base::Process::Current().handle();
|
| - scoped_ptr<base::ProcessMetrics> metric(
|
| -#if !defined(OS_MACOSX)
|
| - base::ProcessMetrics::CreateProcessMetrics(handle));
|
| -#else
|
| - // Getting stats only for the current process is enough, so NULL is fine.
|
| - base::ProcessMetrics::CreateProcessMetrics(handle, NULL));
|
| -#endif
|
| - // Get IO stats. These are currently not supported on Mac, and may not be
|
| - // available for Linux, so we check the result and only show IO stats if
|
| - // they are available.
|
| - bool gotIOCounters = metric->GetIOCounters(&before);
|
| -
|
| - std::vector<SBListChunkRanges> lists;
|
| - EXPECT_TRUE(database->UpdateStarted(&lists));
|
| - database->DeleteChunks(deletes);
|
| - for (size_t i = 0; i < chunks.size(); ++i)
|
| - database->InsertChunks(chunks[i].listname, *chunks[i].chunks);
|
| -
|
| - database->UpdateFinished(true);
|
| -
|
| - gotIOCounters = gotIOCounters && metric->GetIOCounters(&after);
|
| -
|
| - if (gotIOCounters) {
|
| - SB_DLOG(INFO) << StringPrintf("I/O Read Bytes: %" PRIu64,
|
| - after.ReadTransferCount - before.ReadTransferCount);
|
| - SB_DLOG(INFO) << StringPrintf("I/O Write Bytes: %" PRIu64,
|
| - after.WriteTransferCount - before.WriteTransferCount);
|
| - SB_DLOG(INFO) << StringPrintf("I/O Reads: %" PRIu64,
|
| - after.ReadOperationCount - before.ReadOperationCount);
|
| - SB_DLOG(INFO) << StringPrintf("I/O Writes: %" PRIu64,
|
| - after.WriteOperationCount - before.WriteOperationCount);
|
| - }
|
| - SB_DLOG(INFO) << StringPrintf("Finished in %" PRId64 " ms",
|
| - (Time::Now() - before_time).InMilliseconds());
|
| -
|
| - PrintStat("c:SB.HostSelect");
|
| - PrintStat("c:SB.HostSelectForBloomFilter");
|
| - PrintStat("c:SB.HostReplace");
|
| - PrintStat("c:SB.HostInsert");
|
| - PrintStat("c:SB.HostDelete");
|
| - PrintStat("c:SB.ChunkSelect");
|
| - PrintStat("c:SB.ChunkInsert");
|
| - PrintStat("c:SB.ChunkDelete");
|
| - PrintStat("c:SB.TransactionCommit");
|
| -}
|
| -
|
| -void UpdateDatabase(SafeBrowsingDatabaseNew* database,
|
| - const FilePath& database_filename,
|
| - const FilePath& initial_db,
|
| - const FilePath& response_path,
|
| - const FilePath& updates_path) {
|
| - // First we read the chunks from disk, so that this isn't counted in IO bytes.
|
| - std::vector<ChunksInfo> chunks;
|
| -
|
| - SafeBrowsingProtocolParser parser;
|
| - if (!updates_path.empty()) {
|
| - FilePath data_dir = GetFullSBDataPath(updates_path);
|
| - ASSERT_FALSE(data_dir.empty());
|
| - ASSERT_TRUE(file_util::PathExists(data_dir));
|
| - file_util::FileEnumerator file_enum(data_dir, false,
|
| - file_util::FileEnumerator::FILES);
|
| - while (true) {
|
| - FilePath file = file_enum.Next();
|
| - if (file.empty())
|
| - break;
|
| -
|
| - int64 size64;
|
| - bool result = file_util::GetFileSize(file, &size64);
|
| - ASSERT_TRUE(result);
|
| -
|
| - int size = static_cast<int>(size64);
|
| - scoped_array<char> data(new char[size]);
|
| - file_util::ReadFile(file, data.get(), size);
|
| -
|
| - ChunksInfo info;
|
| - info.chunks = new SBChunkList;
|
| -
|
| - bool re_key;
|
| - result = parser.ParseChunk(data.get(), size, "", "",
|
| - &re_key, info.chunks);
|
| - ASSERT_TRUE(result);
|
| -
|
| - info.listname = WideToASCII(file.BaseName().ToWStringHack());
|
| - size_t index = info.listname.find('_'); // Get rid fo the _s or _a.
|
| - info.listname.resize(index);
|
| - info.listname.erase(0, 3); // Get rid of the 000 etc.
|
| -
|
| - chunks.push_back(info);
|
| - }
|
| - }
|
| -
|
| - std::vector<SBChunkDelete> deletes;
|
| - if (!response_path.empty()) {
|
| - std::string update;
|
| - FilePath full_response_path = GetFullSBDataPath(response_path);
|
| - ASSERT_FALSE(full_response_path.empty());
|
| - ASSERT_TRUE(file_util::PathExists(full_response_path));
|
| - if (file_util::ReadFileToString(full_response_path, &update)) {
|
| - int next_update;
|
| - bool result, rekey, reset;
|
| - std::vector<ChunkUrl> urls;
|
| - result = parser.ParseUpdate(update.c_str(),
|
| - static_cast<int>(update.length()),
|
| - "",
|
| - &next_update,
|
| - &rekey,
|
| - &reset,
|
| - &deletes,
|
| - &urls);
|
| - ASSERT_TRUE(result);
|
| - if (!updates_path.empty())
|
| - ASSERT_EQ(urls.size(), chunks.size());
|
| - }
|
| - }
|
| -
|
| - PerformUpdate(database, database_filename, initial_db, chunks, deletes);
|
| -
|
| - // TODO(shess): Make ChunksInfo handle this via scoping.
|
| - for (std::vector<ChunksInfo>::iterator iter = chunks.begin();
|
| - iter != chunks.end(); ++iter) {
|
| - delete iter->chunks;
|
| - iter->chunks = NULL;
|
| - }
|
| -}
|
| -
|
| -// Construct the shared base path used by the GetOld* functions.
|
| -FilePath BasePath() {
|
| - return FilePath(FILE_PATH_LITERAL("old"));
|
| -}
|
| -
|
| -FilePath GetOldSafeBrowsingPath() {
|
| - return BasePath().AppendASCII("SafeBrowsing");
|
| -}
|
| -
|
| -FilePath GetOldResponsePath() {
|
| - return BasePath().AppendASCII("response");
|
| -}
|
| -
|
| -FilePath GetOldUpdatesPath() {
|
| - return BasePath().AppendASCII("updates");
|
| -}
|
| -
|
| -} // 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.
|
| -TEST_F(SafeBrowsingDatabaseTest, DatabaseInitialIO) {
|
| - UpdateDatabase(database_.get(), database_filename_,
|
| - FilePath(), FilePath(), FilePath().AppendASCII("initial"));
|
| -}
|
| -
|
| -// 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_F(SafeBrowsingDatabaseTest, DatabaseOldIO) {
|
| - UpdateDatabase(database_.get(), database_filename_, GetOldSafeBrowsingPath(),
|
| - GetOldResponsePath(), GetOldUpdatesPath());
|
| -}
|
| -
|
| -// Like DatabaseOldIO but only the deletes.
|
| -TEST_F(SafeBrowsingDatabaseTest, DatabaseOldDeletesIO) {
|
| - UpdateDatabase(database_.get(), database_filename_,
|
| - GetOldSafeBrowsingPath(), GetOldResponsePath(), FilePath());
|
| -}
|
| -
|
| -// Like DatabaseOldIO but only the updates.
|
| -TEST_F(SafeBrowsingDatabaseTest, DatabaseOldUpdatesIO) {
|
| - UpdateDatabase(database_.get(), database_filename_,
|
| - GetOldSafeBrowsingPath(), FilePath(), GetOldUpdatesPath());
|
| -}
|
| -
|
| -// Does a a lot of addel's on very large chunks.
|
| -TEST_F(SafeBrowsingDatabaseTest, DatabaseOldLotsofDeletesIO) {
|
| - std::vector<ChunksInfo> chunks;
|
| - std::vector<SBChunkDelete> deletes;
|
| - SBChunkDelete del;
|
| - del.is_sub_del = false;
|
| - del.list_name = safe_browsing_util::kMalwareList;
|
| - del.chunk_del.push_back(ChunkRange(3539, 3579));
|
| - deletes.push_back(del);
|
| - PerformUpdate(database_.get(), database_filename_,
|
| - GetOldSafeBrowsingPath(), chunks, deletes);
|
| -}
|
|
|