summaryrefslogtreecommitdiffstats
path: root/chrome/common/database_util.cc
blob: fe196c672fa486c0abffd6de7fdcd7fd9375aee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/database_util.h"

#if defined(USE_SYSTEM_SQLITE)
#include <sqlite3.h>
#else
#include "third_party/sqlite/preprocessed/sqlite3.h"
#endif

#include "chrome/common/child_thread.h"
#include "chrome/common/render_messages.h"
#include "ipc/ipc_sync_message_filter.h"
#include "third_party/WebKit/WebKit/chromium/public/WebString.h"

using WebKit::WebKitClient;
using WebKit::WebString;

WebKitClient::FileHandle DatabaseUtil::databaseOpenFile(
    const WebString& vfs_file_name, int desired_flags) {
  IPC::PlatformFileForTransit file_handle;
#if defined(OS_WIN)
  file_handle = base::kInvalidPlatformFileValue;
#elif defined(OS_POSIX)
  file_handle =
      base::FileDescriptor(base::kInvalidPlatformFileValue, true);
#endif

  scoped_refptr<IPC::SyncMessageFilter> filter =
      ChildThread::current()->sync_message_filter();

  filter->Send(new ViewHostMsg_DatabaseOpenFile(
      vfs_file_name, desired_flags, &file_handle));

#if defined(OS_WIN)
  return file_handle;
#elif defined(OS_POSIX)
  return file_handle.fd;
#endif
}

int DatabaseUtil::databaseDeleteFile(
    const WebString& vfs_file_name, bool sync_dir) {
  int rv = SQLITE_IOERR_DELETE;
  scoped_refptr<IPC::SyncMessageFilter> filter =
      ChildThread::current()->sync_message_filter();
  filter->Send(new ViewHostMsg_DatabaseDeleteFile(
      vfs_file_name, sync_dir, &rv));
  return rv;
}

long DatabaseUtil::databaseGetFileAttributes(const WebString& vfs_file_name) {
  int32 rv = -1;
  scoped_refptr<IPC::SyncMessageFilter> filter =
      ChildThread::current()->sync_message_filter();
  filter->Send(new ViewHostMsg_DatabaseGetFileAttributes(vfs_file_name, &rv));
  return rv;
}

long long DatabaseUtil::databaseGetFileSize(const WebString& vfs_file_name) {
  int64 rv = 0LL;
  scoped_refptr<IPC::SyncMessageFilter> filter =
      ChildThread::current()->sync_message_filter();
  filter->Send(new ViewHostMsg_DatabaseGetFileSize(vfs_file_name, &rv));
  return rv;
}