summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-01 19:41:02 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-01 19:41:02 +0000
commit918efbf64de58c82ffa3cd8799d9ad822811a37a (patch)
tree5ceffb5e1576177d75f1aa8546bcae074df63c1e /webkit
parente07f44f6b208541c9602bb9cc5f311612aaab64a (diff)
downloadchromium_src-918efbf64de58c82ffa3cd8799d9ad822811a37a.zip
chromium_src-918efbf64de58c82ffa3cd8799d9ad822811a37a.tar.gz
chromium_src-918efbf64de58c82ffa3cd8799d9ad822811a37a.tar.bz2
Move file_util::Delete to the base namespace
BUG= Review URL: https://codereview.chromium.org/16950028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209475 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r--webkit/browser/appcache/appcache_database.cc2
-rw-r--r--webkit/browser/appcache/appcache_storage_impl.cc2
-rw-r--r--webkit/browser/database/database_tracker.cc10
-rw-r--r--webkit/browser/database/vfs_backend.cc2
-rw-r--r--webkit/browser/dom_storage/session_storage_database.cc2
-rw-r--r--webkit/browser/fileapi/file_system_usage_cache.cc2
-rw-r--r--webkit/browser/fileapi/native_file_util.cc4
-rw-r--r--webkit/browser/fileapi/obfuscated_file_util.cc12
-rw-r--r--webkit/browser/fileapi/obfuscated_file_util_unittest.cc4
-rw-r--r--webkit/browser/fileapi/sandbox_database_test_helper.cc2
-rw-r--r--webkit/browser/fileapi/sandbox_directory_database.cc4
-rw-r--r--webkit/browser/fileapi/sandbox_directory_database_unittest.cc6
-rw-r--r--webkit/browser/fileapi/sandbox_isolated_origin_database.cc2
-rw-r--r--webkit/browser/fileapi/sandbox_origin_database.cc6
-rw-r--r--webkit/plugins/npapi/plugin_instance.cc2
-rw-r--r--webkit/plugins/npapi/plugin_stream_posix.cc2
-rw-r--r--webkit/support/simple_database_system.cc319
17 files changed, 351 insertions, 32 deletions
diff --git a/webkit/browser/appcache/appcache_database.cc b/webkit/browser/appcache/appcache_database.cc
index 47b2c85..5f507d1 100644
--- a/webkit/browser/appcache/appcache_database.cc
+++ b/webkit/browser/appcache/appcache_database.cc
@@ -1186,7 +1186,7 @@ bool AppCacheDatabase::DeleteExistingAndCreateNewDatabase() {
// This also deletes the disk cache data.
base::FilePath directory = db_file_path_.DirName();
- if (!file_util::Delete(directory, true) ||
+ if (!base::Delete(directory, true) ||
!file_util::CreateDirectory(directory)) {
return false;
}
diff --git a/webkit/browser/appcache/appcache_storage_impl.cc b/webkit/browser/appcache/appcache_storage_impl.cc
index a22e62c..e516c10 100644
--- a/webkit/browser/appcache/appcache_storage_impl.cc
+++ b/webkit/browser/appcache/appcache_storage_impl.cc
@@ -1811,7 +1811,7 @@ void AppCacheStorageImpl::OnDiskCacheInitialized(int rv) {
if (!is_incognito_) {
VLOG(1) << "Deleting existing appcache data and starting over.";
db_thread_->PostTask(
- FROM_HERE, base::Bind(base::IgnoreResult(&file_util::Delete),
+ FROM_HERE, base::Bind(base::IgnoreResult(&base::Delete),
cache_directory_, true));
}
}
diff --git a/webkit/browser/database/database_tracker.cc b/webkit/browser/database/database_tracker.cc
index 810d133..5adb3bf 100644
--- a/webkit/browser/database/database_tracker.cc
+++ b/webkit/browser/database/database_tracker.cc
@@ -416,8 +416,8 @@ bool DatabaseTracker::DeleteOrigin(const std::string& origin_identifier,
base::FilePath new_file = new_origin_dir.Append(database.BaseName());
file_util::Move(database, new_file);
}
- file_util::Delete(origin_dir, true);
- file_util::Delete(new_origin_dir, true); // might fail on windows.
+ base::Delete(origin_dir, true);
+ base::Delete(new_origin_dir, true); // might fail on windows.
databases_table_->DeleteOriginIdentifier(origin_identifier);
@@ -459,7 +459,7 @@ bool DatabaseTracker::LazyInit() {
kTemporaryDirectoryPattern);
for (base::FilePath directory = directories.Next(); !directory.empty();
directory = directories.Next()) {
- file_util::Delete(directory, true);
+ base::Delete(directory, true);
}
}
@@ -472,7 +472,7 @@ bool DatabaseTracker::LazyInit() {
(!db_->Open(kTrackerDatabaseFullPath) ||
!sql::MetaTable::DoesTableExist(db_.get()))) {
db_->Close();
- if (!file_util::Delete(db_dir_, true))
+ if (!base::Delete(db_dir_, true))
return false;
}
@@ -798,7 +798,7 @@ void DatabaseTracker::DeleteIncognitoDBDirectory() {
base::FilePath incognito_db_dir =
profile_path_.Append(kIncognitoDatabaseDirectoryName);
if (file_util::DirectoryExists(incognito_db_dir))
- file_util::Delete(incognito_db_dir, true);
+ base::Delete(incognito_db_dir, true);
}
void DatabaseTracker::ClearSessionOnlyOrigins() {
diff --git a/webkit/browser/database/vfs_backend.cc b/webkit/browser/database/vfs_backend.cc
index 041c44b..109664d 100644
--- a/webkit/browser/database/vfs_backend.cc
+++ b/webkit/browser/database/vfs_backend.cc
@@ -122,7 +122,7 @@ void VfsBackend::OpenTempFileInDirectory(
int VfsBackend::DeleteFile(const base::FilePath& file_path, bool sync_dir) {
if (!file_util::PathExists(file_path))
return SQLITE_OK;
- if (!file_util::Delete(file_path, false))
+ if (!base::Delete(file_path, false))
return SQLITE_IOERR_DELETE;
int error_code = SQLITE_OK;
diff --git a/webkit/browser/dom_storage/session_storage_database.cc b/webkit/browser/dom_storage/session_storage_database.cc
index 9fc4f62..f7eaba6 100644
--- a/webkit/browser/dom_storage/session_storage_database.cc
+++ b/webkit/browser/dom_storage/session_storage_database.cc
@@ -296,7 +296,7 @@ bool SessionStorageDatabase::LazyOpen(bool create_if_needed) {
DCHECK(db == NULL);
// Clear the directory and try again.
- file_util::Delete(file_path_, true);
+ base::Delete(file_path_, true);
s = TryToOpen(&db);
if (!s.ok()) {
LOG(WARNING) << "Failed to open leveldb in " << file_path_.value()
diff --git a/webkit/browser/fileapi/file_system_usage_cache.cc b/webkit/browser/fileapi/file_system_usage_cache.cc
index a049f3d..b466f26 100644
--- a/webkit/browser/fileapi/file_system_usage_cache.cc
+++ b/webkit/browser/fileapi/file_system_usage_cache.cc
@@ -155,7 +155,7 @@ bool FileSystemUsageCache::Delete(const base::FilePath& usage_file_path) {
TRACE_EVENT0("FileSystem", "UsageCache::Delete");
DCHECK(CalledOnValidThread());
CloseCacheFiles();
- return file_util::Delete(usage_file_path, true);
+ return base::Delete(usage_file_path, true);
}
void FileSystemUsageCache::CloseCacheFiles() {
diff --git a/webkit/browser/fileapi/native_file_util.cc b/webkit/browser/fileapi/native_file_util.cc
index 1bf4f57..1f6a2e8 100644
--- a/webkit/browser/fileapi/native_file_util.cc
+++ b/webkit/browser/fileapi/native_file_util.cc
@@ -242,7 +242,7 @@ PlatformFileError NativeFileUtil::DeleteFile(const base::FilePath& path) {
return base::PLATFORM_FILE_ERROR_NOT_FOUND;
if (file_util::DirectoryExists(path))
return base::PLATFORM_FILE_ERROR_NOT_A_FILE;
- if (!file_util::Delete(path, false))
+ if (!base::Delete(path, false))
return base::PLATFORM_FILE_ERROR_FAILED;
return base::PLATFORM_FILE_OK;
}
@@ -254,7 +254,7 @@ PlatformFileError NativeFileUtil::DeleteDirectory(const base::FilePath& path) {
return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY;
if (!file_util::IsDirectoryEmpty(path))
return base::PLATFORM_FILE_ERROR_NOT_EMPTY;
- if (!file_util::Delete(path, false))
+ if (!base::Delete(path, false))
return base::PLATFORM_FILE_ERROR_FAILED;
return base::PLATFORM_FILE_OK;
}
diff --git a/webkit/browser/fileapi/obfuscated_file_util.cc b/webkit/browser/fileapi/obfuscated_file_util.cc
index d3a680882..a5e5ab3 100644
--- a/webkit/browser/fileapi/obfuscated_file_util.cc
+++ b/webkit/browser/fileapi/obfuscated_file_util.cc
@@ -901,7 +901,7 @@ bool ObfuscatedFileUtil::DeleteDirectoryForOriginAndType(
// implementation.
// Information about failure would be useful for debugging.
DestroyDirectoryDatabase(origin, type);
- if (!file_util::Delete(origin_type_path, true /* recursive */))
+ if (!base::Delete(origin_type_path, true /* recursive */))
return false;
}
@@ -935,7 +935,7 @@ bool ObfuscatedFileUtil::DeleteDirectoryForOriginAndType(
origin_database_->RemovePathForOrigin(
webkit_database::GetIdentifierFromOrigin(origin));
}
- if (!file_util::Delete(origin_path, true /* recursive */))
+ if (!base::Delete(origin_path, true /* recursive */))
return false;
return true;
@@ -1104,7 +1104,7 @@ PlatformFileError ObfuscatedFileUtil::CreateFile(
created = true;
} else {
if (file_util::PathExists(dest_local_path)) {
- if (!file_util::Delete(dest_local_path, true /* recursive */)) {
+ if (!base::Delete(dest_local_path, true /* recursive */)) {
NOTREACHED();
return base::PLATFORM_FILE_ERROR_FAILED;
}
@@ -1129,7 +1129,7 @@ PlatformFileError ObfuscatedFileUtil::CreateFile(
if (handle) {
DCHECK_NE(base::kInvalidPlatformFileValue, *handle);
base::ClosePlatformFile(*handle);
- file_util::Delete(dest_local_path, false /* recursive */);
+ base::Delete(dest_local_path, false /* recursive */);
}
return base::PLATFORM_FILE_ERROR_FAILED;
}
@@ -1145,7 +1145,7 @@ PlatformFileError ObfuscatedFileUtil::CreateFile(
DCHECK_NE(base::kInvalidPlatformFileValue, *handle);
base::ClosePlatformFile(*handle);
}
- file_util::Delete(dest_local_path, false /* recursive */);
+ base::Delete(dest_local_path, false /* recursive */);
return base::PLATFORM_FILE_ERROR_FAILED;
}
TouchDirectory(db, dest_file_info->parent_id);
@@ -1240,7 +1240,7 @@ base::FilePath ObfuscatedFileUtil::GetDirectoryForOrigin(
base::FilePath path = file_system_directory_.Append(directory_name);
bool exists_in_fs = file_util::DirectoryExists(path);
if (!exists_in_db && exists_in_fs) {
- if (!file_util::Delete(path, true)) {
+ if (!base::Delete(path, true)) {
if (error_code)
*error_code = base::PLATFORM_FILE_ERROR_FAILED;
return base::FilePath();
diff --git a/webkit/browser/fileapi/obfuscated_file_util_unittest.cc b/webkit/browser/fileapi/obfuscated_file_util_unittest.cc
index 10a818c..ec87a49 100644
--- a/webkit/browser/fileapi/obfuscated_file_util_unittest.cc
+++ b/webkit/browser/fileapi/obfuscated_file_util_unittest.cc
@@ -867,7 +867,7 @@ TEST_F(ObfuscatedFileUtilTest, TestQuotaOnTruncation) {
UnlimitedContext().get(),
url, &local_path));
ASSERT_FALSE(local_path.empty());
- ASSERT_TRUE(file_util::Delete(local_path, false));
+ ASSERT_TRUE(base::Delete(local_path, false));
EXPECT_EQ(base::PLATFORM_FILE_ERROR_NOT_FOUND,
ofu()->Truncate(
@@ -1670,7 +1670,7 @@ TEST_F(ObfuscatedFileUtilTest, TestIncompleteDirectoryReading) {
base::FilePath local_path;
EXPECT_EQ(base::PLATFORM_FILE_OK,
ofu()->GetLocalFilePath(context.get(), kPath[0], &local_path));
- EXPECT_TRUE(file_util::Delete(local_path, false));
+ EXPECT_TRUE(base::Delete(local_path, false));
entries.clear();
EXPECT_EQ(base::PLATFORM_FILE_OK,
diff --git a/webkit/browser/fileapi/sandbox_database_test_helper.cc b/webkit/browser/fileapi/sandbox_database_test_helper.cc
index b44ba6a..18babdb 100644
--- a/webkit/browser/fileapi/sandbox_database_test_helper.cc
+++ b/webkit/browser/fileapi/sandbox_database_test_helper.cc
@@ -90,7 +90,7 @@ void DeleteDatabaseFile(const base::FilePath& db_path,
EXPECT_TRUE(leveldb::ParseFileName(FilePathToString(file_path.BaseName()),
&number, &file_type));
if (file_type == type) {
- file_util::Delete(file_path, false);
+ base::Delete(file_path, false);
// We may have multiple files for the same type, so don't break here.
}
}
diff --git a/webkit/browser/fileapi/sandbox_directory_database.cc b/webkit/browser/fileapi/sandbox_directory_database.cc
index 9b6d070..41cc429 100644
--- a/webkit/browser/fileapi/sandbox_directory_database.cc
+++ b/webkit/browser/fileapi/sandbox_directory_database.cc
@@ -309,7 +309,7 @@ bool DatabaseCheckHelper::ScanDirectory() {
std::set<base::FilePath>::iterator itr =
files_in_db_.find(relative_file_path);
if (itr == files_in_db_.end()) {
- if (!file_util::Delete(absolute_file_path, false))
+ if (!base::Delete(absolute_file_path, false))
return false;
} else {
files_in_db_.erase(itr);
@@ -748,7 +748,7 @@ bool SandboxDirectoryDatabase::Init(RecoveryOption recovery_option) {
// fall through
case DELETE_ON_CORRUPTION:
LOG(WARNING) << "Clearing SandboxDirectoryDatabase.";
- if (!file_util::Delete(filesystem_data_directory_, true))
+ if (!base::Delete(filesystem_data_directory_, true))
return false;
if (!file_util::CreateDirectory(filesystem_data_directory_))
return false;
diff --git a/webkit/browser/fileapi/sandbox_directory_database_unittest.cc b/webkit/browser/fileapi/sandbox_directory_database_unittest.cc
index f38a5b4..e163c8b 100644
--- a/webkit/browser/fileapi/sandbox_directory_database_unittest.cc
+++ b/webkit/browser/fileapi/sandbox_directory_database_unittest.cc
@@ -100,7 +100,7 @@ class SandboxDirectoryDatabaseTest : public testing::Test {
void ClearDatabaseAndDirectory() {
db_.reset();
- ASSERT_TRUE(file_util::Delete(path(), true /* recursive */));
+ ASSERT_TRUE(base::Delete(path(), true /* recursive */));
ASSERT_TRUE(file_util::CreateDirectory(path()));
db_.reset(new SandboxDirectoryDatabase(path()));
}
@@ -535,7 +535,7 @@ TEST_F(SandboxDirectoryDatabaseTest,
CreateFile(0, FPL("foo"), kBackingFileName, NULL);
EXPECT_TRUE(db()->IsFileSystemConsistent());
- ASSERT_TRUE(file_util::Delete(path().Append(kBackingFileName), false));
+ ASSERT_TRUE(base::Delete(path().Append(kBackingFileName), false));
CreateFile(0, FPL("bar"), kBackingFileName, NULL);
EXPECT_FALSE(db()->IsFileSystemConsistent());
}
@@ -545,7 +545,7 @@ TEST_F(SandboxDirectoryDatabaseTest, TestConsistencyCheck_FileLost) {
CreateFile(0, FPL("foo"), kBackingFileName, NULL);
EXPECT_TRUE(db()->IsFileSystemConsistent());
- ASSERT_TRUE(file_util::Delete(path().Append(kBackingFileName), false));
+ ASSERT_TRUE(base::Delete(path().Append(kBackingFileName), false));
EXPECT_TRUE(db()->IsFileSystemConsistent());
}
diff --git a/webkit/browser/fileapi/sandbox_isolated_origin_database.cc b/webkit/browser/fileapi/sandbox_isolated_origin_database.cc
index f382cf4..1f15573 100644
--- a/webkit/browser/fileapi/sandbox_isolated_origin_database.cc
+++ b/webkit/browser/fileapi/sandbox_isolated_origin_database.cc
@@ -73,7 +73,7 @@ void SandboxIsolatedOriginDatabase::MigrateDatabaseIfNeeded() {
base::FilePath to_path = file_system_directory_.Append(kOriginDirectory);
if (file_util::PathExists(to_path))
- file_util::Delete(to_path, true /* recursive */);
+ base::Delete(to_path, true /* recursive */);
file_util::Move(from_path, to_path);
}
diff --git a/webkit/browser/fileapi/sandbox_origin_database.cc b/webkit/browser/fileapi/sandbox_origin_database.cc
index 02c5a3a..0d7d3ef 100644
--- a/webkit/browser/fileapi/sandbox_origin_database.cc
+++ b/webkit/browser/fileapi/sandbox_origin_database.cc
@@ -108,7 +108,7 @@ bool SandboxOriginDatabase::Init(InitOption init_option,
DB_REPAIR_FAILED, DB_REPAIR_MAX);
// fall through
case DELETE_ON_CORRUPTION:
- if (!file_util::Delete(file_system_directory_, true))
+ if (!base::Delete(file_system_directory_, true))
return false;
if (!file_util::CreateDirectory(file_system_directory_))
return false;
@@ -167,7 +167,7 @@ bool SandboxOriginDatabase::RepairDatabase(const std::string& db_path) {
for (std::set<base::FilePath>::iterator dir_itr = directories.begin();
dir_itr != directories.end();
++dir_itr) {
- if (!file_util::Delete(file_system_directory_.Append(*dir_itr),
+ if (!base::Delete(file_system_directory_.Append(*dir_itr),
true /* recursive */)) {
DropDatabase();
return false;
@@ -301,7 +301,7 @@ base::FilePath SandboxOriginDatabase::GetDatabasePath() const {
void SandboxOriginDatabase::RemoveDatabase() {
DropDatabase();
- file_util::Delete(GetDatabasePath(), true /* recursive */);
+ base::Delete(GetDatabasePath(), true /* recursive */);
}
bool SandboxOriginDatabase::GetLastPathNumber(int* number) {
diff --git a/webkit/plugins/npapi/plugin_instance.cc b/webkit/plugins/npapi/plugin_instance.cc
index beabcd6..d4d74aa 100644
--- a/webkit/plugins/npapi/plugin_instance.cc
+++ b/webkit/plugins/npapi/plugin_instance.cc
@@ -243,7 +243,7 @@ void PluginInstance::NPP_Destroy() {
for (unsigned int file_index = 0; file_index < files_created_.size();
file_index++) {
- file_util::Delete(files_created_[file_index], false);
+ base::Delete(files_created_[file_index], false);
}
// Ensure that no timer callbacks are invoked after NPP_Destroy.
diff --git a/webkit/plugins/npapi/plugin_stream_posix.cc b/webkit/plugins/npapi/plugin_stream_posix.cc
index 775974c..7b02968 100644
--- a/webkit/plugins/npapi/plugin_stream_posix.cc
+++ b/webkit/plugins/npapi/plugin_stream_posix.cc
@@ -38,7 +38,7 @@ bool PluginStream::OpenTempFile() {
temp_file_ = file_util::OpenFile(temp_file_path_, "a");
if (!temp_file_) {
- file_util::Delete(temp_file_path_, false);
+ base::Delete(temp_file_path_, false);
ResetTempFileName();
return false;
}
diff --git a/webkit/support/simple_database_system.cc b/webkit/support/simple_database_system.cc
new file mode 100644
index 0000000..91f7c4f
--- /dev/null
+++ b/webkit/support/simple_database_system.cc
@@ -0,0 +1,319 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "webkit/support/simple_database_system.h"
+
+#include "base/auto_reset.h"
+#include "base/bind.h"
+#include "base/bind_helpers.h"
+#include "base/file_util.h"
+#include "base/message_loop.h"
+#include "base/message_loop/message_loop_proxy.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/synchronization/waitable_event.h"
+#include "base/threading/platform_thread.h"
+#include "third_party/WebKit/public/platform/WebCString.h"
+#include "third_party/WebKit/public/platform/WebString.h"
+#include "third_party/WebKit/public/web/WebDatabase.h"
+#include "third_party/sqlite/sqlite3.h"
+#include "webkit/browser/database/database_util.h"
+#include "webkit/browser/database/vfs_backend.h"
+
+using webkit_database::DatabaseTracker;
+using webkit_database::DatabaseUtil;
+using webkit_database::OriginInfo;
+using webkit_database::VfsBackend;
+
+SimpleDatabaseSystem* SimpleDatabaseSystem::instance_ = NULL;
+
+SimpleDatabaseSystem* SimpleDatabaseSystem::GetInstance() {
+ DCHECK(instance_);
+ return instance_;
+}
+
+SimpleDatabaseSystem::SimpleDatabaseSystem()
+ : db_thread_("SimpleDBThread"),
+ quota_per_origin_(5 * 1024 * 1024),
+ open_connections_(new webkit_database::DatabaseConnectionsWrapper) {
+ DCHECK(!instance_);
+ instance_ = this;
+ CHECK(temp_dir_.CreateUniqueTempDir());
+ db_tracker_ =
+ new DatabaseTracker(temp_dir_.path(), false, NULL, NULL, NULL);
+ db_tracker_->AddObserver(this);
+ db_thread_.Start();
+ db_thread_proxy_ = db_thread_.message_loop_proxy();
+}
+
+SimpleDatabaseSystem::~SimpleDatabaseSystem() {
+ base::WaitableEvent done_event(false, false);
+ db_thread_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleDatabaseSystem::ThreadCleanup,
+ base::Unretained(this), &done_event));
+ done_event.Wait();
+ instance_ = NULL;
+}
+
+void SimpleDatabaseSystem::databaseOpened(const WebKit::WebDatabase& database) {
+ std::string origin_identifier =
+ database.securityOrigin().databaseIdentifier().utf8();
+ base::string16 database_name = database.name();
+ open_connections_->AddOpenConnection(origin_identifier, database_name);
+ db_thread_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleDatabaseSystem::DatabaseOpened,
+ base::Unretained(this),
+ origin_identifier,
+ database_name, database.displayName(),
+ database.estimatedSize()));
+}
+
+void SimpleDatabaseSystem::databaseModified(
+ const WebKit::WebDatabase& database) {
+ db_thread_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleDatabaseSystem::DatabaseModified,
+ base::Unretained(this),
+ database.securityOrigin().databaseIdentifier().utf8(),
+ database.name()));
+}
+
+void SimpleDatabaseSystem::databaseClosed(const WebKit::WebDatabase& database) {
+ std::string origin_identifier =
+ database.securityOrigin().databaseIdentifier().utf8();
+ base::string16 database_name = database.name();
+ db_thread_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleDatabaseSystem::DatabaseClosed,
+ base::Unretained(this), origin_identifier, database_name));
+}
+
+base::PlatformFile SimpleDatabaseSystem::OpenFile(
+ const base::string16& vfs_file_name, int desired_flags) {
+ base::PlatformFile result = base::kInvalidPlatformFileValue;
+ base::WaitableEvent done_event(false, false);
+ db_thread_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleDatabaseSystem::VfsOpenFile,
+ base::Unretained(this),
+ vfs_file_name, desired_flags,
+ &result, &done_event));
+ done_event.Wait();
+ return result;
+}
+
+int SimpleDatabaseSystem::DeleteFile(
+ const base::string16& vfs_file_name, bool sync_dir) {
+ int result = SQLITE_OK;
+ base::WaitableEvent done_event(false, false);
+ db_thread_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleDatabaseSystem::VfsDeleteFile,
+ base::Unretained(this),
+ vfs_file_name, sync_dir,
+ &result, &done_event));
+ done_event.Wait();
+ return result;
+}
+
+uint32 SimpleDatabaseSystem::GetFileAttributes(
+ const base::string16& vfs_file_name) {
+ uint32 result = 0;
+ base::WaitableEvent done_event(false, false);
+ db_thread_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleDatabaseSystem::VfsGetFileAttributes,
+ base::Unretained(this), vfs_file_name, &result, &done_event));
+ done_event.Wait();
+ return result;
+}
+
+int64 SimpleDatabaseSystem::GetFileSize(const base::string16& vfs_file_name) {
+ int64 result = 0;
+ base::WaitableEvent done_event(false, false);
+ db_thread_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleDatabaseSystem::VfsGetFileSize,
+ base::Unretained(this), vfs_file_name, &result, &done_event));
+ done_event.Wait();
+ return result;
+}
+
+int64 SimpleDatabaseSystem::GetSpaceAvailable(
+ const std::string& origin_identifier) {
+ int64 result = 0;
+ base::WaitableEvent done_event(false, false);
+ db_thread_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleDatabaseSystem::VfsGetSpaceAvailable,
+ base::Unretained(this), origin_identifier,
+ &result, &done_event));
+ done_event.Wait();
+ return result;
+}
+
+void SimpleDatabaseSystem::ClearAllDatabases() {
+ open_connections_->WaitForAllDatabasesToClose();
+ db_thread_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleDatabaseSystem::ResetTracker, base::Unretained(this)));
+}
+
+void SimpleDatabaseSystem::SetDatabaseQuota(int64 quota) {
+ if (!db_thread_proxy_->BelongsToCurrentThread()) {
+ db_thread_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&SimpleDatabaseSystem::SetDatabaseQuota,
+ base::Unretained(this), quota));
+ return;
+ }
+ quota_per_origin_ = quota;
+}
+
+void SimpleDatabaseSystem::DatabaseOpened(
+ const std::string& origin_identifier,
+ const base::string16& database_name,
+ const base::string16& description,
+ int64 estimated_size) {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ int64 database_size = 0;
+ db_tracker_->DatabaseOpened(
+ origin_identifier, database_name, description,
+ estimated_size, &database_size);
+ OnDatabaseSizeChanged(origin_identifier, database_name,
+ database_size);
+}
+
+void SimpleDatabaseSystem::DatabaseModified(
+ const std::string& origin_identifier,
+ const base::string16& database_name) {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ db_tracker_->DatabaseModified(origin_identifier, database_name);
+}
+
+void SimpleDatabaseSystem::DatabaseClosed(
+ const std::string& origin_identifier,
+ const base::string16& database_name) {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ db_tracker_->DatabaseClosed(origin_identifier, database_name);
+ open_connections_->RemoveOpenConnection(origin_identifier, database_name);
+}
+
+void SimpleDatabaseSystem::OnDatabaseSizeChanged(
+ const std::string& origin_identifier,
+ const base::string16& database_name,
+ int64 database_size) {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ // We intentionally call into webkit on our background db_thread_
+ // to better emulate what happens in chrome where this method is
+ // invoked on the background ipc thread.
+ WebKit::WebDatabase::updateDatabaseSize(
+ WebKit::WebString::fromUTF8(origin_identifier),
+ database_name, database_size);
+}
+
+void SimpleDatabaseSystem::OnDatabaseScheduledForDeletion(
+ const std::string& origin_identifier,
+ const base::string16& database_name) {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ // We intentionally call into webkit on our background db_thread_
+ // to better emulate what happens in chrome where this method is
+ // invoked on the background ipc thread.
+ WebKit::WebDatabase::closeDatabaseImmediately(
+ WebKit::WebString::fromUTF8(origin_identifier), database_name);
+}
+
+void SimpleDatabaseSystem::VfsOpenFile(
+ const base::string16& vfs_file_name, int desired_flags,
+ base::PlatformFile* file_handle, base::WaitableEvent* done_event ) {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ base::FilePath file_name = GetFullFilePathForVfsFile(vfs_file_name);
+ if (file_name.empty()) {
+ VfsBackend::OpenTempFileInDirectory(
+ db_tracker_->DatabaseDirectory(), desired_flags, file_handle);
+ } else {
+ VfsBackend::OpenFile(file_name, desired_flags, file_handle);
+ }
+ done_event->Signal();
+}
+
+void SimpleDatabaseSystem::VfsDeleteFile(
+ const base::string16& vfs_file_name, bool sync_dir,
+ int* result, base::WaitableEvent* done_event) {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ // We try to delete the file multiple times, because that's what the default
+ // VFS does (apparently deleting a file can sometimes fail on Windows).
+ // We sleep for 10ms between retries for the same reason.
+ const int kNumDeleteRetries = 3;
+ int num_retries = 0;
+ *result = SQLITE_OK;
+ base::FilePath file_name = GetFullFilePathForVfsFile(vfs_file_name);
+ do {
+ *result = VfsBackend::DeleteFile(file_name, sync_dir);
+ } while ((++num_retries < kNumDeleteRetries) &&
+ (*result == SQLITE_IOERR_DELETE) &&
+ (base::PlatformThread::Sleep(
+ base::TimeDelta::FromMilliseconds(10)),
+ 1));
+
+ done_event->Signal();
+}
+
+void SimpleDatabaseSystem::VfsGetFileAttributes(
+ const base::string16& vfs_file_name,
+ uint32* result, base::WaitableEvent* done_event) {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ *result = VfsBackend::GetFileAttributes(
+ GetFullFilePathForVfsFile(vfs_file_name));
+ done_event->Signal();
+}
+
+void SimpleDatabaseSystem::VfsGetFileSize(
+ const base::string16& vfs_file_name,
+ int64* result, base::WaitableEvent* done_event) {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ *result = VfsBackend::GetFileSize(GetFullFilePathForVfsFile(vfs_file_name));
+ done_event->Signal();
+}
+
+void SimpleDatabaseSystem::VfsGetSpaceAvailable(
+ const std::string& origin_identifier,
+ int64* result, base::WaitableEvent* done_event) {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ // This method isn't actually part of the "vfs" interface, but it is
+ // used from within webcore and handled here in the same fashion.
+ OriginInfo info;
+ if (db_tracker_->GetOriginInfo(origin_identifier, &info)) {
+ int64 space_available = quota_per_origin_ - info.TotalSize();
+ *result = space_available < 0 ? 0 : space_available;
+ } else {
+ NOTREACHED();
+ *result = 0;
+ }
+ done_event->Signal();
+}
+
+base::FilePath SimpleDatabaseSystem::GetFullFilePathForVfsFile(
+ const base::string16& vfs_file_name) {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ if (vfs_file_name.empty()) // temp file, used for vacuuming
+ return base::FilePath();
+ return DatabaseUtil::GetFullFilePathForVfsFile(
+ db_tracker_.get(), vfs_file_name);
+}
+
+void SimpleDatabaseSystem::ResetTracker() {
+ DCHECK(db_thread_proxy_->BelongsToCurrentThread());
+ db_tracker_->CloseTrackerDatabaseAndClearCaches();
+ base::Delete(db_tracker_->DatabaseDirectory(), true);
+}
+
+void SimpleDatabaseSystem::ThreadCleanup(base::WaitableEvent* done_event) {
+ ResetTracker();
+ db_tracker_->RemoveObserver(this);
+ db_tracker_ = NULL;
+ done_event->Signal();
+}
+