Index: chrome/browser/renderer_host/database_dispatcher_host.cc |
=================================================================== |
--- chrome/browser/renderer_host/database_dispatcher_host.cc (revision 25936) |
+++ chrome/browser/renderer_host/database_dispatcher_host.cc (working copy) |
@@ -64,8 +64,13 @@ |
// Make sure the flags used to open a DB file are consistent. |
static bool OpenFileFlagsAreConsistent(const OpenFileParams& params) { |
- if (params.file_name == params.db_dir) { |
- return (params.desired_flags == SQLITE_OPEN_READONLY); |
+ // Is this a request for a temp file? |
+ // We should be able to delete temp files when they're closed |
+ // and create them as needed |
+ if ((params.file_name == params.db_dir) && |
+ (!(params.desired_flags & SQLITE_OPEN_DELETEONCLOSE) || |
+ !(params.desired_flags & SQLITE_OPEN_CREATE))) { |
+ return false; |
} |
const int file_type = params.desired_flags & 0x00007F00; |
@@ -166,9 +171,20 @@ |
base::PLATFORM_FILE_DELETE_ON_CLOSE; |
} |
+ // If this is a request for a handle to a temp file, get a unique file name |
+ FilePath file_name; |
+ if (params.file_name == params.db_dir) { |
+ if (!file_util::CreateTemporaryFileInDir(params.db_dir, &file_name)) { |
+ file_name = FilePath(); |
+ } |
+ } else { |
+ file_name = params.file_name; |
+ } |
+ |
// Try to open/create the DB file. |
base::PlatformFile file_handle = |
- base::CreatePlatformFile(params.file_name.ToWStringHack(), flags, NULL); |
+ (file_name.empty() ? base::kInvalidPlatformFileValue : |
+ base::CreatePlatformFile(file_name.ToWStringHack(), flags, NULL)); |
if (file_handle != base::kInvalidPlatformFileValue) { |
#if defined(OS_WIN) |
// Duplicate the file handle. |
@@ -200,17 +216,17 @@ |
} |
} |
- ViewMsg_DatabaseOpenFileResponse_Params response_params = |
+ ViewMsg_DatabaseOpenFileResponse_Params response_params; |
#if defined(OS_WIN) |
- { target_handle }; |
+ response_params.file_handle = target_handle; |
#elif defined(OS_POSIX) |
- { base::FileDescriptor(target_handle, true), |
- base::FileDescriptor(target_dir_handle, true) }; |
+ response_params.file_handle = base::FileDescriptor(target_handle, true); |
+ response_params.dir_handle = base::FileDescriptor(target_dir_handle, true); |
#endif |
io_thread_message_loop->PostTask(FROM_HERE, |
- NewRunnableFunction(SendMessage, sender, |
- new ViewMsg_DatabaseOpenFileResponse(message_id, response_params))); |
+ NewRunnableFunction(SendMessage, sender, |
+ new ViewMsg_DatabaseOpenFileResponse(message_id, response_params))); |
} |
// Scheduled by the IO thread on the file thread. |
@@ -227,17 +243,17 @@ |
// after kNumDeleteRetries times. |
if (!reschedule_count) { |
io_thread_message_loop->PostTask(FROM_HERE, |
- NewRunnableFunction(SendMessage, sender, |
- new ViewMsg_DatabaseDeleteFileResponse( |
- message_id, SQLITE_IOERR_DELETE))); |
+ NewRunnableFunction(SendMessage, sender, |
+ new ViewMsg_DatabaseDeleteFileResponse( |
+ message_id, SQLITE_IOERR_DELETE))); |
return; |
} |
// If the file does not exist, we're done. |
if (!file_util::PathExists(params.file_name)) { |
io_thread_message_loop->PostTask(FROM_HERE, |
- NewRunnableFunction(SendMessage, sender, |
- new ViewMsg_DatabaseDeleteFileResponse(message_id, SQLITE_OK))); |
+ NewRunnableFunction(SendMessage, sender, |
+ new ViewMsg_DatabaseDeleteFileResponse(message_id, SQLITE_OK))); |
return; |
} |
@@ -245,8 +261,8 @@ |
// If the file could not be deleted, try again. |
if (!file_util::Delete(params.file_name, false)) { |
MessageLoop::current()->PostDelayedTask(FROM_HERE, |
- NewRunnableFunction(DatabaseDeleteFile, io_thread_message_loop, |
- params, message_id, reschedule_count - 1, sender), |
+ NewRunnableFunction(DatabaseDeleteFile, io_thread_message_loop, |
+ params, message_id, reschedule_count - 1, sender), |
kDelayDeleteRetryMs); |
return; |
} |
@@ -270,8 +286,8 @@ |
#endif |
io_thread_message_loop->PostTask(FROM_HERE, |
- NewRunnableFunction(SendMessage, sender, |
- new ViewMsg_DatabaseDeleteFileResponse(message_id, error_code))); |
+ NewRunnableFunction(SendMessage, sender, |
+ new ViewMsg_DatabaseDeleteFileResponse(message_id, error_code))); |
} |
// Scheduled by the IO thread on the file thread. |
@@ -299,8 +315,9 @@ |
#endif |
io_thread_message_loop->PostTask(FROM_HERE, |
- NewRunnableFunction(SendMessage, sender, |
- new ViewMsg_DatabaseGetFileAttributesResponse(message_id, attributes))); |
+ NewRunnableFunction(SendMessage, sender, |
+ new ViewMsg_DatabaseGetFileAttributesResponse( |
+ message_id, attributes))); |
} |
// Scheduled by the IO thread on the file thread. |
@@ -318,8 +335,8 @@ |
} |
io_thread_message_loop->PostTask(FROM_HERE, |
- NewRunnableFunction(SendMessage, sender, |
- new ViewMsg_DatabaseGetFileSizeResponse(message_id, size))); |
+ NewRunnableFunction(SendMessage, sender, |
+ new ViewMsg_DatabaseGetFileSizeResponse(message_id, size))); |
} |
} // namespace |
@@ -388,15 +405,17 @@ |
FilePath db_file_name = GetDBFileFullPath(file_name); |
if (db_file_name.empty()) { |
- ViewMsg_DatabaseOpenFileResponse_Params response_params = |
+ ViewMsg_DatabaseOpenFileResponse_Params response_params; |
#if defined(OS_WIN) |
- { base::kInvalidPlatformFileValue }; |
+ response_params.file_handle = base::kInvalidPlatformFileValue; |
#elif defined(OS_POSIX) |
- { base::FileDescriptor(base::kInvalidPlatformFileValue, true), |
- base::FileDescriptor(base::kInvalidPlatformFileValue, true) }; |
+ response_params.file_handle = |
+ base::FileDescriptor(base::kInvalidPlatformFileValue, true); |
+ response_params.dir_handle = |
+ base::FileDescriptor(base::kInvalidPlatformFileValue, true); |
#endif |
resource_message_filter_->Send(new ViewMsg_DatabaseOpenFileResponse( |
- message_id, response_params)); |
+ message_id, response_params)); |
return; |
} |
@@ -404,8 +423,8 @@ |
resource_message_filter_->handle() }; |
resource_message_filter_->AddRef(); |
file_thread_message_loop_->PostTask(FROM_HERE, |
- NewRunnableFunction(DatabaseOpenFile, MessageLoop::current(), |
- params, message_id, resource_message_filter_)); |
+ NewRunnableFunction(DatabaseOpenFile, MessageLoop::current(), |
+ params, message_id, resource_message_filter_)); |
} |
void DatabaseDispatcherHost::OnDatabaseDeleteFile( |
@@ -413,15 +432,15 @@ |
FilePath db_file_name = GetDBFileFullPath(file_name); |
if (db_file_name.empty()) { |
resource_message_filter_->Send(new ViewMsg_DatabaseDeleteFileResponse( |
- message_id, SQLITE_IOERR_DELETE)); |
+ message_id, SQLITE_IOERR_DELETE)); |
return; |
} |
DeleteFileParams params = { GetDBDir(), db_file_name, sync_dir }; |
resource_message_filter_->AddRef(); |
file_thread_message_loop_->PostTask(FROM_HERE, |
- NewRunnableFunction(DatabaseDeleteFile, MessageLoop::current(), |
- params, message_id, kNumDeleteRetries, resource_message_filter_)); |
+ NewRunnableFunction(DatabaseDeleteFile, MessageLoop::current(), |
+ params, message_id, kNumDeleteRetries, resource_message_filter_)); |
} |
void DatabaseDispatcherHost::OnDatabaseGetFileAttributes( |
@@ -429,15 +448,15 @@ |
FilePath db_file_name = GetDBFileFullPath(file_name); |
if (db_file_name.empty()) { |
resource_message_filter_->Send( |
- new ViewMsg_DatabaseGetFileAttributesResponse( |
- message_id, -1)); |
+ new ViewMsg_DatabaseGetFileAttributesResponse( |
+ message_id, -1)); |
return; |
} |
resource_message_filter_->AddRef(); |
file_thread_message_loop_->PostTask(FROM_HERE, |
- NewRunnableFunction(DatabaseGetFileAttributes, MessageLoop::current(), |
- db_file_name, message_id, resource_message_filter_)); |
+ NewRunnableFunction(DatabaseGetFileAttributes, MessageLoop::current(), |
+ db_file_name, message_id, resource_message_filter_)); |
} |
void DatabaseDispatcherHost::OnDatabaseGetFileSize( |
@@ -445,12 +464,12 @@ |
FilePath db_file_name = GetDBFileFullPath(file_name); |
if (db_file_name.empty()) { |
resource_message_filter_->Send(new ViewMsg_DatabaseGetFileSizeResponse( |
- message_id, 0)); |
+ message_id, 0)); |
return; |
} |
resource_message_filter_->AddRef(); |
file_thread_message_loop_->PostTask(FROM_HERE, |
- NewRunnableFunction(DatabaseGetFileSize, MessageLoop::current(), |
- db_file_name, message_id, resource_message_filter_)); |
+ NewRunnableFunction(DatabaseGetFileSize, MessageLoop::current(), |
+ db_file_name, message_id, resource_message_filter_)); |
} |