Home | History | Annotate | Download | only in indexeddb
      1 /*
      2  * Copyright (C) 2010 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 IDBDatabaseBackendInterface_h
     27 #define IDBDatabaseBackendInterface_h
     28 
     29 #include "modules/indexeddb/IndexedDB.h"
     30 #include "wtf/PassRefPtr.h"
     31 #include "wtf/RefCounted.h"
     32 #include "wtf/text/WTFString.h"
     33 
     34 namespace WebCore {
     35 
     36 class IDBCallbacks;
     37 class IDBDatabaseCallbacks;
     38 class IDBKey;
     39 class IDBKeyPath;
     40 class IDBKeyRange;
     41 struct IDBDatabaseMetadata;
     42 class SharedBuffer;
     43 
     44 // This is implemented by IDBDatabaseBackendImpl and optionally others (in order to proxy
     45 // calls across process barriers). All calls to these classes should be non-blocking and
     46 // trigger work on a background thread if necessary.
     47 class IDBDatabaseBackendInterface : public RefCounted<IDBDatabaseBackendInterface> {
     48 public:
     49     virtual ~IDBDatabaseBackendInterface() { }
     50 
     51     virtual void createObjectStore(int64_t transactionId, int64_t objectStoreId, const String& name, const IDBKeyPath&, bool autoIncrement) = 0;
     52     virtual void deleteObjectStore(int64_t transactionId, int64_t objectStoreId) = 0;
     53     virtual void createTransaction(int64_t transactionId, PassRefPtr<IDBDatabaseCallbacks>, const Vector<int64_t>& objectStoreIds, unsigned short mode) = 0;
     54     virtual void close(PassRefPtr<IDBDatabaseCallbacks>) = 0;
     55 
     56     // Transaction-specific operations.
     57     virtual void commit(int64_t transactionId) = 0;
     58     virtual void abort(int64_t transactionId) = 0;
     59 
     60     virtual void createIndex(int64_t transactionId, int64_t objectStoreId, int64_t indexId, const String& name, const IDBKeyPath&, bool unique, bool multiEntry) = 0;
     61     virtual void deleteIndex(int64_t transactionId, int64_t objectStoreId, int64_t indexId) = 0;
     62 
     63     enum TaskType {
     64         NormalTask = 0,
     65         PreemptiveTask
     66     };
     67 
     68     enum PutMode {
     69         AddOrUpdate,
     70         AddOnly,
     71         CursorUpdate
     72     };
     73 
     74     static const int64_t MinimumIndexId = 30;
     75 
     76     typedef Vector<RefPtr<IDBKey> > IndexKeys;
     77 
     78     virtual void get(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange>, bool keyOnly, PassRefPtr<IDBCallbacks>) = 0;
     79     // Note that 'value' may be consumed/adopted by this call.
     80     virtual void put(int64_t transactionId, int64_t objectStoreId, PassRefPtr<SharedBuffer> value, PassRefPtr<IDBKey>, PutMode, PassRefPtr<IDBCallbacks>, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) = 0;
     81     virtual void setIndexKeys(int64_t transactionId, int64_t objectStoreId, PassRefPtr<IDBKey> prpPrimaryKey, const Vector<int64_t>& indexIds, const Vector<IndexKeys>&) = 0;
     82     virtual void setIndexesReady(int64_t transactionId, int64_t objectStoreId, const Vector<int64_t>& indexIds) = 0;
     83     virtual void openCursor(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange>, IndexedDB::CursorDirection, bool keyOnly, TaskType, PassRefPtr<IDBCallbacks>) = 0;
     84     virtual void count(int64_t transactionId, int64_t objectStoreId, int64_t indexId, PassRefPtr<IDBKeyRange>, PassRefPtr<IDBCallbacks>) = 0;
     85     virtual void deleteRange(int64_t transactionId, int64_t objectStoreId, PassRefPtr<IDBKeyRange>, PassRefPtr<IDBCallbacks>) = 0;
     86     virtual void clear(int64_t transactionId, int64_t objectStoreId, PassRefPtr<IDBCallbacks>) = 0;
     87 };
     88 
     89 } // namespace WebCore
     90 
     91 #endif // IDBDatabaseBackendInterface_h
     92