1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "content/child/database_util.h" 6 7 #include "content/common/database_messages.h" 8 #include "ipc/ipc_sync_message_filter.h" 9 #include "third_party/WebKit/public/platform/WebString.h" 10 #include "third_party/sqlite/sqlite3.h" 11 12 using WebKit::Platform; 13 using WebKit::WebString; 14 15 namespace content { 16 17 Platform::FileHandle DatabaseUtil::DatabaseOpenFile( 18 const WebString& vfs_file_name, 19 int desired_flags, 20 IPC::SyncMessageFilter* sync_message_filter) { 21 IPC::PlatformFileForTransit file_handle = 22 IPC::InvalidPlatformFileForTransit(); 23 24 scoped_refptr<IPC::SyncMessageFilter> filter(sync_message_filter); 25 filter->Send(new DatabaseHostMsg_OpenFile( 26 vfs_file_name, desired_flags, &file_handle)); 27 28 return IPC::PlatformFileForTransitToPlatformFile(file_handle); 29 } 30 31 int DatabaseUtil::DatabaseDeleteFile( 32 const WebString& vfs_file_name, 33 bool sync_dir, 34 IPC::SyncMessageFilter* sync_message_filter) { 35 int rv = SQLITE_IOERR_DELETE; 36 scoped_refptr<IPC::SyncMessageFilter> filter(sync_message_filter); 37 filter->Send(new DatabaseHostMsg_DeleteFile( 38 vfs_file_name, sync_dir, &rv)); 39 return rv; 40 } 41 42 long DatabaseUtil::DatabaseGetFileAttributes( 43 const WebString& vfs_file_name, 44 IPC::SyncMessageFilter* sync_message_filter) { 45 int32 rv = -1; 46 scoped_refptr<IPC::SyncMessageFilter> filter(sync_message_filter); 47 filter->Send(new DatabaseHostMsg_GetFileAttributes(vfs_file_name, &rv)); 48 return rv; 49 } 50 51 long long DatabaseUtil::DatabaseGetFileSize( 52 const WebString& vfs_file_name, 53 IPC::SyncMessageFilter* sync_message_filter) { 54 int64 rv = 0LL; 55 scoped_refptr<IPC::SyncMessageFilter> filter(sync_message_filter); 56 filter->Send(new DatabaseHostMsg_GetFileSize(vfs_file_name, &rv)); 57 return rv; 58 } 59 60 long long DatabaseUtil::DatabaseGetSpaceAvailable( 61 const WebString& origin_identifier, 62 IPC::SyncMessageFilter* sync_message_filter) { 63 int64 rv = 0LL; 64 scoped_refptr<IPC::SyncMessageFilter> filter(sync_message_filter); 65 filter->Send(new DatabaseHostMsg_GetSpaceAvailable(origin_identifier.utf8(), 66 &rv)); 67 return rv; 68 } 69 70 } // namespace content 71