diff options
-rw-r--r-- | base/file_util_posix.cc | 9 | ||||
-rw-r--r-- | chrome/browser/renderer_host/database_dispatcher_host.cc | 97 |
2 files changed, 62 insertions, 44 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index a919b16..0b7763e 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -424,11 +424,10 @@ FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, FilePath* path) { return fdopen(fd, "a+"); } -// TODO(port): implement me. -bool CreateTemporaryFileInDir(const FilePath& dir, - FilePath* temp_file) { - NOTREACHED(); - return false; + +bool CreateTemporaryFileInDir(const FilePath& dir, FilePath* temp_file) { + int fd = CreateAndOpenFdForTemporaryFile(dir, temp_file); + return ((fd >= 0) && !close(fd)); } bool CreateNewTempDirectory(const FilePath::StringType& prefix, diff --git a/chrome/browser/renderer_host/database_dispatcher_host.cc b/chrome/browser/renderer_host/database_dispatcher_host.cc index 1dcf93b..c0ab282 100644 --- a/chrome/browser/renderer_host/database_dispatcher_host.cc +++ b/chrome/browser/renderer_host/database_dispatcher_host.cc @@ -64,8 +64,13 @@ static void SendMessage(ResourceMessageFilter* sender, // 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 @@ static void DatabaseOpenFile(MessageLoop* io_thread_message_loop, 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 @@ static void DatabaseOpenFile(MessageLoop* io_thread_message_loop, } } - 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 @@ static void DatabaseDeleteFile( // 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 @@ static void DatabaseDeleteFile( // 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 @@ static void DatabaseDeleteFile( #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 @@ static void DatabaseGetFileAttributes( #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 @@ static void DatabaseGetFileSize( } 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 @@ void DatabaseDispatcherHost::OnDatabaseOpenFile( 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 @@ void DatabaseDispatcherHost::OnDatabaseOpenFile( 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 @@ void DatabaseDispatcherHost::OnDatabaseDeleteFile( 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 @@ void DatabaseDispatcherHost::OnDatabaseGetFileAttributes( 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 @@ void DatabaseDispatcherHost::OnDatabaseGetFileSize( 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_)); } |