Home | History | Annotate | Download | only in chromium
      1 /*
      2  * Copyright (C) 2009 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      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
     13  * distribution.
     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.
     17  *
     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.
     29  */
     30 
     31 #include "config.h"
     32 #include "SQLiteFileSystem.h"
     33 
     34 #include "ChromiumBridge.h"
     35 #include "CString.h"
     36 #include "SQLiteDatabase.h"
     37 #include <sqlite3.h>
     38 
     39 #ifndef SQLITE_OPEN_FULLMUTEX
     40 #define SQLITE_OPEN_FULLMUTEX 0x00010000
     41 #endif
     42 
     43 // SQLiteFileSystem::registerSQLiteVFS() is implemented in the
     44 // platform-specific files SQLiteFileSystemChromium{Win|Posix}.cpp
     45 namespace WebCore {
     46 
     47 SQLiteFileSystem::SQLiteFileSystem()
     48 {
     49 }
     50 
     51 int SQLiteFileSystem::openDatabase(const String& fileName, sqlite3** database)
     52 {
     53     if (!ChromiumBridge::sandboxEnabled()) {
     54         String path = fileName;
     55         return sqlite3_open16(path.charactersWithNullTermination(), database);
     56     }
     57 
     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,
     62                            "chromium_vfs");
     63 }
     64 
     65 String SQLiteFileSystem::getFileNameForNewDatabase(
     66   const String&, const String& dbName, const String &originIdentifier, SQLiteDatabase*)
     67 {
     68     // Chromium names DB files based on origin and DB name only
     69     return originIdentifier + "_" + dbName + ".db";
     70 }
     71 
     72 String SQLiteFileSystem::appendDatabaseFileNameToPath(const String&, const String& fileName)
     73 {
     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
     77     return fileName;
     78 }
     79 
     80 bool SQLiteFileSystem::ensureDatabaseDirectoryExists(const String&)
     81 {
     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
     85     return true;
     86 }
     87 
     88 bool SQLiteFileSystem::ensureDatabaseFileExists(const String&, bool)
     89 {
     90     // all database directories will be created as needed by the browser process
     91     return true;
     92 }
     93 
     94 bool SQLiteFileSystem::deleteEmptyDatabaseDirectory(const String&)
     95 {
     96     // Chromium does not use a separate directory for each database,
     97     // so there's nothing to do here
     98     return true;
     99 }
    100 
    101 bool SQLiteFileSystem::deleteDatabaseFile(const String& fileName)
    102 {
    103     return (ChromiumBridge::databaseDeleteFile(fileName) == SQLITE_OK);
    104 }
    105 
    106 long long SQLiteFileSystem::getDatabaseFileSize(const String& fileName)
    107 {
    108     return ChromiumBridge::databaseGetFileSize(fileName);
    109 }
    110 
    111 } // namespace WebCore
    112