OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2013 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 10 matching lines...) Expand all Loading... |
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 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 | 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 | 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 | 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. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 */ | 27 */ |
28 #ifndef SQLTransactionBackend_h | 28 #ifndef SQLTransactionBackend_h |
29 #define SQLTransactionBackend_h | 29 #define SQLTransactionBackend_h |
30 | 30 |
31 #include "modules/webdatabase/AbstractSQLStatement.h" | |
32 #include "modules/webdatabase/AbstractSQLTransactionBackend.h" | |
33 #include "modules/webdatabase/DatabaseBasicTypes.h" | 31 #include "modules/webdatabase/DatabaseBasicTypes.h" |
| 32 #include "modules/webdatabase/SQLStatement.h" |
34 #include "modules/webdatabase/SQLTransactionStateMachine.h" | 33 #include "modules/webdatabase/SQLTransactionStateMachine.h" |
35 #include "platform/heap/Handle.h" | 34 #include "platform/heap/Handle.h" |
36 #include "wtf/Deque.h" | 35 #include "wtf/Deque.h" |
37 #include "wtf/Forward.h" | 36 #include "wtf/Forward.h" |
38 #include "wtf/ThreadingPrimitives.h" | 37 #include "wtf/ThreadingPrimitives.h" |
39 #include "wtf/text/WTFString.h" | |
40 | 38 |
41 namespace blink { | 39 namespace blink { |
42 | 40 |
43 class AbstractSQLTransaction; | |
44 class DatabaseBackend; | 41 class DatabaseBackend; |
45 class SQLErrorData; | 42 class SQLErrorData; |
46 class SQLiteTransaction; | 43 class SQLiteTransaction; |
47 class SQLStatementBackend; | 44 class SQLStatementBackend; |
| 45 class SQLTransaction; |
48 class SQLTransactionBackend; | 46 class SQLTransactionBackend; |
49 class SQLValue; | 47 class SQLValue; |
50 | 48 |
51 class SQLTransactionWrapper : public ThreadSafeRefCountedWillBeGarbageCollectedF
inalized<SQLTransactionWrapper> { | 49 class SQLTransactionWrapper : public ThreadSafeRefCountedWillBeGarbageCollectedF
inalized<SQLTransactionWrapper> { |
52 public: | 50 public: |
53 virtual ~SQLTransactionWrapper() { } | 51 virtual ~SQLTransactionWrapper() { } |
54 virtual void trace(Visitor*) { } | 52 virtual void trace(Visitor*) { } |
55 virtual bool performPreflight(SQLTransactionBackend*) = 0; | 53 virtual bool performPreflight(SQLTransactionBackend*) = 0; |
56 virtual bool performPostflight(SQLTransactionBackend*) = 0; | 54 virtual bool performPostflight(SQLTransactionBackend*) = 0; |
57 virtual SQLErrorData* sqlError() const = 0; | 55 virtual SQLErrorData* sqlError() const = 0; |
58 virtual void handleCommitFailedAfterPostflight(SQLTransactionBackend*) = 0; | 56 virtual void handleCommitFailedAfterPostflight(SQLTransactionBackend*) = 0; |
59 }; | 57 }; |
60 | 58 |
61 class SQLTransactionBackend FINAL : public AbstractSQLTransactionBackend, public
SQLTransactionStateMachine<SQLTransactionBackend> { | 59 class SQLTransactionBackend FINAL : public ThreadSafeRefCountedWillBeGarbageColl
ectedFinalized<SQLTransactionBackend>, public SQLTransactionStateMachine<SQLTran
sactionBackend> { |
62 public: | 60 public: |
63 static PassRefPtrWillBeRawPtr<SQLTransactionBackend> create(DatabaseBackend*
, | 61 static PassRefPtrWillBeRawPtr<SQLTransactionBackend> create(DatabaseBackend*
, |
64 PassRefPtrWillBeRawPtr<AbstractSQLTransaction>, PassRefPtrWillBeRawPtr<S
QLTransactionWrapper>, bool readOnly); | 62 PassRefPtrWillBeRawPtr<SQLTransaction>, PassRefPtrWillBeRawPtr<SQLTransa
ctionWrapper>, bool readOnly); |
65 | 63 |
66 virtual ~SQLTransactionBackend(); | 64 virtual ~SQLTransactionBackend(); |
67 virtual void trace(Visitor*) OVERRIDE; | 65 void trace(Visitor*); |
68 | 66 |
69 void lockAcquired(); | 67 void lockAcquired(); |
70 void performNextStep(); | 68 void performNextStep(); |
71 | 69 |
72 DatabaseBackend* database() { return m_database.get(); } | 70 DatabaseBackend* database() { return m_database.get(); } |
73 bool isReadOnly() { return m_readOnly; } | 71 bool isReadOnly() { return m_readOnly; } |
74 void notifyDatabaseThreadIsShuttingDown(); | 72 void notifyDatabaseThreadIsShuttingDown(); |
75 | 73 |
| 74 // APIs called from the frontend published: |
| 75 void requestTransitToState(SQLTransactionState); |
| 76 SQLErrorData* transactionError(); |
| 77 SQLStatement* currentStatement(); |
| 78 void setShouldRetryCurrentStatement(bool); |
| 79 void executeSQL(PassOwnPtrWillBeRawPtr<SQLStatement>, const String& statemen
t, |
| 80 const Vector<SQLValue>& arguments, int permissions); |
| 81 |
76 private: | 82 private: |
77 SQLTransactionBackend(DatabaseBackend*, PassRefPtrWillBeRawPtr<AbstractSQLTr
ansaction>, | 83 SQLTransactionBackend(DatabaseBackend*, PassRefPtrWillBeRawPtr<SQLTransactio
n>, |
78 PassRefPtrWillBeRawPtr<SQLTransactionWrapper>, bool readOnly); | 84 PassRefPtrWillBeRawPtr<SQLTransactionWrapper>, bool readOnly); |
79 | 85 |
80 // APIs called from the frontend published via AbstractSQLTransactionBackend
: | |
81 virtual void requestTransitToState(SQLTransactionState) OVERRIDE; | |
82 virtual SQLErrorData* transactionError() OVERRIDE; | |
83 virtual AbstractSQLStatement* currentStatement() OVERRIDE; | |
84 virtual void setShouldRetryCurrentStatement(bool) OVERRIDE; | |
85 virtual void executeSQL(PassOwnPtrWillBeRawPtr<AbstractSQLStatement>, const
String& statement, | |
86 const Vector<SQLValue>& arguments, int permissions) OVERRIDE; | |
87 | |
88 void doCleanup(); | 86 void doCleanup(); |
89 | 87 |
90 void enqueueStatementBackend(PassRefPtrWillBeRawPtr<SQLStatementBackend>); | 88 void enqueueStatementBackend(PassRefPtrWillBeRawPtr<SQLStatementBackend>); |
91 | 89 |
92 // State Machine functions: | 90 // State Machine functions: |
93 virtual StateFunction stateFunctionFor(SQLTransactionState) OVERRIDE; | 91 virtual StateFunction stateFunctionFor(SQLTransactionState) OVERRIDE; |
94 void computeNextStateAndCleanupIfNeeded(); | 92 void computeNextStateAndCleanupIfNeeded(); |
95 | 93 |
96 // State functions: | 94 // State functions: |
97 SQLTransactionState acquireLock(); | 95 SQLTransactionState acquireLock(); |
98 SQLTransactionState openTransactionAndPreflight(); | 96 SQLTransactionState openTransactionAndPreflight(); |
99 SQLTransactionState runStatements(); | 97 SQLTransactionState runStatements(); |
100 SQLTransactionState postflightAndCommit(); | 98 SQLTransactionState postflightAndCommit(); |
101 SQLTransactionState cleanupAndTerminate(); | 99 SQLTransactionState cleanupAndTerminate(); |
102 SQLTransactionState cleanupAfterTransactionErrorCallback(); | 100 SQLTransactionState cleanupAfterTransactionErrorCallback(); |
103 | 101 |
104 SQLTransactionState unreachableState(); | 102 SQLTransactionState unreachableState(); |
105 SQLTransactionState sendToFrontendState(); | 103 SQLTransactionState sendToFrontendState(); |
106 | 104 |
107 SQLTransactionState nextStateForCurrentStatementError(); | 105 SQLTransactionState nextStateForCurrentStatementError(); |
108 SQLTransactionState nextStateForTransactionError(); | 106 SQLTransactionState nextStateForTransactionError(); |
109 SQLTransactionState runCurrentStatementAndGetNextState(); | 107 SQLTransactionState runCurrentStatementAndGetNextState(); |
110 | 108 |
111 void getNextStatement(); | 109 void getNextStatement(); |
112 | 110 |
113 RefPtrWillBeMember<AbstractSQLTransaction> m_frontend; // Has a reference cy
cle, and will break in doCleanup(). | 111 RefPtrWillBeMember<SQLTransaction> m_frontend; // Has a reference cycle, and
will break in doCleanup(). |
114 RefPtrWillBeMember<SQLStatementBackend> m_currentStatementBackend; | 112 RefPtrWillBeMember<SQLStatementBackend> m_currentStatementBackend; |
115 | 113 |
116 RefPtrWillBeMember<DatabaseBackend> m_database; | 114 RefPtrWillBeMember<DatabaseBackend> m_database; |
117 RefPtrWillBeMember<SQLTransactionWrapper> m_wrapper; | 115 RefPtrWillBeMember<SQLTransactionWrapper> m_wrapper; |
118 OwnPtr<SQLErrorData> m_transactionError; | 116 OwnPtr<SQLErrorData> m_transactionError; |
119 | 117 |
120 bool m_hasCallback; | 118 bool m_hasCallback; |
121 bool m_hasSuccessCallback; | 119 bool m_hasSuccessCallback; |
122 bool m_hasErrorCallback; | 120 bool m_hasErrorCallback; |
123 bool m_shouldRetryCurrentStatement; | 121 bool m_shouldRetryCurrentStatement; |
124 bool m_modifiedDatabase; | 122 bool m_modifiedDatabase; |
125 bool m_lockAcquired; | 123 bool m_lockAcquired; |
126 bool m_readOnly; | 124 bool m_readOnly; |
127 bool m_hasVersionMismatch; | 125 bool m_hasVersionMismatch; |
128 | 126 |
129 Mutex m_statementMutex; | 127 Mutex m_statementMutex; |
130 Deque<RefPtrWillBeMember<SQLStatementBackend> > m_statementQueue; | 128 Deque<RefPtrWillBeMember<SQLStatementBackend> > m_statementQueue; |
131 | 129 |
132 OwnPtr<SQLiteTransaction> m_sqliteTransaction; | 130 OwnPtr<SQLiteTransaction> m_sqliteTransaction; |
133 }; | 131 }; |
134 | 132 |
135 } // namespace blink | 133 } // namespace blink |
136 | 134 |
137 #endif // SQLTransactionBackend_h | 135 #endif // SQLTransactionBackend_h |
OLD | NEW |