diff options
author | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-18 02:33:13 +0000 |
---|---|---|
committer | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-18 02:33:13 +0000 |
commit | 9f1dd654dcfa8b84f2ee5718e1dc0daf0b9cdf89 (patch) | |
tree | bd58066c75b1fb65d9d42f8e244fbf929b3e9bf8 /webkit/tools/test_shell | |
parent | 041b0bbba0efec8bd026aee1165e4be697cbf8ce (diff) | |
download | chromium_src-9f1dd654dcfa8b84f2ee5718e1dc0daf0b9cdf89.zip chromium_src-9f1dd654dcfa8b84f2ee5718e1dc0daf0b9cdf89.tar.gz chromium_src-9f1dd654dcfa8b84f2ee5718e1dc0daf0b9cdf89.tar.bz2 |
Fixes a crash source in test_shell when running DB tests.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/404013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@32262 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/tools/test_shell')
-rw-r--r-- | webkit/tools/test_shell/simple_database_system.cc | 36 | ||||
-rw-r--r-- | webkit/tools/test_shell/simple_database_system.h | 17 |
2 files changed, 46 insertions, 7 deletions
diff --git a/webkit/tools/test_shell/simple_database_system.cc b/webkit/tools/test_shell/simple_database_system.cc index 14c3249..4bab033 100644 --- a/webkit/tools/test_shell/simple_database_system.cc +++ b/webkit/tools/test_shell/simple_database_system.cc @@ -44,8 +44,7 @@ base::PlatformFile SimpleDatabaseSystem::OpenFile( const string16& vfs_file_name, int desired_flags, base::PlatformFile* dir_handle) { base::PlatformFile file_handle = base::kInvalidPlatformFileValue; - FilePath file_name = - DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); + FilePath file_name = GetFullFilePathForVfsFile(vfs_file_name); if (file_name.empty()) { VfsBackend::OpenTempFileInDirectory( db_tracker_->DatabaseDirectory(), desired_flags, @@ -67,8 +66,7 @@ int SimpleDatabaseSystem::DeleteFile( const int kNumDeleteRetries = 3; int num_retries = 0; int error_code = SQLITE_OK; - FilePath file_name = - DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); + FilePath file_name = GetFullFilePathForVfsFile(vfs_file_name); do { error_code = VfsBackend::DeleteFile(file_name, sync_dir); } while ((++num_retries < kNumDeleteRetries) && @@ -80,12 +78,11 @@ int SimpleDatabaseSystem::DeleteFile( long SimpleDatabaseSystem::GetFileAttributes(const string16& vfs_file_name) { return VfsBackend::GetFileAttributes( - DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name)); + GetFullFilePathForVfsFile(vfs_file_name)); } long long SimpleDatabaseSystem::GetFileSize(const string16& vfs_file_name) { - return VfsBackend::GetFileSize( - DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name)); + return VfsBackend::GetFileSize(GetFullFilePathForVfsFile(vfs_file_name)); } void SimpleDatabaseSystem::DatabaseOpened(const string16& origin_identifier, @@ -96,6 +93,8 @@ void SimpleDatabaseSystem::DatabaseOpened(const string16& origin_identifier, int64 space_available = 0; db_tracker_->DatabaseOpened(origin_identifier, database_name, description, estimated_size, &database_size, &space_available); + SetFullFilePathsForVfsFile(origin_identifier, database_name); + OnDatabaseSizeChanged(origin_identifier, database_name, database_size, space_available); } @@ -139,4 +138,27 @@ void SimpleDatabaseSystem::databaseClosed(const WebKit::WebDatabase& database) { void SimpleDatabaseSystem::ClearAllDatabases() { db_tracker_->CloseTrackerDatabaseAndClearCaches(); file_util::Delete(db_tracker_->DatabaseDirectory(), true); + file_names_.clear(); +} + +void SimpleDatabaseSystem::SetFullFilePathsForVfsFile( + const string16& origin_identifier, + const string16& database_name) { + string16 vfs_file_name = origin_identifier + ASCIIToUTF16("/") + + database_name + ASCIIToUTF16("#"); + FilePath file_name = + DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_, vfs_file_name); + + AutoLock file_names_auto_lock(file_names_lock_); + file_names_[vfs_file_name] = file_name; + file_names_[vfs_file_name + ASCIIToUTF16("-journal")] = + FilePath::FromWStringHack(file_name.ToWStringHack() + + ASCIIToWide("-journal")); +} + +FilePath SimpleDatabaseSystem::GetFullFilePathForVfsFile( + const string16& vfs_file_name) { + AutoLock file_names_auto_lock(file_names_lock_); + DCHECK(file_names_.find(vfs_file_name) != file_names_.end()); + return file_names_[vfs_file_name]; } diff --git a/webkit/tools/test_shell/simple_database_system.h b/webkit/tools/test_shell/simple_database_system.h index f741b97..689bb43 100644 --- a/webkit/tools/test_shell/simple_database_system.h +++ b/webkit/tools/test_shell/simple_database_system.h @@ -5,6 +5,9 @@ #ifndef WEBKIT_TOOLS_TEST_SHELL_SIMPLE_DATABASE_SYSTEM_H_ #define WEBKIT_TOOLS_TEST_SHELL_SIMPLE_DATABASE_SYSTEM_H_ +#include "base/file_path.h" +#include "base/hash_tables.h" +#include "base/lock.h" #include "base/platform_file.h" #include "base/ref_counted.h" #include "base/scoped_temp_dir.h" @@ -51,11 +54,25 @@ class SimpleDatabaseSystem : public webkit_database::DatabaseTracker::Observer, void ClearAllDatabases(); private: + // The calls that come from the database tracker run on the main thread. + // Therefore, we can only call DatabaseUtil::GetFullFilePathForVfsFile() + // on the main thread. However, the VFS calls run on the DB thread and + // they need to crack VFS file paths. To resolve this problem, we store + // a map of vfs_file_names to file_paths. The map is updated on the main + // thread on each DatabaseOpened() call that comes from the database + // tracker, and is read on the DB thread by each VFS call. + void SetFullFilePathsForVfsFile(const string16& origin_identifier, + const string16& database_name); + FilePath GetFullFilePathForVfsFile(const string16& vfs_file_name); + static SimpleDatabaseSystem* instance_; ScopedTempDir temp_dir_; scoped_refptr<webkit_database::DatabaseTracker> db_tracker_; + + Lock file_names_lock_; + base::hash_map<string16, FilePath> file_names_; }; #endif // WEBKIT_TOOLS_TEST_SHELL_SIMPLE_DATABASE_SYSTEM_H_ |