summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-28 05:47:15 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-28 05:47:15 +0000
commitc870c76357fc05d3f7181f8121181f983bd25e7f (patch)
tree4757d379e295e2a594e63d53a0d3b4fe51c77379
parent0b88baec73430cb25a4d6181b47c221f99fe5d0f (diff)
downloadchromium_src-c870c76357fc05d3f7181f8121181f983bd25e7f.zip
chromium_src-c870c76357fc05d3f7181f8121181f983bd25e7f.tar.gz
chromium_src-c870c76357fc05d3f7181f8121181f983bd25e7f.tar.bz2
Safe browsing cleanup:
* wstring -> FilePath * create versions of WriteFile/ReadFile with FilePath signatures Review URL: http://codereview.chromium.org/19610 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8797 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/file_util.cc6
-rw-r--r--base/file_util.h4
-rw-r--r--base/file_util_posix.cc8
-rw-r--r--base/file_util_win.cc16
-rw-r--r--chrome/browser/safe_browsing/database_perftest.cc14
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database.cc10
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database.h11
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_bloom.cc9
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_bloom.h2
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_impl.cc4
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_impl.h2
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_database_unittest.cc26
-rw-r--r--chrome/browser/safe_browsing/safe_browsing_service.cc11
-rw-r--r--chrome/common/chrome_constants.cc6
-rw-r--r--chrome/common/chrome_constants.h4
-rw-r--r--chrome/common/sqlite_utils.cc10
-rw-r--r--chrome/common/sqlite_utils.h9
17 files changed, 94 insertions, 58 deletions
diff --git a/base/file_util.cc b/base/file_util.cc
index 916bc3c..d388e67 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -468,6 +468,9 @@ bool PathExists(const std::wstring& path) {
bool PathIsWritable(const std::wstring& path) {
return PathIsWritable(FilePath::FromWStringHack(path));
}
+int ReadFile(const std::wstring& filename, char* data, int size) {
+ return ReadFile(FilePath::FromWStringHack(filename), data, size);
+}
bool SetCurrentDirectory(const std::wstring& directory) {
return SetCurrentDirectory(FilePath::FromWStringHack(directory));
}
@@ -496,5 +499,8 @@ void UpOneDirectoryOrEmpty(std::wstring* dir) {
else
*dir = directory.ToWStringHack();
}
+int WriteFile(const std::wstring& filename, const char* data, int size) {
+ return WriteFile(FilePath::FromWStringHack(filename), data, size);
+}
} // namespace
diff --git a/base/file_util.h b/base/file_util.h
index 3a06671..ba9f29a 100644
--- a/base/file_util.h
+++ b/base/file_util.h
@@ -327,10 +327,14 @@ bool TruncateFile(FILE* file);
// Reads the given number of bytes from the file into the buffer. Returns
// the number of read bytes, or -1 on error.
+int ReadFile(const FilePath& filename, char* data, int size);
+// Deprecated temporary compatibility function.
int ReadFile(const std::wstring& filename, char* data, int size);
// Writes the given buffer into the file, overwriting any data that was
// previously there. Returns the number of bytes written, or -1 on error.
+int WriteFile(const FilePath& filename, const char* data, int size);
+// Deprecated temporary compatibility function.
int WriteFile(const std::wstring& filename, const char* data, int size);
// Gets the current working directory for the process.
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 9ab29eb..d44b743 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -353,8 +353,8 @@ FILE* OpenFile(const FilePath& filename, const char* mode) {
return fopen(filename.value().c_str(), mode);
}
-int ReadFile(const std::wstring& filename, char* data, int size) {
- int fd = open(WideToUTF8(filename).c_str(), O_RDONLY);
+int ReadFile(const FilePath& filename, char* data, int size) {
+ int fd = open(filename.value().c_str(), O_RDONLY);
if (fd < 0)
return -1;
@@ -363,8 +363,8 @@ int ReadFile(const std::wstring& filename, char* data, int size) {
return ret_value;
}
-int WriteFile(const std::wstring& filename, const char* data, int size) {
- int fd = creat(WideToUTF8(filename).c_str(), 0666);
+int WriteFile(const FilePath& filename, const char* data, int size) {
+ int fd = creat(filename.value().c_str(), 0666);
if (fd < 0)
return -1;
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index 0bd50cb..0947827 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -497,8 +497,8 @@ FILE* OpenFile(const std::string& filename, const char* mode) {
return file;
}
-int ReadFile(const std::wstring& filename, char* data, int size) {
- ScopedHandle file(CreateFile(filename.c_str(),
+int ReadFile(const FilePath& filename, char* data, int size) {
+ ScopedHandle file(CreateFile(filename.value().c_str(),
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
@@ -519,8 +519,8 @@ int ReadFile(const std::wstring& filename, char* data, int size) {
return ret_value;
}
-int WriteFile(const std::wstring& filename, const char* data, int size) {
- ScopedHandle file(CreateFile(filename.c_str(),
+int WriteFile(const FilePath& filename, const char* data, int size) {
+ ScopedHandle file(CreateFile(filename.value().c_str(),
GENERIC_WRITE,
0,
NULL,
@@ -528,7 +528,7 @@ int WriteFile(const std::wstring& filename, const char* data, int size) {
0,
NULL));
if (file == INVALID_HANDLE_VALUE) {
- LOG(WARNING) << "CreateFile failed for path " << filename <<
+ LOG(WARNING) << "CreateFile failed for path " << filename.value() <<
" error code=" << GetLastError() <<
" error text=" << win_util::FormatLastWin32Error();
return -1;
@@ -541,13 +541,13 @@ int WriteFile(const std::wstring& filename, const char* data, int size) {
if (!result) {
// WriteFile failed.
- LOG(WARNING) << "writing file " << filename <<
+ LOG(WARNING) << "writing file " << filename.value() <<
" failed, error code=" << GetLastError() <<
" description=" << win_util::FormatLastWin32Error();
} else {
// Didn't write all the bytes.
- LOG(WARNING) << "wrote" << written << " bytes to " << filename <<
- " expected " << size;
+ LOG(WARNING) << "wrote" << written << " bytes to " <<
+ filename.value() << " expected " << size;
}
return -1;
}
diff --git a/chrome/browser/safe_browsing/database_perftest.cc b/chrome/browser/safe_browsing/database_perftest.cc
index 0da2ffc..9fd1f0e 100644
--- a/chrome/browser/safe_browsing/database_perftest.cc
+++ b/chrome/browser/safe_browsing/database_perftest.cc
@@ -389,10 +389,9 @@ class SafeBrowsingDatabaseTest {
logging::LOCK_LOG_FILE,
logging::DELETE_OLD_LOG_FILE);
- std::wstring tmp_path;
+ FilePath tmp_path;
PathService::Get(base::DIR_TEMP, &tmp_path);
- path_ = FilePath::FromWStringHack(tmp_path);
- path_ = path_.Append(filename);
+ path_ = tmp_path.Append(filename);
}
void Create(int size) {
@@ -400,7 +399,7 @@ class SafeBrowsingDatabaseTest {
scoped_ptr<SafeBrowsingDatabase> database(SafeBrowsingDatabase::Create());
database->SetSynchronous();
- EXPECT_TRUE(database->Init(path_.ToWStringHack(), NULL));
+ EXPECT_TRUE(database->Init(path_, NULL));
int chunk_id = 0;
int total_host_keys = size;
@@ -433,7 +432,7 @@ class SafeBrowsingDatabaseTest {
scoped_ptr<SafeBrowsingDatabase> database(SafeBrowsingDatabase::Create());
database->SetSynchronous();
- EXPECT_TRUE(database->Init(path_.ToWStringHack(), NULL));
+ EXPECT_TRUE(database->Init(path_, NULL));
PerfTimer total_timer;
int64 db_ms = 0;
@@ -475,14 +474,13 @@ class SafeBrowsingDatabaseTest {
void BuildBloomFilter() {
file_util::EvictFileFromSystemCache(path_);
- file_util::Delete(SafeBrowsingDatabase::BloomFilterFilename(
- path_.ToWStringHack()), false);
+ file_util::Delete(SafeBrowsingDatabase::BloomFilterFilename(path_), false);
PerfTimer total_timer;
scoped_ptr<SafeBrowsingDatabase> database(SafeBrowsingDatabase::Create());
database->SetSynchronous();
- EXPECT_TRUE(database->Init(path_.ToWStringHack(), NULL));
+ EXPECT_TRUE(database->Init(path_, NULL));
int64 total_ms = total_timer.Elapsed().InMilliseconds();
diff --git a/chrome/browser/safe_browsing/safe_browsing_database.cc b/chrome/browser/safe_browsing/safe_browsing_database.cc
index 174c867..149b31a 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database.cc
@@ -16,7 +16,8 @@
using base::Time;
// Filename suffix for the bloom filter.
-static const wchar_t kBloomFilterFile[] = L" Filter";
+static const FilePath::CharType kBloomFilterFile[] =
+ FILE_PATH_LITERAL(" Filter");
// Factory method.
SafeBrowsingDatabase* SafeBrowsingDatabase::Create() {
@@ -60,9 +61,10 @@ bool SafeBrowsingDatabase::NeedToCheckUrl(const GURL& url) {
return false;
}
-std::wstring SafeBrowsingDatabase::BloomFilterFilename(
- const std::wstring& db_filename) {
- return db_filename + kBloomFilterFile;
+// static
+FilePath SafeBrowsingDatabase::BloomFilterFilename(
+ const FilePath& db_filename) {
+ return FilePath(db_filename.value() + kBloomFilterFile);
}
void SafeBrowsingDatabase::LoadBloomFilter() {
diff --git a/chrome/browser/safe_browsing/safe_browsing_database.h b/chrome/browser/safe_browsing/safe_browsing_database.h
index 6e6612a..72ed129 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database.h
+++ b/chrome/browser/safe_browsing/safe_browsing_database.h
@@ -10,6 +10,7 @@
#include <string>
#include <vector>
+#include "base/file_path.h"
#include "base/hash_tables.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
@@ -35,7 +36,7 @@ class SafeBrowsingDatabase {
// Initializes the database with the given filename. The callback is
// executed after finishing a chunk.
- virtual bool Init(const std::wstring& filename,
+ virtual bool Init(const FilePath& filename,
Callback0::Type* chunk_inserted_callback) = 0;
// Deletes the current database and creates a new one.
@@ -86,13 +87,13 @@ class SafeBrowsingDatabase {
virtual bool UpdateStarted() { return true; }
virtual void UpdateFinished(bool update_succeeded) {}
- virtual std::wstring filename() const { return filename_; }
+ virtual FilePath filename() const { return filename_; }
protected:
friend class SafeBrowsingDatabaseTest;
FRIEND_TEST(SafeBrowsingDatabase, HashCaching);
- static std::wstring BloomFilterFilename(const std::wstring& db_filename);
+ static FilePath BloomFilterFilename(const FilePath& db_filename);
// Load the bloom filter off disk, or generates one if it doesn't exist.
virtual void LoadBloomFilter();
@@ -128,8 +129,8 @@ class SafeBrowsingDatabase {
PrefixCache prefix_miss_cache_;
PrefixCache* prefix_miss_cache() { return &prefix_miss_cache_; }
- std::wstring filename_;
- std::wstring bloom_filter_filename_;
+ FilePath filename_;
+ FilePath bloom_filter_filename_;
scoped_refptr<BloomFilter> bloom_filter_;
};
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc b/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
index 44636f3..996cb52 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_bloom.cc
@@ -42,7 +42,8 @@ static const int kOnResumeHoldupMs = 5 * 60 * 1000; // 5 minutes.
static const int kMaxStalenessMinutes = 45;
// The bloom filter based file name suffix.
-static const wchar_t kBloomFilterFileSuffix[] = L" Bloom";
+static const FilePath::CharType kBloomFilterFileSuffix[] =
+ FILE_PATH_LITERAL(" Bloom");
// Implementation --------------------------------------------------------------
@@ -60,11 +61,11 @@ SafeBrowsingDatabaseBloom::~SafeBrowsingDatabaseBloom() {
Close();
}
-bool SafeBrowsingDatabaseBloom::Init(const std::wstring& filename,
+bool SafeBrowsingDatabaseBloom::Init(const FilePath& filename,
Callback0::Type* chunk_inserted_callback) {
DCHECK(!init_ && filename_.empty());
- filename_ = filename + kBloomFilterFileSuffix;
+ filename_ = FilePath(filename.value() + kBloomFilterFileSuffix);
bloom_filter_filename_ = BloomFilterFilename(filename_);
hash_cache_.reset(new HashCache);
@@ -111,7 +112,7 @@ bool SafeBrowsingDatabaseBloom::Open() {
if (db_)
return true;
- if (sqlite3_open(WideToUTF8(filename_).c_str(), &db_) != SQLITE_OK) {
+ if (OpenSqliteDb(filename_, &db_) != SQLITE_OK) {
sqlite3_close(db_);
db_ = NULL;
return false;
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_bloom.h b/chrome/browser/safe_browsing/safe_browsing_database_bloom.h
index c04d872..22b85a8 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_bloom.h
+++ b/chrome/browser/safe_browsing/safe_browsing_database_bloom.h
@@ -32,7 +32,7 @@ class SafeBrowsingDatabaseBloom : public SafeBrowsingDatabase {
// Initializes the database with the given filename. The callback is
// executed after finishing a chunk.
- virtual bool Init(const std::wstring& filename,
+ virtual bool Init(const FilePath& filename,
Callback0::Type* chunk_inserted_callback);
// Deletes the current database and creates a new one.
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_impl.cc b/chrome/browser/safe_browsing/safe_browsing_database_impl.cc
index 47c0e85..ede649f 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_impl.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_impl.cc
@@ -76,7 +76,7 @@ SafeBrowsingDatabaseImpl::~SafeBrowsingDatabaseImpl() {
Close();
}
-bool SafeBrowsingDatabaseImpl::Init(const std::wstring& filename,
+bool SafeBrowsingDatabaseImpl::Init(const FilePath& filename,
Callback0::Type* chunk_inserted_callback) {
DCHECK(!init_ && filename_.empty());
@@ -114,7 +114,7 @@ bool SafeBrowsingDatabaseImpl::Init(const std::wstring& filename,
}
bool SafeBrowsingDatabaseImpl::Open() {
- if (sqlite3_open(WideToUTF8(filename_).c_str(), &db_) != SQLITE_OK)
+ if (OpenSqliteDb(filename_, &db_) != SQLITE_OK)
return false;
// Run the database in exclusive mode. Nobody else should be accessing the
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_impl.h b/chrome/browser/safe_browsing/safe_browsing_database_impl.h
index a69b419..1d46626 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_impl.h
+++ b/chrome/browser/safe_browsing/safe_browsing_database_impl.h
@@ -31,7 +31,7 @@ class SafeBrowsingDatabaseImpl : public SafeBrowsingDatabase {
// Initializes the database with the given filename. The callback is
// executed after finishing a chunk.
- virtual bool Init(const std::wstring& filename,
+ virtual bool Init(const FilePath& filename,
Callback0::Type* chunk_inserted_callback);
// Deletes the current database and creates a new one.
diff --git a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
index 0713e7d..fcd89df 100644
--- a/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_database_unittest.cc
@@ -23,7 +23,10 @@
using base::Time;
-static const wchar_t kBloomSuffix[] = L" Bloom";
+static const FilePath::CharType kBloomSuffix[] =
+ FILE_PATH_LITERAL(" Bloom");
+static const FilePath::CharType kFilterSuffix[] =
+ FILE_PATH_LITERAL(" Filter");
namespace {
SBPrefix Sha256Prefix(const std::string& str) {
@@ -59,18 +62,18 @@ namespace {
}
// Common database test set up code.
- std::wstring GetTestDatabaseName() {
+ FilePath GetTestDatabaseName() {
FilePath filename;
PathService::Get(base::DIR_TEMP, &filename);
filename = filename.AppendASCII("SafeBrowsingTestDatabase");
- return filename.ToWStringHack();
+ return filename;
}
SafeBrowsingDatabase* SetupTestDatabase() {
- std::wstring filename = GetTestDatabaseName();
+ FilePath filename = GetTestDatabaseName();
// In case it existed from a previous run.
- file_util::Delete(filename + kBloomSuffix, false);
+ file_util::Delete(FilePath(filename.value() + kBloomSuffix), false);
file_util::Delete(filename, false);
SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create();
@@ -81,10 +84,11 @@ namespace {
}
void TearDownTestDatabase(SafeBrowsingDatabase* database) {
- std::wstring filename = database->filename();
+ FilePath filename = database->filename();
delete database;
file_util::Delete(filename, false);
- file_util::Delete(filename + L" Filter", false);
+ file_util::Delete(FilePath(filename.value() + kFilterSuffix),
+ false);
}
void GetListsInfo(SafeBrowsingDatabase* database,
@@ -1049,19 +1053,19 @@ void PeformUpdate(const std::wstring& initial_db,
FilePath path;
PathService::Get(base::DIR_TEMP, &path);
path = path.AppendASCII("SafeBrowsingTestDatabase");
- std::wstring filename = path.ToWStringHack();
// In case it existed from a previous run.
- file_util::Delete(filename, false);
+ file_util::Delete(path, false);
if (!initial_db.empty()) {
std::wstring full_initial_db = GetFullSBDataPath(initial_db);
- ASSERT_TRUE(file_util::CopyFile(full_initial_db, filename));
+ ASSERT_TRUE(file_util::CopyFile(
+ FilePath::FromWStringHack(full_initial_db), path));
}
SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create();
database->SetSynchronous();
- EXPECT_TRUE(database->Init(filename, NULL));
+ EXPECT_TRUE(database->Init(path, NULL));
Time before_time = Time::Now();
base::ProcessHandle handle = base::Process::Current().handle();
diff --git a/chrome/browser/safe_browsing/safe_browsing_service.cc b/chrome/browser/safe_browsing/safe_browsing_service.cc
index ba6701e..57d4697 100644
--- a/chrome/browser/safe_browsing/safe_browsing_service.cc
+++ b/chrome/browser/safe_browsing/safe_browsing_service.cc
@@ -55,10 +55,11 @@ void SafeBrowsingService::Initialize(MessageLoop* io_loop) {
io_loop_ = io_loop;
// Get the profile's preference for SafeBrowsing.
- std::wstring user_data_dir;
+ FilePath user_data_dir;
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
ProfileManager* profile_manager = g_browser_process->profile_manager();
- Profile* profile = profile_manager->GetDefaultProfile(user_data_dir);
+ Profile* profile = profile_manager->GetDefaultProfile(
+ user_data_dir.ToWStringHack());
PrefService* pref_service = profile->GetPrefs();
if (pref_service->GetBoolean(prefs::kSafeBrowsingEnabled))
Start();
@@ -394,12 +395,10 @@ SafeBrowsingDatabase* SafeBrowsingService::GetDatabase() {
if (database_)
return database_;
- std::wstring path;
+ FilePath path;
bool result = PathService::Get(chrome::DIR_USER_DATA, &path);
DCHECK(result);
-
- path.append(L"\\");
- path.append(chrome::kSafeBrowsingFilename);
+ path = path.Append(chrome::kSafeBrowsingFilename);
Time before = Time::Now();
SafeBrowsingDatabase* database = SafeBrowsingDatabase::Create();
diff --git a/chrome/common/chrome_constants.cc b/chrome/common/chrome_constants.cc
index 17c8314..35cb15f 100644
--- a/chrome/common/chrome_constants.cc
+++ b/chrome/common/chrome_constants.cc
@@ -4,6 +4,10 @@
#include "chrome/common/chrome_constants.h"
+#include "base/file_path.h"
+
+#define FPL FILE_PATH_LITERAL
+
namespace chrome {
// The following should not be used for UI strings; they are meant
// for system strings only. UI changes should be made in the GRD.
@@ -31,7 +35,7 @@ const wchar_t kCookieFilename[] = L"Cookies";
const wchar_t kHistoryFilename[] = L"History";
const wchar_t kLocalStateFilename[] = L"Local State";
const wchar_t kPreferencesFilename[] = L"Preferences";
-const wchar_t kSafeBrowsingFilename[] = L"Safe Browsing";
+const FilePath::CharType kSafeBrowsingFilename[] = FPL("Safe Browsing");
const wchar_t kThumbnailsFilename[] = L"Thumbnails";
const wchar_t kUserDataDirname[] = L"User Data";
const wchar_t kUserScriptsDirname[] = L"User Scripts";
diff --git a/chrome/common/chrome_constants.h b/chrome/common/chrome_constants.h
index 5e59578..2cf8c2d 100644
--- a/chrome/common/chrome_constants.h
+++ b/chrome/common/chrome_constants.h
@@ -7,6 +7,8 @@
#ifndef CHROME_COMMON_CHROME_CONSTANTS_H__
#define CHROME_COMMON_CHROME_CONSTANTS_H__
+#include "base/file_path.h"
+
namespace chrome {
extern const wchar_t kBrowserProcessExecutableName[];
@@ -28,7 +30,7 @@ extern const wchar_t kCookieFilename[];
extern const wchar_t kHistoryFilename[];
extern const wchar_t kLocalStateFilename[];
extern const wchar_t kPreferencesFilename[];
-extern const wchar_t kSafeBrowsingFilename[];
+extern const FilePath::CharType kSafeBrowsingFilename[];
extern const wchar_t kThumbnailsFilename[];
extern const wchar_t kUserDataDirname[];
extern const wchar_t kUserScriptsDirname[];
diff --git a/chrome/common/sqlite_utils.cc b/chrome/common/sqlite_utils.cc
index d881a49..e45614a 100644
--- a/chrome/common/sqlite_utils.cc
+++ b/chrome/common/sqlite_utils.cc
@@ -4,8 +4,17 @@
#include "chrome/common/sqlite_utils.h"
+#include "base/file_path.h"
#include "base/logging.h"
+int OpenSqliteDb(const FilePath& filepath, sqlite3** database) {
+#if defined(OS_WIN)
+ return sqlite3_open16(filepath.value().c_str(), database);
+#elif defined(OS_POSIX)
+ return sqlite3_open(filepath.value().c_str(), database);
+#endif
+}
+
bool DoesSqliteTableExist(sqlite3* db,
const char* db_name,
const char* table_name) {
@@ -71,7 +80,6 @@ bool DoesSqliteTableHaveRow(sqlite3* db, const char* table_name) {
return s.step() == SQLITE_ROW;
}
-
SQLTransaction::SQLTransaction(sqlite3* db) : db_(db), began_(false) {
}
diff --git a/chrome/common/sqlite_utils.h b/chrome/common/sqlite_utils.h
index fcf384d..f704141 100644
--- a/chrome/common/sqlite_utils.h
+++ b/chrome/common/sqlite_utils.h
@@ -13,6 +13,7 @@
#include "third_party/sqlite/preprocessed/sqlite3.h"
// forward declarations of classes defined here
+class FilePath;
class SQLTransaction;
class SQLNestedTransaction;
class SQLNestedTransactionSite;
@@ -311,6 +312,13 @@ class SQLStatement : public scoped_sqlite3_stmt_ptr {
DISALLOW_COPY_AND_ASSIGN(SQLStatement);
};
+// TODO(estade): wrap the following static functions in a namespace.
+
+// Opens the DB in the file pointed to by |filepath|.
+// See http://www.sqlite.org/capi3ref.html#sqlite3_open for an explanation
+// of the return value.
+int OpenSqliteDb(const FilePath& filepath, sqlite3** database);
+
// Returns true if there is a table with the given name in the database.
// For the version where a database name is specified, it may be NULL or the
// empty string if no database name is necessary.
@@ -321,7 +329,6 @@ inline bool DoesSqliteTableExist(sqlite3* db, const char* table_name) {
return DoesSqliteTableExist(db, NULL, table_name);
}
-
// Test whether a table has a column matching the provided name and type.
// Returns true if the column exist and false otherwise. There are two
// versions, one that takes a database name, the other that doesn't. The