2 * Copyright (C) 2010 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
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.
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.
26 #ifndef IDBTransaction_h
27 #define IDBTransaction_h
29 #include "bindings/v8/ScriptWrappable.h"
30 #include "core/dom/ActiveDOMObject.h"
31 #include "core/dom/DOMError.h"
32 #include "core/events/EventListener.h"
33 #include "modules/EventModules.h"
34 #include "modules/EventTargetModules.h"
35 #include "modules/indexeddb/IDBMetadata.h"
36 #include "modules/indexeddb/IndexedDB.h"
37 #include "platform/heap/Handle.h"
38 #include "public/platform/WebIDBDatabase.h"
39 #include "public/platform/WebIDBTypes.h"
40 #include "wtf/HashSet.h"
49 class IDBOpenDBRequest;
50 struct IDBObjectStoreMetadata;
52 class IDBTransaction FINAL
53 : public RefCountedGarbageCollectedWillBeGarbageCollectedFinalized<IDBTransaction>
54 , public ScriptWrappable
55 , public EventTargetWithInlineData
56 , public ActiveDOMObject {
57 DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<IDBTransaction>);
58 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(IDBTransaction);
60 static IDBTransaction* create(ExecutionContext*, int64_t, const Vector<String>& objectStoreNames, blink::WebIDBTransactionMode, IDBDatabase*);
61 static IDBTransaction* create(ExecutionContext*, int64_t, IDBDatabase*, IDBOpenDBRequest*, const IDBDatabaseMetadata& previousMetadata);
62 virtual ~IDBTransaction();
63 virtual void trace(Visitor*) OVERRIDE;
65 static const AtomicString& modeReadOnly();
66 static const AtomicString& modeReadWrite();
67 static const AtomicString& modeVersionChange();
69 static blink::WebIDBTransactionMode stringToMode(const String&, ExceptionState&);
70 static const AtomicString& modeToString(blink::WebIDBTransactionMode);
72 // When the connection is closed backend will be 0.
73 blink::WebIDBDatabase* backendDB() const;
75 int64_t id() const { return m_id; }
76 bool isActive() const { return m_state == Active; }
77 bool isFinished() const { return m_state == Finished; }
78 bool isFinishing() const { return m_state == Finishing; }
79 bool isReadOnly() const { return m_mode == blink::WebIDBTransactionModeReadOnly; }
80 bool isVersionChange() const { return m_mode == blink::WebIDBTransactionModeVersionChange; }
82 // Implement the IDBTransaction IDL
83 const String& mode() const;
84 IDBDatabase* db() const { return m_database.get(); }
85 PassRefPtrWillBeRawPtr<DOMError> error() const { return m_error; }
86 IDBObjectStore* objectStore(const String& name, ExceptionState&);
87 void abort(ExceptionState&);
89 void registerRequest(IDBRequest*);
90 void unregisterRequest(IDBRequest*);
91 void objectStoreCreated(const String&, IDBObjectStore*);
92 void objectStoreDeleted(const String&);
94 void setError(PassRefPtrWillBeRawPtr<DOMError>);
96 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
97 DEFINE_ATTRIBUTE_EVENT_LISTENER(complete);
98 DEFINE_ATTRIBUTE_EVENT_LISTENER(error);
100 void onAbort(PassRefPtrWillBeRawPtr<DOMError>);
104 virtual const AtomicString& interfaceName() const OVERRIDE;
105 virtual ExecutionContext* executionContext() const OVERRIDE;
107 using EventTarget::dispatchEvent;
108 virtual bool dispatchEvent(PassRefPtrWillBeRawPtr<Event>) OVERRIDE;
111 virtual bool hasPendingActivity() const OVERRIDE;
112 virtual void stop() OVERRIDE;
115 IDBTransaction(ExecutionContext*, int64_t, const Vector<String>&, blink::WebIDBTransactionMode, IDBDatabase*, IDBOpenDBRequest*, const IDBDatabaseMetadata&);
117 void enqueueEvent(PassRefPtrWillBeRawPtr<Event>);
120 Inactive, // Created or started, but not in an event callback
121 Active, // Created or started, in creation scope or an event callback
122 Finishing, // In the process of aborting or completing.
123 Finished, // No more events will fire and no new requests may be filed.
127 Member<IDBDatabase> m_database;
128 const Vector<String> m_objectStoreNames;
129 Member<IDBOpenDBRequest> m_openDBRequest;
130 const blink::WebIDBTransactionMode m_mode;
132 bool m_hasPendingActivity;
133 bool m_contextStopped;
134 RefPtrWillBeMember<DOMError> m_error;
136 HeapListHashSet<Member<IDBRequest> > m_requestList;
138 typedef HeapHashMap<String, Member<IDBObjectStore> > IDBObjectStoreMap;
139 IDBObjectStoreMap m_objectStoreMap;
141 typedef HeapHashSet<Member<IDBObjectStore> > IDBObjectStoreSet;
142 IDBObjectStoreSet m_deletedObjectStores;
144 typedef HeapHashMap<Member<IDBObjectStore>, IDBObjectStoreMetadata> IDBObjectStoreMetadataMap;
145 IDBObjectStoreMetadataMap m_objectStoreCleanupMap;
146 IDBDatabaseMetadata m_previousMetadata;
149 } // namespace WebCore
151 #endif // IDBTransaction_h