OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008, 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 void Database::closeImmediately() | 133 void Database::closeImmediately() |
134 { | 134 { |
135 ASSERT(m_executionContext->isContextThread()); | 135 ASSERT(m_executionContext->isContextThread()); |
136 DatabaseThread* databaseThread = databaseContext()->databaseThread(); | 136 DatabaseThread* databaseThread = databaseContext()->databaseThread(); |
137 if (databaseThread && !databaseThread->terminationRequested() && opened()) { | 137 if (databaseThread && !databaseThread->terminationRequested() && opened()) { |
138 logErrorMessage("forcibly closing database"); | 138 logErrorMessage("forcibly closing database"); |
139 databaseThread->scheduleTask(DatabaseCloseTask::create(this, 0)); | 139 databaseThread->scheduleTask(DatabaseCloseTask::create(this, 0)); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 void Database::changeVersion(const String& oldVersion, const String& newVersion,
PassRefPtr<SQLTransactionCallback> callback, PassRefPtr<SQLTransactionErrorCall
back> errorCallback, PassRefPtr<SQLVoidCallback> successCallback) | 143 void Database::changeVersion(const String& oldVersion, const String& newVersion,
PassOwnPtr<SQLTransactionCallback> callback, PassOwnPtr<SQLTransactionErrorCall
back> errorCallback, PassOwnPtr<SQLVoidCallback> successCallback) |
144 { | 144 { |
145 ChangeVersionData data(oldVersion, newVersion); | 145 ChangeVersionData data(oldVersion, newVersion); |
146 runTransaction(callback, errorCallback, successCallback, false, &data); | 146 runTransaction(callback, errorCallback, successCallback, false, &data); |
147 } | 147 } |
148 | 148 |
149 void Database::transaction(PassRefPtr<SQLTransactionCallback> callback, PassRefP
tr<SQLTransactionErrorCallback> errorCallback, PassRefPtr<SQLVoidCallback> succe
ssCallback) | 149 void Database::transaction(PassOwnPtr<SQLTransactionCallback> callback, PassOwnP
tr<SQLTransactionErrorCallback> errorCallback, PassOwnPtr<SQLVoidCallback> succe
ssCallback) |
150 { | 150 { |
151 runTransaction(callback, errorCallback, successCallback, false); | 151 runTransaction(callback, errorCallback, successCallback, false); |
152 } | 152 } |
153 | 153 |
154 void Database::readTransaction(PassRefPtr<SQLTransactionCallback> callback, Pass
RefPtr<SQLTransactionErrorCallback> errorCallback, PassRefPtr<SQLVoidCallback> s
uccessCallback) | 154 void Database::readTransaction(PassOwnPtr<SQLTransactionCallback> callback, Pass
OwnPtr<SQLTransactionErrorCallback> errorCallback, PassOwnPtr<SQLVoidCallback> s
uccessCallback) |
155 { | 155 { |
156 runTransaction(callback, errorCallback, successCallback, true); | 156 runTransaction(callback, errorCallback, successCallback, true); |
157 } | 157 } |
158 | 158 |
159 static void callTransactionErrorCallback(ExecutionContext*, PassRefPtr<SQLTransa
ctionErrorCallback> callback, PassRefPtr<SQLError> error) | 159 static void callTransactionErrorCallback(ExecutionContext*, PassOwnPtr<SQLTransa
ctionErrorCallback> callback, PassRefPtr<SQLError> error) |
160 { | 160 { |
161 callback->handleEvent(error.get()); | 161 callback->handleEvent(error.get()); |
162 } | 162 } |
163 | 163 |
164 void Database::runTransaction(PassRefPtr<SQLTransactionCallback> callback, PassR
efPtr<SQLTransactionErrorCallback> errorCallback, | 164 void Database::runTransaction(PassOwnPtr<SQLTransactionCallback> callback, PassO
wnPtr<SQLTransactionErrorCallback> errorCallback, |
165 PassRefPtr<SQLVoidCallback> successCallback, bool readOnly, const ChangeVers
ionData* changeVersionData) | 165 PassOwnPtr<SQLVoidCallback> successCallback, bool readOnly, const ChangeVers
ionData* changeVersionData) |
166 { | 166 { |
167 RefPtr<SQLTransactionErrorCallback> anotherRefToErrorCallback = errorCallbac
k; | 167 // FIXME: Rather than passing errorCallback to SQLTransaction and then somet
imes firing it ourselves, |
168 RefPtr<SQLTransaction> transaction = SQLTransaction::create(this, callback,
successCallback, anotherRefToErrorCallback, readOnly); | 168 // this code should probably be pushed down into DatabaseBackend so that we
only create the SQLTransaction |
169 | 169 // if we're actually going to run it. |
170 RefPtr<SQLTransactionBackend> transactionBackend; | 170 #if !ASSERT_DISABLED |
171 transactionBackend = backend()->runTransaction(transaction.release(), readOn
ly, changeVersionData); | 171 SQLTransactionErrorCallback* originalErrorCallback = errorCallback.get(); |
172 if (!transactionBackend && anotherRefToErrorCallback) { | 172 #endif |
173 RefPtr<SQLError> error = SQLError::create(SQLError::UNKNOWN_ERR, "databa
se has been closed"); | 173 RefPtr<SQLTransaction> transaction = SQLTransaction::create(this, callback,
successCallback, errorCallback, readOnly); |
174 executionContext()->postTask(createCallbackTask(&callTransactionErrorCal
lback, anotherRefToErrorCallback, error.release())); | 174 RefPtr<SQLTransactionBackend> transactionBackend = backend()->runTransaction
(transaction, readOnly, changeVersionData); |
| 175 if (!transactionBackend) { |
| 176 OwnPtr<SQLTransactionErrorCallback> callback = transaction->releaseError
Callback(); |
| 177 ASSERT(callback == originalErrorCallback); |
| 178 if (callback) { |
| 179 RefPtr<SQLError> error = SQLError::create(SQLError::UNKNOWN_ERR, "da
tabase has been closed"); |
| 180 executionContext()->postTask(createCallbackTask(&callTransactionErro
rCallback, callback.release(), error.release())); |
| 181 } |
175 } | 182 } |
176 } | 183 } |
177 | 184 |
178 class DeliverPendingCallbackTask : public ExecutionContextTask { | 185 class DeliverPendingCallbackTask : public ExecutionContextTask { |
179 public: | 186 public: |
180 static PassOwnPtr<DeliverPendingCallbackTask> create(PassRefPtr<SQLTransacti
on> transaction) | 187 static PassOwnPtr<DeliverPendingCallbackTask> create(PassRefPtr<SQLTransacti
on> transaction) |
181 { | 188 { |
182 return adoptPtr(new DeliverPendingCallbackTask(transaction)); | 189 return adoptPtr(new DeliverPendingCallbackTask(transaction)); |
183 } | 190 } |
184 | 191 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 backend()->reportStartTransactionResult(errorSite, webSqlErrorCode, sqliteEr
rorCode); | 267 backend()->reportStartTransactionResult(errorSite, webSqlErrorCode, sqliteEr
rorCode); |
261 } | 268 } |
262 | 269 |
263 void Database::reportCommitTransactionResult(int errorSite, int webSqlErrorCode,
int sqliteErrorCode) | 270 void Database::reportCommitTransactionResult(int errorSite, int webSqlErrorCode,
int sqliteErrorCode) |
264 { | 271 { |
265 backend()->reportCommitTransactionResult(errorSite, webSqlErrorCode, sqliteE
rrorCode); | 272 backend()->reportCommitTransactionResult(errorSite, webSqlErrorCode, sqliteE
rrorCode); |
266 } | 273 } |
267 | 274 |
268 | 275 |
269 } // namespace WebCore | 276 } // namespace WebCore |
OLD | NEW |