2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "SQLiteFileSystem.h"
34 #include "ChromiumBridge.h"
36 #include "SQLiteDatabase.h"
39 #ifndef SQLITE_OPEN_FULLMUTEX
40 #define SQLITE_OPEN_FULLMUTEX 0x00010000
43 // SQLiteFileSystem::registerSQLiteVFS() is implemented in the
44 // platform-specific files SQLiteFileSystemChromium{Win|Posix}.cpp
47 SQLiteFileSystem::SQLiteFileSystem()
51 int SQLiteFileSystem::openDatabase(const String& fileName, sqlite3** database)
53 if (!ChromiumBridge::sandboxEnabled()) {
54 String path = fileName;
55 return sqlite3_open16(path.charactersWithNullTermination(), database);
58 // open databases using the default VFS
59 // in renderers, it should be Chromium's VFS; in the browser process it should be SQLite's default VFS
60 return sqlite3_open_v2(fileName.utf8().data(), database,
61 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX,
65 String SQLiteFileSystem::getFileNameForNewDatabase(
66 const String&, const String& dbName, const String &originIdentifier, SQLiteDatabase*)
68 // Chromium names DB files based on origin and DB name only
69 return originIdentifier + "_" + dbName + ".db";
72 String SQLiteFileSystem::appendDatabaseFileNameToPath(const String&, const String& fileName)
74 // Chromium saves all DB files in the same directory (known by
75 // the browser process only); as far as the renderer processes
76 // are concerned, all DB files are saved in the "current" directory
80 bool SQLiteFileSystem::ensureDatabaseDirectoryExists(const String&)
82 // if the directory where Chromium stores the databases does not exist,
83 // it will be automatically created by the browser process;
84 // so as far as the WebKit code is concerned, this directory always exists
88 bool SQLiteFileSystem::ensureDatabaseFileExists(const String&, bool)
90 // all database directories will be created as needed by the browser process
94 bool SQLiteFileSystem::deleteEmptyDatabaseDirectory(const String&)
96 // Chromium does not use a separate directory for each database,
97 // so there's nothing to do here
101 bool SQLiteFileSystem::deleteDatabaseFile(const String& fileName)
103 return (ChromiumBridge::databaseDeleteFile(fileName) == SQLITE_OK);
106 long long SQLiteFileSystem::getDatabaseFileSize(const String& fileName)
108 return ChromiumBridge::databaseGetFileSize(fileName);
111 } // namespace WebCore