blob: b52c9c35295f33f12a889b3689d3d17f3745d45e [file] [log] [blame]
andersca4912acec2007-11-01 01:16:23 +00001/*
fpizlo@apple.com73985982015-08-18 19:31:28 +00002 * Copyright (C) 2007, 2013, 2015 Apple Inc. All rights reserved.
andersca4912acec2007-11-01 01:16:23 +00003 *
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.
mjs@apple.com92047332014-03-15 04:08:27 +000013 * 3. Neither the name of Apple Inc. ("Apple") nor the names of
andersca4912acec2007-11-01 01:16:23 +000014 * its contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
commit-queue@webkit.org553e8d32016-11-12 08:57:21 +000028
29#pragma once
andersca4912acec2007-11-01 01:16:23 +000030
mark.lam@apple.comad8bdf62013-02-14 22:31:20 +000031#include "SQLTransactionStateMachine.h"
zandobersek@gmail.com04836432014-02-03 19:07:29 +000032#include <memory>
beidson@apple.comeffd1c72007-11-14 00:26:48 +000033#include <wtf/Forward.h>
mark.lam@apple.comf9b77d62013-02-16 03:03:50 +000034#include <wtf/text/WTFString.h>
beidson@apple.comeffd1c72007-11-14 00:26:48 +000035
andersca4912acec2007-11-01 01:16:23 +000036namespace WebCore {
37
andersca@apple.com88fedf12015-01-12 21:58:08 +000038class Database;
mark.lam@apple.comf009ae42013-03-05 15:54:13 +000039class OriginLock;
beidson@apple.comeffd1c72007-11-14 00:26:48 +000040class SQLError;
dumi@chromium.org5d072b82010-06-01 21:39:11 +000041class SQLiteTransaction;
andersca@apple.com61fc0d52015-08-06 23:35:12 +000042class SQLStatement;
andersca@apple.com2cf28b62015-01-08 22:11:44 +000043class SQLTransaction;
andersca@apple.com471b81f2016-08-10 16:47:12 +000044class SQLTransactionWrapper;
beidson@apple.comeffd1c72007-11-14 00:26:48 +000045
andersca@apple.com53042772016-08-10 18:41:33 +000046class SQLTransactionBackend : public SQLTransactionStateMachine<SQLTransactionBackend> {
beidson@apple.comeffd1c72007-11-14 00:26:48 +000047public:
andersca@apple.comabcc69a2016-08-10 20:30:14 +000048 explicit SQLTransactionBackend(SQLTransaction&);
andersca@apple.com53042772016-08-10 18:41:33 +000049 ~SQLTransactionBackend();
abarth@webkit.org56314f22009-08-27 05:22:54 +000050
dumi@chromium.org5cfa18f2010-02-01 23:32:44 +000051 void notifyDatabaseThreadIsShuttingDown();
ap@webkit.org64984712008-02-12 19:37:03 +000052
andersca@apple.com33935992016-08-10 21:31:07 +000053 // API called from the frontend published via SQLTransactionBackend:
andersca@apple.com668e9122015-01-08 21:13:41 +000054 void requestTransitToState(SQLTransactionState);
andersca@apple.com33935992016-08-10 21:31:07 +000055
mark.lam@apple.comad8bdf62013-02-14 22:31:20 +000056private:
andersca@apple.com33935992016-08-10 21:31:07 +000057 friend class SQLTransaction;
mark.lam@apple.comad8bdf62013-02-14 22:31:20 +000058
59 void doCleanup();
abarth@webkit.org56314f22009-08-27 05:22:54 +000060
mark.lam@apple.comad8bdf62013-02-14 22:31:20 +000061 // State Machine functions:
darin@apple.com11ff47c2016-03-04 16:47:55 +000062 StateFunction stateFunctionFor(SQLTransactionState) override;
mark.lam@apple.coma9ac1a42013-02-20 21:10:18 +000063 void computeNextStateAndCleanupIfNeeded();
mark.lam@apple.comad8bdf62013-02-14 22:31:20 +000064
65 // State functions:
andersca@apple.comcf216012015-08-24 17:16:47 +000066 void acquireLock();
67 void openTransactionAndPreflight();
68 void runStatements();
69 void cleanupAndTerminate();
70 void cleanupAfterTransactionErrorCallback();
mark.lam@apple.comad8bdf62013-02-14 22:31:20 +000071
andersca@apple.comcf216012015-08-24 17:16:47 +000072 NO_RETURN_DUE_TO_ASSERT void unreachableState();
mark.lam@apple.comad8bdf62013-02-14 22:31:20 +000073
andersca@apple.com53042772016-08-10 18:41:33 +000074 SQLTransaction& m_frontend;
andersca4912acec2007-11-01 01:16:23 +000075};
abarth@webkit.org56314f22009-08-27 05:22:54 +000076
andersca4912acec2007-11-01 01:16:23 +000077} // namespace WebCore