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.
5 #include "content/common/database_util.h"
7 #include "content/common/child_thread.h"
8 #include "content/common/database_messages.h"
9 #include "ipc/ipc_sync_message_filter.h"
10 #include "third_party/sqlite/sqlite3.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
13 using WebKit::WebKitPlatformSupport
;
14 using WebKit::WebString
;
18 WebKitPlatformSupport::FileHandle
DatabaseUtil::DatabaseOpenFile(
19 const WebString
& vfs_file_name
, int desired_flags
) {
20 IPC::PlatformFileForTransit file_handle
=
21 IPC::InvalidPlatformFileForTransit();
23 scoped_refptr
<IPC::SyncMessageFilter
> filter(
24 ChildThread::current()->sync_message_filter());
25 filter
->Send(new DatabaseHostMsg_OpenFile(
26 vfs_file_name
, desired_flags
, &file_handle
));
28 return IPC::PlatformFileForTransitToPlatformFile(file_handle
);
31 int DatabaseUtil::DatabaseDeleteFile(
32 const WebString
& vfs_file_name
, bool sync_dir
) {
33 int rv
= SQLITE_IOERR_DELETE
;
34 scoped_refptr
<IPC::SyncMessageFilter
> filter(
35 ChildThread::current()->sync_message_filter());
36 filter
->Send(new DatabaseHostMsg_DeleteFile(
37 vfs_file_name
, sync_dir
, &rv
));
41 long DatabaseUtil::DatabaseGetFileAttributes(const WebString
& vfs_file_name
) {
43 scoped_refptr
<IPC::SyncMessageFilter
> filter(
44 ChildThread::current()->sync_message_filter());
45 filter
->Send(new DatabaseHostMsg_GetFileAttributes(vfs_file_name
, &rv
));
49 long long DatabaseUtil::DatabaseGetFileSize(const WebString
& vfs_file_name
) {
51 scoped_refptr
<IPC::SyncMessageFilter
> filter(
52 ChildThread::current()->sync_message_filter());
53 filter
->Send(new DatabaseHostMsg_GetFileSize(vfs_file_name
, &rv
));
57 long long DatabaseUtil::DatabaseGetSpaceAvailable(
58 const WebString
& origin_identifier
) {
60 scoped_refptr
<IPC::SyncMessageFilter
> filter(
61 ChildThread::current()->sync_message_filter());
62 filter
->Send(new DatabaseHostMsg_GetSpaceAvailable(origin_identifier
, &rv
));
66 } // namespace content