diff options
author | shess <shess@chromium.org> | 2015-04-06 11:52:16 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-06 18:52:57 +0000 |
commit | 10ce3cc97b63b6e2a294f8279490e91ed22f06f4 (patch) | |
tree | 8e0f9c13b28681ecf1be9257af6c56fcf01eab41 | |
parent | c02ea23b81f95b4161a395d6b229cd680de63375 (diff) | |
download | chromium_src-10ce3cc97b63b6e2a294f8279490e91ed22f06f4.zip chromium_src-10ce3cc97b63b6e2a294f8279490e91ed22f06f4.tar.gz chromium_src-10ce3cc97b63b6e2a294f8279490e91ed22f06f4.tar.bz2 |
Add SetFileSize() IPC for WebSQL.
The sandbox on OSX and Linux restricts ftruncate(), which SQLite uses.
Provide a browser hook for chromium_vfs.
BUG=457905
Review URL: https://codereview.chromium.org/1006423008
Cr-Commit-Position: refs/heads/master@{#323925}
-rw-r--r-- | content/browser/renderer_host/database_message_filter.cc | 53 | ||||
-rw-r--r-- | content/browser/renderer_host/database_message_filter.h | 10 | ||||
-rw-r--r-- | content/child/blink_platform_impl.cc | 5 | ||||
-rw-r--r-- | content/child/blink_platform_impl.h | 2 | ||||
-rw-r--r-- | content/child/database_util.cc | 31 | ||||
-rw-r--r-- | content/child/database_util.h | 4 | ||||
-rw-r--r-- | content/common/database_messages.h | 6 | ||||
-rw-r--r-- | content/renderer/renderer_blink_platform_impl.cc | 6 | ||||
-rw-r--r-- | content/renderer/renderer_blink_platform_impl.h | 2 | ||||
-rw-r--r-- | storage/browser/database/vfs_backend.cc | 12 | ||||
-rw-r--r-- | storage/browser/database/vfs_backend.h | 2 |
11 files changed, 91 insertions, 42 deletions
diff --git a/content/browser/renderer_host/database_message_filter.cc b/content/browser/renderer_host/database_message_filter.cc index bb5bdd6..4b37773 100644 --- a/content/browser/renderer_host/database_message_filter.cc +++ b/content/browser/renderer_host/database_message_filter.cc @@ -89,16 +89,15 @@ void DatabaseMessageFilter::OverrideThreadForMessage( bool DatabaseMessageFilter::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(DatabaseMessageFilter, message) - IPC_MESSAGE_HANDLER_DELAY_REPLY(DatabaseHostMsg_OpenFile, - OnDatabaseOpenFile) + IPC_MESSAGE_HANDLER(DatabaseHostMsg_OpenFile, OnDatabaseOpenFile) IPC_MESSAGE_HANDLER_DELAY_REPLY(DatabaseHostMsg_DeleteFile, OnDatabaseDeleteFile) - IPC_MESSAGE_HANDLER_DELAY_REPLY(DatabaseHostMsg_GetFileAttributes, - OnDatabaseGetFileAttributes) - IPC_MESSAGE_HANDLER_DELAY_REPLY(DatabaseHostMsg_GetFileSize, - OnDatabaseGetFileSize) + IPC_MESSAGE_HANDLER(DatabaseHostMsg_GetFileAttributes, + OnDatabaseGetFileAttributes) + IPC_MESSAGE_HANDLER(DatabaseHostMsg_GetFileSize, OnDatabaseGetFileSize) IPC_MESSAGE_HANDLER_DELAY_REPLY(DatabaseHostMsg_GetSpaceAvailable, OnDatabaseGetSpaceAvailable) + IPC_MESSAGE_HANDLER(DatabaseHostMsg_SetFileSize, OnDatabaseSetFileSize) IPC_MESSAGE_HANDLER(DatabaseHostMsg_Opened, OnDatabaseOpened) IPC_MESSAGE_HANDLER(DatabaseHostMsg_Modified, OnDatabaseModified) IPC_MESSAGE_HANDLER(DatabaseHostMsg_Closed, OnDatabaseClosed) @@ -114,7 +113,7 @@ DatabaseMessageFilter::~DatabaseMessageFilter() { void DatabaseMessageFilter::OnDatabaseOpenFile( const base::string16& vfs_file_name, int desired_flags, - IPC::Message* reply_msg) { + IPC::PlatformFileForTransit* handle) { DCHECK_CURRENTLY_ON(BrowserThread::FILE); base::File file; const base::File* tracked_file = NULL; @@ -156,19 +155,15 @@ void DatabaseMessageFilter::OnDatabaseOpenFile( // Then we duplicate the file handle to make it useable in the renderer // process. The original handle is closed, unless we saved it in the // database tracker. - IPC::PlatformFileForTransit target_handle = - IPC::InvalidPlatformFileForTransit(); + *handle = IPC::InvalidPlatformFileForTransit(); if (file.IsValid()) { - target_handle = IPC::TakeFileHandleForProcess(file.Pass(), PeerHandle()); + *handle = IPC::TakeFileHandleForProcess(file.Pass(), PeerHandle()); } else if (tracked_file) { DCHECK(tracked_file->IsValid()); - target_handle = + *handle = IPC::GetFileHandleForProcess(tracked_file->GetPlatformFile(), PeerHandle(), false); } - - DatabaseHostMsg_OpenFile::WriteReplyParams(reply_msg, target_handle); - Send(reply_msg); } void DatabaseMessageFilter::OnDatabaseDeleteFile( @@ -228,30 +223,24 @@ void DatabaseMessageFilter::DatabaseDeleteFile( void DatabaseMessageFilter::OnDatabaseGetFileAttributes( const base::string16& vfs_file_name, - IPC::Message* reply_msg) { + int32* attributes) { DCHECK_CURRENTLY_ON(BrowserThread::FILE); - int32 attributes = -1; + *attributes = -1; base::FilePath db_file = DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_.get(), vfs_file_name); if (!db_file.empty()) - attributes = VfsBackend::GetFileAttributes(db_file); - - DatabaseHostMsg_GetFileAttributes::WriteReplyParams( - reply_msg, attributes); - Send(reply_msg); + *attributes = VfsBackend::GetFileAttributes(db_file); } void DatabaseMessageFilter::OnDatabaseGetFileSize( - const base::string16& vfs_file_name, IPC::Message* reply_msg) { + const base::string16& vfs_file_name, + int64* size) { DCHECK_CURRENTLY_ON(BrowserThread::FILE); - int64 size = 0; + *size = 0; base::FilePath db_file = DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_.get(), vfs_file_name); if (!db_file.empty()) - size = VfsBackend::GetFileSize(db_file); - - DatabaseHostMsg_GetFileSize::WriteReplyParams(reply_msg, size); - Send(reply_msg); + *size = VfsBackend::GetFileSize(db_file); } void DatabaseMessageFilter::OnDatabaseGetSpaceAvailable( @@ -288,6 +277,16 @@ void DatabaseMessageFilter::OnDatabaseGetUsageAndQuota( Send(reply_msg); } +void DatabaseMessageFilter::OnDatabaseSetFileSize( + const base::string16& vfs_file_name, int64 size, bool* success) { + DCHECK_CURRENTLY_ON(BrowserThread::FILE); + *success = false; + base::FilePath db_file = + DatabaseUtil::GetFullFilePathForVfsFile(db_tracker_.get(), vfs_file_name); + if (!db_file.empty()) + *success = VfsBackend::SetFileSize(db_file, size); +} + void DatabaseMessageFilter::OnDatabaseOpened( const std::string& origin_identifier, const base::string16& database_name, diff --git a/content/browser/renderer_host/database_message_filter.h b/content/browser/renderer_host/database_message_filter.h index dcac74a..13f27bc 100644 --- a/content/browser/renderer_host/database_message_filter.h +++ b/content/browser/renderer_host/database_message_filter.h @@ -8,6 +8,7 @@ #include "base/containers/hash_tables.h" #include "base/strings/string16.h" #include "content/public/browser/browser_message_filter.h" +#include "ipc/ipc_platform_file.h" #include "storage/browser/database/database_tracker.h" #include "storage/common/database/database_connections.h" #include "storage/common/quota/quota_types.h" @@ -40,14 +41,17 @@ class DatabaseMessageFilter : public BrowserMessageFilter, // VFS message handlers (file thread) void OnDatabaseOpenFile(const base::string16& vfs_file_name, int desired_flags, - IPC::Message* reply_msg); + IPC::PlatformFileForTransit* handle); void OnDatabaseDeleteFile(const base::string16& vfs_file_name, const bool& sync_dir, IPC::Message* reply_msg); void OnDatabaseGetFileAttributes(const base::string16& vfs_file_name, - IPC::Message* reply_msg); + int32* attributes); void OnDatabaseGetFileSize(const base::string16& vfs_file_name, - IPC::Message* reply_msg); + int64* size); + void OnDatabaseSetFileSize(const base::string16& vfs_file_name, + int64 size, + bool* success); // Quota message handler (io thread) void OnDatabaseGetSpaceAvailable(const std::string& origin_identifier, diff --git a/content/child/blink_platform_impl.cc b/content/child/blink_platform_impl.cc index e15f65f..454a2b3 100644 --- a/content/child/blink_platform_impl.cc +++ b/content/child/blink_platform_impl.cc @@ -1192,6 +1192,11 @@ long long BlinkPlatformImpl::databaseGetSpaceAvailableForOrigin( return 0; } +bool BlinkPlatformImpl::databaseSetFileSize( + const blink::WebString& vfs_file_name, long long size) { + return false; +} + blink::WebString BlinkPlatformImpl::signedPublicKeyAndChallengeString( unsigned key_size_index, const blink::WebString& challenge, diff --git a/content/child/blink_platform_impl.h b/content/child/blink_platform_impl.h index 12ecf5e..b607cba 100644 --- a/content/child/blink_platform_impl.h +++ b/content/child/blink_platform_impl.h @@ -61,6 +61,8 @@ class CONTENT_EXPORT BlinkPlatformImpl virtual long long databaseGetFileSize(const blink::WebString& vfs_file_name); virtual long long databaseGetSpaceAvailableForOrigin( const blink::WebString& origin_identifier); + virtual bool databaseSetFileSize( + const blink::WebString& vfs_file_name, long long size); virtual blink::WebString signedPublicKeyAndChallengeString( unsigned key_size_index, const blink::WebString& challenge, const blink::WebURL& url); diff --git a/content/child/database_util.cc b/content/child/database_util.cc index 34cf157..3a0e80b 100644 --- a/content/child/database_util.cc +++ b/content/child/database_util.cc @@ -21,8 +21,7 @@ Platform::FileHandle DatabaseUtil::DatabaseOpenFile( IPC::PlatformFileForTransit file_handle = IPC::InvalidPlatformFileForTransit(); - scoped_refptr<IPC::SyncMessageFilter> filter(sync_message_filter); - filter->Send(new DatabaseHostMsg_OpenFile( + sync_message_filter->Send(new DatabaseHostMsg_OpenFile( vfs_file_name, desired_flags, &file_handle)); return IPC::PlatformFileForTransitToPlatformFile(file_handle); @@ -33,9 +32,8 @@ int DatabaseUtil::DatabaseDeleteFile( bool sync_dir, IPC::SyncMessageFilter* sync_message_filter) { int rv = SQLITE_IOERR_DELETE; - scoped_refptr<IPC::SyncMessageFilter> filter(sync_message_filter); - filter->Send(new DatabaseHostMsg_DeleteFile( - vfs_file_name, sync_dir, &rv)); + sync_message_filter->Send( + new DatabaseHostMsg_DeleteFile(vfs_file_name, sync_dir, &rv)); return rv; } @@ -43,8 +41,8 @@ long DatabaseUtil::DatabaseGetFileAttributes( const WebString& vfs_file_name, IPC::SyncMessageFilter* sync_message_filter) { int32 rv = -1; - scoped_refptr<IPC::SyncMessageFilter> filter(sync_message_filter); - filter->Send(new DatabaseHostMsg_GetFileAttributes(vfs_file_name, &rv)); + sync_message_filter->Send( + new DatabaseHostMsg_GetFileAttributes(vfs_file_name, &rv)); return rv; } @@ -52,8 +50,8 @@ long long DatabaseUtil::DatabaseGetFileSize( const WebString& vfs_file_name, IPC::SyncMessageFilter* sync_message_filter) { int64 rv = 0LL; - scoped_refptr<IPC::SyncMessageFilter> filter(sync_message_filter); - filter->Send(new DatabaseHostMsg_GetFileSize(vfs_file_name, &rv)); + sync_message_filter->Send( + new DatabaseHostMsg_GetFileSize(vfs_file_name, &rv)); return rv; } @@ -61,9 +59,18 @@ long long DatabaseUtil::DatabaseGetSpaceAvailable( const WebString& origin_identifier, IPC::SyncMessageFilter* sync_message_filter) { int64 rv = 0LL; - scoped_refptr<IPC::SyncMessageFilter> filter(sync_message_filter); - filter->Send(new DatabaseHostMsg_GetSpaceAvailable(origin_identifier.utf8(), - &rv)); + sync_message_filter->Send( + new DatabaseHostMsg_GetSpaceAvailable(origin_identifier.utf8(), &rv)); + return rv; +} + +bool DatabaseUtil::DatabaseSetFileSize( + const WebString& vfs_file_name, + int64 size, + IPC::SyncMessageFilter* sync_message_filter) { + bool rv = false; + sync_message_filter->Send( + new DatabaseHostMsg_SetFileSize(vfs_file_name, size, &rv)); return rv; } diff --git a/content/child/database_util.h b/content/child/database_util.h index c53e7ce..1449d6b 100644 --- a/content/child/database_util.h +++ b/content/child/database_util.h @@ -34,6 +34,10 @@ class DatabaseUtil { static long long DatabaseGetSpaceAvailable( const blink::WebString& origin_identifier, IPC::SyncMessageFilter* sync_message_filter); + static bool DatabaseSetFileSize( + const blink::WebString& vfs_file_name, + int64 size, + IPC::SyncMessageFilter* sync_message_filter); }; } // namespace content diff --git a/content/common/database_messages.h b/content/common/database_messages.h index 849b347..713db98 100644 --- a/content/common/database_messages.h +++ b/content/common/database_messages.h @@ -61,6 +61,12 @@ IPC_SYNC_MESSAGE_CONTROL1_1(DatabaseHostMsg_GetSpaceAvailable, std::string /* origin identifier */, int64 /* remaining space available */) +// Asks the browser set the size of a DB file +IPC_SYNC_MESSAGE_CONTROL2_1(DatabaseHostMsg_SetFileSize, + base::string16 /* vfs file name */, + int64 /* expected size of the given DB file */, + bool /* indicates success */) + // Notifies the browser process that a new database has been opened IPC_MESSAGE_CONTROL4(DatabaseHostMsg_Opened, std::string /* origin identifier */, diff --git a/content/renderer/renderer_blink_platform_impl.cc b/content/renderer/renderer_blink_platform_impl.cc index 2b4bc10..b4a106b 100644 --- a/content/renderer/renderer_blink_platform_impl.cc +++ b/content/renderer/renderer_blink_platform_impl.cc @@ -623,6 +623,12 @@ long long RendererBlinkPlatformImpl::databaseGetSpaceAvailableForOrigin( sync_message_filter_.get()); } +bool RendererBlinkPlatformImpl::databaseSetFileSize( + const WebString& vfs_file_name, long long size) { + return DatabaseUtil::DatabaseSetFileSize( + vfs_file_name, size, sync_message_filter_.get()); +} + bool RendererBlinkPlatformImpl::canAccelerate2dCanvas() { RenderThreadImpl* thread = RenderThreadImpl::current(); GpuChannelHost* host = thread->EstablishGpuChannelSync( diff --git a/content/renderer/renderer_blink_platform_impl.h b/content/renderer/renderer_blink_platform_impl.h index a9e39ad..7691aca 100644 --- a/content/renderer/renderer_blink_platform_impl.h +++ b/content/renderer/renderer_blink_platform_impl.h @@ -92,6 +92,8 @@ class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl { const blink::WebString& vfs_file_name); virtual long long databaseGetSpaceAvailableForOrigin( const blink::WebString& origin_identifier); + virtual bool databaseSetFileSize( + const blink::WebString& vfs_file_name, long long size); virtual blink::WebString signedPublicKeyAndChallengeString( unsigned key_size_index, const blink::WebString& challenge, diff --git a/storage/browser/database/vfs_backend.cc b/storage/browser/database/vfs_backend.cc index 1f8c97b..2cd0246 100644 --- a/storage/browser/database/vfs_backend.cc +++ b/storage/browser/database/vfs_backend.cc @@ -155,4 +155,16 @@ int64 VfsBackend::GetFileSize(const base::FilePath& file_path) { return (base::GetFileSize(file_path, &size) ? size : 0); } +// static +bool VfsBackend::SetFileSize(const base::FilePath& file_path, int64 size) { + int flags = 0; + flags |= base::File::FLAG_READ; + flags |= base::File::FLAG_WRITE; + flags |= base::File::FLAG_OPEN; + base::File file = base::File(file_path, flags); + if (!file.IsValid()) + return false; + return file.SetLength(size); +} + } // namespace storage diff --git a/storage/browser/database/vfs_backend.h b/storage/browser/database/vfs_backend.h index 0ee1dd3..2b625d1 100644 --- a/storage/browser/database/vfs_backend.h +++ b/storage/browser/database/vfs_backend.h @@ -30,6 +30,8 @@ class STORAGE_EXPORT VfsBackend { static int64 GetFileSize(const base::FilePath& file_path); + static bool SetFileSize(const base::FilePath& file_path, int64 size); + // Used to make decisions in the DatabaseDispatcherHost. static bool OpenTypeIsReadWrite(int desired_flags); |