18e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project/*
28e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
38e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
48e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * Redistribution and use in source and binary forms, with or without
58e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * modification, are permitted provided that the following conditions
68e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * are met:
78e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
88e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 1.  Redistributions of source code must retain the above copyright
98e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *     notice, this list of conditions and the following disclaimer.
108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 2.  Redistributions in binary form must reproduce the above copyright
118e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *     notice, this list of conditions and the following disclaimer in the
128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *     documentation and/or other materials provided with the distribution.
138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *     its contributors may be used to endorse or promote products derived
158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *     from this software without specific prior written permission.
168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project *
178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
188e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
198e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
218e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
228e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
238e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
248e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
258e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
268e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
278e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project */
288e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
298e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#ifndef Database_h
308e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#define Database_h
318e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
328ccf722629b08f2a06b2cadbdc3d0c9dc885e25dBen Murdoch#if ENABLE(DATABASE)
3306ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen#include "AbstractDatabase.h"
34967717af5423377c967781471ee106e2bb4e11c8Ben Murdoch#include "ExceptionCode.h"
358e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include "PlatformString.h"
368e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
378e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#include <wtf/Deque.h>
38545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch#include <wtf/Forward.h>
398e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
408e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectnamespace WebCore {
418e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
42dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Blockclass DatabaseCallback;
43d0825bca7fe65beaee391d30da42e937db621564Steve Blockclass ScriptExecutionContext;
44545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochclass SecurityOrigin;
45545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochclass SQLTransaction;
468e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass SQLTransactionCallback;
47231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockclass SQLTransactionClient;
48231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Blockclass SQLTransactionCoordinator;
498e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectclass SQLTransactionErrorCallback;
50545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochclass VoidCallback;
51231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
5206ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsenclass Database : public AbstractDatabase {
538e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectpublic:
5406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    virtual ~Database();
558e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
5621939df44de1705786c545cd1bf519d47250322dBen Murdoch    // Direct support for the DOM API
57545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    static PassRefPtr<Database> openDatabase(ScriptExecutionContext*, const String& name, const String& expectedVersion, const String& displayName,
58545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch                                             unsigned long estimatedSize, PassRefPtr<DatabaseCallback>, ExceptionCode&);
59ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    virtual String version() const;
60545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    void changeVersion(const String& oldVersion, const String& newVersion, PassRefPtr<SQLTransactionCallback>,
61545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch                       PassRefPtr<SQLTransactionErrorCallback>, PassRefPtr<VoidCallback> successCallback);
62dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch    void transaction(PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>, PassRefPtr<VoidCallback> successCallback);
63dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch    void readTransaction(PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>, PassRefPtr<VoidCallback> successCallback);
64231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
6521939df44de1705786c545cd1bf519d47250322dBen Murdoch    // Internal engine support
668e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    Vector<String> tableNames();
678e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
6806ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    virtual SecurityOrigin* securityOrigin() const;
698e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
7006ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    virtual void markAsDeletedAndClose();
718e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool deleted() const { return m_deleted; }
728e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
73ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    void close();
7406ea8e899e48f1f2f396b70e63fae369f2f23232Kristian Monsen    virtual void closeImmediately();
75dcc8cf2e65d1aa555cce12431a16547e66b469eeSteve Block
768e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    unsigned long long databaseSize() const;
778e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    unsigned long long maximumSize() const;
788e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
79545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    void scheduleTransactionCallback(SQLTransaction*);
80545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    void scheduleTransactionStep(SQLTransaction*, bool immediately = false);
81545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch
82231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    SQLTransactionClient* transactionClient() const;
83231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    SQLTransactionCoordinator* transactionCoordinator() const;
84231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
858e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Projectprivate:
86ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    class DatabaseOpenTask;
87ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    class DatabaseCloseTask;
88ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    class DatabaseTransactionTask;
89ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    class DatabaseTableNamesTask;
90ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
91545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    Database(ScriptExecutionContext*, const String& name, const String& expectedVersion,
92ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block             const String& displayName, unsigned long estimatedSize);
93dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch    void runTransaction(PassRefPtr<SQLTransactionCallback>, PassRefPtr<SQLTransactionErrorCallback>,
94dd8bb3de4f353a81954234999f1fea748aee2ea9Ben Murdoch                        PassRefPtr<VoidCallback> successCallback, bool readOnly);
958e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
96ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    bool openAndVerifyVersion(bool setVersionInNewDatabase, ExceptionCode&);
97ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    virtual bool performOpenAndVerify(bool setVersionInNewDatabase, ExceptionCode&);
988e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
99ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    void inProgressTransactionCompleted();
1008e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    void scheduleTransaction();
101231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
102ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    Vector<String> performGetTableNames();
103ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
104ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block    static void deliverPendingCallback(void*);
105ca9cb53ed1119a3fd98fafa0972ffeb56dee1c24Steve Block
106643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    Deque<RefPtr<SQLTransaction> > m_transactionQueue;
1078e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    Mutex m_transactionInProgressMutex;
1088e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool m_transactionInProgress;
109643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    bool m_isTransactionQueueEnabled;
1108e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
111cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block    RefPtr<SecurityOrigin> m_databaseThreadSecurityOrigin;
1128e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1138e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project    bool m_deleted;
1148e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project};
1158e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1168e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project} // namespace WebCore
1178e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project
1188ccf722629b08f2a06b2cadbdc3d0c9dc885e25dBen Murdoch#endif // ENABLE(DATABASE)
1198ccf722629b08f2a06b2cadbdc3d0c9dc885e25dBen Murdoch
1208e35f3cfc7fba1d1c829dc557ebad6409cbe16a2The Android Open Source Project#endif // Database_h
121