initial import
[vuplus_webkit] / Source / WebCore / storage / IDBLevelDBBackingStore.h
1 /*
2  * Copyright (C) 2011 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
6  * are met:
7  *
8  * 1.  Redistributions of source code must retain the above copyright
9  *     notice, this list of conditions and the following disclaimer.
10  * 2.  Redistributions in binary form must reproduce the above copyright
11  *     notice, this list of conditions and the following disclaimer in the
12  *     documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
18  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #ifndef IDBLevelDBBackingStore_h
27 #define IDBLevelDBBackingStore_h
28
29 #if ENABLE(INDEXED_DATABASE)
30 #if ENABLE(LEVELDB)
31
32 #include "IDBBackingStore.h"
33 #include <wtf/OwnPtr.h>
34
35 namespace WebCore {
36
37 class LevelDBComparator;
38 class LevelDBDatabase;
39 class LevelDBTransaction;
40 class IDBFactoryBackendImpl;
41
42 class IDBLevelDBBackingStore : public IDBBackingStore {
43 public:
44     static PassRefPtr<IDBBackingStore> open(SecurityOrigin*, const String& pathBase, int64_t maximumSize, const String& fileIdentifier, IDBFactoryBackendImpl*);
45     virtual ~IDBLevelDBBackingStore();
46
47     virtual bool extractIDBDatabaseMetaData(const String& name, String& foundVersion, int64_t& foundId);
48     virtual bool setIDBDatabaseMetaData(const String& name, const String& version, int64_t& rowId, bool invalidRowId);
49
50     virtual void getObjectStores(int64_t databaseId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<String>& foundKeyPaths, Vector<bool>& foundAutoIncrementFlags);
51     virtual bool createObjectStore(int64_t databaseId, const String& name, const String& keyPath, bool autoIncrement, int64_t& assignedObjectStoreId);
52     virtual void deleteObjectStore(int64_t databaseId, int64_t objectStoreId);
53     virtual PassRefPtr<ObjectStoreRecordIdentifier> createInvalidRecordIdentifier();
54     virtual String getObjectStoreRecord(int64_t databaseId, int64_t objectStoreId, const IDBKey&);
55     virtual bool putObjectStoreRecord(int64_t databaseId, int64_t objectStoreId, const IDBKey&, const String& value, ObjectStoreRecordIdentifier*);
56     virtual void clearObjectStore(int64_t databaseId, int64_t objectStoreId);
57     virtual void deleteObjectStoreRecord(int64_t databaseId, int64_t objectStoreId, const ObjectStoreRecordIdentifier*);
58     virtual double nextAutoIncrementNumber(int64_t databaseId, int64_t objectStoreId);
59     virtual bool keyExistsInObjectStore(int64_t databaseId, int64_t objectStoreId, const IDBKey&, ObjectStoreRecordIdentifier* foundRecordIdentifier);
60
61     virtual bool forEachObjectStoreRecord(int64_t databaseId, int64_t objectStoreId, ObjectStoreRecordCallback&);
62
63     virtual void getIndexes(int64_t databaseId, int64_t objectStoreId, Vector<int64_t>& foundIds, Vector<String>& foundNames, Vector<String>& foundKeyPaths, Vector<bool>& foundUniqueFlags);
64     virtual bool createIndex(int64_t databaseId, int64_t objectStoreId, const String& name, const String& keyPath, bool isUnique, int64_t& indexId);
65     virtual void deleteIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId);
66     virtual bool putIndexDataForRecord(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&, const ObjectStoreRecordIdentifier*);
67     virtual bool deleteIndexDataForRecord(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const ObjectStoreRecordIdentifier*);
68     virtual String getObjectViaIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&);
69     virtual PassRefPtr<IDBKey> getPrimaryKeyViaIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey&);
70     virtual bool keyExistsInIndex(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKey& indexKey, RefPtr<IDBKey>& foundPrimaryKey);
71
72     virtual PassRefPtr<Cursor> openObjectStoreCursor(int64_t databaseId, int64_t objectStoreId, const IDBKeyRange*, IDBCursor::Direction);
73     virtual PassRefPtr<Cursor> openIndexKeyCursor(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKeyRange*, IDBCursor::Direction);
74     virtual PassRefPtr<Cursor> openIndexCursor(int64_t databaseId, int64_t objectStoreId, int64_t indexId, const IDBKeyRange*, IDBCursor::Direction);
75
76     virtual PassRefPtr<Transaction> createTransaction();
77     virtual IDBFactoryBackendInterface::BackingStoreType backingStoreType() const { return IDBFactoryBackendInterface::LevelDBBackingStore; }
78
79     static bool backingStoreExists(SecurityOrigin*, const String& name, const String& pathBase);
80
81 private:
82     IDBLevelDBBackingStore(const String& identifier, IDBFactoryBackendImpl*, PassOwnPtr<LevelDBDatabase>);
83
84     String m_identifier;
85     RefPtr<IDBFactoryBackendImpl> m_factory;
86     OwnPtr<LevelDBDatabase> m_db;
87     OwnPtr<LevelDBComparator> m_comparator;
88     RefPtr<LevelDBTransaction> m_currentTransaction;
89
90     class Transaction : public IDBBackingStore::Transaction {
91     public:
92         static PassRefPtr<Transaction> create(IDBLevelDBBackingStore*);
93         virtual void begin();
94         virtual void commit();
95         virtual void rollback();
96
97     private:
98         Transaction(IDBLevelDBBackingStore*);
99         IDBLevelDBBackingStore* m_backingStore;
100     };
101 };
102
103 } // namespace WebCore
104
105
106 #endif // ENABLE(LEVELDB)
107 #endif // ENABLE(INDEXED_DATABASE)
108
109 #endif // IDBLevelDBBackingStore_h